akhauriyash/Code-Regression huggingface dataset:
from math import gcd
from functools import reduce
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))

g=reduce(gcd,a)
if g!=1:
  print("not coprime")
  exit()

def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1: return 0
            t <<= 1
    return 1
def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g): return g
            elif isPrimeMR(n // g): return n // g
            return findFactorRho(g)
def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i*i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += 1 + i % 2
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1: ret[n] = 1
    if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
    return ret
d=defaultdict(int)
for q in a:
  p=primeFactor(q)
  for j in p:
    d[j]+=1

for _,di in d.items():
  if di>=2:
    print("setwise coprime")
    exit()
print("pairwise coprime")


Measured memory_bytes: 184680
import math  # noqa
import bisect  # noqa
import queue  # noqa


if __name__ == '__main__':
    sx, sy, tx, ty = map(int, input().split())

    ans = []

    for _ in range(ty - sy):
        ans.append('U')
    for _ in range(tx - sx):
        ans.append('R')

    for _ in range(ty - sy):
        ans.append('D')
    for _ in range(tx - sx):
        ans.append('L')

    ans.append('L')
    for _ in range(ty - sy):
        ans.append('U')
    ans.append('U')
    ans.append('R')
    for _ in range(tx - sx):
        ans.append('R')
    ans.append('D')

    ans.append('R')
    for _ in range(ty - sy):
        ans.append('D')
    ans.append('D')
    ans.append('L')
    for _ in range(tx - sx):
        ans.append('L')
    ans.append('U')

    print(''.join(ans))


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define esort(s) sort((s).begin(),(s).end())

typedef long long ll;
typedef pair<int,int> ipair;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

int A,B;

void solve(){
    cin>>A>>B;
    if(A>=10||B>=10) cout<<"-1"<<endl;
    else cout<<A*B<<endl;
    return;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}
int main()
{
    int A, B, C;
    cin >> A >> B >> C;

    if (C >= A && C <= B) { cout << "Yes" << endl; }
    else { cout << "No" << endl; }

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
int n;
long long a[1000];
double MAX(double b,double c){
    if(b>c)return b;
    return c;
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    double ans=0;
    for(int i=0;i<n-3;i++){
        ans=MAX((a[n-1]+a[n-2])/(a[i+1]-a[i]+0.0),ans);
    }
    ans=MAX((a[n-1]+a[n-4])/(a[n-2]-a[n-3]+0.0),ans);
    ans=MAX((a[n-3]+a[n-4])/(a[n-1]-a[n-2]+0.0),ans);
    cout<<fixed<<setprecision(10)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	string s, t;
 	cin >> s >> t; 	
 	
 	for(int i = s.size()-1; i >= t.size()-1; i--){
 		if(s[i] == '?' or s[i] == t.back()){
 			bool exist = 1;
 			string str = s;
 			for(int j = 0; j < t.size(); j++){
 				if(s[i-j] != '?' and s[i-j] != t[t.size()-1-j]){
 					exist = 0;
 				} else {
 					str[i-j] = t[t.size()-1-j];
 				}
 			}
 			if(exist){
 				for(int i = 0; i < str.size(); i++){
 					if(str[i] == '?') str[i] = 'a';
 				}
 				cout << str << endl;
 				return 0;
 			}
 		}
 	}
 	cout << "UNRESTORABLE" << endl;
 	return 0;
 }

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

int X, t;

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

  cout << max(X - t, 0) << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int dp[301][301];

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


	int N, M;
	scanf("%d %d", &N, &M);

	int xm[301][4], xM[301][4];
	bool aru[301] = {};
	rep1(i, N) {
		xm[i][1] = N;
		xm[i][2] = N;
		xM[i][2] = -1;
		xM[i][3] = -1;
	}
	rep(i, M) {
		int l, r, x;
		scanf("%d %d %d", &l, &r, &x);
		chmin(xm[r][x], l);
		chmax(xM[r][x], l);
		aru[r] = 1;
	}

	const int mod = 1e9 + 7;
	dp[0][0] = 1;
	rep1(i, N) {
		for (int j = i - 1; j >= 0; j--) for (int k = i - 1; k >= j; k--) {
			dp[j][i] += dp[j][k];
			if (dp[j][i] >= mod) dp[j][i] -= mod;
			dp[k][i] += dp[j][k];
			if (dp[k][i] >= mod) dp[k][i] -= mod;
		}
		if (aru[i]) {
			for (int j = i; j > xm[i][2]; j--) {
				for (int k = i; k >= j; k--) dp[j][k] = 0;
			}
			for (int j = xm[i][2]; j > xM[i][3]; j--) {
				for (int k = i; k > xm[i][1]; k--) dp[j][k] = 0;
				for (int k = xM[i][2]; k >= 0; k--) dp[j][k] = 0;
			}
			for (int j = xM[i][3]; j >= 0; j--) {
				for (int k = i; k >= j; k--) dp[j][k] = 0;
			}
		}
	}

	ll kotae = 0;
	rep(j, N + 1) rep(k, N + 1) {
		kotae += dp[j][k];
	}
	printf("%lld", kotae% mod);

	Would you please return 0;
}

Measured memory_bytes: 512
N = int(input())
L = list(map(int,input().split()))
ans = 1
flag = 0
for i in range(N-1) :
    if flag == 0 :
        if L[i+1]-L[i] > 0 :
            flag = 1
        elif L[i+1]-L[i] < 0 :
            flag = -1
    elif flag == 1 :
        if L[i+1]-L[i] < 0 :
            ans += 1
            flag = 0
    else :
        if L[i+1]-L[i] > 0 :
            ans += 1
            flag = 0
            
print(ans)


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

public class Main {

    private static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException exp) {
                    throw new RuntimeException(exp);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }

    public static void main(String[] args) {    //throws FileNotFoundException {
        InputStream inputStream = System.in;    //new FileInputStream("input.txt");
        OutputStream outputStream = System.out; //new FileOutputStream("output.txt");
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task newTask = new Task();
        newTask.solve(in, out);

        out.close();
    }

    private static class Task {
        //.constant
        private final int INF = Integer.MAX_VALUE;
        private final int MOD = (int)1e9 + 7;

        //.data
        private long[] cntCgtB = new long[100001];

        private int upperBound(Integer[] arr, int x) {
            int l = 0;
            int r = arr.length - 1;
            while (l <= r) {
                int mid = (l + r) >> 1;
                if (arr[mid] > x) {
                    l = mid + 1;
                } else {
                    r = mid - 1;
                }
            }
            return r + 1;
        }

        //.code
        public void solve(InputReader in, PrintWriter out) {
            int n = in.nextInt();
            Integer[][] arr = new Integer[3][n];
            for (int j = 0; j < 3; ++j) {
                for (int i = 0; i < n; ++i) {
                    arr[j][i] = in.nextInt();
                }
            }

            Arrays.sort(arr[2], Comparator.reverseOrder());
            Arrays.sort(arr[1], Comparator.reverseOrder());

            cntCgtB[0] = upperBound(arr[2], arr[1][0]);
            for (int i = 1; i < n; ++i) {
                cntCgtB[i] = cntCgtB[i - 1] + upperBound(arr[2], arr[1][i]);
            }

            long ans = 0;
            for (int i = 0; i < n; ++i) {
                int k = upperBound(arr[1], arr[0][i]) - 1;
                if (k >= 0) {
                    ans += cntCgtB[k];
                }
            }

            out.println(ans);

        }//end

    }

}

Measured memory_bytes: 54788
#include<iostream>
#include<iomanip>

int main(){
        double a,b,c,d,e,f;
        while(std::cin >> a >> b >> c >> d >> e >> f){
                double x, y;
                x = (b*f-e*c)/(b*d-e*a);
                y = (c-a*x)/b;
                if(x == 0) x=0.000;
                if(y == 0) y=0.000;
                std::cout << std::fixed << std::setprecision(3) << x << " " << y << std::endl;
        }
        return 0;
}

Measured memory_bytes: 3232
#define se second
#define sz(x) (int)(x.size())
#define ll long long
#define rep(i,x,y) for(int i = x; i <= y; ++i)
#define repr(i,x,y) for(int i = x; i >= y; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define ull unsigned ll
 
#define pi 3.14159265358979
 
#include <iostream>
 
using namespace std;
 
const int N = (int)(1e6) + 322;
const ll INF = 2e18 + 17;
const int inf = 2e9;
const int mod = 1000000007;
const double eps = 1e-9;
 
int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }
 
int nbr_bits(int a){
	return log2(a)+1;
}
 
 
int binpow(int a, int n, int mod) {
    int res = 1;
    while (n) {
        if (n & 1) {
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
        n >>= 1;
    }
    return res;
}

int fastpow(int a, int n, int mod) {
    if(n==0)
    	return 1;
    if(n%2==0){
    	int res = fastpow(a,n/2,mod);
    	res*=res;
    	res%=mod;
    	return res;
	}
	int res = (fastpow(a,n-1,mod)*a)%mod;
	return res;
    
}
 
// ---------------------------------------------------- 
 
signed main()
{

	int n, k;
	cin >> n >> k;
	int sum = n*3 + k;
	cout << sum / 2 << endl;
	return 0;
}
	

Measured memory_bytes: 3144
#include <iostream>

int main() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    for(long long N,A,B; std::cin >> N >> A >> B; )
        std::cout << ((A>B || (A<B && N<2))? 0: (B-A)*(N-2)+1) << std::endl;
}

Measured memory_bytes: 256
// 154 B

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>
#include <climits>
#include <string>

using namespace std;

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[MAX][MAX];

int prim(){
	int u,minv;
	int d[MAX],p[MAX],color[MAX];
	for (int i = 0; i < n; ++i) {
		d[i]=INFTY;
		p[i]=-1;
		color[i]=WHITE;
	}
	d[0]=0;
	while(1){
		minv=INFTY;
		u=-1;
		for (int i = 0; i < n; ++i) {
			if (minv>d[i]&&color[i]!=BLACK) {
				u=i;
				minv=d[i];
			}
		}
		if(u==-1)break;
		color[u]=BLACK;
		for (int v = 0; v < n; ++v) {
			if(color[v]!=BLACK&&M[u][v]!=INFTY){
				if(d[v]>M[u][v]){
					d[v]=M[u][v];
					p[v]=u;
					color[v]=GRAY;
				}
			}
		}
	}
	int sum=0;
	for (int i = 0; i < n; ++i) {
		if(p[i]!=-1)sum+=M[i][p[i]];
	}
	return sum;
}



int main(){
	cin>>n;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			int e;cin>>e;
			M[i][j]=(e==-1)?INFTY:e;
		}
	}
	cout<<prim()<<endl;
	return 0;
}

Measured memory_bytes: 3052
import bisect

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
A.sort()
C.sort()
for b in B:
    ans += bisect.bisect_left(A, b)*(N-bisect.bisect_right(C, b))
print(ans)

Measured memory_bytes: 23328
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int flag1=0,flag2=0;
	if(s[2]==s[3]){
		flag1=1;
	}
	if(s[4]==s[5]){
		flag2=1;
	}
	if(flag1 && flag2){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    s += s;
    if(s.find(t) != string::npos) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <stack>
#include <map>

const int MaxN = 1e5;
typedef long long LL;
using namespace std;

int n;
int a[MaxN + 5];
int bbb[MaxN + 5];
 
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		bbb[i] = bbb[i - 1] + abs(a[i] - a[i - 1]);
	}
	for(int i = 1; i <= n; i++)
	{
		if(i == n)
		{
			printf("%d\n", bbb[n - 1] + abs(a[n - 1]));
		}
		else
		{
			printf("%d\n", bbb[i - 1] + bbb[n] - bbb[i + 1] + abs(a[i + 1] - a[i - 1]) + abs(a[n]));
		}
	}
	return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a == b){
        cout << "Draw";
        return 0;
    }

    if(a == 1){
        cout << "Alice";
        return 0;
    }else if(b == 1){
        cout << "Bob";
        return 0;
    }
    a>b?cout<<"Alice":cout<<"Bob";
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
//#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 300000;
int mod = 1e9 + 7;
int d[N], l[N], r[N], c[N];
vector < pair < int, int > > events1[N], events2[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++){
        cin >> l[i] >> r[i] >> c[i];
        events1[l[i]].pb({r[i], c[i]});
        events2[r[i] + 1].pb({l[i], c[i]});
    }
    for (int i = 1; i <= n; i++) d[i] = 1e18;
    multiset < int > s;
    d[1] = 0;
    for (auto i: events1[1]) s.insert(d[1] + i.S);
    for (int i = 2; i <= n; i++){
        for (auto j: events2[i]){
            s.erase(s.find(d[j.F] + j.S));
        }
        if (!s.empty()) d[i] = *s.begin(); else{
            cout << -1;
            return 0;
        }
        for (auto j: events1[i]) s.insert(d[i] + j.S);
    }
    cout << d[n];
}


Measured memory_bytes: 31488
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int N, M;

long long int H[100005];

int A[100005], B[100005];

vector<int> Adj[100005];

int check[100005];

int main(void) {

	cin >> N >> M;

	for (int i = 1; i <= N; i++) { cin >> H[i]; }

	for (int i = 1; i <= M; i++) {
		cin >> A[i] >> B[i];
		Adj[A[i]].push_back(B[i]);
		Adj[B[i]].push_back(A[i]);
	}

	for (int i = 1; i <= N; i++) {

		int sign = 1;
		for (auto y : Adj[i]) {
			if (H[y] >= H[i]) { sign = -1; break; }
		}

		if (sign == 1) { check[i] = 1; }
	}

	int ans = 0;

	for (int i = 1; i <= N; i++) {
		if (check[i] == 1) { ans++; }
	}


	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 10708
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX=2e5+10;
vector<int>g[MAX];
ll sub[MAX],ans[MAX];
void dfs(int u,int par)
{
    ans[u]+=sub[u];
    for(int v:g[u])
    {
        if(v==par)continue;
        ans[v]+=ans[u];
        dfs(v,u);
    }
}
int main ()
{
    int N,u,v,Q;cin >> N >> Q;
    for(int i=1;i<=N-1;i++){
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    while(Q--)
    {
        int u,p;cin >> u >> p;
        sub[u]+=p;
    }
    dfs(1,0);
    for(int i=1;i<=N;i++)cout<<ans[i]<<" ";
    return 0;
}


Measured memory_bytes: 25600
"use strict"

const arg_str = require('fs').readFileSync('/dev/stdin', 'UTF-8')
const s = arg_str.split('')

let odd = []
let not_odd = []

s.forEach((item, index)=>{
    // 奇数
    if(index%2==0){
        odd.push(item)
    }else{
        not_odd.push(item)
    }
})

if(odd.indexOf("L") == -1 && not_odd.indexOf("R") == -1){
    console.log("Yes")
}else{
    console.log("No")
}

Measured memory_bytes: 7372
#include<stdio.h>
int main()
{
    int A,B,C,D,i;
    scanf("%d%d%d%d",&A,&B,&C,&D);
    for(i=1;;i++){
        if(i%2){
           C-=B;
           if(C<=0){
              printf("Yes\n");
              break;
           }
        }
        else{
            A-=D;
            if(A<=0){
               printf("No\n");
               break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1648
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,m;
  string s,s2,s3;
  cin>>a;
  cin>>s;
  m=s.length();
  if(m>a)
  {
      for(int i=0;i<a;i++)
      {
         char c=s[i];
         s2.push_back(c);
      }
      s3=s2+"...";
      cout<<s3<<endl;
      return 0;
  }
  else
  {
      cout<<s<<endl;
      return 0;
  }

}

Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
int bsr(int x) { return 31 - __builtin_clz(x); }

struct UnionFind {
    vector<int> ig;
    vector<vector<int>> gi;
    int gn;
    UnionFind(int N) {
        ig.resize(N); gi.resize(N);
        for (int i = 0; i < N; i++) {
            ig[i] = i; gi[i] = {i};
        }
        gn = N;
    }
    void merge(int a, int b) {
        if (same(a, b)) return;
        gn--;
        int x = ig[a], y = ig[b];
        if (gi[x].size() < gi[y].size()) swap(x, y);
        for (int j: gi[y]) {
            ig[j] = x;
        }
        gi[x].insert(gi[x].end(), gi[y].begin(), gi[y].end());
        gi[y].clear();
    }
    bool same(int a, int b) {
        return ig[a] == ig[b];
    }
};


const int MN = 100100;
vector<int> g[MN];

int main() {
    ios::sync_with_stdio(0);
    cout << setprecision(20);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int x;
            cin >> x;
            g[x].push_back(i);
        }
    }
    UnionFind uf(n);
    for (int i = 0; i < MN; i++) {
        int l = int(g[i].size());
        for (int j = 0; j < l; j++) {
            int a = g[i][j];
            int b = g[i][(j+1)%l];
            uf.merge(a, b);
        }
    }
    if (uf.gn == 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


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

void main_()
{
    int N;
    cin >> N;
    vector<int> Hs;
    copy_n(istream_iterator<int>(cin), N, back_inserter(Hs));

    auto ans = "Yes";

    for (auto it0 = rbegin(Hs), it1 = rbegin(Hs) + 1; it1 != rend(Hs); ++it0, ++it1) {
        if (*it1 - *it0 > 1) {
            ans = "No";
            break;
        }
        if (*it1 - *it0 == 1) {
            (*it1)--;
        }
    }

    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 892
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;

int n, q;
long long int t;
long long int a[100000];
int d[100000];
int x[100000];

vector<long long int> v;
const long long int INF = 3e18;

int main(){
	scanf("%d %lld %d", &n, &t, &q);
	for(int i=0; i<n; i++) scanf("%lld %d", &a[i], &d[i]);
	for(int i=0; i<q; i++) scanf("%d", &x[i]);

	v.push_back(-INF);
	bool f = false;
	long long int p;
	for(int i=0; i<n; i++){
		if(d[i] == 1){
			p = a[i];
			f = true;
		}else if(f){
			v.push_back(p / 2 + a[i] / 2);
			f = false;
		}
	}
	v.push_back(INF);

	long long int s;
	for(int i=0; i<q; i++){
		if(d[x[i]-1] == 1){
			s = *upper_bound(v.begin(), v.end(), a[x[i]-1]);
			if(s - a[x[i]-1] < t) printf("%lld\n", s);
			else printf("%lld\n", a[x[i]-1] + t);
		}else{
			s = *(lower_bound(v.begin(), v.end(), a[x[i]-1])-1);
			if(a[x[i]-1] - s < t) printf("%lld\n", s);
			else printf("%lld\n", a[x[i]-1] - t);
		}
	}
/*
	printf("\n");
	for(int i=0; i<v.size(); i++)
		printf("%lld\n", v[i]);
*/	return 0;
}

Measured memory_bytes: 4112
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }


int main() {
    int n;
    cin >> n;
    auto v = make_v(n, n, 0);
    for (auto &&i : v) {
        for (auto &&j : i) {
            scanf("%d", &j);
        }
    }
    vector<vector<int>> t(n+1);
    vector<int> dp(1 << n, 0);
    for (int i = 0; i < (1 << n); ++i) {
        t[__builtin_popcount(i)].emplace_back(i);
    }
    dp[0] = 1;
    for (int p = 0; p < n; ++p) {
        for (auto &&i : t[p]) {
            for (int j = 0; j < n; ++j) {
                if (!(i & (1<<j)) && v[p][j]) {
                    (dp[i | (1<<j)] += dp[i]) %= MOD;
                }
            }
        }
    }
    cout << dp[(1 << n)-1] << "\n";
    return 0;
}


Measured memory_bytes: 18368
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a,vector<vector<ll>> b,int n){
	int i,j,k,t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k]*b[k][j] % M)%M;
			c[i].push_back(t);
		}
	}
	return c;
}
int main() {
	int k, i, p=1;
	char s[111];
	cin >> s >> k;
	for (i = 0; s[i] != '\0'&&i < k; i++) {
		if (s[i] != '1') {
			p = s[i] - '0';
			break;
		}
	}
	cout << p << endl;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

// 素数判定
int isprime(int a) {
  int i;
  
  if (a == 2) return 1;
  if (a < 2 || (a % 2 == 0)) return 0;
  
  i = 3;
  while (i <= sqrt(a)) {
    if (a % i == 0) return 0;
    i = i + 2;
  }
  
  return 1;
}

int main () {
  int *a, i, j, n, cnt;
  
  // 動的配列の生成
  scanf("%d", &n);
  a = (int *)malloc(sizeof(int) * n);
  
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  cnt = n;
  
  for (j = 0; j < n; j++) {
    if (!isprime(a[j])) cnt--;
  }
  
  printf("%d\n", cnt);
  
  return 0;
}

Measured memory_bytes: 624
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctime>
#include<queue>
#include<set>

using namespace std;
using ll = long long;

struct UnionFind {
  vector<int> par;//parent

  vector<int>nodes;

  UnionFind(int N): par(N), nodes(N)
  {
    for(int i = 0; i < N; i++){
      par[i] = i;
      nodes[i] = 1;
    }
  }

  int root(int x) {//find the root and path compression
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    nodes[ry] += nodes[rx];
    par[rx] = ry;
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }

};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start--------------------
  ll n, m, k; cin >> n >> m >> k;
  vector<ll> ans(n, 0);
  UnionFind uf = (n);
  vector<ll> s(n, 0);
  for(int i = 0; i < m ; i++){
    int a, b;
    cin >> a >> b;
    a--, b--;
    if(!uf.same(a, b)) uf.unite(a, b);
    ans[a]--; ans[b]--;
  }
  for(int i = 0; i < n; i++){
    ans[i] += uf.nodes[uf.root(i)]-1;
  }
  for(int i = 0; i < k; i++){
    int a, b;
    cin >> a >> b;
    a--, b--;
    if(uf.same(a, b)) ans[a]--, ans[b]--;
  }
  for(int i = 0; i < n; i++) cout << ans[i] << ' ';
  cout << endl;
  // end-----------------------------------------------
  cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 3584
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
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;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    // char ;
    ll h,w,ans=INF;
    scanf("%lld%lld",&h,&w);
    if(h%3==0 || w%3==0){
        printf("0\n");
        return 0;
    }
    if(h%2){
        rep(i,1,w){
            ll s[3]={h*i,(h/2+1)*(w-i),h/2*(w-i)};
            sortup(s,3);
            // if( ans < s[2]-s[0] ) break;
            ans= min2(ans,s[2]-s[0] );
            // printf("%lld ",ans);
        }
    }else{
        rep(i,1,w){
            // if( ans < ABS(h*i-h/2*(w-i)) ) break;
            ans= min2(ans,ABS(h*i-h/2*(w-i))) ;
        }
    }
    if(w%2){
        rep(i,1,h){
            ll s[3]={w*i,(w/2+1)*(h-i),w/2*(h-i)};
            sortup(s,3);
            ans= min2( ans , s[2]-s[0] );
            // printf("%lld ",ans);
        }
    }else{
        rep(i,1,h){
            ans= min2( ans , ABS(w*i-w/2*(h-i)) );
        }
    }
    ans = min2(ans,h);
    ans=min2(ans,w);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

void main(){
	string s = readln.chomp;
	
	
	
	long ans;
	for(long x = 0; x < 2 ^^ (s.length - 1); x ++){
		long a = 0, tmp = ("" ~ s[0]).to!long;
		for(int i = 0; i < s.length - 1; i ++){
			if(x & 2 ^^ i){
				tmp *= 10, tmp += ("" ~ s[i + 1]).to!long;
				}
			else{
				a += tmp, tmp = ("" ~ s[i + 1]).to!long;
				}
			}
		if(tmp > 0) a += tmp, tmp = 0;
		ans += a;
		}
	
	ans.writeln;
	}

Measured memory_bytes: 380
#include "bits/stdc++.h"
using namespace std;
#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 ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    ll c=0,d=0,n,m,ans=0;
    string s,s2;
    cin >> n >> m >> c;
    VVI a(n,vector<int>(m));
    VI b(m);
    for(int j=0;j<m;j++)
        cin >> b[j];

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
            cin >> a[i][j];
    }
    for(int i=0; i<n;i++){
        for(int j=0;j<m;j++){
            d += a[i][j] * b[j];
        }
        if(d+c > 0){
           ans++; 
        }
        d=0;
    }
    cout << ans <<endl;
    return 0;
}


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

int main(void)
{
    int n, k;
    scanf("%d%d", &n, &k);
    int ans = 0;
    while (n > 0)
    {
        n /= k;
        ++ans;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define INF 99999999
#define x first
#define y second

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;

int main(){
	int d,g,p[11],c[11];
	cin >> d >> g;
	g /= 100;
	rep(i,d){
		cin >> p[i] >> c[i];
		c[i] /= 100;
	}
	int  ans = INF;
	rep(i,1<<d){
		int cnt = 0,point = g;
		rep(j,d){
			if(i&(1<<j)){
				cnt += p[j];
				point -= p[j]*(j+1)+c[j];
			}
		}
		int j = d - 1;
		while(point > 0 && j >= 0){
			if(!(i&(1<<j))){
				int tmp_p = min(point/(j+1), p[j] - 1);
				cnt += tmp_p;
				point -= tmp_p * (j+1);
			}
			j--;
		}
		
	//	cout << cnt <<" " <<  point << endl;
		if(point <= 0){
			ans = min(ans, cnt);
		}
	}
	cout << ans << endl;
	return 0;
}



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

void exc( int& x, int& y ) {
    int buf;
    buf = x;
    x = y;
    y = buf;
}

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if( b < a ) exc( b, a );
    if( c < b ) exc( c, b );
    if( b < a ) exc( b, a );
    cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 1164
N = int(input())
ABC = [list(map(int, input().split())) for _ in range(N)]
# dp[i][j] i日目にjをする 0:a 1:b 3:c
dp = [[0] * 3 for _ in range(N)]

# 初期化
for j in range(3):
    dp[0][j] = ABC[0][j]

# 緩和
for i in range(1, N):
    a, b, c = ABC[i]
    dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a)
    dp[i][1] = max(dp[i - 1][0] + b, dp[i - 1][2] + b)
    dp[i][2] = max(dp[i - 1][1] + c, dp[i - 1][0] + c)
print(max(dp[-1]))


Measured memory_bytes: 78296
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;

#define debug(x) cerr<<#x<<'='<<x<<'\n'

char s[233], t[233];
char ans[233], tmp[233];

int main(void) {
	scanf("%s%s", s+1, t+1);
	int ls=strlen(s+1);
	int lt=strlen(t+1);
	for (int i=1; i<=ls; i++) {
		for (int j=1; j<=lt; j++) {
			if (s[i-1+j]!=t[j] && s[i-1+j]!='?') break;
			if (j==lt) {
				for (int k=1; k<=ls; k++) {
					if (i<=k && k<=i-1+lt) {
						tmp[k]=t[k-i+1];
						continue;
					}
					tmp[k] = s[k]=='?' ? 'a' : s[k];
				}
				bool flag=false;
				for (int k=1; k<=ls; k++) {
					if (tmp[k]==ans[k]) continue;
					if (tmp[k]<ans[k] || ans[k]=='\0') {
						flag=true;
						break;
					}
				}
				if (flag) {
					for (int k=1; k<=ls; k++) {
						ans[k]=tmp[k];
					}
				}
			}
		}
	}
	if (strlen(ans+1)) {
	    for (int i=1; i<=ls; i++) {
	   	    putchar(ans[i]);
	    }
    } else {
	    puts("UNRESTORABLE");
    }
}

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

using P = pair<int, int>;

int n, m;
vector<P> v;
vector<int> r;
priority_queue<int, vector<int>, greater<int>> pq;

int solve();

int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    v.emplace_back(a, b);
  }
  sort(v.begin(), v.end());
  cout << solve() << endl;
  return 0;
}
int solve() {
  int res = 0, cnt = 0, len = v.size();
  for (int i = 0; i < len; ++i) {
    pq.push(v[i].second);
    if (pq.size() > v[i].first) {
      r.push_back(pq.top());
      pq.pop();
    }
  }
  sort(r.begin(), r.end(), greater<int>());
  for (auto &p : r) p = m + 1 - p;
  len = r.size();
  for (int i = 0; i < len; ++i)
    if (++cnt > r[i]) ++res, --cnt;
  res += max((int)pq.size() + cnt - m, 0);
  return res;
}

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

void program(); 
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    program();
}

#define INF 0x7fffffffffffffff
#define UINF 0xffffffffffffffff
#define MOD 1000000007

#define int long long
#define unsigned unsigned long long
#define double long double

#define endl "\n"

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

class UF{
public:
    int n;
    vector<int> par, sz;
    UF(int size) : n(size), par(size), sz(size){
        for(int i=0; i<n; i++){
            par[i] = i;
            sz[i] = 1;
        }
    }
    void join(int x, int y){
        if ((x = find(x)) == (y = find(y))) return;
        if (sz[y] < sz[x]) std::swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        sz[x] = 0;
    }
    int find(int x){ return par[x] = (x == par[x] ? x : find(par[x])); }
    bool connected(int x, int y){ return find(x) == find(y); }
};

template<class Iter> void _print_range(ostream& o, Iter s, Iter e){
    for(;s != e;s++) o << *s << " ";
    o << endl;
} 
template<class T> std::ostream& operator<<(ostream& o, const std::vector<T> &ds)
{
    _print_range(o,ds.begin(),ds.end()); 
    return o;
}
template<class T> std::ostream& operator<<(ostream& o, const std::set<T> &ds)
{
    _print_range(o,ds.begin(),ds.end()); 
    return o;
}
template<class T, class U> std::ostream& operator<<(ostream& o, const std::pair<T,U> &ds)
{
    o << "<" << ds.first << "," << ds.second << ">" << endl;
    return o;
}
template<typename ...Args>
void print(Args&&... args) {
    for(auto&& x: {args...})
        cout << x << " ";
    cout << endl;
}

#define debug(x) cout << "DEBUG    " <<  #x << ": " << x << endl;

#define fr(i, a, b) for(int i = a; i != (b); i += (a<b ? 1 : -1))
#define rep(i, a) for(int i = 0; i < (a); i++)

#define trav(x, a) for(auto& x : a)
#define all(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define vi vector<int>
#define si set<int>
#define pii pair<int,int>




#define N 100005
int a[3][N], dp[3][N];
void program(){
    int n;
    cin>>n;
    rep(i,n){
        for(int j=0;j<3;j++){
            int v;
            cin>>v;
            a[j][i] = v;
        }
    }
    memset(dp,0,3*N*sizeof(int));
    for(int j=0;j<3;j++)
        dp[j][0] = a[j][0];
    for(int i=1;i<n;i++)
        for(int j=0;j<3;j++)
            for(int J=0;J<3;J++) if(j!=J)
                dp[j][i] = max(dp[j][i], a[j][i]+dp[J][i-1]);
    cout << max({dp[0][n-1],dp[1][n-1],dp[2][n-1]}) << endl;
}

/*
WA:
-bounds on loops
-truncating
-intialization
-0 vs 1 indexing

TLE:
-might need unordered_set/map
-infinite while loop

Stuck:
-bruteforce?
-reduce dimensionality with problem contraints?
*/


Measured memory_bytes: 4992
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define vv vector
#define pp pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define fastio                    \
	ios_base::sync_with_stdio(0); \
	cin.tie(0);
typedef pair<ll, ll> pll;
typedef vv<ll> vll;
typedef vv<pll> vpll;
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//adds two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set]
//(2)set.order_of_key(k)[count of elements strictly less than k]
#define LG(args...)                               \
	{                                             \
		string _s = #args;                        \
		replace(_s.begin(), _s.end(), ',', ' ');  \
		stringstream _ss(_s);                     \
		err(istream_iterator<string>(_ss), args); \
		cerr << endl;                             \
	}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "(" << *it << ":" << a << ") ";
	err(++it, args...);
}
//:::::::::::::::::::::::::::::::::::::::::::::
const ll INF = 9e18;
const ll MOD = 1e9 + 7;
// #define dbg

string s, t, ans;

int main() {
	fastio;
	cin >> s >> t;
	ll n, m;
	n = s.size(), m = t.size();
	s = '@' + s;
	t = '#' + t;
	/* s[i] == t[j]
		dp[i][j] = 1+dp[i-1][j-1];
		else
		dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
	*/

	// dp[i][j] is the length of maxsubsequence of strings
	// s(0...i) and t[0..j]

	vv<vll> dp(n + 1, vll(m + 1, 0));

	for (ll i = 1; i <= n; i++) {
		for (ll j = 1; j <= m; j++) {
			if (s[i] == t[j])
				dp[i][j] = 1 + dp[i - 1][j - 1];
			else
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}

	// for(ll i=0; i<n; i++){
	// 	for(ll j=0; j<m; j++){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	// for (ll i = 2; i <= n; i++) {
	// 	for (ll j = 2; j <= n; j++) {
	// 		if (dp[i][j] == dp[i - 1][j - 1] + 1) {
	// 			LG(i, j)
	// 			assert(s[i] == t[j]);
	// 		}
	// 	}
	// }
	// the above assertion can fail

	ll i = n, j = m;
	while (i > 0 && j > 0) {
		if (s[i] == t[j]) {
			ans.push_back(s[i]);
			i--;
			j--;
		} else if (dp[i - 1][j] > dp[i][j - 1])
			i--;
		else
			j--;
	}
	reverse(all(ans));
	cout << ans << endl;
}

Measured memory_bytes: 73680
#include<stdio.h>
int main(void){
	int mi[1000],mo[1000],li[1000],lo[1000],pcsum,msum,r,q,time,m,sw,ts,te,i,j,k,s,cnt,ans,tx,flag;
	while(1){
		scanf("%d %d",&pcsum,&msum);
		if(pcsum==0&&msum==0){
			break;
		}
		for(i=0;i<1000;i++){
			mi[i]=0;
			mo[i]=0;
		}
		scanf("%d",&r);
		j=k=0;
		while(r!=0){
			scanf("%d %d %d %d",&time,&i,&m,&sw);
			if(sw==1){
				mi[j]=time+m*10000;
				j++;
			}
			else if(sw==0){
				mo[k]=time+m*10000;
				k++;
			}
			r--;	
		}
		scanf("%d",&q);
		while(q!=0){
			scanf("%d %d %d",&ts,&te,&m);
			for(i=0;i<1000;i++){
				li[i]=0;
				lo[i]=0;
			}
			i=0;
			cnt=0;
			while(cnt!=j){
				if(mi[cnt]/10000==m){
					li[i]=mi[cnt]%10000;
					i++;
				}
				cnt++;
			}
			i=0;
			cnt=0;
			while(cnt!=k){
				if(mo[cnt]/10000==m){
					lo[i]=mo[cnt]%10000;
					i++;
				}
				cnt++;
			}
			tx=540;
			flag=0;
			i=s=0;
			ans=0;
			while(tx<=1260){
				if(li[i]==tx){
					while(1){
						flag++;
						i++;
						if(li[i]!=tx){
							break;
						}
					}
				}
				if(lo[s]==tx){
					while(1){
						flag--;
						s++;
						if(lo[s]!=tx){
							break;
						}
					}
				}
				if(flag>0&&tx>=ts&&tx<te){
					ans++;
				}
				tx++;
			}
			printf("%d\n",ans);
			q--;
		}
	}
	return 0;
}

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

int main(){
    ll n, m, t;
    vector<ll> a, b, c;
    cin >> n;
    for(ll i = 0; i < n; i++){
        cin >> t;
        a.push_back(t);
    }
    cin >> m;
    for(ll i = 0; i < m; i++){
        cin >> t;
        b.push_back(t);
    }
    set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(c));
    for(auto i = c.begin(); i != c.end(); i++){
        cout << *i << endl;
    }
    return 0;
}



Measured memory_bytes: 10100
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	string s, t;
	cin >> s >> t;
	int n = (int)s.length();
	vector<int> a(n), b(n), p(256, -1), q(256, -1);
	int si = 0, pi = 0;
	for (int i = 0; i < n; ++i) {
		char c = s[i];
		if (p[c] < 0) {
			p[c] = si++;
		}
		a[i] = p[c];
		c = t[i];
		if (q[c] < 0) {
			q[c] = pi++;
		}
		b[i] = q[c];
	}
	bool ans = a == b;
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


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

using namespace std;
typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
      cin.tie(0);
      ios::sync_with_stdio(false);

      int N;
      cin >> N;
      vector<int> a (N);
      for(int i = 0;i < N;i++){
          cin >> a[i];
      }

      vector<int> put (N,0);
      vector<int> ans;
      int sum_ans = 0;
      for(int i = N;i > 0;i--){
//          cout << "Mission = " << a[i-1] << endl;
          int sum = 0;
          for(int j = 2;i*j <= N;j++){
//              cout << i*j << "=" << put[i*j-1] << endl;
              sum += put[i*j-1];
          }
          if(a[i-1] != sum%2){
              put[i-1] = 1;
//              cout << "sum = " << i << endl;
              ans.push_back(i);
              sum_ans++;
          }
      }

      cout << sum_ans << endl;

      for(int i = 0;i < sum_ans;i++){
          cout << ans[i];
          if(i != sum_ans-1){
              cout << " ";
          }
      }
}


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

int main(void)
{
	int N;
	cin >> N;
	int tmp;
	int count = 0;
	vector<int>vec;
	for (int i = 0; i < N; i++)
	{
		cin >> tmp;
		vec.push_back(tmp);
	}

	sort(vec.begin(), vec.end());
	for (int i = 0; i < N - 1; i++)
	{
		if (vec[i] == vec[i + 1])
		{
			count++;
		}
	}
	int num = vec.size() - count;
	cout << num;
}

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;


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

	int a,b;cin>>a>>b;

	if(a <= 2*b){
		writeln(0);
	}else {
		writeln(a-b*2);
	}

}




Measured memory_bytes: 256