akhauriyash/Code-Regression huggingface dataset:
import collections
N, M = map(int, input().split())
nodes = [None] * N
for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    if nodes[A] is None:
        nodes[A] = set()
    nodes[A].add(B)
    if nodes[B] is None:
        nodes[B] = set()
    nodes[B].add(A)
r = [None] * N
r[0] = "Yes"
Q = collections.deque([0])
while len(Q) != 0:
    i = Q.popleft()
    for j in nodes[i]:
        if r[j] is None:
            r[j] = i+1
            Q.append(j)
for x in r:
    print(x)

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

int main(){
	int n, m, i, j;
	cin >> n >> m;
	int a[n*m], b[m], ans[m];
	
	for(i = 0; i <= n*m-1; i++){
		cin >> a[i];
	}
	for(i = 0; i <= m-1; i++){
		cin >> b[i];
	}
	
	for(i = 0; i <= n-1; i++){
		ans[i] = 0;
		for(j = m*i; j <= m*i+(m-1); j++){
				ans[i] += a[j]*b[j%m];
		}
	}
	
	for(i = 0; i <= n-1; i++){
		cout << ans[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1196
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

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

    ll a,b;
    cin>>a>>b;
    b = min(b,a+5000);
    ll res = 2020;
    FOR(i,a,b+1){
      FOR(j,i+1,b+1){
        res = min(res, i*j%2019);
      }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(300000)
class uf:
    def __init__(self,n):
        self.n=n
        self.l=[-1]*n
    def ro(self,n):         #root
        if self.l[n]<0:
            return n
        r=self.ro(self.l[n])
        self.l[n]=r
        return r
    def me(self,a,b):       #merge
        ra=self.ro(a)
        rb=self.ro(b)
        if self.l[ra]>self.l[rb]:
            ra,rb=rb,ra
        if ra!=rb:
            self.l[ra]+=self.l[rb]
            self.l[rb]=ra
    def size(self,n):
        return -self.l[self.ro(n)]
    def sa(self,a,b):       #same
        return self.ro(a)==self.ro(b)
    def rl(self):           #roots list
        return [i for i,v in enumerate(self.l) if v<0]
    
    def len(self):          #len(roots)
        return len(self.rl())
    def ul(self):
        d={n:i for i,n in enumerate(self.rl())}
        m=[[]for i in range(self.len())]
        for i in range(self.n):
            m[d[self.ro(i)]].append(i)
        return m
    def __str__(self):
        return f"{self.ul()}"
    def __setitem__(self,i,v):
        self.l[i]=v
N,Q=map(int,input().split())
g=uf(N)
for i in range(Q):
    t,u,v=map(int,input().split())
    if t:
        if g.sa(u,v):
            print(1)
        else:
            print(0)
    else:
        g.me(u,v)

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

using namespace std;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  while(true){
    C -= B;
    if(C <= 0)
      break;
    A -= D;
    if(A <= 0)
      break;
  }
  
  if(A > 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3632
package main

import (
	"bufio"
	"fmt"
	"strings"

	"os"
	"sort"
	"strconv"
)

//scanで一行づつ読み込む
var sc = bufio.NewScanner(os.Stdin)
var wtr = bufio.NewWriter(os.Stdout)

//sort
// array := []int{5, 1, 4, 2, 3}
// sort.Sort(sort.IntSlice(array))

func main() {
	// a := make([]int, n)
	n := nextLine()
	n2 := strings.Split(n, " ")
	arr := []int{}
	for _, i := range n2 {
		j, _ := strconv.Atoi(i)
		arr = append(arr, j)
	}
	sort.Sort(sort.IntSlice(arr))
	a, b := arr[0], arr[1]

	fmt.Fprintln(wtr, (a*b)/2)
	_ = wtr.Flush()
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 640
#include<iostream>
        #include<vector>
        #include<string>
        #include<math.h>
        #include<algorithm>
        #include<cstring>//memset needs this head
        using namespace std;
        int canReach[2][16001];
        bool DP(vector<int> v,int t,int start){//v is the step vector of each axis
            memset(canReach,0,sizeof(canReach));
                canReach[0][8000+start]=1;//the initial place
            if(v.size()==0)
                return canReach[0][8000+t];
            int i;
            for(i=1;i<=v.size();i++){
                for(int j=0;j<=16000;j++){
                    canReach[i%2][j]=((j+v[i-1])>16000?0:canReach[(i-1)%2][j+v[i-1]])||((j-v[i-1])<0?0:canReach[(i-1)%2][j-v[i-1]]);
                }
            }
            return canReach[(i-1)%2][8000+t];
        }
        int main(){
            string S;
            int tx,ty;
            cin>>S>>tx>>ty;
            bool whichAxis=0;//the initial axis is x,1 is y;
            vector<int> vx;
            vector<int> vy;
            int count=0;
            for(auto c:S){
                if(c=='T'){
                    ((whichAxis==0)?vx:vy).push_back(count);
                    count=0;
                    whichAxis=!whichAxis;
                }
                else{
                    count++;
                }
            }
            ((whichAxis==0)?vx:vy).push_back(count);//that is important,the last several T's
           // tx-=vx[0];//the first several step in x have decided direction.That is an error
            int start=vx[0];
            vx.erase(vx.begin());
            if(DP(vx,tx,start)&&DP(vy,ty,0))
                cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
            return 0;
 
        }

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#include<cstdio>
#define el "\n"
#define sp " "
typedef long long ll;



main()
{
	ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll k;
cin>>k;
string s;
queue<string> q;
for(int i=1;i<10;i++)
{
	s=i+'0';
	q.push(s);
}
while(!q.empty())
{
	s=q.front();
	//cout<<s<<"   ";
	q.pop();
	k--;
	if(k==0)
	{
		cout<<s;
		break;
	}
	int n=s.size();
	if(s[n-1]=='0')
	{
		q.push(s+"0");
		q.push(s+"1");
	}
	else if(s[n-1]=='9')
	{
		q.push(s+"8");
		q.push(s+"9");
	}
	else
	{
		string t;
		t=s[n-1]-1;
		q.push(s+t);
		t=s[n-1];
		q.push(s+t);
		t=s[n-1]+1;
		q.push(s+t);
		
	}
}
}

Measured memory_bytes: 13824
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

int main() {
	int n, m;
	cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
	return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define pb push_back
#define umap unordered_map
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli power(lli x, lli y){
    lli res = 1;
    x = x ;
    while (y > 0) {
        if (y & 1)
            res = (res*x) ;
        y = y>>1;
        x = (x*x);
    }
    return res;
}
lli solve(){
	lli m1, d1, m2, d2;
	cin>>m1>>d1>>m2>>d2;
	if(m1 == 2){
		if(d1 == 28)
			cout<<1<<"\n";
		else
			cout<<0<<"\n";
	}
	else{
		if(m1 == 1 || m1 == 3 || m1 == 5 || m1 == 7 || m1 == 8 || m1==10 || m1== 12){
			if(d1 == 31)
				cout<<1<<"\n";
			else
				cout<<0<<"\n";
		}
		else{
			if(d1 == 30)
				cout<<1<<"\n";
			else
				cout<<0<<"\n";
		}
	}
	return 0;
}
int main(){
	fastio;
	lli t;
//	cin>>t;
	t = 1;
	while(t>0){
		t--;
		solve();
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    string N;
    cin >> N;
    bool ok = false;
    for(size_t i=2;i<4; i++)
    {
        if(N[i]==N[i-1] && N[i-1] == N[i-2]) ok = true;
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3616
#include <cstdio>
using namespace std;

typedef long long int LLI;

LLI d;

int main() {
  while (1) {
    if (scanf("%lld", &d) != 1) break;
    
    LLI ans = 0;
    for (LLI i=0; i<600; i+=d) {
      ans += i*i*d;
    }
    printf("%lld\n", ans);
  }
}

Measured memory_bytes: 2688
n = int(input())
a = list(map(int, input().split(' ')))
m = int(input())
b = list(map(int, input().split(' ')))

rst = None

loop_num = n if n <= m else m
for i in range(loop_num):
    if a[i] < b[i]:
        rst = 1
    elif a[i] > b[i]:
        rst = 0
    if rst != None: break

if rst == None:
    if len(a) < len(b):
        rst = 1
    else:
        rst = 0

print(rst)


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define alpha_size 26

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int f[N], cur[N];

int powermod(int a, int b, int m = MOD){
  int res = 1ll;
  while (b){
    if (b & 1) res = res * a % m;
    a = a * a % m, b >>= 1;
  }
  return res;
}

// ref: Ashishgup
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);    

    int n, k;
    cin >> n >> k;
    int ret = 0;
    for (int i = k; i >= 1; --i){
      cur[i] = powermod(k / i, n);
      for (int j = 2; i * j <= k; j++){
        cur[i] -= cur[i * j];
        cur[i] += MOD;
        cur[i] %= MOD;
      }
      ret += i * cur[i];
      ret %= MOD;
    }
    cout << ret << endl;
}




Measured memory_bytes: 4372
#include <bits/stdc++.h>
 
#define ll long long
#define cint const int
#define ld long double
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
 
using namespace std;
 
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef pair <int, int> pi;
 
int n, a[200005];
 
int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  int c = 1, s = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] == c) {
      c++;
      continue;
    }
    s++;
  }
  if (s == n) {
    cout << -1;
    return 0;
  }
  cout << s;
  return 0;
}

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

int main() {
  long n,x=-1;
  cin >> n;
  for(long double i=1;i<60000;i++) {
    if(n==floor(i*1.08)) x=i;
  }
  if(x==-1) cout << ":(" << endl;
  else cout << x << endl;
}

Measured memory_bytes: 256
using System;

class D
{
	static void Main()
	{
		var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		double a = h[0], b = h[1], x = h[2];

		var tan = x < a * a * b / 2 ? a * b * b / (2 * x) : 2 * (a * a * b - x) / (a * a * a);
		Console.WriteLine(Math.Atan(tan) * 180 / Math.PI);
	}
}


Measured memory_bytes: 11092
n = int(input())
dic = {}
m = 0
for i in range(n):
  s = input()
  if s in dic:
    dic[s] += 1
    m = max(m, dic[s])
  else:
    dic[s] = 1
    m = max(m, dic[s])
ans = []
for s in dic:
  if dic[s] == m:
    ans.append(s)
print('\n'.join(sorted(ans)))

Measured memory_bytes: 34132
#include <iostream>
#include <vector>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <deque>
#include <math.h>
#include <map>
#include <stack>
#include <list>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <cstring>
#include <climits>
#include <iterator>
#include <cassert>
#include <string>
using namespace std;
int main(){
  int a, b; cin >> a >> b;
  string c; cin >> c;
  for(int i=0;i<c.size();i++){
    if((i==a && c[i] != '-') || (i!=a && !isdigit(c[i]))) {cout << "No\n"; return 0;}
  }

  cout << "Yes\n";
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int a[200000];
int b[200000];

int main() {
    int n, l, r, m, i, j;
    
    scanf("%d", &n);
    
    for (i = 0; i < n * 2 - 1; i++) scanf("%d", &a[i]);
    
    l = 1, r = n * 2 - 1, m = (l + r) / 2;
    
    while (r - l > 1) {
        int c;
        
        for (i = 0; i < n * 2 - 1; i++) {
            if (a[i] >= m) {
                b[i] = 1;
            } else {
                b[i] = 0;
            }
        }
        
        if (b[n - 1] == b[n - 2] || b[n - 1] == b[n]) {
            c = b[n - 1];
        } else {
            for (i = n; i < n * 2 - 1; i++) {
                if (b[i] == b[i - 1]) break;
            }
            
            for (j = n - 2; j >= 0; j--) {
                if (b[j] == b[j + 1]) break;
            }
            
            if (i >= n * 2 - 1 && j < 0) {
                c = (b[n - 1] + n - 1) % 2;
            } else if (i >= n * 2 - 1) {
                c = b[j];
            } else if (j < 0) {
                c = b[i];
            } else {
                if (i - (n - 1) < n - 1 - j) {
                    c = b[i];
                } else {
                    c = b[j];
                }
            }
        }
        
        if (c == 1) {
            l = m;
            m = (l + r) / 2;
        } else {
            r = m;
            m = (l + r) / 2;
        }
    }
    
    printf("%d\n", l);
    
    return 0;
}


Measured memory_bytes: 1792
N = int(input())
L1 = []
for i in range(N):
    L1.append(list(input().split()))

L2 = L1

ans=[]
for i in L1:
    seq = 1
    for j in L2:
        if i[0] > j[0]:
            seq += 1
        elif i[0] == j[0]:
            if int(i[1]) < int(j[1]):
                seq += 1
    ans.append(seq)
    
for i in range(N):
    print(ans.index(i+1)+1)
    


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <set>

#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)

typedef long long int lli;

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<lli> v(N);
    vector<lli> pos(N);
    set<int> s;
    REP (i, 0, N) {
        cin >> v[i];
        pos[v[i] - 1] = i + 1;
    }
    lli ans = 0;
    s.insert(0);
    s.insert(N + 1);
    for (int i = 0; i < N; i++) {
        lli p = pos[i];
        auto pre = s.lower_bound(p);
        auto post = pre;
        pre--;
        ans += ((*post - p) * (p - *pre) * (i + 1));
        s.insert(p);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1000000007;

//↓combination(ll a, ll b) でaCr計算。
//------------------------------------------------------------------------------------------
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}
ll kj(ll x){
    ll s = 1;
    for(ll i = 1; i <= x; i++){
        s = s * i % MOD;
    }
    return s;
}
ll combination(ll a, ll b){
    if(a == 0 && b == 0) return 1;
    if(a < b || a < 0) return 0;
    return (kj(a) * mpow(kj(b), MOD-2) % MOD) * mpow(kj(a-b), MOD-2) % MOD;
}
//---------------------------------------------------------------------------------------------
//↑combination(ll a, ll b) でaCr計算。

int main(){
    int N;
    cin >> N;
    ll sum=0;
    for(int i=1; i <= N; i++){
        if(i%3 != 0 and i%5 != 0){
            sum += i;
        }
    }
    cout << sum;
}

Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (233)
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c);c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c) {
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
int n,K,P;
int solve(int n,int K){
	int f[N][N],ans=0; memset(f,0,sizeof(f)); f[0][0]=1;
	for(int i=0;i<n;i++)
	for(int j=0;j<=K;j++)
	(f[i+1][0]+=f[i][j])%=P,(f[i+1][j+1]+=f[i][j])%=P;
	for(int i=0;i<=K;i++)(ans+=f[n][i])%=P; return ans;
}
int main(){
	read(n),read(K),read(P);
	if(K&1){
		int f[N][N][N]; memset(f,0,sizeof(f));
		f[0][0][0]=1;
		for(int i=1;i<=n+1;i++)
		for(int j=0;j<=n;j++)
		for(int k=0,tmp;k<=K+1;k++)
		if(f[i-1][j][k]){
			(f[i][0][0]+=f[i-1][j][k])%=P;
			if(i*2<=n)(f[i][j+1][0]+=f[i-1][j][k])%=P;
			if(i*2-K>0&&i*2-K<=n&&k+1<K+2)(f[i][0][k?k+1:0]+=f[i-1][j][k])%=P;
            if(i*2-K>0&&i*2<=n&&(tmp=max(j+2,k+1))<K+2)(f[i][j+1][tmp]+=f[i-1][j][k])%=P;
		}
		printf("%d\n",f[n+1][0][0]);
	}
	else printf("%lld\n",1ll*solve(n/2,K/2)*solve((n+1)/2,K/2)%P);
}


Measured memory_bytes: 51712
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define endl '\n'

using namespace std;
struct custom_hash 
{
    static unsigned long long splitmix64(unsigned long long x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(unsigned long long x) const 
    {
        static const unsigned long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
mt19937 random_generator(chrono::steady_clock::now().time_since_epoch().count());

string s; 
void read()
{
	cin >> s; 
}

const int maxn = 2e5 + 3; 
const int inf = 1e9; 

int dp[maxn][2], par[maxn][2];
void solve()
{
	if (s[0] == 'P')
	dp[1][0] = 0, dp[1][1] = -inf;
	
	else 
	if (s[0] == 'D')
	dp[1][0] = -inf, dp[1][1] = 1; 
	
	else 
	dp[1][0] = 0, dp[1][1] = 1;
	
	for (int i = 2; i <= (int)s.size(); i++)
	{
		if (s[i-1] == 'P')
		{
			dp[i][1] = -inf;
			dp[i][0] = max(dp[i-1][0], dp[i-1][1]); 
		}
		
		else 
		if (s[i-1] == 'D')
		{
			dp[i][0] = -inf;
			dp[i][1] = max(dp[i-1][0] + 2, dp[i-1][1] + 1);
		}
		
		else 
		{
			dp[i][0] = max(dp[i-1][0], dp[i-1][1]); 
			dp[i][1] = max(dp[i-1][0] + 2, dp[i-1][1] + 1);
		}
		
		if (dp[i][0] != -inf)
		{
			if (dp[i][0] == dp[i-1][0])
			par[i][0] = 0; 
			
			else 
			par[i][0] = 1; 
		}
		
		if (dp[i][1] != -inf)
		{
			if (dp[i][1] == dp[i-1][0] + 2)
			par[i][1] = 0; 
			
			else 
			par[i][1] = 1; 
		}
	}
	
	string ans;
	int pos = (int)s.size();
	int let = 0;
	if (dp[pos][1] > dp[pos][0])
	let = 1; 
	
	while (pos >= 1)
	{
		if (let == 0)
		ans += 'P';
		
		else
	    ans += 'D';
		 
		int nxt = par[pos][let];
		pos--;
		let = nxt; 
	}
	
	reverse(ans.begin(), ans.end());
	cout << ans << endl; 
}

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


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

int main()
{
    ll n,q;
    cin>>n;
    vector<ll>v;
    vector<ll>f(100005,0);
    ll sum=0;
    for(ll i = 0 ; i < n ; i++)
    {
        ll temp;
        cin>>temp;
        sum += temp;
        f[temp]++;
        v.push_back(temp);
    }
    cin>>q;
    bool flag = false;
    while(q--)
    {
        ll a,b,s=sum;
        cin>>a>>b;
        if(f[a])
        {
            flag = true;
            s = s - f[a]*a;
            s = s + f[a]*b;
            f[b] += f[a];
            f[a] = 0;
            sum = s;
            cout<<sum<<endl;
        }
        else
           cout<<s<<endl;
    }
}

Measured memory_bytes: 4996
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

char c[2][3];

int main(){
  rep(i,2){
      rep(j,3){
          cin>>c[i][j];
      }
  }
  rep(i,3){
      if(c[0][i]!=c[1][2-i]){
          out("NO");
          return 0;
      }
  }
  out("YES");  
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>

const long long MOD_CONST = 1000000007;

using namespace std;


int main() {
	string s;
	cin >> s;
	int len = s.length();
	
	vector<vector<long long>> dp(len+1, vector<long long>(13));

	dp[0][0] = 1;

	for (int i = 0; i < len;i++) {
		int num;
		if (s[i] == '?') {
			num = -1;
		}
		else {
			num = s[i] - '0';
		}

		

		for (int j = 0; j < 10; j++) {
			if (num != -1 && num != j) {
				continue;
			}

			for (int k = 0; k < 13;k++) {
				
				dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
				dp[i + 1][(k * 10 + j) % 13] %= MOD_CONST;
			}

			
		}

		
	}

	long long ans = dp[len][5];

	printf("%lld", ans);

}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF INT_MAX
#define eps LDBL_EPSILON
#define moder 100000
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
string s;
signed main(){
	cin>>s;
	for(int i=0;i<s.size()-1;i++){
		if(i!=s.size()-2){
			if(s[i]==s[i+2]){
				cout<<i+1<<" "<<i+3<<endl;
				return 0;
			}
		}
		if(s[i]==s[i+1]){
			cout<<i+1<<" "<<i+2<<endl;
			return 0;
		}
	}
	cout<<-1<<" "<<-1<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define N_MAX 1000
using namespace std;

int main() {
	int N, M; 
	cin >> N >> M;
	vector<int> p(M);
	vector<string> S(M);
	for (int i = 0; i < M; i++) cin >> p[i] >> S[i];
	bool b[N+1] = {};

	int ac = 0, wa = 0;
	int wanum[100500] = {};
	for (int i = 0; i < M; i++) {
		if (b[p[i]] == 1) continue;
		
		if (S[i] == "WA") wanum[p[i]]++;
		if (S[i] == "AC") {
			b[p[i]] = 1;
			ac++;
			wa += wanum[p[i]];
		}
	}

	cout << ac << ' ' << wa << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = 0; i < (a); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VI a(n);
  set<int> s;
  int count = 0;
  rep(i, n) {
    cin >> a[i];
    if(s.find(a[i]) != s.end()) count++;
    s.insert(a[i]);
  }
  int ans;
  if (count == 0) ans = n;
  else if(count & 1) ans = n - count - 1;
  else ans = n - count;

  out(ans);

  return 0;
}


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

using namespace std;

long MOD = 1000000007;

int main(){
    long H, W, K;
    cin>>H>>W>>K;
    vector<string> S(H);
    vector<vector<int> > a(H);
    for(int i=0; i<H; ++i){
        cin>>S[i];
        a[i].resize(W);
    }

    for(int i=0; i<H; ++i){
        for(int j=0; j<W; ++j){
            a[i][j] = -1;
        }
    }

    int k = 0;
    for(int i=0; i<H; ++i){
        int j=0;
        while(j<W){
            //cout<<j<<endl;
            if(S[i][j] == '#'){
                k += 1;
                a[i][j] = k;
                j++;
                while(j<W && S[i][j] == '.'){
                    a[i][j] = k;
                    j++;
                }
            }else{
                j++;
            }
        }
    }

    int c;
    for(int i=0; i<H; ++i){
        for(int j=W-1-1; j>=0; --j){
            c = a[i][j+1];
            if(a[i][j] == -1){
                a[i][j] = c;
            }
        }
    }

    for(int i=1; i<H; ++i){
        if(a[i][0] == -1){
            for(int j=0; j<W; ++j){
                a[i][j] = a[i-1][j];
            }
        }
    }

    for(int i=H-1-1; i>=0; --i){
        if(a[i][0] == -1){
            for(int j=0; j<W; ++j){
                a[i][j] = a[i+1][j];
            }
        }
    }

    for(int i=0; i<H; ++i){
        for(int j=0; j<W; ++j){
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }

    return 0;
}

Measured memory_bytes: 1280
#!/usr/bin/env python3

# from numba import njit
from collections import Counter
# input = stdin.readline

# @njit
def solve(n,p):
  def primeList(num):
    res = []
    if num == 1:
      return [1]
    f = 2
    while f * f <= num:
      if num % f == 0:
        res.append(f)
        num //= f
      else:
        f += 1
    if num != 1:
      res.append(num)
    return res


  ans = 1
  Lst = primeList(p)
  d = Counter(Lst)
  for k,v in d.items():
    ans *= k**(v//n)
  
  return ans



def main():
  N,P = map(int,input().split())
  print(solve(N,P))
  return

if __name__ == '__main__':
  main()


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

#define rep(i,n) for(int i=0;i<(n);++i)

signed main(){

  int d;
  vector<int> c(26);
  cin>>d;
  for(auto& ci:c)cin>>ci;
  vector<vector<int>> s(d,vector<int>(26));
  for(auto& si:s)for(auto& sij:si)cin>>sij;

  auto calc_satisfaction_level = [&s,&c](int d,int i,auto last){
    int64_t res = s[d][i];
    for(int j=0;j<26;++j){
      if(i==j)continue;
      res -= c[j]*(d-last[j]+1);
    }
    return res;
  };

  //-----------------------------------------------------

  int k = 100;
  vector<vector<int>> last(k,vector<int>(26));
  vector<vector<int>> ans(k,vector<int>(d));
  vector<int64_t> top_k_val(k);

  auto test_all_get_max = [&](int di,auto last){
    // 日付を引数にして全てのコンテストタイプを試してmaxscoreになるタイプを返す
    // 上位k個を返す
    vector<pair<int,int>> valtype_max(26);
    for(int type=0;type<26;++type){
      valtype_max[type] = {calc_satisfaction_level(di,type,last),type};
    }
    sort(begin(valtype_max),end(valtype_max),greater<>());
    valtype_max.erase(begin(valtype_max)+k,end(valtype_max));
    assert(size(valtype_max)==k);
    return valtype_max;
  };

  rep(di,d){
    vector<tuple<int,int,int>> next_top_k;
    next_top_k.reserve(k*26);
    rep(ki,k){
      auto tmp = test_all_get_max(di,last[ki]);
      for(int i=0;i<26;++i)next_top_k.emplace_back(tmp[i].first+top_k_val[ki],tmp[i].second,ki);
    }
    sort(begin(next_top_k),end(next_top_k),greater<>());
    next_top_k.erase(begin(next_top_k)+k,end(next_top_k));
    vector<vector<int>> nxt_last(k,vector<int>(26));
    vector<vector<int>> nxt_ans(k,vector<int>(d));
    vector<int64_t> nxt_top_k_val(k);
    rep(i,k){
      auto [val,type,prv_ki] = next_top_k[i];
      nxt_last[i] = last[prv_ki];
      nxt_last[i][type] = di+1;
      nxt_ans[i] = ans[prv_ki];
      nxt_ans[i][di] = type;
      nxt_top_k_val[i] = val;
    }
    last = nxt_last;
    ans = nxt_ans;
    top_k_val = nxt_top_k_val;
  }

  //-----------------------------------------------------

  for(int i=0;i<d;++i)cout<<ans[0][i]+1<<endl;

}

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

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if (a > b) {
        cout << b*c + (a - b)*d << endl;
    }
    else {
        cout << a*c << endl;
    }
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, X;
    cin >> N >> X;
    ll ans = N;
    vector<ll> M(N);
    rep(i, N) cin >> M[i], X -= M[i];
    sort(M.begin(), M.end());
    ans += X / M.front();
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
N,M,X,Y= list(map(int,input().split()))
x = list(map(int,input().split()))
y= list(map(int,input().split()))

# if not (max(x)<min(y) and X<min(y) and Y>max(x)):
#     print("War")
# else :
#     print('No War')

x_max= max(x)
y_min = min(y)


for Z in range(-100,101):
    if X<Z<=Y and x_max < Z and y_min>=Z:
        print("No War")
        exit()

else:
    print("War")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    Int(n);
    int ans = 0;
    Rep(i, INF) {
        ans += i;
        if (ans >= n) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}



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

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

struct Kadomatsu {
  int a;
  int b;
  int c;
  int mp;
  int size;
};
const int INF = 1e9;

int calc_cost(const Kadomatsu& k, int A, int B, int C) {
  if(k.a == 0 || k.b == 0 || k.c == 0) {
    return INF;
  }
  int mp = k.mp;
  mp += abs(k.a - A);
  mp += abs(k.b - B);
  mp += abs(k.c - C);
  return mp;
}

int main() {
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<int> ls(N);
  for(int i = 0; i < N; ++i) {
    cin >> ls[i];
  }
  queue<Kadomatsu> ks;
  ks.push({0, 0, 0, 0, 0});
  int ans = INF;
  while(!ks.empty()) {
    auto k = ks.front();
    ks.pop();
    if(k.size == N) {
      chmin(ans, calc_cost(k, A, B, C));
      continue;
    }
    int l = ls[k.size];
    ks.push({k.a + l, k.b, k.c, k.mp + (k.a == 0 ? 0 : 10), k.size + 1});
    ks.push({k.a, k.b + l, k.c, k.mp + (k.b == 0 ? 0 : 10), k.size + 1});
    ks.push({k.a, k.b, k.c + l, k.mp + (k.c == 0 ? 0 : 10), k.size + 1});
    ks.push({k.a, k.b, k.c, k.mp, k.size + 1});
  }

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

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

const int INF = (int)1e9;

int n, m;
int l = -INF, r = INF;

int main() {
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        l = max(l, a);
        r = min(r, b);
    }
    cout << max(0, r - l + 1) << endl;
}

Measured memory_bytes: 256
size = gets.to_i
array = gets.split(" ").map(&:to_i)

change_count = 0
(0..(size -1)).each do |i|
  min = i
  (i..(size-1)).each do |j|
    min = j if array[j] < array[min]
  end
  if min != i
    tmp = array[i]
    array[i] = array[min]
    array[min] = tmp
    change_count += 1
  end
end

puts array.join(" ")
puts change_count


Measured memory_bytes: 6860
package main

import (
	"fmt"
)

func main() {

	var A, B, C int
	fmt.Scanf("%d %d %d", &A, &B, &C)

	flag := 0
	if A == B && B != C {
		flag = 1
	}
	if B == C && C != A {
		flag = 1
	}
	if C == A && A != B {
		flag = 1
	}

	if flag == 1 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


Measured memory_bytes: 1832
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INF = 1ll << 60;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << (a - b + 1) * (a - c + 1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e9;

int main(){
  int N,cnt;string S;cin>>N>>S;
  cnt=0;
  REP(i,0,N-2){
    if(S.substr(i,3)=="ABC")cnt++;
  }
  print(cnt)
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
int prime[123457*2];
bool is_prime(int n){
	for(int i=2;i*i<=n;i++){
		if(n%i==0)return false;
	}
	return n!=1;
}
int main(){
	int a,d,n,ans;
	while(cin>>a>>d>>n,a,d,n){
		int cnt=0;
		while(1){
			if(is_prime(a))cnt++;
			if(cnt==n){
				ans=a;
				break;
			}
			a+=d;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <string>
#include <cstring>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#include <tuple>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i < n - 1) {
            ans = max(ans, abs(a[i] - a[i + 1]));
        } else {
            ans = max(ans, k - a[i] + a[0]);
        }
    }
    cout << k - ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> sum(n+1, 0);
    rep(i, n) {
        cin >> a[i];
        sum[i+1] = sum[i] + a[i];
    }
    ll ans = 1e18;
    for (int i = 1; i < n; ++i) {
        //cout << i << " " << abs(sum[i] - (sum[n] - sum[i])) << endl;
        ans = min(ans, abs(sum[i] - (sum[n] - sum[i])));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6380
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

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

int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<char>> hw(h, vector<char>(w));
    rep(i, h) rep(j, w) cin >> hw[i][j];
    vector<int> h_idx;
    vector<int> w_idx;
    rep(i, h) {
        bool flg = true;
        rep(j, w) if ( hw[i][j] == '#' ) flg = false;
        if ( flg ) {
            h_idx.push_back(i);
        }
    }
    rep(j, w) {
        bool flg = true;
        rep(i, h) if ( hw[i][j] == '#' ) flg = false;
        if ( flg ) {
            w_idx.push_back(j);
        }
    }
    rep(i, h) {
        bool h_flg = false;
        for ( auto idx : h_idx ) {
            if ( idx == i ) h_flg = true;
        }
        if ( h_flg ) continue;
        rep(j, w) {
            bool w_flg = false;
            for ( auto idx : w_idx ) {
                if ( idx == j ) w_flg = true;
            }
            if ( h_flg || w_flg ) continue;
            cout << hw[i][j];
        }
        if ( !h_flg ) cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    class BIT:
        def __init__(self,n):
            self.num=n
            self.dat=[0]*(self.num+1)
            self.depth=n.bit_length()
        
        def add(self,i,x):
            i+=1
            while i<=self.num:
                self.dat[i]+=x
                i+=i&-i
        
        def sum(self,i):
            i+=1
            s=0
            while i>0:
                s+=self.dat[i]
                i-=i&-i
            return s
        
        def lower_bound(self,x):
            sum_=0
            pos=0
            for i in range(self.depth,-1,-1):
                k=pos+(1<<i)
                if k<=self.num and sum_+self.dat[k]<x:
                    sum_+=self.dat[k]
                    pos+=1<<i
            return pos, sum_
    
    N,Q=map(int,input().split())
    S,T,X=[0]*N,[0]*N,[0]*N
    for i in range(N):
        S[i],T[i],X[i]=map(int,input().split())
    unique_X=sorted(list(set(X)))
    d={unique_X[i]:i for i,x in enumerate(unique_X)}
    l=[]
    for i in range(N):
        l.append((S[i]-X[i],1,d[X[i]]))
        l.append((T[i]-X[i],-1,d[X[i]]))
    for i in range(Q):
        l.append((int(input()),2,0))
    l.sort(key=lambda t: t[0])
    b=BIT(len(unique_X))
    for t,q,x in l:
        if q==-1:
            b.add(x,-1)
        elif q==1:
            b.add(x,1)
        else:
            res,_=b.lower_bound(1)
            print(unique_X[res] if res<len(unique_X) else -1)
        


if __name__ == '__main__':
    main()


Measured memory_bytes: 132940
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    x,y=map(int, input().split())
    ans=0
    if x<=3:
        ans+=100000
        if x<=2:
            ans+=100000
            if x==1:
                ans+=100000
    if y<=3:
        ans+=100000
        if y<=2:
            ans+=100000
            if y==1:
                ans+=100000
    if x==1 and y==1:
        ans+=400000
    print(ans)

resolve()


Measured memory_bytes: 3060
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            MyDebugger.Test(process, "../TextFile1.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            Console.WriteLine(ret);
#endif
        }
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var a = long.Parse(spl[0]);
        var v = long.Parse(spl[1]);
        spl = input.ReadLine().Split(' ');
        var b = long.Parse(spl[0]);
        var w = long.Parse(spl[1]);
        var t = long.Parse(input.ReadLine());
        
        if(a < b) {
            return (a + v * t) >= (b + w * t) ? "YES" : "NO";
        } else {
            return (a - v * t) <= (b - w * t) ? "YES" : "NO";
        }
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 27464
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// Still trying to be normal
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    ll ans=0;
    cin>>n;
    string s;
    cin>>s;
    vector<ll> posr,posg,posb;
    rep(i,0,sz(s)){
        if(s[i]=='R'){
            posr.push_back(i);
        }
        if(s[i]=='G'){
            posg.push_back(i);
        }
        if(s[i]=='B'){
            posb.push_back(i);
        }
    }
    ll pre[n+2][4];
    memset(pre,0,sizeof pre);
    rep(i,0,sz(s)){
        if(s[i]=='R'){
            pre[i+1][1]++;
        }
        if(s[i]=='G'){
            pre[i+1][2]++;
        }
        if(s[i]=='B'){
            pre[i+1][3]++;
        }
        rep(j,1,4){
            pre[i+1][j]+=pre[i][j];
        }
    }
    // cout<<pre[n+1][3]<<endl;
    rep(i,0,sz(posr)){  /// RG
        rep(j,0,sz(posg)){
            auto i2 = posr[i];
            auto j2 = posg[j];
            if(j2<i2)continue;
            ans+=pre[n][3]-pre[j2+1][3];
            // cout<<ans<<endl;
            if(((j2+(j2-i2)<n) && s[j2+(j2-i2)]=='B'))ans--;
        }
    }
    // cout<<ans<<endl;
    rep(i,0,sz(posr)){ /// RB
        rep(j,0,sz(posb)){
            auto i2 = posr[i];
            auto j2 = posb[j];
            if(j2<i2)continue;
            ans+=pre[n][2]-pre[j2+1][2];
            if(((j2+(j2-i2)<n) && s[j2+(j2-i2)]=='G'))ans--;
        }
    }


    rep(i,0,sz(posb)){/// BG
        rep(j,0,sz(posg)){
            auto i2 = posb[i];
            auto j2 = posg[j];
            if(j2<i2)continue;
            ans+=pre[n][1]-pre[j2+1][1];
            if(((j2+(j2-i2)<n) && s[j2+(j2-i2)]=='R'))ans--;
        }
    }

    rep(i,0,sz(posb)){/// BR
        rep(j,0,sz(posr)){
            auto i2 = posb[i];
            auto j2 = posr[j];
            if(j2<i2)continue;
            ans+=pre[n][2]-pre[j2+1][2];
            if(((j2+(j2-i2)<n) && s[j2+(j2-i2)]=='G'))ans--;
        }
    }

    rep(i,0,sz(posg)){/// GB
        rep(j,0,sz(posb)){
            auto i2 = posg[i];
            auto j2 = posb[j];
            if(j2<i2)continue;
            ans+=pre[n][1]-pre[j2+1][1];
            if(((j2+(j2-i2)<n) && s[j2+(j2-i2)]=='R'))ans--;
        }
    }

    rep(i,0,sz(posg)){/// GR
        rep(j,0,sz(posr)){
            auto i2 = posg[i];
            auto j2 = posr[j];
            if(j2<i2)continue;
            ans+=pre[n][3]-pre[j2+1][3];
            if(((j2+(j2-i2)<n) && s[j2+(j2-i2)]=='B'))ans--;
        }   
    }
    cout<<ans<<'\n';
    return 0;   
}   

Measured memory_bytes: 3808
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())

if int(str(N)[-1]) in [2, 4, 5, 7, 9]:
    print('hon')
elif str(N)[-1] in ['0', '1', '6', '8']:
    print('pon')
else:
    print('bon')


Measured memory_bytes: 9492
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  

//////////

signed main()
{
	fastio;
	int n;
	cin>>n;
	int mo=1000000007;
	int a[n+1]={};
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
	}
	int ans[n+1]={};
	ans[0]=1;
	int f[200001]={};
	for(int i=1;i<=n;++i)
	{
		if(a[i-1]==a[i])
		{
			ans[i]=ans[i-1];
			f[a[i]]=ans[i];
		}
		else
		{
			ans[i]=ans[i-1]+f[a[i]];
			ans[i]%=mo;
			f[a[i]]=ans[i];
		}
	}
	cout<<ans[n]%mo;
}

Measured memory_bytes: 4992