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

#define F first
#define S second
#define pb push_back
#define ll long long
#define int long long

using namespace std ;


const int MAXN = 101 * 1001 , MOD = 1e9 + 7 ; 

vector<int> adj[MAXN] ; 

bool dp[MAXN][2] ; 

void dfs(int u , int p)
{
	dp[u][0] = 0 ;
    dp[u][1] = 1 ; 	
	set<int> s ;
	int c = 0 ; 
	for(auto v : adj[u])
	{
		if(v==p) continue ;
		dfs(v,u) ;
	    c++ ; 	
		dp[u][1] &= dp[v][0] ; 
		if(dp[v][0]) s.insert(v) ; 
	}
	for(auto v : adj[u])
	{
		if(v==p) continue ; 
		bool f = 0 ; 
		if(s.size()==c) f = 1 ;
		if(s.size()==c-1&&!s.count(v)) f = 1 ;
		dp[u][0] |= (dp[v][1] & f) ; 
	}

}

int32_t main()
{
	ios::sync_with_stdio(0) ; cin.tie(0) ; 
	int n  ; 
	cin >> n ; 
	for(int i = 1 ; i < n ; i ++ ) 
	{
		int x , y ; 
		cin >> x >> y ; 
		adj[x].pb(y) ; 
		adj[y].pb(x) ; 
	}
	dfs(1,0) ; 
	cout << (dp[1][0]?"Second":"First") << endl ; 

}

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

#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

using namespace std;

int main(){
	string S,T;
	cin >> S;
	cin >> T;
	int ans = -1;

	rep(i,0,S.size()){
		int count = 0;
		while((S[i+count] == T[count] || S[i+count] == '?') && T.size() != count && S.size() > i+count){
			count++;
		}
		if(count == T.size()){
			ans = i;
		}
	}
	if(ans == -1){
		cout << "UNRESTORABLE" << endl;
	}else{
		rep(i,0,S.size()){
			if(ans == i){
				cout << T;
				i += T.size()-1;
			}else if(S[i] == '?'){
				cout << "a";
			}else{
				cout << S[i];
			}
		}
		cout << endl;
	}

}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    Int X;
    cin>>X;

    Int coin_500 = X/500;
    X = X%500;
    Int coin_5 = X/5;

    cout<<coin_500*1000+coin_5*5<<endl;

    return 0;
}


Measured memory_bytes: 504
from functools import lru_cache
@lru_cache(None)
def f(n,k):
  if n<10:
    if k<1: return 1
    if k<2: return n
    return 0
  d,m=divmod(n,10)
  c=0
  if k:
    c+=f(d,k-1)*m
    c+=f(d-1,k-1)*(9-m)
  c+=f(d,k)
  return c
print(f(int(input()),int(input())))

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

using namespace std;

int main() {
    int H, W;
    cin >> H >> W;

    std::vector<std::string> s(H);
    for (int i = 0; i < H; ++i) {
        cin >> s[i];
    }

    constexpr int dh[4] = {0, 0, 1, -1};
    constexpr int dw[4] = {1, -1, 0, 0};

    constexpr auto is_in_range = [](const int val, const int min, int max) -> bool {
        return min <= val && val <= max;
    };

    bool yes = true;

    for (int h = 0; h < H; ++h) {
        for (int w = 0; w < H; ++w) {
            if (s[h][w] != '#') { continue; }

            bool can_draw = false;

            for (int i = 0; i < 4; ++i) {
                if (!is_in_range(h + dh[i], 0, H - 1)) { continue; }
                if (!is_in_range(w + dw[i], 0, W - 1)) { continue; }

                if (s[h][w] == s[h + dh[i]][w + dw[i]]) {
                    can_draw = true;
                    break;
                }
            }

            if (!can_draw) {
                yes = false;
                break;
            }
        }
    }

    cout << (yes ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
  string S;
  bool a[26];
  
  cin >> S;
  for(int i=0;i<26;i++) a[i] = false;
  
  for(int i=0;i<S.size();i++) a[S[i] - 'a'] = true;
  
  for(int i=0;i<26;i++){
    if(!a[i]){
      cout << (char)(i + 'a') << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,c=0,i,j;
    string s,t;
    cin>>s>>t;
    for(int i=0;i<s.size();i++)
        if(s[i]==t[i])
            c++;

    if(c==s.size())cout<<"Yes";
    else cout<<"No";
}



Measured memory_bytes: 3600
/*Lucky_Glass*/
#include<set>
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=2e5;

struct BLOCK{int Stim,Ttim,Vpos;}blk[N+3];
int n,m,Id;

bool cmpBLOCK(const BLOCK &Ca,const BLOCK &Cb){
	if(Ca.Stim-Ca.Vpos!=Cb.Stim-Cb.Vpos) return Ca.Stim-Ca.Vpos<Cb.Stim-Cb.Vpos;
	return Ca.Ttim-Ca.Vpos<Cb.Ttim-Ca.Vpos;
}
set< pair<int,int> > Tcnt;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d%d%d",&blk[i].Stim,&blk[i].Ttim,&blk[i].Vpos);
	}
	sort(blk+1,blk+1+n,cmpBLOCK);
	priority_queue< pair<int,int>,vector< pair<int,int> >,greater< pair<int,int> > > que;
	int Np=1;
	for(int i=1;i<=m;i++){
		scanf("%d",&Id);
		while(Np<=n && blk[Np].Stim-blk[Np].Vpos<=Id){
			que.push(make_pair(blk[Np].Ttim-blk[Np].Vpos,Np));
			Tcnt.insert(make_pair(blk[Np].Vpos,Np));
			Np++;
		}
		while(!que.empty() && Id>=que.top().first){
			Tcnt.erase(make_pair(blk[que.top().second].Vpos,que.top().second));
			que.pop();
		}
		if(que.empty()) printf("-1\n");
		else printf("%d\n",Tcnt.begin()->first);
	}
	return 0;
}

Measured memory_bytes: 14576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<vector<int>> f(n,vector<int>(10));
	vector<vector<int>> p(n,vector<int>(11));
	rep(i,n){
		rep(j,10){
			cin >> f[i][j];
		}
	}
	rep(i,n){
		rep(j,11){
			cin >> p[i][j];
		}
	}
	int sum=0;
	int ans=-1000000000;
	vector<int> cnt(n);
	for(int i=1;i<(1<<10);++i){
		rep(j,n) cnt.at(j)=0;
		sum=0;
		rep(j,10){
			if(i&(1<<j)){
				rep(k,n){
					if(f[k][j]) cnt.at(k)++;
				}
			}
		}
		rep(j,n) sum+=p[j][cnt.at(j)];
		ans=max(ans,sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define ALLG(v) v.begin(), v.end() ,greater<int>()
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }
ll GetDigit(ll num) {
	ll digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}

using namespace std;
int main() {
	ll n,k;
	cin >> n >> k ;

	ll ans = 0;


	n = n % k;
	ans = abs(n - k);

	ans = min(ans, n);

	cout << ans << endl;
}

Measured memory_bytes: 256
/*
ID: yzshang1
LANG: C++11
TASK:
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define repn(i, n) for (int (i) = 1; (i) <= (int)n; (i)++)
#define rep(i, n) for (int (i) = 0; (i) < (int)n; (i)++)
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;

int main() {
	char c;
	cin >> c;
	cout << (char)(c + 1) << endl;
	return 0;
}


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

int main(){
	string s;
	cin >> s;
	list<char>str;
	for(int i = 0; i<s.length();i++){
		str.push_back(s[i]);
	}
	string ans;
	int n, t, f, sw = 0;
	cin >> n;
	for(int i = 0;i < n ; i++){
		cin >> t;
		if(t == 1){
			sw = sw ^ 1;
		}
		else
		{
			char ch;
			cin >> f >> ch;
			if(sw) f = 3-f;
			if(f == 1) str.push_front(ch);
				else str.push_back(ch);
		}
	}
	if(sw)
		while(!str.empty()){
			char temp = str.back();
			str.pop_back();
			cout << temp;
		}
	else{
		while(!str.empty()){
			char temp = str.front();
			str.pop_front();
			cout << temp;
		}
	}
}

Measured memory_bytes: 9984
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,K=MI()
    A=[0]*N
    B=[0]*N
    for i in range(N):
        a,b=MI()
        A[i]=a
        B[i]=b
        
    """
    xorだと思っていたので馬鹿みたいにむずかった...
    
    最大値の最大値，的な．
    Kを二進数表記して，bitが立っている桁を選び，i桁目とする．
    iよりも高位側はKと同じで，
    低位側を全部1にした数K2を考える．
    orがK2を超えなければOk
    """
    
    ans=0
    M=len(bin(K))-2
    
    for i in range(M):
        temp=0
        if K>>i & 1:
            K2=K-(1<<i)
            K2=K2 | ((1<<i)-1)
                    
            for k in range(N):#k番目の数を使うかどうか
                if K2 | A[k] == K2:
                    temp+=B[k]  
            ans=max(ans,temp)
           
    temp=0 
    for k in range(N):#k番目の数を使うかどうか
        if K | A[k] == K:
            temp+=B[k]
    ans=max(ans,temp)
    
    print(ans)
                    
                    
            
        
    
    

main()


Measured memory_bytes: 75688
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;
using mat2d_t = std::vector<std::vector<int64_t>>;



int main(int argc, char **argv) {
    int n, r;
    cin >> n >> r;
    int ans;
    if (n >= 10) ans = r;
    else ans = 100*(10-n) + r;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); ++i)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define INF 1e9

void init()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
}

int main()
{
    init();
    string s;
    cin>>s;

    if(s[s.size()-1]=='s'){
        s.push_back('e');
        s.push_back('s');
    }else s.push_back('s');
    cout<<s<<endl;
}


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


int main()
{

    long long int n;
    cin>>n;
    long long int arr[n],ans=0,b,t;

    for(t=0;t<n;t++){
        cin>>arr[t];
        arr[t]=arr[t]-t-1;
    }


    sort(arr,arr+n);

    b= arr[n/2];

    //cout<<b;

    for(t=0;t<n;t++){
        ans+=abs(arr[t]-b);
    }

    cout<<ans;





    return 0;
}

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

int main(){
  int N;
  cin >> N;
  if(N%2==1){
    cout << 0 << endl;
    exit(1);
  }
  int d[N];
  for(int i=0;i<N;i++){
    cin >>d[i];
  }

  sort(d,d+N);
  int temp=0;
  temp=d[N/2]-d[N/2-1];
  cout<<temp;

}


Measured memory_bytes: 640
def calc(a):
    if (a%2) == 0:
        return a/2
    else:
        return a*3+1

s = int(input())
slist = []
p = calc(s)
slist.append(s)
slist.append(p)
s = p
while slist.count(p) != 2:
    p = calc(s)
    slist.append(p)
    s = p
slist.remove(p)
print(slist.index(p)+2)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=1000010;
const ll mod=1e9+7;

int main(){
  vector<int> a(4);
  cin >> a[0] >> a[1];
  a[2]=a[0]-1;
  a[3]=a[1]-1;
  sort(a.rbegin(),a.rend());
  cout << a[0]+a[1] << endl;
  return 0;
}


Measured memory_bytes: 256
(* O(n log n) *)
open Hashtbl
let n, k = Scanf.scanf " %d %d" @@ fun a b -> a, b
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let h = create n
let ans = ref 0
let _ =
  Array.iter (fun a -> if mem h a then replace h a @@ find h a + 1 else add h a 1) a_s;
  let c = length h in
  let cs = fold (fun _ c acc -> c :: acc) h [] |> List.sort (-) |> Array.of_list in
  for i = 0 to c - k - 1 do ans := !ans + cs.(i) done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 35708
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<deque>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<tuple>
#include<map>
#include<memory>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<double> VD;
typedef pair<int, int> P1;
typedef long long int ll;

//number
#define INF 1e9
#define NUM 1000000007

//itr
#define all(x) begin(x),end(x)

//repeat
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define RREPS(i,x) for(int i=((int)(x));i>=0;i--)

//max,min
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

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

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a * (b / g);
}*/

/*int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}*/

//grid template
int x[] = { -1, 0, 1, 0 };
int y[] = { 0,-1,0,1 };
int xx[] = { -1,-1,1,1 };
int yy[] = { 1,-1,1,-1 };

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

	bool flag = false;
	if (b > 4) {
		flag = true;
	}

	if (flag) cout << "TBD" << endl;
	else cout << "Heisei" << endl;

}


 

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

lli n;
vll a;
priority_queue<lli,vector<lli>,greater<lli> > mq;
priority_queue<lli> pq;
lli sum;
vll dp;
lli ans;

int main(){
    cin >> n;
    a = vll(3*n);
    dp = vll(n+1);
    for(lli i = 0;i < 3*n;i++) cin >> a[i];
    sum = 0;
    for(lli i = 0;i < n;i++) mq.push(a[i]),sum += a[i];
    dp[0] = sum;
    for(lli i = 0;i < n;i++){
        sum += a[i+n];
        mq.push(a[n+i]);
        sum -= mq.top();
        mq.pop();
        dp[i+1] = sum;
    }
    sum = 0;
    for(lli i = 2*n;i < 3*n;i++) pq.push(a[i]),sum += a[i];
    ans = dp[n] - sum;
    for(lli i = 2*n-1;i >= n;i--){
        sum += a[i];
        pq.push(a[i]);
        sum -= pq.top();
        pq.pop();
        ans = max(ans,dp[i-n] - sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5748
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	map<Int,Int> cnt;
	Int temp;
	for (Int i = 0; i < N; i++) {
		cin >> temp;
		cnt[temp]++;
	}

	Int flag = 0;
	mint ans = 1;
	if (N % 2) {
		if (cnt[0] != 1)flag = 1;
		for (Int i = 2; i < N; i+=2) {
			if (cnt[i] != 2)flag = 1;
			break;
		}
		for (Int i = 0; i < (N-1)/2; i++) {
			ans *= 2;
		}
	}
	else {
		for (Int i = 1; i < N; i++) {
			if (cnt[i] != 2)flag = 1;
			break;
		}
		for (Int i = 0; i < N/2; i++) {
			ans *= 2;
		}
	}

	if (flag == 1) {
		cout << 0 << "\n";
	}
	else {
		cout << ans << "\n";
	}

}

Measured memory_bytes: 4224
n=int(input())
a=list(map(int,input().split()))
ans=sum(a)
li=[0 for i in range(100000+1)]
for i in range(n):
  li[a[i]]+=1
q=int(input())
for dummy in range(q):
  b,c=map(int,input().split())
  ans+=li[b]*(c-b)
  print(ans)
  li[c]+=li[b]
  li[b]=0

Measured memory_bytes: 21052
from collections import defaultdict
S = input()[::-1]
mod = 2019
d = defaultdict(int)
ruijo = 1
tmp = 0
for i in range(len(S)):
    tmp += int(S[i]) * ruijo % mod
    d[tmp % mod] += 1
    ruijo *= 10
    ruijo %= mod
ans = 0
for k, v in d.items():
    ans += v * (v - 1) // 2
    if k == 0:
        ans += v
print(ans)

Measured memory_bytes: 69460
#include<iostream>
#include<map>
using namespace std;
const int MAXN=200005;
 
struct DSU {
	int fa[MAXN];
	int Find(int x) {
        return fa[x]== 0 ? x : fa[x] = Find(fa[x]);
        }
	void Union(int x,int y) {
		int r1=Find(x),r2=Find(y);
		if(r1==r2) return;
		fa[r1]=r2;
	}
};
 
DSU s1,s2;
map<int,int> cnt[MAXN];
 
int main()
{
	int n,k,l;
	cin >> n >> k >> l;
	for(int i=1,x,y; i<=k; i++) {
		cin >> x >> y;
		s1.Union(x,y);
	}
	for(int i=1,x,y; i<=l;i++) {
		cin >> x >> y;
		s2.Union(x,y);
	}
	for(int i=1; i<=n; i++) cnt[s1.Find(i)][s2.Find(i)]++;
	for(int i=1; i<=n; i++) cout << cnt[s1.Find(i)][s2.Find(i)] << " ";
	cout << "\n";
	return 0;
}

Measured memory_bytes: 19456
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

int n;
double x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4;

int main() {
	scanf( "%d", &n );
	for ( int i = 0; i < n; i++ ) {
		scanf( "%lf %lf %lf %lf %lf %lf", &x_1, &y_1, &x_2, &y_2, &x_3, &y_3 );
		double a1 = 2 * ( x_2 - x_1 );
		double b1 = 2 * ( y_2 - y_1 );
		double c1 = sq( x_1 ) - sq( x_2 ) + sq( y_1 ) - sq( y_2 );
		double a2 = 2 * ( x_3 - x_1 );
		double b2 = 2 * ( y_3 - y_1 );
		double c2 = sq( x_1 ) - sq( x_3 ) + sq( y_1 ) - sq( y_3 );
		double x = ( b1 * c2 - b2 * c1 ) / ( a1 * b2 - a2 * b1 );
		double y = ( c1 * a2 - c2 * a1 ) / ( a1 * b2 - a2 * b1 );

		double r = sqrt( sq( x - x_1 ) + sq( y - y_1 ) );
		printf( "%.3f %.3f %.3f\n", x, y, r );
	}
	return 0;
}

Measured memory_bytes: 1248
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long INF = 1e9 + 7;
using namespace std;
typedef long long ll;
map<int, int> mp;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<bool> counter(4);
	for (int i = 0; i < 4; i++) counter[i] = false;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s.at(i) == 'N') counter[0] = true;
		else if (s.at(i) == 'W') counter[1] = true;
		else if (s.at(i) == 'S') counter[2] = true;
		else counter[3] = true;
	}
	if ((counter[0] == true && counter[2] == false) || (counter[0] == false && counter[2] == true) || (counter[1] == true && counter[3] == false) || (counter[1] == false && counter[3] == true)) {
		cout << "No\n";
	}
	else cout << "Yes\n";
	return 0;
}

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

using namespace std;


int main()
{
    string s;
    while(cin >> s)
    {
        int c = 0;
        for(int i = 0; i < s.size(); i++)
            if(s[i] == 'o')
            c++;
        if(15 - s.size() + c >= 8)
        {
            cout << "YES" << endl;
        }
        else
            cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    string s;
    cin>>s;
    int y;
    cin>>y;
    for (int i=0;i<s.length();i++){
        if (i+1==y)
        {
            cout<<s[i]<<endl;
            break;
        }
        if (s[i]!='1'){
            cout<<s[i]<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
    ll n; cin >> n;
    vector<ll> v;
    ll sum = 0, i = 0;
    while(sum <= n){
        v.emplace_back(sum+i);
        sum += i;
        i++;
    }
    int d = v.back() - n;
    if(d == 0){
        for(int i = 1; i < v.size(); i++){
            cout << i << endl;
        }
    }
    else{
        for(int i = 1; i < v.size(); i++){
            if(i == d)continue;
            cout << i << endl;
        }
    }
    

    system("pause");
}

Measured memory_bytes: 632
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    H,W=map(int,input().split())
    ans=W*(H//2)
    if H%2:
        ans+=-(-W//2)
    if H==1 or W==1:
        print(1)
    else:
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int H, W;
int h, w;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W;
  cin >> h >> w;

  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (i >= h && j >= w) {
        ans++;
      }
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int nomor[3][3];
	int n, inp[10],cek[3][3];
	for (int i=0;i<3;i++)
	{
		for (int j=0;j<3;j++)
		{
			scanf("%d", &nomor[i][j]);
		}
	}
	scanf("%d", &n);
	for (int k=0;k<n;k++)
	{
		scanf("%d", &inp[k]);
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
		{
			if (inp[k]==nomor[i][j])
			{
				cek[i][j]=1;
			}
		}
	}
	}
	if( (cek[1][1] == 1&& cek[2][2] == 1 && cek[0][0] == 1 )
    || (cek[2][0] == 1 && cek[1][1] == 1 && cek[0][2] == 1  )
    || (cek[0][0] == 1 && cek[0][1] == 1 && cek[0][2] == 1  )
    || (cek[1][0] == 1 && cek[1][1] == 1 && cek[1][2] == 1  )
    || (cek[2][0] == 1 && cek[2][1] == 1 && cek[2][2] == 1  )
    || (cek[0][0] == 1 && cek[1][0] == 1 && cek[2][0] == 1  )
    || (cek[0][1] == 1 && cek[1][1] == 1 && cek[2][1] == 1  )
    || (cek[0][2] == 1 && cek[1][2] == 1 && cek[2][2] == 1  )
    ) 
	{
        printf("Yes\n");
    }
	else 
	{
        printf("No\n");
    }

	return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <string>
 
using namespace std;
 
int main() { 
  string input_str;
 
  while (getline(cin, input_str)) {
    for (int shift = 0; shift < 26; shift++) {
      for (int str_i = 0; str_i < input_str.size(); str_i++) {
        if (input_str[str_i] >= 'a' && input_str[str_i] < 'z')
          input_str[str_i] ++;
        else if (input_str[str_i] == 'z')
          input_str[str_i] = 'a';
      }
      if (input_str.find("the") != string::npos || input_str.find("this") != string::npos || input_str.find("that") != string::npos)
        break;
    }
    cout << input_str << endl;
  }
 
  return 0;
}


Measured memory_bytes: 2968
s = input()

mmyy = 1 <= int(s[:2]) <= 12
yymm = 1 <= int(s[2:]) <= 12

if yymm and mmyy:
    print("AMBIGUOUS")
elif yymm:
    print("YYMM")
elif mmyy:
    print("MMYY")
else:
    print("NA")

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

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    string s;
    cin >> s;
    bool ans=true;
    if(s[0]!='A') ans=false;
    int cnt_C=0;
    for(int i=1;i<s.size();i++){
        if(s[i]<'a'){
            if(s[i]=='C'&&cnt_C==0&&1<i&&i<s.size()-1){
                cnt_C++;
                continue;
            }
            ans=false;
            break;
        }
    }
    if(cnt_C!=1) ans=false;
    puts(ans?"AC":"WA");
}

Measured memory_bytes: 256
n = int(input())
a = [int(input()) for i in range(n)]
a.sort()
now = a[0]
num = 1
b = []
for i in a[1:]:
  if i == now:
    num += 1
  else:
    b.append(num)
    num = 1
  now = i
b.append(num)
c = [i % 2 for i in b]
print(sum(c))

Measured memory_bytes: 8908
#include <bits/stdc++.h> 
#include <time.h>
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 2e5+10;
const int N = 1e5+10;
const int E = 2e5+10;  
ll n,k;
ll pre[maxn],suf[maxn];

int main(){
	cin>>n>>k;
	F(i,1,n){
		pre[i] = pre[i-1]+i;
	}
	dF(i,n,0){
		suf[i] = suf[i+1]+i;
	}
	ll ans = 0 ;
	F(i,k,n+1){
		ans = (ans+suf[n-i+1]-pre[i-1]+1)%mods;
	}
	cout<<ans<<endl; 
}

Measured memory_bytes: 6716
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

ans = 10000
L = 10 ** (N - 1)
if N == 1:
    L = 0
U = 10**N

for i in range(L, U):
    x = str(i).zfill(N)
    for s, c in sc:
        if x[s - 1] == str(c):
            continue
        break
    else:
        ans = min(ans, i)

if ans >= 10000:
    ans = -1

print(ans)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] strs = br.readLine().split(" ");
		int[] nums = new int[strs.length];
		int count = 0;
		for(int i = 0 ; i < strs.length ; i++){
			int d = Integer.parseInt(strs[i]);
			nums[i] = d;
			for(int j = 0 ; j < i ; j++){
				int p = Integer.parseInt(strs[j]);
				if(d == p){
					count--;
					break;
				}
			}
			count++;
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 8148
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 998244353
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int a,b;cin>>a>>b;
    ll ans=0;
    for(int i=a;i<=b;i++){
        string s=to_string(i);
        int n=s.length();
        int abc=1;
        for(int i=0;i<n/2;i++)
        {
            if(s[i]!=s[n-i-1])
                abc=0;
        }
        if(abc==1)
            ans++;
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T>
vector<vector<T> > make_v(size_t a,size_t b){
  return vector<vector<T> >(a,make_v<T>(b));
}
template<typename T>
vector<vector<vector<T> > > make_v(size_t a,size_t b,size_t c){
  return vector<vector<vector<T> > > (a,make_v<T>(b,c));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//INSERT ABOVE HERE
signed main(){
  Int h,w;
  cin>>h>>w;
  vector<string> s(h);
  for(Int i=0;i<h;i++) cin>>s[i];
  using P = pair<Int, Int>;
  queue<P> q;
  auto dp=make_v<Int>(h,w);
  fill_v(dp,-1);
  dp[0][0]=1;
  q.emplace(0,0);
  Int dy[]={1,-1,0,0};
  Int dx[]={0,0,1,-1};
  auto in=[&](Int y,Int x){return 0<=y&&y<h&&0<=x&&x<w;};
  while(!q.empty()){
    Int y,x;
    tie(y,x)=q.front();q.pop();
    for(Int k=0;k<4;k++){
      Int ny=y+dy[k],nx=x+dx[k];
      if(!in(ny,nx)||s[ny][nx]=='#') continue;
      if(~dp[ny][nx]) continue;
      dp[ny][nx]=dp[y][x]+1;
      q.emplace(ny,nx);
    }
  }
  
  if(dp[h-1][w-1]<0){
    cout<<-1<<endl;
    return 0;
  }
  Int cnt=0;
  for(Int i=0;i<h;i++)
    for(Int j=0;j<w;j++)
      cnt+=s[i][j]=='.';
  cout<<cnt-dp[h-1][w-1]<<endl;
  return 0;
}


Measured memory_bytes: 256
# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 22/08/2020

from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007

n = ii1()
arr = iia()
res = 0
for i in range(1, n):
    if arr[i] < arr[i - 1]:
        res += arr[i - 1] - arr[i]
        arr[i] = arr[i - 1]
print(res)
    

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

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define F0R(i, n) for (int i = 0; i < (n); i++)
#define print(x) cout << x << '\n'
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int INF = 1e9 + 5;
const int MAX_N = 1e5 + 5;
ll dp[MAX_N];

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

  int N,W;
  cin >> N >> W;
  ll maxValue = 0;

  for (int item = 0; item < N; item ++) { 
      ll weight, value;
      cin >> weight >> value;

      for (int sackWeight = W - weight; sackWeight >=0; sackWeight-- ) {
          dp[sackWeight + weight] = max(dp[sackWeight + weight], dp[sackWeight] + value);
          if (dp[sackWeight+weight] > maxValue) maxValue = dp[sackWeight+weight]; 
      }
  }
  cout << maxValue <<endl;



  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
int main (){
  char S[100],l;
  scanf("%s",S);
  l=strlen(S);
  
  for(int i=0;i<(l)/2;i++){
    if(S[i]==S[l-i-1]){
    }else{
      printf("No");
      return 0;
    }
  }
  
  l=(l-1)/2;
  for(int i=0;i<l/2;i++){
    if(S[i]==S[l-i-1]){
    }else{
      printf("No");
      return 0;
    }
  }
  printf("Yes");
  return 0;
}


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

using ll = long long int;

const int MAX_N = (int)1e5 + 5;

struct rd {int v, cost;};

int n, m;

int l, r, d;
ll grid[MAX_N];
bool visited[MAX_N];
vector<vector<rd>> graph(MAX_N);
vector<int> nodes;

int main(void){
  // Here your code !
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d %d", &l, &r, &d);
    rd tokenl;
    tokenl.v = r;
    tokenl.cost = d;
    graph[l].push_back(tokenl);
    rd tokenr;
    tokenr.v = l;
    tokenr.cost = -1 * d;
    graph[r].push_back(tokenr);
    nodes.push_back(l);
    nodes.push_back(r);
  }
  fill(visited, visited + MAX_N, false);

  sort(nodes.begin(), nodes.end());
  nodes.erase(unique(nodes.begin(), nodes.end()), nodes.end());

  stack<int> stk;
  for (int i = 0; i < nodes.size(); ++i) {
    int cnode = nodes[i];
    if (visited[cnode]) continue;
    grid[cnode] = 0;
    visited[cnode] = true;

    stk.push(cnode);
    while (!stk.empty()) {
      int tnode = stk.top();
      stk.pop();
      vector<rd> cgraph = graph[tnode];

      for (int j = 0; j < cgraph.size(); ++j) {
        if (visited[cgraph[j].v]) {
            if (grid[tnode] + cgraph[j].cost != grid[cgraph[j].v]) {
              printf("No\n");
              return 0;
            }
            else {continue;}
        }
        grid[cgraph[j].v] = grid[tnode] + cgraph[j].cost;
        stk.push(cgraph[j].v);
        visited[cgraph[j].v] = true;
      }
    }
  }
  printf("Yes\n");

  return 0;
}

Measured memory_bytes: 12004
import sys
input = sys.stdin.readline
from collections import *

N, K = map(int, input().split())
A = list(map(int, input().split()))
acc = [0]

for Ai in A:
    acc.append(acc[-1]+Ai)

cnt = defaultdict(int)
ans = 0

for i in range(N+1):
    ans += cnt[(acc[i]-i)%K]
    cnt[(acc[i]-i)%K] += 1
    
    if i>=K-1:
        j = i-(K-1)
        cnt[(acc[j]-j)%K] -= 1

print(ans)

Measured memory_bytes: 107400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<53;
ll Sum[100];
ll n,m,a,b,p,q;


ll calc(ll k){
  static ll used[101]={},mem[101]={};
  if(used[k]++) return mem[k];
  ll A = 1,B = 1;
  ll &res =mem[k]=p+q;
  while(0<res&&res<=INF&&k--)A*=a,B*=b,res=p*A+q*B;
  if(res<0||res>INF)res=INF;
  return res;
}


ll ans = INF;
set<ll> used[101];
void dfs(ll pos,ll sum){
  if(sum<0LL||sum>INF) return;
  ans = min(ans,(ll)abs(m-sum));
  if(pos==-1)return;
  if(Sum[pos]+sum<m){ans=min(ans,m-(Sum[pos]+sum));return;}
  if(m<sum) return;
  if(used[pos].count(sum)) return ;
  used[pos].insert(sum);
  
  ll r = calc(pos);
  if(r<INF)dfs(pos-1,sum+r);  
  dfs(pos-1,sum);
}


int main(){
  cin>>n>>m>>a>>b>>p>>q;
  for(int i=0;i<60;i++) Sum[i] = INF;
  Sum[0] = calc(0);
  for(int i=1;i<60;i++)Sum[i]=min(INF,calc(i)+Sum[i-1]);

  if(max(a,b)==1) {
    ll s = abs(m - (m/(p+q))*(p+q));
    ll t = abs(m - (m/(p+q))*(p+q) - (p+q));
    if(m/(p+q)==n) t = INF;
    if(m/(p+q)<=n) cout<<min(s,t)<<endl;
    else cout<< m-(p+q)*n <<endl;
    return 0;
  }
  
  dfs(min(n-1,50LL),0);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3100
from collections import defaultdict
from bisect import bisect_left

n, m = map(int, input().split())
years = defaultdict(list)
sorted_years = defaultdict(list)
PY = []
for i in range(m):
    prefecture, year = map(int, input().split())
    years[prefecture].append(year)
    PY.append((prefecture, year))

for prefecture, year_list in years.items():
    temp = year_list
    temp.sort()
    sorted_years[prefecture] = temp

for pair in PY:
    p, y = pair
    years[p]
    num = 1 + bisect_left(sorted_years[p], y)
    print(str(p).zfill(6) + str(num).zfill(6))


Measured memory_bytes: 46260
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
#define all(cont) cont.begin(), cont.end()
#define unique(a)  sort(all(a)) , (a).erase(unique((a).begin(), (a).end()),(a).end())
#define rall(cont) cont.rbegin(), cont.rend()
#define sz(x) (int)(x).size()
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define f first
#define s second
#define mset(m,v) memset(m,v,sizeof(m))
#define mod 1000000007
const int N = 2e5 + 5, INF = 1E9 + 7;
#define PI acos(-1.0)
long double EPS = 1e-9;
typedef long long ll;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
#define pqll_max priority_queue<ll> // max heap. push(),pop(),top(),size(),empty()
#define pqll_min priority_queue<ll,vector<ll>,greater<ll> >
#define lb(v,val)   lower_bound(v.begin(),v.end(),val) //first equal to or lower than [------------
#define ub(v,val)   upper_bound(v.begin(),v.end(),val) //first greater than ------------)
#define bs(v,x) binary_search(v.begin(),v.end(),x)
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x; }
inline ll sub(int x, int y) { x -= y; if (x < 0) x += mod; return x; }
inline ll mul(ll x, ll y) { return (x%mod * 1ll * y%mod) % mod; }
inline ll pwr(ll a, ll b) { ll x = 1 % mod; while (b) { if (b & 1) x = mul(x, a); a = mul(a, a); b >>= 1; }return x % mod; }
inline ll inv(ll a) { return pwr(a, mod - 2) % mod; }
ll gcd(ll a, ll b) { if (!a)return b % mod; return gcd(b%a, a) % mod; }
#define debug(x) cout << #x << " = " << x << endl;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#define in(container) for (auto &it : container) cin>>it;
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
void solve() {
	string s;
	cin >> s;
	if (s[sz(s) - 1] != 's') {
		cout << s + 's' << endl;
	}
	else {
		cout << s+ "es" << endl;
	}
}
signed main()
{
	fastio;
	//cout<<fixed<<setprecision(15);
	//clock_t begin = clock();
	int tc;
	tc = 1;
	//cin >> tc;
	while (tc--) {
		solve();
	}
	//clock_t end = clock();double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;cerr << elapsed_secs;
}


//Error?
// clear lists for every test case
// print new line for each tc
// check for int or ll
// check if problem can be solved without any heavy DS like priority_queue or map



Measured memory_bytes: 3652
abc = gets.strip.split(" ").map(&:to_i).sort

ans = 0
while !(abc[0] == abc[1] && abc[1] == abc[2]) do
  ans += 1
  if abc[1] - abc[0] >= 2
    abc[0] += 2
  else
    abc[0] += 1
    abc[1] += 1
  end

  abc.sort!
end

puts ans


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

int main(){
	string s;
	cin >> s;
	vector<char> ans;
	rep(i,s.size()){
		if(i%2 == 0){
			ans.push_back(s[i]);
		}
	}
	rep(i,ans.size()){
		cout << ans[i];
	}
	cout << endl;
}

Measured memory_bytes: 3732
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        long[] KX=cin.ArrayLong(2,0);
        long start=KX[1]-KX[0]+1;
        long goal = KX[1]+KX[0]-1;
        for(long i=start;i<goal;i++)
        {
          Console.Write(i+" ");
        }
       Console.WriteLine(goal);
        
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public static void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }//Answer.IntArrayAns(x);
    public static void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}







Measured memory_bytes: 13140
#include <algorithm>
#include <numeric>
#include <vector>
#include <iostream>
using namespace std;

int i = 0, n;
int ans[10000];
vector<int> adj[10000];
int c[10000]; 

void dfs(int v, int p) {
    for (int u : adj[v]) {
        if (u == p) continue;
        dfs(u, v);
    }
    ans[v] = c[i++];
    // cerr << i << endl;
}

int main() {
    int n; cin >> n;
    for (int i = 1; i < n; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        adj[a].push_back(b); adj[b].push_back(a);
    }
    for (int i = 0; i < n; i++) cin >> c[i];
    sort(c, c+n);
    dfs(0, -1);
    cout << accumulate(c, c+n-1, 0LL) << endl;
    for (int i = 0; i < n; i++) cout << ans[i] << ' ';
    cout << endl;
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}





void _main() {
        int n, k; cin >> n >> k;
        vector<int> freq(n + 1);
        while (n--) {
                int x; cin >> x;
                freq[x]++;
        }

        sort(all(freq), greater<int>());
        while (freq.size() && !freq.back()) freq.pop_back();
        int ans = 0;
        while (freq.size() > k) {
                ans += freq.back();
                freq.pop_back();
        }

        cout << ans;
}




signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3960