akhauriyash/Code-Regression huggingface dataset:
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N-1)]
sortedAB = sorted(AB)
con = {i: [] for i in range(1, N+1)}
color = [0] * (N + 1)
for a, b in sortedAB:
    con[a].append(b)

for i in range(1, N + 1):
    now_c = 1
    for c in con[i]:
        if color[i] == now_c:
            now_c += 1
        color[c] = now_c
        now_c += 1

print(max(color))
for i in range(N-1):
    print(color[AB[i][1]])

a = 0

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

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Set<String> set = new HashSet<>();
        int n = Integer.parseInt(br.readLine());
        String[] str = new String[n];
        for(int i=0; i<n; ++i)
            str[i] = br.readLine();
        Arrays.sort(str);
        set.addAll(Arrays.asList(str));
        System.out.println(set.size());
    }
}


Measured memory_bytes: 66812
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
long long computeXOR(long long n) 
{ 
    // Modulus operator are expensive on most of the  
    // computers. n & 3 will be equivalent to n % 4.    
  
    switch(n & 3) // n % 4  
    { 
    case 0: return n;     // if n is multiple of 4 
    case 1: return 1;     // If n % 4 gives remainder 1   
    case 2: return n + 1; // If n % 4 gives remainder 2     
    case 3: return 0;     // If n % 4 gives remainder 3   
    } 
} 
using namespace std;
int main()
{
    Senky_Bansal
    IIIT_ALLAHABAD
     ll a,b;
     cin>>a>>b;
     ll p=(computeXOR(b));
     ll q=(computeXOR(a-1));
     cout<<(p^q)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
  char c[1000000];
  cin>>c;
  int a[29];
  for(int i=0;i<29;i++){
   a[i]=0;   
  }
  for(int i=0;i<strlen(c);i++){
      a[c[i]-'a'+1]++;
  }
  int k=0;
  for(int i=0;i<26;i++){
   if(a[i+1]==0){
      
       char d='a'+i;
       cout<<d;
       
       k=1;
       break;
   }
  }
  if(k==0){
   cout<<"None";   
  }
}

Measured memory_bytes: 384
<?php
fscanf(STDIN, '%s', $input);
$steps = str_split($input);
$length = count($steps);

$valid = true;

for ($i=0; $i < $length; $i++) { 
    $check = $steps[$i];
    if ($check === 'U' || $check === 'D') {
        continue;
    }
    if ($i % 2 === 0 && $check !== 'R') {
        $valid = false;
        break;
    } elseif ($i % 2 !== 0 && $check !== 'L') {
        $valid = false;
        break;
    }   
}
echo $valid ? 'Yes' : 'No';
echo "\n";

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<ll, ll> ll_ll;
typedef pair<double, int> d_i;
const int MOD = 1e9 + 7;
const ll INF = LLONG_MAX / 10;
struct edge { int v, w; };

int main() {
	int N; cin >> N;
	vector<ll> x(N), y(N);
	rep(i, N) cin >> x[i] >> y[i];
	double pi = acos(-1);
	rep(i, N) {
		vector<double> a;
		rep(j, N) if (j != i) a.pb(atan2(y[j] - y[i], x[j] - x[i]));
		sort(a.begin(), a.end());
		rep(i, N - 1) a.pb(a[i] + pi * 2);
		sort(a.begin(), a.end());
		double ma = 0;
		for (int i = 0; i + 1 < (N - 1) * 2; i++)
			ma = max(ma, a[i + 1] - a[i]);
		ma = max(0.0, ma - pi);
		printf("%.15f\n", ma / pi / 2);
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;

int N,T;

struct Edge{
	int a,b,t,m,v;
	Edge(){}
	Edge(int a,int b,int t,int m,int v) : a(a), b(b), t(t), m(m), v(v) {}
};
vector<Edge> g[310];
vector<int> seg;
vector<int> rev;
int gen_seg(int x,int p){
	seg.push_back(x);
	rev.push_back(0);
	for(int i = 0 ; i < g[x].size() ; i++){
		if( g[x][i].b != p ) gen_seg(g[x][i].b,x);
	}
	if( p != -1 ) seg.push_back(p) , rev.push_back(1);
}
vector<int> pos[310];

vector<Edge> G[310];

long long dp[610][10010] = {};
long long dp2[10010] = {};

map< pair<int,int> , Edge > info;



int main(){
	for(int i = 0 ; i < 610 ; i++)
		for(int j = 0 ; j < 10010 ; j++)
			dp[i][j] = -1e12;
	
	cin >> N >> T;
	for(int i = 0; i < N-1 ; i++){
		int a,b,t,m,v;
		cin >> a >> b >> t >> m >> v;
		a--,b--;
		g[a].push_back(Edge(a,b,t,m,v));
		g[b].push_back(Edge(b,a,t,m,v));
		info[make_pair(a,b)] = info[make_pair(b,a)] = Edge(a,b,t,m,v);
	}
	gen_seg(0,-1);
	for(int i = 0 ; i < seg.size() ; i++)
		pos[seg[i]].push_back(i);
	dp[0][0] = 0;
	for(int i = 0 ; i+1 < seg.size() ; i++){
		Edge e = info[make_pair(seg[i],seg[i+1])];
		if( rev[i+1] ){
			for(int j = 0 ; j <= T ; j++){
				dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
			}
		}else{
			// use
			int m = e.m / 2, v = e.v * 2, t = e.t * 2;
			for(int j = 0 ; j <= T ; j++) dp2[j] = -1e12;
			if( m > 0 ){
				//ikkai ugoku
				m--;
				for(int j = t ; j <= T ; j++) dp2[j] = dp[i][j-t]+v;
				if(e.m%2){
					for(int j = T ; j >= 2*e.t ; j--){
						dp2[j] = max(dp2[j],dp2[j-2*e.t]+e.v);
					}
				}
			}else{
				// ikkai ugoku
				if(e.m%2)
					for(int j = 2*e.t ; j <= T ; j++) dp2[j] = dp[i][j-2*e.t]+e.v;
			}
			// muda ni move
			for(int j = t ; j <= T ; j++)
				dp2[j] = max(dp2[j],dp[i][j-t]);
				
			for(int k = 1; m > 0 ; k *= 2 ){
				int wei = min(m,k);
				int VV = v * wei;
				int TT = t * wei;
				for(int j = T ; j >= TT ; j--){
					dp2[j] = max(dp2[j],dp2[j-TT]+VV);
				}
				m -= wei;
			}
			
			for(int j = 0 ; j <= T ; j++)
				dp[i+1][j] = max(dp[i+1][j],dp2[j]);
			
			// unuse
			int next = *upper_bound(pos[seg[i]].begin(),pos[seg[i]].end(),i);
			for(int j = 0 ; j <= T ; j++){
				dp[next][j] = max(dp[next][j],dp[i][j]);
			}
		}
	}
	cout << *max_element(dp[seg.size()-1],dp[seg.size()-1]+T+1) << endl;
	
	
	
	
}

Measured memory_bytes: 49112
import sys
from math import factorial


def main(S):
    pass


if __name__ == '__main__':
    A = []
    B = [0] * 9
    for i in range(3):
        A += list(map(int, input().split()))
    n = int(input())

    for i in range(n):
        tmp = int(input())
        for j in range(9):
            if A[j] == tmp:
                B[j] = 1
    ans = 0
    for i in range(3):
        if (B[0 + 3 * i] == 1 and B[1 + 3 * i] == 1 and B[2 + 3 * i] == 1):
            ans = 1
    for i in range(3):
        if (B[0 + i] == 1 and B[3 + i] == 1 and B[6 + i] == 1):
            ans = 1
    if (B[0] == 1 and B[4] == 1 and B[8] == 1):
        ans = 1
    if (B[2] == 1 and B[4] == 1 and B[6] == 1):
        ans = 1

    if (ans == 1):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,a[100005],ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n-1;i++)
		cin>>a[i];
	for(int i=1;i<=n-1;i++)
		ans+=min(a[i],a[i+1]);
	cout<<ans+a[n-1]+a[1];
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 
char a[25][25];
ll vis[25][25];
ll d[25][25],lev[25][25];
ll N,M,INF=1e10;
void clean()
{
	for(ll i=1;i<=N;i++)
	{
		for(ll j=1;j<=M;j++)
		{
			vis[i][j]=0,d[i][j]=0;
		}
	}
}

void bfs(ll i,ll j)
{
	queue<pll>Q;
	Q.push(mp(i,j));
	vis[i][j]=1;

	while(!Q.empty())
	{
		pll P=Q.front();
		Q.pop();

		if(P.ff-1>=1 && !vis[P.ff-1][P.ss] && a[P.ff-1][P.ss]=='.')
		{
			d[P.ff-1][P.ss]=d[P.ff][P.ss]+1;
			Q.push(mp(P.ff-1,P.ss));
			vis[P.ff-1][P.ss]=1;
		}
		if(P.ff+1<=N && !vis[P.ff+1][P.ss] && a[P.ff+1][P.ss]=='.')
		{
			d[P.ff+1][P.ss]=d[P.ff][P.ss]+1;
			Q.push(mp(P.ff+1,P.ss));
			vis[P.ff+1][P.ss]=1;
		}
		if(P.ss-1>=1 && !vis[P.ff][P.ss-1] && a[P.ff][P.ss-1]=='.')
		{
			d[P.ff][P.ss-1]=d[P.ff][P.ss]+1;
			Q.push(mp(P.ff,P.ss-1));
			vis[P.ff][P.ss-1]=1;
		}
		if(P.ss+1<=M && !vis[P.ff][P.ss+1] && a[P.ff][P.ss+1]=='.')
		{
			d[P.ff][P.ss+1]=d[P.ff][P.ss]+1;
			Q.push(mp(P.ff,P.ss+1));
			vis[P.ff][P.ss+1]=1;
		}
	}
}

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	cin >> n >> m;
	N=n,M=m;
	for(i=1;i<=n;i++)
	{
		string s;
		cin >> s;
		for(j=1;j<=m;j++)
			a[i][j]=s[j-1];
	}
	ll ans=0;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			for(k=1;k<=n;k++)
			{
				for(ll p=1;p<=m;p++)
				{
					if(a[i][j]=='.')
					{
						clean();
						bfs(i,j);
						if(vis[k][p])
							ans=max(ans,d[k][p]);
					}
				}
			}
		}
	}
	cout<<ans<<endl;
}

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

int main() {
    int x, y;
    cin >> x >> y;
    string s = "No";
    erep(turu, 100) {
        erep(kame, 100) {
            if (turu + kame == x) {
                if (turu * 2 + kame * 4 == y) {
                    s = "Yes";
                }
            }
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 3572
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
const long long md=1e9+7;
long long n,k,a[101010],pw[101010],mx,mn;
bool vis[101010];
vector<int>pr;
int mp[101010];
int main()
{
	for(int i=2;i<100101;++i)
	{
		if(!vis[i])
		{
			pr.push_back(i);
			for(int j=i+i;j<100101;j+=i)
			{
				vis[j]=true;
			}
		}
	}
	cin>>n>>k;/*
	for(int i=2;i<k;++i)
	{
		int x=i;
		for(int j=0;j<pr.size();++j)
		{
			if(x==1)
			{
				break;
			}
			if(x%pr[j]!=0)
			{
				continue;
			}
			while(x%pr[j]==0)
			{
				++jian[pr[j]];
				++mp[pr[j]];
				x/=pr[j];
			}
		}
	}*/
	for(int i=k;i<=n;++i)
	{
		pw[i]=1;
		for(int j=0;j<pr.size();++j)
		{
			long long x=pr[j]*1ll;
			if(mp[x])
			{
				int now=mp[x];
				long long ans=1;
				while(now)
				{
					if(now&1==1)
					{
						ans*=x*1ll;
						ans%=md;
					}
					x*=x;
					x%=md;
					now>>=1;
				}
				pw[i]*=ans;
				pw[i]%=md;
			}
		}
		int x=i;
		for(int j=0;j<pr.size();++j)
		{
			if(x==1)
			{
				break;
			}
			if(x%pr[j]!=0)
			{
				continue;
			}
			while(x%pr[j]==0)
			{
				++mp[pr[j]];
				x/=pr[j];
			}
		}
		x=i-k+1;
		for(int j=0;j<pr.size();++j)
		{
			if(x==1 || x==0)
			{
				break;
			}
			if(x%pr[j]!=0)
			{
				continue;
			}
			while(x%pr[j]==0)
			{
				--mp[pr[j]];
				x/=pr[j];
			}
		}
	}/*
	for(int i=1;i<=n;i++)
	{
		cout<<pw[i]<<endl;
	}*/
	for(int i=1;i<=n;++i)
	{
		scanf("%lld",&a[i]);
	}
	sort(a+1,a+n+1);
	for(int i=k;i<=n;++i)
	{
		mx+=a[i]*pw[i]%md;
		mx%=md;
	}
	reverse(a+1,a+n+1);
	for(int i=k;i<=n;++i)
	{
		mn+=a[i]*pw[i]%md;
		mn%=md;
	}
	cout<<(mx-mn+md)%md<<endl;
	return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include<string.h>
#include<math.h>
using namespace std;

int main() {
	int N, L, n[200], min, SUM = 0;
	cin >> N >> L;
	min = L;
	for (int i = 0; i < N; i++) {
		n[i] = L + i;
		SUM += n[i];
		if (abs(min) > abs(n[i]))min = n[i];
	}
	cout << SUM - min << endl;
		return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0582?year=2006>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    vector<ll> ans(4);
    
    ll a,b,c;
    while(cin >> a >> b >> c){
        vector<ll> abc = {a,b,c};
        sort(abc.rbegin(),abc.rend());
        a = abc[0]; b = abc[1]; c = abc[2];
        
        if(b+c>a){
            ans[0]++;
            
            if(a*a == b*b+c*c){
                ans[1]++;
            }else if(a*a > b*b + c*c){
                ans[3]++;
            }else{
                ans[2]++;
            }
        }else{
            cout << ans << endl;
            break;
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    // cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}



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

int main(){
    string S;
    string result = "Yes";
    cin >> S;

    for(int i=0; i<S.size(); i++){
        if(i%2==0){
            if(S[i]!='R' && S[i]!='U' && S[i]!='D'){
                result = "No";
            }
        }
        else{
            if(S[i]!='L' && S[i]!='U' && S[i]!='D'){
                result = "No";
            }
        }
    }

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
	char Ans[256]={};
	for(int i=0;i<3;i++){
		char Temp[256]={};
		scanf(" %s",Temp);
		Ans[i]=Temp[0]+('A'-'a');
	}
	Ans[3]=NULL;
	printf("%s\n",Ans);
	return 0;
}

Measured memory_bytes: 128
import itertools
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
p=list(map(int,input().split()))
sss=0
for c in itertools.product([0,1],repeat=n):
  ans=0
  for i in range(m):
    cnt=0
    for j in range(l[i][0]):
      if c[l[i][j+1]-1]==1:
        cnt+=1
    if cnt%2==p[i]:
      ans+=1
  if ans==m:
    sss+=1
print(sss)

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

int main()
{
	int k,panjangstring; string s;
	cin >> k;
	cin >> s;
	panjangstring = s.size();
	if(panjangstring <= k){
		cout << s << endl;
	}else
	{
		for(int i = 0;i<k;i++)
		{
		cout << s[i];
		}
		cout << "..." << endl;
	}
	return 0;
}


Measured memory_bytes: 3628
import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		int a = sc.nextInt(); int b = sc.nextInt();
		System.out.println((a/b)+" "+(a%b)+" "+(String.format("%.6f",(double)a/(double)b)));
		
	}
}


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

public class Main {
	static final int MOD = (int)1e9+7;

	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		int[] d = sc.nextIntArray(n);
		
		Arrays.sort(d);
		
		out.println(d[n / 2] - d[n / 2 - 1]);
		
		
	}
	
	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}

	public static long factorial(int n) {
		long a;

		if(n > 0) {
			a = n * factorial(n - 1);
		}else{
			a = 1;
		}

		return a;
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(K key, V value) {
        super(key, value);
    }

    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }

class UnionFind {
	int[] par;

	public UnionFind(int n) {
		par = new int[n];

		Arrays.fill(par, -1);
	}

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

	boolean unite(int x,int y) {
		x = root(x);
		y = root(y);

		if(x == y) return false;

		if(size(x) < size(y)) {
			int tmp = x;
			x = y;
			y = tmp;
		}

		par[x] += par[y];
		par[y] = x;

		return true;
	}

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

	int size(int a) {
		return -par[root(a)];
	}
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 34104
#pragma GCC optimize("O3")
    #pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize("unroll-loops")
     
    #include <algorithm>
    #include <bitset>
    #include <cassert>
    #include <chrono>
    #include <cmath>
    #include <complex>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    #include <deque>
    #include <functional>
    #include <iomanip>
    #include <iostream>
    #include <iterator>
    #include <limits>
    #include <climits>
    #include <list>
    #include <map>
    #include <numeric>
    #include <queue>
    #include <random>
    #include <ratio>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <string>
    #include <unordered_map>
    #include <unordered_set>
    #include <utility>
    #include <vector>
    using namespace std;
     
    typedef long long ll;
    typedef long double LD;
    #define int ll
    #define double LD
    #define pb push_back
    #define mp make_pair
    #define REP(i,n) for (int i = 0; i < n; i++)
    #define loop(i,n) for (int i = 0; i < n; i++)
    #define FOR(i,a,b) for (int i = a; i < b; i++)
    #define REPD(i,n) for (int i = n-1; i >= 0; i--)
    #define FORD(i,a,b) for (int i = a; i >= b; i--)
    #define remax(a,b) a = max(a,b)
    #define remin(a,b) a = min(a,b)
    #define mem(a, b) memset(a, b, sizeof a)
    #define append push_back
    #define all(v) v.begin(),v.end()
    #define F first
    #define S second
    #define print(x) cout << (x) << endl
    #define PRECISION(x) cout << fixed << setprecision(x)
    #define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
     
    const double PI=acos(-1);
    const int MOD = 1000000007;
    const int FMOD = 998244353;
    const double eps = 1e-9;
     
    mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
    
    signed main()
    {
    	
		int n;
		cin>>n;
		int a[n];
		loop(i,n)
		{
			cin>>a[i];
		}
		int flag=0;
		loop(i,n)
		{
			if(a[i]%2==0)
			{
				if(a[i]%3==0 || a[i]%5==0)
				{
					
				}
				else
				{
					flag=1;
					break;
				}
			}
		}
		if(flag)
		cout<<"DENIED"<<endl;
		else
		cout<<"APPROVED"<<endl;
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    int n,count = 0,after_size;
    bool flg = false;
    cin >> n;
    vector<string> si;
    string atari;

    for (int i = 0; i < n; i++)
    {
        cin >> atari;
        si.push_back(atari);
    }

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

    after_size = si.size();

    cout << after_size << endl;
    
}



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

const int maxn = 2e5+10;

int n;
long long k;
int a[maxn<<1], nxt[maxn], b[maxn<<1];
bool inq[maxn];
long long vis[maxn];
vector<pair<long long, int> > v;
vector<int> u;

int main() {
	cin >> n >> k;
	k *= n;
	for (int i = 0; i < n; ++i) {
		scanf("%d", a+i);
		a[i+n] = a[i];
	}

	memset(nxt, -1, sizeof(nxt));
	memset(b, -1, sizeof(b));
	for (int i = (n<<1)-1; ~i; --i) {
		b[i] = nxt[a[i]]+1;
		nxt[a[i]] = i;
	}
//	for (int i = 0; i < n; ++i) printf("a[%d]=%d, b[i]=%d\n", i, a[i], b[i]);

	memset(vis, -1, sizeof(vis));
	int i = 0;
	long long loop = 0;
	while (1) {
		if (~vis[i]) break;
		vis[i] = loop;
		v.push_back(make_pair(vis[i], i));
//		printf("%d(%d): %lld\n", i, a[i], loop);

		loop += b[i]-i;
		i = b[i]%n;
	}
	loop -= vis[i];
//	printf("i=%d, loop=%d\n", i, loop);
	if (k >= vis[i]) k = (k-vis[i])%loop+vis[i];
	int pos = (--upper_bound(v.begin(), v.end(), make_pair(k, 0)))->second;
//	printf("pos=%d\n", pos);
	for (long long j = vis[pos]+1, l = pos; j <= k; ++j) {
		if (inq[a[l]]) {
			while (inq[a[l]]) {
				inq[u.back()] = false;
				u.pop_back();
			}
		}
		else {
			u.push_back(a[l]);
			inq[a[l]] = true;
		}
		l = (l+1)%n;
//		for (int _ = 0; _ < u.size(); ++_) printf("%d ", u[_]); puts("");
	}
	for (int j = 0; j < u.size(); ++j) printf("%d ", u[j]); puts("");
}


Measured memory_bytes: 12140
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


from collections import Counter


class FastFactorization:
    def __init__(self, N: int):
        '''構築O(NloglogN)、クエリO(logN)'''
        self.N = N
        self.min_prime = self._make_minimum_prime()

    def _make_minimum_prime(self):
        # xの最小の素因数表を作成
        min_prime = [x for x in range(self.N + 1)]
        # min_prime[0] = 0  # 0と1は素数ではない
        # min_prime[1] = 1
        for i in range(2, int(self.N ** 0.5) + 1):
            if min_prime[i] == i:  # 素数だったら更新
                for j in range(2 * i, self.N + 1, i):  # iの倍数は素数でない
                    if min_prime[j] == j:
                        min_prime[j] = i
        return min_prime

    def query(self, x: int):
        # -> Counter[p,n] (素数,冪数) を格納
        # 最小素数配列min_primeを使ってO(log N)で因数分解
        if x == 1:
            return Counter()  # 1は素数ではない

        # 素因数分解
        arr = []
        tmp = x
        while tmp != 1:
            p = self.min_prime[tmp]
            tmp //= p
            arr.append(p)
        return Counter(arr)


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from math import gcd


N = a_int()
A = ints()

fact = FastFactorization(max(A))

# setかはすぐわかる
# setでなければ not coprime
# pairは互いに素かをみればいいのか
# つまり因数分解して足してったときにすべての素数のべき数が1以下であれば良い

g_set = 0
cnt = defaultdict(lambda: 0)
flg = 1  # pairwiseであるフラグ
for a in A:
    g_set = gcd(g_set, a)
    if flg:
        for p, n in fact.query(a).items():
            if cnt[p] != 0:
                flg = 0
            cnt[p] += n


# print(cnt)
# for v in cnt.values():
#     if v > 1:
#         flg = 0
#         break

if g_set > 1:
    print('not coprime')
elif flg:
    print('pairwise coprime')
else:
    print('setwise coprime')


Measured memory_bytes: 215292
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#define mod 1000000007
typedef long long ll;
using namespace std;

const int MAX = 55;
int A[MAX],B[MAX];
bool G[MAX][MAX];
bool visited[MAX]; // ある頂点がすでに訪問されたかどうか判定する
int N,M;

void dfs(int v){
  visited[v] = true;
  for(int i=0;i<N;i++){
    if(G[v][i] == false) continue;
    if(visited[i] == true) continue;
    dfs(i);
  }
}

int main(){
  cin >> N >> M;
  for(int i=0;i<M;i++){
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
    G[A[i]][B[i]] = G[B[i]][A[i]] = true;
  }
  
  int ans = 0;
  
  for(int i=0;i<M;i++){
    G[A[i]][B[i]] = G[B[i]][A[i]] = false; // 毎回辺を一本だけ落とす.
    for(int i=0;i<N;i++) visited[i] = false; // 全ての頂点を未訪問とする.
    
    dfs(0); // 頂点0を起点としたDFS.頂点0と連結する頂点を探索する.
    
    bool judge = true; // グラフが連結かどうか判定する
    for(int i=0;i<N;i++){
      if(visited[i] == false) judge = false; // 1か所でも非連結だとダメ.
    }
    if(judge == false) ans++;
    G[A[i]][B[i]] = G[B[i]][A[i]] = true; // 元に戻す.
  }
  
  cout << ans << endl;
  return 0;
}
  

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

int swap(int *,int time);
int main(void){
	int i,count=0,time,*num;
	
	scanf("%d",&time);
	num=malloc(sizeof(int)*time);
	for(i=0;i<time;i++)
		scanf("%d",&num[i]);
	if(time!=1)
		count=swap(num,time);
	for(i=0;i<time;i++){
		printf("%d",num[i]);
		if(i!=time-1)
			printf(" ");
	}
	printf("\n%d\n",count);
	return 0;
}

int swap(int *num,int time){
	int temp,i,j,count=0;
	for(i=time;i>0;i--)
		for(j=0;j<i-1;j++)
			if(*(num+j)>*(num+j+1)){
				temp=*(num+j);
				*(num+j)=*(num+j+1);
				*(num+j+1)=temp;
				count++;
			}
	return count;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
int main() {
  string A,B;
  cin >> A >> B;
  bool k = true;
  if (A.size() != B.size()) {
    if (A.size() > B.size()) cout << "GREATER" << endl;
    else cout << "LESS" << endl;
  }
  else {
    for (int i = 0; i < A.size(); i++) {
      if (int(A[i]) > int(B[i])) {
        cout << "GREATER" << endl; k = false; break;
      }
      else if (int(A[i]) < int(B[i])) {
        cout << "LESS" << endl;  k = false; break;
    }
  }
    if(k) cout << "EQUAL" << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
    int x,y;
    cin >> x >> y;
    int ans = 0;

    if (x==1 && y==1) ans+=400000;
    if (x==1) ans+=300000;
    if (x==2) ans+=200000;
    if (x==3) ans+=100000;
    if (y==1) ans+=300000;
    if (y==2) ans+=200000;
    if (y==3) ans+=100000;

    cout << ans << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N, K;
    cin >> N >> K;
    int P[N]; ll C[N];
    rep(i, N){
        cin >> P[i];
        P[i]--;
    }
    rep(i, N) cin >> C[i];
    ll ans = -INF;
    rep(i, N){
        ll tmp = -INF;
        int now = i, cnt = 0; ll sum = 0;
        ll M = -INF;
        while(true){
            cnt++;
            sum += C[now = P[now]];
            chmax(M, sum);
            if(now == i) break;
        }
        if(K >= cnt) chmax(tmp, M);
        if(K/cnt >= 1) chmax(tmp, sum*(K/cnt-1)+M);
        sum *= K/cnt;
        rep(j, K%cnt){
            sum += C[now = P[now]];
            chmax(tmp, sum);
        }
        chmax(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3696
#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() {
    ll x, k, d;
    cin >> x >> k >> d;
    ll num = x / d;
    x = abs(x);
    ll tmp = min(k, x/d);
    k -= tmp;
    x -= tmp * d;
    if (k % 2 == 0) {
        cout << x << endl;
    }
    else {
        cout << abs(x - d) << endl;
    }
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
typedef pair<int,int> pi;
#define FAST ios_base::sync_with_stdio(0);
const int maxn = 100010;
const int mod = 1e9+7;

int n,k;
vector <int> adjlist[maxn];
int ans;

void mul(int &a, int b) {
	a *= b;
	a %= mod;
}

void dfs(int x, int p) {
	int co = (p == -1 ? 1 : 2);
	//~ cout << x << " " << co << "\n";
	for (auto i: adjlist[x]) {
		if (i == p) continue;
		mul(ans,k-co);
		co++;
		dfs(i,x);
	}
}

int32_t main() {
	cin >> n >> k;
	for (int i =0;i<n-1;i++) {
		int a,b; cin >> a >> b;
		adjlist[a].push_back(b);
		adjlist[b].push_back(a);
	}
	
	ans = k;
	dfs(1,-1);
	cout << ans % mod;
}



Measured memory_bytes: 10368
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, k;
ll F(ll n, ll k) {
	if (n <= k) {
		return min(n, k - n);
	}
	return F(n % k, k);
}
int main() {
	cin >> n >> k;
	cout << F(n, k);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  cout << char(s1[0] - 'a' + 'A') << char(s2[0] - 'a' + 'A') << char(s3[0] - 'a' + 'A') << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    char x,y;
    cin>> x >> y;
    if(x<y){
        cout<<"<"<<endl;
    }
    if(x>y){
        cout<<">"<<endl;
    
    }
    if(x==y){
        cout<<"="<<endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long int
int main()
{
    int a,b,c;
    ll k;
    cin>>a>>b>>c>>k;
    ll sum = 0;
    if(a>=k){
        cout<<k<<endl;
        return 0;
    }
    else if(a<k){
        sum+=a;
        k = k-a;
        if(b>=k){
            cout<<sum<<endl;
            return 0;
        }else{
            k = k-b;
        }
        if(c>=k && k!=0){
            sum -= k;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3652
#pragma region header
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n,a,b,c,d,e;cin >> n >> a >> b >> c >> d >> e;
    int k = min({a,b,c,d,e});
    cout << (n+k-1)/k + 4 << endl;
    return 0;
}

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

const int MAXN = 100005;

ll a[MAXN];
ll b[MAXN];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
    }

    ll s = 0;
    for (int i = n-1; i >= 0; i--)
    {
        s += (b[i] - (s + a[i]) % b[i] ) % b[i];
    }
    cout << s;

    return 0;
}


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

using namespace std;

typedef long long ll;

using V = vector<int>;
using Q = queue<int>;
using Graph = vector<vector<int>>;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define inn(x, y) int x,y;cin>>x>>y
#define innn(x, y, z) int x,y,z;cin>>x>>y>>z
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl
#define outt(x,y) cout<<(x)<<" "<<(y)<<endl
#define err(x) cerr<<(x)<<endl
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl
#define errrr(x,y,z) cerr<<(x)<<" "<<(y)<<" "<<(z)<<endl

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 200010
#define lim9 1000000010

#define deg(_rad) (((_rad)/2/M_PI)*360)
#define rad(_deg) (((_deg)/360)*2*M_PI)
#define mid(min, max) ((min + max) / 2)

int main() {
	inn(a, b);
	out(a * b);

    return 0;
}


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

int main() {
  int A,B,C,D,e,f;
  cin >> A>>B>>C>>D;
  e=A+B;
  f=C+D;

  if (e>f) {
    cout << "Left" << endl;
  }
  else if(e==f){
  cout << "Balanced" << endl;
}
  else if(e<f){
    cout<<"Right"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int a,b,c,ans=1;
  cin>>a>>b>>c;
  if(a!=b)
    ans++;
  if(a!=c&&b!=c)
    ans++;
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;
const int MAX_N = 2e5;

int main(){
  int n;
  cin >> n;
  int a = 0 , w= 0 , t=0, r=0;
  rep(i, n){
    string s;
    cin >> s;
    if(s == "AC") a++;
    if(s == "WA") w++;
    if(s == "TLE") t++;
    if(s == "RE") r++;
  }
  cout <<" AC x "<< a <<endl;
  cout <<"WA x "<< w << endl;
  cout << "TLE x "<<t<<endl;
  cout << "RE x " << r << endl;
}


Measured memory_bytes: 3600
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <utility>
using namespace std;

typedef pair<int, int> ii;
typedef long long ll;

ll h, w;
ll solve(ll a, ll b, ll c)
{
  if (a > b)
    swap(a, b);
  if (b > c)
    swap(b, c);
  if (a > b)
    swap(a, b);
  return c-a;
}
int main()
{
  scanf("%lld %lld", &h, &w);
  ll ans = h*w;
  for (int i = 0; i < 2; ++i, swap(h, w))
  for (ll i = 1; i < h; ++i)
    {
      ans = min(ans, solve(i, (h-i)/2, (h-i+1)/2)*w);
      ans = min(ans, solve(i*w, w/2*(h-i), (w+1)/2*(h-i)));
    }
  printf("%lld\n", ans);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long  n;
  cin>>n;
  long long  d=n/2*2;
  vector<pair<long long  ,long long >> vp;
  for(long long  i=0;i<n;i++)
  {for(long long j=i+1;j<n;j++)
    {
    if(i+j+2==d+1)continue;
    vp.push_back(make_pair(i,j));
    
    }}
  cout<<vp.size()<<'\n';
  for(auto e:vp)
    cout<<e.first+1<<" "<<e.second+1<<'\n';
  return 0;
}

Measured memory_bytes: 512
from sys import stdin
read = stdin.read
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())

MAX_A = 300005

class SegTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

def main():
    N, K = i_map()
    A = list(map(int, read().strip().splitlines()))
    s = SegTree([0]*MAX_A, lambda x, y : max(x,y), 0)
    ans = 0
    for a in A:
        l, r = max(a - K, 0), min(a + K + 1, MAX_A)
        now = s.query(l, r) + 1
        s.update(a, now)
        ans = max(ans, now)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 121520
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    string s;
    cin >> s;
    int sum = 0;
    for (int i = 0; i < s.length(); i++)
    {
        int tmp = s[i] - '0';
        sum += tmp;
    }
    int N;
    N = stoi(s);
    if (N % sum == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      x: usize,
    }
    if x == 1 || x == (2*n-1) {
        return puts!("{}\n", "No");
    }

    puts!("{}\n", "Yes");
    let mut ans = vec![0; 2*n-1];
    ans[(2*n-1)/2-1] = x-1;
    ans[(2*n-1)/2] = x;
    ans[(2*n-1)/2+1] = x+1;

    let mut idx = 0;
    let mut cur = 1;
    while idx < 2*n-1 {
        if idx == (2*n-1)/2-1 {
            idx = (2*n-1)/2+2;
        }
        if idx == 2*n-1 {
            break;
        }
        if cur == x-1 {
            cur = x+2;
        }
        ans[idx] = cur;
        idx += 1;
        cur += 1;
    }

    for a in ans {
        puts!("{}\n", a);
    }
}


Measured memory_bytes: 7676
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
  int N,i;
  double a[105],ans,num;
  char str[2000],*p;
  
  
  fgets(str,sizeof(str),stdin);
  N=atoi(str);
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  a[0]=atof(p);
  
  for(i=1;i<N;i++){
    p=strtok(NULL," \n");
  	a[i]=atof(p);
  }
  
  for(i=0,num=0.0;i<N;i++){
    num+=1.0/a[i];
  }
  
  ans=1.0/num;
  
  printf("%.8f\n",ans);
  
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, unsigned long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll = long long;

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

  ll n,x;
  std::cin>>n>>x;

  if(x==1||x==2*n-1){
    std::cout<<"No\n";
    return 0;
  }

  std::cout<<"Yes\n";

  if(x==n){
    rep(i,0,2*n-1)std::cout<<i+1<<"\n";
    std::cout<<"\n";
    return 0;
  }

  if(x<n){
    bool back=true;
    std::deque<ll> que;
    que.emplace_back(1);
    que.emplace_back(x);
    rep(i,x+1,2*n){
      if(back)que.emplace_back(i);
      else que.emplace_front(i);
      back^=true;
    }
    rep(i,2,x){
      if(back)que.emplace_back(i);
      else que.emplace_front(i);
      back^=true;
    }
    while(!que.empty()){
      ll tmp=que.front();que.pop_front();
      std::cout<<tmp<<"\n";
    }
    std::cout<<"\n";
  }else{
    bool back=true;
    std::deque<ll> que;
    que.emplace_back(2*n-1);
    que.emplace_back(x);
    rep(i,1,x){
      if(back)que.emplace_back(i);
      else que.emplace_front(i);
      back^=true;
    }
    rep(i,x+1,2*n-1){
      if(back)que.emplace_back(i);
      else que.emplace_front(i);
      back^=true;
    }
    while(!que.empty()){
      ll tmp=que.front();que.pop_front();
      std::cout<<tmp<<"\n";
    }
    std::cout<<"\n";
  }

  return 0;
}

Measured memory_bytes: 3200
n = STDIN.gets.to_i

strings = Hash.new { 0 }

n.times do
  s = STDIN.gets
  strings[s] += 1
end

m = STDIN.gets.to_i

m.times do
  t = STDIN.gets
  strings[t] -= 1
end

max = strings.values.max
if max < 0
  puts 0
else
  puts max
end


Measured memory_bytes: 1788
def gcd(a,b):
	while b!=0:
		a,b=b,a%b
	return a
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
  
A,B = map(int, input().split())
fac = factorization(gcd(A,B))
if fac[0][0] == 1:
  print(1)
else: print(len(fac)+1)

Measured memory_bytes: 3064