akhauriyash/Code-Regression huggingface dataset:
import sys
input=sys.stdin.readline


def solve():
    N, M = map(int, input().split())
    d = {i:[] for i in range(1, N+1)}
    e = {i:[] for i in range(1, N+1)}
    h = [0] * (N+1)

    for _ in range(N+M-1):
        A, B = map(int, input().split())
        d[A].append(B)
        e[B].append(A)
        h[B] += 1

    st = set()
    for i in range(1, N+1):
        if h[i]==0:
            st.add(i)

    tp = {}
    c = 0
    while st:
        i = st.pop()
        c += 1
        tp[i] = c
        for j in d[i]:
            h[j] -= 1
            if h[j] == 0:
                st.add(j)

    ans = [0] * (N+1)
    for i in range(1, N+1):
        s, t = 0, 0
        for j in e[i]:
            if s < tp[j]:
                s = tp[j]
                t = j
        print(t)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 89956
N = int(input())
A = list(map(int,input().split()))

def prime_decomposition(n):
  i = 2
  d = {}
  while i * i <= n:
    while n % i == 0:
      n //= i
      if i not in d:
          d[i] = 0
      d[i] += 1
    i += 1
  if n > 1:
    if n not in d:
        d[n] = 1
  return d

A.sort()
M = A[-1]
d = {}
ans = 0

for i in range(N):
    if A[i] not in d:
        primes = prime_decomposition(A[i])
        for p in primes:
            for j in range(1,M//p+1):
                d[j*p] = 0
    else:
        ans = 1
        break
if ans == 0:
    print('pairwise coprime')
else:
    def gcd(a, b):
    	while b:
    		a, b = b, a % b
    	return a
    a = A[0]
    for i in range(N):
        a = gcd(a,A[i])
    if a==1:
        print('setwise coprime')
    else:
        print('not coprime')

Measured memory_bytes: 211740
#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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 500050;
const int K = 230000;
const int mod = 1e9 + 7;
int a[N], d[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
     //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int k, q;
    cin >> k >> q;
    for (int i = 0; i < k; i++) cin >> d[i];
    while(q--){
        int n, x, m;
        cin >> n >> x >> m;
        x %= m;
        int s = 0;
        for (int i = 0; i < k; i++){
            s += d[i] % m;
        }
        x += (n - 1) / k * s;
        for (int i = 0; i < (n - 1) % k; i++){
            x += d[i] % m;
        }
        int q = 0;
        for (int i = 0; i < k; i++){
            if (d[i] % m == 0){
                q += (n - 1) / k;
                if (i < (n - 1) % k) q++;
            }
        }
        cout << n - 1 - x / m - q << endl;
    }
}


Measured memory_bytes: 3712
#include<stdio.h>
int quicksort (int a[],int low,int high);
int main()
{
    int n;
    int a[200010];
    int m,b,flag=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    quicksort(a,0,n-1);
    for(int i=0;i<n-1;i++)
        if(a[i]==a[i+1]) {flag=1;break;}
    if(flag==1) printf("NO");
    else printf("YES");
    return 0;
}
int quicksort (int a[],int low,int high)
{
    int temp,t;
    int i,j;
    if(low>high)
        return ;
    temp=a[low];
    i=low;j=high;
    while(i!=j)
    {
        while(a[j]>=temp && j>i) j--;
        while(a[i]<=temp && i<j) i++;
        if(i<j)
            {t=a[i];a[i]=a[j];a[j]=t;}
    }
    a[low]=a[i];
    a[i]=temp;
    quicksort(a,low,i-1);
    quicksort(a,i+1,high);
    return ;

}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x, y;
    cin >> x >> y;
    bool can = false;
    //iは鶴、jは亀
    for(int i = 0; i <= x; i++){
        int j = x - i;
        if(2*i + 4*j == y) can = true;
    }

    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpl;
typedef vector<tuple<int, int, int>> vti;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, k;
    cin >> n >> k;

    int v = n;
    vd rates;
    for (int i=0;i<k;i++){
        double m = pow(2, i);
        while (v * m >= k && v > 0){
            rates.push_back(1 / m);
            v--;
        }
    }
    double ans = 0;
    rep(i, n){
        ans += rates[i];
    }
    ans /= n;
    printf("%.9f\n", ans);
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define nmod         -1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define xxx         exit(0);
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x) 
{
    return (ll)(log(x)/log(base));
}

double dp[3001][3001],p[3005],l;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS; 
    while(TESTS--)
    {
    	ll i,j,x1,y1,x,y,q,h,n;
    	cin>>n; l=0.00;
    	cout<<fixed<<setprecision(9);
    	repi(i,1,n) cin>>p[i];
    	dp[1][0]=1.0-p[1]; dp[1][1]=p[1];
    	repi(i,2,n)
    	{
    		repi(j,0,i)
    		{
    			if(j>0)
    			dp[i][j] = dp[i-1][j]*(1.0-p[i]) + dp[i-1][j-1]*p[i];
    			else
    			dp[i][j]=dp[i-1][j]*(1.0-p[i]);
			}
		}
		repi(j,(n+1)/2,n) l+=dp[n][j];
		cout<<l;
	}
	return 0;
}

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

#include <iomanip>

int main() {
  long double L;

  cin >> L;
  cout << fixed << setprecision(10) << (L/3)*(L/3)*(L/3) << endl;

  return 0;
}


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

int main(){
    int N, Q;
    cin >> N >> Q;
    string s;
    cin >> s;
    vector<char> t(Q), d(Q);
    for (int i = 0; i < Q; i++) cin >> t[i] >> d[i];
    
    int l = -1;
    int r = N;
    while (r - l > 1) {
        int c = (l+r)/2;
        bool lerase = false;
        int pos = c;
        for (int i = 0; i < Q; i++) {
            if (t[i] == s[pos]) {
                if (d[i] == 'L') pos--;
                else pos++;
            }
            if (pos < 0) {
                lerase = true;
                break;
            }
            if (pos >= N) break;
        }
        if (lerase) l = c;
        else r = c;
    }
    int ansl = r;
    
    l = -1;
    r = N;
    while (r - l > 1) {
        int c = (l+r)/2;
        bool rerase = false;
        int pos = c;
        for (int i = 0; i < Q; i++) {
            if (t[i] == s[pos]) {
                if (d[i] == 'L') pos--;
                else pos++;
            }
            if (pos >= N) {
                rerase = true;
                break;
            }
            if (pos < 0) break;
        }
        if (rerase) r = c;
        else l = c;
    }
    int ansr = r;
    cout << ansr-ansl << endl;
    return 0;
}

Measured memory_bytes: 900
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

    string s, t;
    cin >> s >> t;

    vector<char> vecS, vecT;
    REP(i, s.size())
        vecS.push_back(s[i]);
    REP(i, t.size())
        vecT.push_back(t[i]);

    sort(vecS.begin(), vecS.end()); // 昇順ソート
    sort(vecT.begin(), vecT.end(), greater<int>()); // 降順ソート

    bool ans = false;
    if (vecS.size() < vecT.size()) {
        int count = 0;
        for (auto itr = vecS.begin(); itr != vecS.end(); itr++) {
            if (*itr < vecT.at(distance(vecS.begin(), itr))) {
                ans = true;
                break ;
            }
            if (*itr == vecT.at(distance(vecS.begin(), itr)))
                count++;
        }
        if (count == vecS.size())
            ans = true;
    } else {
        for (auto itr = vecT.begin(); itr != vecT.end(); itr++) {
            if (*itr > vecS.at(distance(vecT.begin(), itr))) {
                ans = true;
                break ;
            }
        }
    }

    // REP(i, vecS.size()) cout << vecS[i] << ' ';
    // cout << endl;
    // REP(i, vecT.size()) cout << vecT[i] << ' ';
    // cout << endl;

    if (ans) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 256
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

const int MOD = 1e9 + 7;

#define pow abcdef

int pow(int a, int b) {
  if (b == 0) return 1;
  int t = pow(a, b / 2);
  t = (t * t) % MOD;
  if (b % 2) return (a * t) % MOD;
  return t;
}

int mmi(int x) {
  return pow(x, MOD - 2);
}

void MAIN() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  map<char, int> m;
  for (auto &i : s) {
    m[i]++;
  }
  int ans = pow(2, n);
  for (auto &i : m) {
    ans *= ((i.sc + 1) * mmi(pow(2, i.sc))) % MOD;
    ans %= MOD;
  }
  cout << ans - 1 << '\n';
}

signed main() {
#ifdef _DEBUG
  freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

int main(){
	int A,B;
	int i=1;
	string S;

	cin >> A >> B;
	cin >> S;

	bool correct=true;
	for(const auto& c : S){
		if(i==A+1){
			if(c!='-'){
				correct=false;
				break;
			}
		}else{
			if(c<'0' || '9'<c){
				correct=false;
				break;
			}
		}
		i++;
	}

	if(correct){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

ll n;
vll s(500000);

ll merge(ll l, ll m, ll r) {
  ll n1 = m - l;
  ll n2 = r - m;
  vll lv(n1 + 1, HIGHINF), rv(n2 + 1, HIGHINF);
  REP(i, n1) lv.at(i) = s.at(l + i);
  REP(i, n2) rv.at(i) = s.at(m + i);
  ll i = 0, j = 0, com = 0;
  rep(k, l, r) {
    if (lv.at(i) <= rv.at(j)) s.at(k) = lv.at(i++);
    else s.at(k) = rv.at(j++);
    com++;
  }
  return com;
}

ll mergeSort(ll l, ll r) {
  ll ans = 0;
  if (l + 1 < r) {
    ll mid = (l + r) / 2;
    ans += mergeSort(l, mid);
    ans += mergeSort(mid, r);
    ans += merge(l, mid, r);
  }
  return ans;
}

int main() {
  cin >> n;
  REP(i, n) cin >> s.at(i);
  ll ans = mergeSort(0, n);
  REP(i, n) {
    cout << s.at(i);
    if (i != n-1) cout << ' ';
  }
  cout << endl;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 10596
#include <iostream>
#include <string>
using namespace std;
struct Dice{
    int s[6];
    void roll(char c){
        int tmp;
        if(c=='N'){
            tmp=s[0];
            s[0]=s[1];
            s[1]=s[5];
            s[5]=s[4];
            s[4]=tmp;
        }
        if(c=='E'){
            tmp=s[0];
            s[0]=s[3];
            s[3]=s[5];
            s[5]=s[2];
            s[2]=tmp;
        }
        if(c=='W'){
            tmp=s[0];
            s[0]=s[2];
            s[2]=s[5];
            s[5]=s[3];
            s[3]=tmp;
        }
        if(c=='S'){
            tmp=s[0];
            s[0]=s[4];
            s[4]=s[5];
            s[5]=s[1];
            s[1]=tmp;
        }
        if(c=='R'){
            tmp=s[1];
            s[1]=s[2];
            s[2]=s[4];
            s[4]=s[3];
            s[3]=tmp;
        }
    }
    int top(){
        return s[0];
    }
    int right(){
        return s[2];
    }
    int left(){
        return s[3];
    }
    int front(){
        return s[1];
    }
};


int main(void){
    Dice d;
    int n,t,f;
    
    for(int i=0; i<6; i++) cin>>d.s[i];
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>t>>f;
        if(d.left()==t) d.roll('E');
        if(d.right()==t) d.roll('W');
        while(d.top()!=t) d.roll('N');
        while(d.front()!=f) d.roll('R');
        cout<<d.right()<<endl;
    }
    return 0;
}


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

int main(){
  int n;
  int64_t c = 0;
  cin >> n;
  vector<int>v(n);
  rep(i,n)
    cin >> v.at(i);
  rep(i,n-1)
    if(v.at(i) > v.at(i+1)){
      c += v.at(i)-v.at(i+1);
      v.at(i+1) = v.at(i);
    }
  cout << c;
}


Measured memory_bytes: 4048
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {

    int n; cin >> n;

    ll sum = 0;

    rep (i, n+1) {
        if (i % 3 == 0 || i % 5 == 0) continue;
        sum += i;
    }

    cout << sum << endl;


    return 0;
}

Measured memory_bytes: 3644
import sys
from io import StringIO
import unittest


def resolve():
    s = input()
    t = input()
    ans = 0
    for i, j in zip(s, t):
        if i == j:
            ans += 1
    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """CSS
CSR"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """SSR
SSR"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """RRR
SSS"""
        output = """0"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 5680
//\\//\\ * * * //\\// ||
#include <bits/stdc++.h> 

#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int cur = 0;
  int k;
  cin >> k;
  for (int i = 1; i <= k; i++) {
    cur *= 10;
    cur += 7;
    cur %= k;
    if (cur == 0) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}


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

using namespace std;

const int M = 1000000007;
int main() {
	long long N, K;
	cin >> N >> K;

	vector<int> a(N);
	for(auto &x: a) cin >> x;

	vector<vector<int> > dp(N, vector<int>(K + 1, 0));

	long long m = 0;
	for(int i = 0; i < N; i++) {
		m += a[i];
		int acc = 0;
		for(int j = 0;j <= min(K, m); j++) {
			if(i == 0) {
				dp[i][j] = 1;
				continue;
			}
			acc += dp[i-1][j];
			acc %= M;
			if(j > a[i]) {
				acc += M - dp[i-1][j - a[i] - 1];
				acc %= M;
			}
			dp[i][j] = acc;
		}
	}

	cout << dp[N - 1][K] << endl;
	return 0;
}


Measured memory_bytes: 39808
#include <stdio.h>
#include <stdlib.h>
typedef struct node_s node;
struct node_s{
  int key;
  node *prev;
  node *next;
};
node *head;
void insert(int x){
  node *t=malloc(sizeof(node));
  t->key=x;  t->next=head->next; t->prev=head; head->next->prev=t; head->next=t;
}
void delete(node *n){
  if (n==NULL)return;
  n->prev->next=n->next;
  n->next->prev=n->prev;
  free(n);
}
node *find(int key){
  node *p;
  for (p=head->next;p->key!=-1;p=p->next){
    if (p->key==key){
      return p;}
  }
  return NULL;
}
int main(){
  int i,total,x;
  char cmd[16];
  node *tp;
  head = malloc(sizeof(node));
  head->key=-1;
  head->prev=head;
  head->next=head;
  scanf("%d",&total);
  for (i=0;i<total;i++){
    scanf("%s", &cmd);
    if (cmd[0]=='i'){
      scanf("%d",&x);
      insert(x);}
    else if (cmd[0]=='d'&&cmd[6]=='\0'){
      scanf("%d",&x);
      delete(find(x));
    }else if (cmd[0]=='d'&&cmd[6]=='F'){
      delete(head->next);
    }else if (cmd[0]=='d'&&cmd[6]=='L'){
      delete(head->prev);
    }
  }
  for (tp=head->next;tp->next->key!=-1;tp=tp->next)
    printf("%d " ,tp->key);
  printf("%d\n" ,tp->key);
  return 0;
}


Measured memory_bytes: 33024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef long double ld;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll exp(ll x,ll y){if(y==0) return 1;if(y%2 == 1) return x*exp(x,y/2)*exp(x,y/2);return exp(x,y/2) * exp(x,y/2);}
ll exp(ll x,ll y,ll modd) {if(y==0) return 1;ll t=exp(x,y/2,modd);t = t%modd;t=t*t;t=t%modd;if(y % 2 == 1) return (x*t)%modd ;return t%modd;}
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target ("sse4")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0ll, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define revn(i,a,b) for(ll i=a;i>=b;--i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vs vector<string>
#define vsi vector<pair<string,int>>
#define vll vector<pair<ll,ll> >
#define vlll vector<pair<ll,pair<ll,ll>>>
#define vlvl vector<pair<pair<ll,ll>,ll>>>
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
	
	string s, t;
	cin>>s>>t;
	int m = s.size(), n = t.size();
	vector<vector<int>> dp(m+1, vector<int>(n+1,0));
	
	for(int i=1;i<=n;i++)
		if(s[0]==t[i-1])
			dp[0][i]=1;
	for(int i=1;i<m;i++)
		if(s[i-1]==t[0])
			dp[i][0]=1;
	
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++)
		{
			if(s[i-1]==t[j-1])
				dp[i][j] = dp[i-1][j-1]+1;
			else
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
		
	string ans = "";
	
	int i=m, j=n;
	while(i>0 && j>0)
	{
		if(s[i-1]==t[j-1])
		{
			ans=s[i-1]+ans;
			i--;
			j--;
		}
		else if(dp[i-1][j]>dp[i][j-1])
		{
			i--;
		}
		else
		{
			j--;
		}
	}
	
	cout<<ans;
    return 0;
}

Measured memory_bytes: 35584
A,B = list(map(int,input().split()))

bit=[0 for i in range(50)]

if int(bin(A)[-1])==0:
    if int(bin(B)[-1])==0:
        if (B-A)%4==2:
            bit[1]+=1
    else:
        if (B-A+1)%4==2:
            bit[1]+=1
else:
    if int(bin(B)[-1])==0:
        if (B-A+1)%4==2:
            bit[1]+=1
    else:
        if (B-A)%4==0:
            bit[1]+=1

for i in range(2,50):
    if len(bin(A))-2>=i:
        if int(bin(A)[-i])!=0:
            if A%2!=0:
                bit[i]+=1

    if len(bin(B))-2>=i:
        if int(bin(B)[-i])!=0:
            if B%2==0:
                bit[i]+=1
            

ans=0
for i in range(1,50):
    #print(bit[i]%2)
    ans+=(bit[i]%2)*(2**(i-1))

print(ans)

Measured memory_bytes: 3064
import sys

input = sys.stdin.readline

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

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x%y == 0:
        return y
    else:
        while y != 0:
            x, y = y, x%y
        else:
            return x

A.sort()
ans = A[0]
for i in range(1, N):
    ans = gcd(ans, A[i])
print(ans)



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

typedef long long ll;

const ll        MOD=1000000007;  ///1e9+7

#define forn(i,n) for(i=0;i<n;i++)
#define mem(a,b) memset(a, b, sizeof(a))

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///
ll h,w,dp[1000][1000],dx[]={+1,0},dy[]={0,+1};
string a[1000];

ll rec(ll x,ll y)
{
    if(x>=h or y>=w) return 0;
    if(a[x][y]=='#') return 0;
    if(dp[x][y]>-1) return dp[x][y]%MOD;
    ll opt1=0,opt2=0;
    for(int i=0;i<2;i++){
        opt1+=rec(x+dx[i],y+dy[i]);
    }
    dp[x][y]=opt1;
    return dp[x][y]%MOD;
}

void _case()
{
    cin>>h>>w;
    ll i;
    forn(i,h) cin>>a[i];
    mem(dp,-1);
    dp[h-1][w-1]=1;
    cout<<rec(0,0)<<'\n';
}

main()
{
        fastio();
        _case();
}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 12612
import java.util.*;

public class Main {

	static class Item implements Comparable<Item> {
		public int cost;
		public int id;

		public Item(int id, int cost) {
			this.id = id;
			this.cost = cost;
		}

		@Override
		public int compareTo(Item that) {
			return this.cost - that.cost;
		}
	}

	static void printArray(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i] + ", ");
		}
		System.out.println();
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		@SuppressWarnings("unchecked")
		ArrayList<Item>[] edge = new ArrayList[N + 1];
		for (int i = 0; i < N - 1; i++) {
			int src = sc.nextInt();
			int dst = sc.nextInt();
			int cost = sc.nextInt() % 2 + 2;
			if (edge[src] == null) {
				edge[src] = new ArrayList<Item>();
			}
			edge[src].add(new Item(dst, cost));
			if (edge[dst] == null) {
				edge[dst] = new ArrayList<Item>();
			}
			edge[dst].add(new Item(src, cost));
		}

		int[] C = new int[N + 1];
		Arrays.fill(C, -1);
		PriorityQueue<Item> que = new PriorityQueue<Item>();
		que.add(new Item(1, 0));
		while (que.size() > 0) {
			Item item = que.poll();
			if (C[item.id] < 0) {
				C[item.id] = item.cost;
				if (edge[item.id] != null) {
					for (Item item2 : edge[item.id]) {
						int nextId = item2.id;
						if (C[nextId] < 0) {
							int nextCost = item.cost + item2.cost;
							que.add(new Item(nextId, nextCost));
						}
					}
				}
			}
		}
		// printArray(C);
		for (int i = 1; i <= N; i++) {
			System.out.println(C[i] % 2 == 0 ? 0 : 1);
		}
	}
}


Measured memory_bytes: 107516
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

long long combi2(long long n) {
    return n*(n-1)/2;
}

int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   long long n;
   map<long long, long long> m;
   map<long long, long long> ans;
   long long one = -1;
   vector<long long> vc;
   cin >> n;
   for(int i = 0;i < n;i++) {
       long long x;
       cin >> x;
       vc.push_back(x);
       auto iter = m.find(x);
        if (iter != m.end()) {
            iter->second++;
        } else {
            m.emplace(x, 1);
        }
   }
   for(int k = 0;k < n;k++) {
        long long sum = 0;
        auto it = m.find(vc[k]);
        if(it->second == 1) {
            if(one==-1) {
                m[vc[k]]--;
                for(auto itr = m.begin(); itr != m.end(); ++itr) {
                    sum += combi2(itr->second);
                }
                m[vc[k]]++;
                cout << sum << endl;
                one = sum;
            } else {
                cout << one << endl;
            }
        }
        else {
            auto iter = ans.find(m[vc[k]]);
            if (iter != ans.end()) {
                cout << iter->second << endl;
            } else {
                m[vc[k]]--;
                for(auto itr = m.begin(); itr != m.end(); ++itr) {
                    sum += combi2(itr->second);
                }
                m[vc[k]]++;
                ans[m[vc[k]]] = sum;
                cout << sum << endl;  
            }
        }
   }
}


Measured memory_bytes: 12128
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    string n;
    cin >> n;

    if ((n[0]==n[1]&&n[1]==n[2])||(n[1]==n[2]&&n[2]==n[3])) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class CCleaning {
public:

    vector<ll> a;
    vector<int> graph[100005];
    vector<ll> now;
    vector<bool> used;
    bool flag = true;

    void dfs(int p) {
      if (!flag) return;
      used[p] = true;
      vector<ll> vec;
      int cnt = 0;
      ll sum = 0;
      for(auto e: graph[p]) {
        if (used[e]) continue;
        dfs(e);
        vec.push_back(now[e]);
        sum += now[e];
        cnt++;
      }
      if (p == 0) {
        if (cnt==1 && a[p]==sum) {
          return;
        }
        // cnt>1
        if (sum%2 != 0 || a[p] != sum/2) {
          flag = false;
          return;
        }
        sort(vec.rbegin(), vec.rend());
        if (vec[0] > sum/2) {
          flag = false;
          return;
        }
        return;
      }

      // p != 0
      if (cnt==0 || a[p] == sum) {
        now[p] = a[p];
        return;
      }
      if (a[p] > sum) {
        flag = false;
        return;
      }

      if (a[p] < sum) {
        int k = sum - a[p];
        sort(vec.rbegin(), vec.rend());
        int r = min(sum - vec[0], sum/2);
        if (k > r) {
          flag = false;
        }
        now[p] = a[p] - k;
      }
    }

    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      a.resize(n);
      now.resize(n);
      used.resize(n);
      rep(i, n) {
        cin >> a[i];
      }
      rep(i, n-1) {
        int x, y; cin >> x >> y;
        x--; y--;
        graph[x].push_back(y);
        graph[y].push_back(x);
      }
      dfs(0);
      if (flag) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    }
};

signed main() {
  CCleaning solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> k(n);
  vector<vector<int>> A(n,vector<int>(m));
     for(int i = 0;i < n;i++){
       cin >> k.at(i);
         for(int h = 0;h < k.at(i);h++){
           cin >> A.at(i).at(h);
         }
       }
  vector<int> count(m+1);
  for(int i = 0; i < m+1;i++){
    count.at(i) = 0;
  }
  for(int i = 1;i < m+1;i++){
    for(int j = 0;j < n;j++){
      for(int h = 0;h < k.at(j);h++){
        if(A.at(j).at(h) == i){
          count.at(i)++;
        }
      }
    }
  }
    int ans = 0;
    for(int i = 1;i < count.size();i++){
      if(count.at(i) == n){
        ans++;
      }
    }
    
      cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
let Karray=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
let Kline:Int = Int(readLine()!)!
print(Karray[Kline-1])


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

/* 入力 */
int D; //D:'D'とかくことができる最大個数
int x; //x:空欄1マスな数
char a[30]; //a[i]:i番目の正答
int p[30]; //p[i]:i番目の配点
int y; //y:空欄2マスな数
char b[30], c[30]; //b[i],c[i]:i番目の正答
int q[30]; //q[i]i番目の配点
/* おわり */

int dp[14][20][2];

int rec( int mul, int idx, bool one){ //残りＤ個数, 今のところ, 空欄1マスか
  // if(~dp[mul][idx][one]) return dp[mul][idx][one];
  int ret = 0;
  if(one){
    if(idx == x) ret = rec( mul, 0, !one); //空欄2マスのやつ
    else{
      ret = rec( mul, idx + 1, one);
      if(mul > 0 && a[idx] == 'D') ret = max( ret, rec( mul - 1, idx + 1, one) + p[idx]);
    }
  }else{
    if(idx == y) return 0;
    else{
      ret = rec( mul, idx + 1, one);
      if(mul > 1 && b[idx] == 'D' && c[idx] == 'D') ret = max( ret, rec( mul - 2, idx + 1, one) + q[idx]);
    }
  }
  return /*dp[mul][idx][one] = */ret;
}
int main(){
  fill_n( **dp, 14 * 20 * 2, -1);
  cin >> D >> x;
  for(int i = 0; i < x; i++){
    cin >> a[i] >> p[i];  
  }
  cin >> y;
  for(int i = 0; i < y; i++){
    cin >> b[i] >> c[i] >> q[i];
  }
  cout << rec( D, 0, true) << endl;
  return(0);
}

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

const int maxn = 1E5 + 10;

string s;
int n, m, cnt, rt, p[maxn];

int main()
{
	#ifdef vv
		freopen("vv.txt", "r", stdin);
	#endif

	cin >> s; n = s.length();
	for (int i = 0; i < n; i++)
		p[i + 1] = s[i] == '1' ? 1 : 0;
	if (p[n]) {puts("-1"); return 0;}
	for (int i = 1; i < n; i++)
		if (p[i] && !p[n - i]) {puts("-1"); return 0;}
	if (!p[1]) {puts("-1"); return 0;}

	for (int i = 1; i <= n; i++)
		if (!p[i]) {m = i - 1; break;}
	for (int i = 1; i <= m; i++)
		printf("%d %d\n", i, i + 1);
	cnt = rt = m + 1;
	for (int i = m + 1; i <= n / 2; i++)
	{
		if (!p[i]) continue;
		for (int j = cnt + 1; j <= i; j++)
			printf("%d %d\n", rt, j);
		printf("%d %d\n", rt, i + 1);
		rt = cnt = i + 1;
	}
	for (int i = cnt + 1; i <= n; i++) printf("%d %d\n", i, rt);
	return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
typedef unsigned long long int uli;
using namespace std;
int main() {
	int i,j;
	int n;
	cin >> n;
	vector<int> a(n),b(n);
	for(i = 0; i < n; ++i) {
		cin >> a.at(i);
		b.at(i) = a.at(i);
	}
	sort(b.begin(), b.end());
	if(a == b) {
		cout << "YES" << endl;
		return 0;
	}
	for(i = 0; i < n-1; ++i) {
		for(j = i + 1; j < n; ++j) {
			if(a.at(i) > a.at(j)) {
				swap(a.at(i), a.at(j));
				if(a == b) {
					cout << "YES" << endl;
					return 0;
				}
				else {
					swap(a.at(i), a.at(j));
				}
			}
		}
	}
	cout << "NO" << endl;
}

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 fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

string s;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>s;
	string tt = "keyence";
	for(int i=0;i<=s.length();i++)
	{
		for(int j=i;j<=s.length();j++)
		{
			string t = s.substr(0,i);
			if(j<s.length()) t+=s.substr(j,int(s.length())-j);
			if(t==tt){cout<<"YES\n"; return 0;}
		}
	}
	cout<<"NO\n";
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.Scanner;

public class Main {
	static Prime pm;
	static int passedNum;
	static boolean passedFlag;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		passedFlag = false;
		long dTimeStart, dTimeNow = 0;
		dTimeStart = System.currentTimeMillis();
		ExecutorService executor = Executors.newFixedThreadPool(4);
		pm = new Prime();
		int[] array = new int[3];
		int count;
		int num;
		List<Integer> out = new ArrayList<>(0);
		while (!((array[0] = sc.nextInt()) == 0 & (array[1] = sc.nextInt()) == 0 & (array[2] = sc.nextInt()) == 0)) {
			passedNum = 2;
			num = array[0];
			count = 0;
			while (count != array[2]) {
				if (pm.primeJudge(num)) {
					passedNum = num;
					count++;
				}
				num += array[1];
			}
			out.add(passedNum);
		}
		for (int n : out) {
			System.out.println(n);
		}
	}
	
	static class Prime {
		boolean primeArray[];
		
		public Prime() {
			primeArray = new boolean[(int) Math.sqrt(10E+6)];
			int tmp = 3;
			Arrays.fill(primeArray, true);
			primeArray[0] = false;
			primeArray[1] = false;
			FalseN fn = new FalseN(2);
			fn.start();
			int tmp3 = (int) Math.sqrt(primeArray.length);
			while (tmp3 > tmp) {
				boolean flag = true;
				if (flag = primeJudge(tmp)) {
					fn = new FalseN(tmp);
					fn.start();
				}
				tmp = getTrue(tmp);
			}
		}
		
		public int getTrue(int n) {
			for (int i = n + 2; i < primeArray.length; i += 2) {
				if (primeArray[i]) {
					return i;
				}
			}
			return -1;
		}
		
		public int getLargePrimeNumber() {
			for (int i = primeArray.length - 1; i > 1; i--) {
				if (primeArray[i]) {
					return i;
				}
			}
			return -1;
		}
		
		public boolean primeJudge(long n) {
			passedFlag = false;
			if (n == 1){
				return passedFlag;
			}
			if (n > Math.pow(primeArray.length - 1, 2) || (n % 2 == 0 && n != 2)) {
				return false;
			}
			int tmp = (int) Math.sqrt(n);
			for (int i = 3; i <= tmp; i += 2) {
				if (primeArray[i] && n % i == 0 && n != i) {
					return false;
				}
			}
			return true;
		}
		
		class FalseN extends Thread implements Runnable {
			int tmp;
			
			public FalseN(int tmp2) {
				tmp = tmp2;
			}
			
			public void run() {
				int tmp2;
				for (int i = 2; (tmp2 = tmp * i) < primeArray.length; i++) {
					primeArray[tmp2] = false;
				}
			}
		}
	}
}



Measured memory_bytes: 30752
import copy
from functools import lru_cache
#import numpy as np
#from numba import njit

def resolve():
    N, K = map(int, input().split())
    #A = np.array(list(map(int, input().split())))
    A = list(map(int, input().split()))

    #N = 2 * 10**5
    #K = 2 * 10**5
    #A = np.array([0] *  N)

    def func(A):
        B = [0] * N
        for i in range(N):
            l = max(0, i - A[i])
            r = min(i + A[i], N-1)
            B[l] += 1
            if r+1 < N:
                B[r+1] -= 1

        for i in range(1, N):
            B[i] += B[i-1]
        return B

    for k in range(K):
        #print(k)
        A = func(A)
        if k >= 50:
            break

    print(" ".join(map(str, A)))

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 169716
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

static class Program
{
    static IEnumerable<string> Solve(int N, string[] S)
    {
        int max = 0;
        var dict = new Dictionary<string, int>();
        foreach (string s in S)
        {
            if (!dict.ContainsKey(s)) { dict[s] = 0; }
            max = Math.Max(++dict[s], max);
        }
        var ci = new System.Globalization.CultureInfo("ja-JP").CompareInfo;
        var ans = dict.Where(pair => pair.Value == max).Select(pair => pair.Key).ToArray();
        Array.Sort(ans, (a, b) => ci.Compare(a, b, System.Globalization.CompareOptions.Ordinal));
        return ans;
    }

    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        var S = new string[N];
        for (int i = 0; i < N; ++i) { S[i] = Console.ReadLine(); }
        foreach (var s in Solve(N, S))
        {
            Console.WriteLine(s);
        }
    }
}


Measured memory_bytes: 48828
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

x = int(sys.stdin.readline())
m = x // 11
a = m * 11
m *= 2
if x - a > 0:
    a += 6
    m += 1
if x - a > 0:
    m += 1

print(m)


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


int main(){
	int k, a, b;
	cin >> k >> a >> b;
	
	if(b-a<=2){
		cout << k+1 << endl;
	} else {
		if(k<a+1){
			cout << k+1 << endl;
		} else {
			long int d = (k-a)/2;
			int r = (a-k)%2;
			if( r == 0 ){
				cout << d * b - (d-1) * a + 1 << endl;
			} else {
				cout << (d+1) * b - d * a << endl;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
int main(){
    ll n,W;cin>>n>>W;
    vector<ll>w(n),v(n);
    rep(i,n)cin>>w[i]>>v[i];
    vector<vector<ll> >dp(n,vector<ll>(100010,inf));
    dp[0][0]=0,dp[0][v[0]]=w[0];
    REP(i,1,n){
        rep(j,v[i])dp[i][j]=dp[i-1][j];
        REP(j,v[i],100001){
            if(dp[i-1][j-v[i]]>W)dp[i][j]=dp[i-1][j];
            else dp[i][j]=min(dp[i-1][j-v[i]]+w[i],dp[i-1][j]);
        }
    }
    ll ma;
    for(int i=100000;i>=0;i--){
        if(dp[n-1][i]<=W){
            ma=i;
            break;
        }
    }
    cout<<ma<<endl;
}

Measured memory_bytes: 79488
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	int h[n];
	for(int i=0;i<n;i++)
		cin >> h[i];
	int dp[n];
	for(int i=0;i<n;i++)
		dp[i] = 1000000001;
	dp[0] = 0;
	for(int i=0;i<n;i++) {
		for(int j=1;j<=k;j++)
			if(i+j<n)
				dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
	}
	cout << dp[n-1] << "\n";
	return 0;
}


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

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    while (A > 0 && C > 0)
    {
        C -= B;
        if (C <= 0)
        {
            cout << "Yes" << endl;
            break;
        }
        A -= D;
        if (A <= 0)
        {
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3636
N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(M):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

from collections import deque
def solve():
    prev = [-1]*N
    prev[0]='Yes'
    d = deque([(0,0)])
    while len(d):
        v,cnt = d.popleft()
        for u in edge[v]:
            if prev[u]==-1:
                prev[u]=v+1
                d.append((u,cnt+1))
    if -1 in prev:
        return ['No']
    return prev
print(*solve(),sep='\n')


Measured memory_bytes: 101072
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    string s;cin>>s;
    rep(i,s.size()){
        if(i==3){
            cout<<'8';
        }else{
            cout<<s.at(i);
        }
    }
    cout<<endl;
}


Measured memory_bytes: 3580
import java.util.*;
import java.io.*;
import static java.lang.System.*;

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
      if (ptr < buflen) {
          return true;
      }else{
          ptr = 0;
          try {
              buflen = in.read(buffer);
          } catch (IOException e) {
              e.printStackTrace();
          }
          if (buflen <= 0) {
              return false;
          }
      }
      return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
  public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while(isPrintableChar(b)) {
          sb.appendCodePoint(b);
          b = readByte();
      }
      return sb.toString();
  }
  public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
          minus = true;
          b = readByte();
      }
      if (b < '0' || '9' < b) {
          throw new NumberFormatException();
      }
      while(true){
          if ('0' <= b && b <= '9') {
              n *= 10;
              n += b - '0';
          }else if(b == -1 || !isPrintableChar(b)){
              return minus ? -n : n;
          }else{
              throw new NumberFormatException();
          }
          b = readByte();
      }
  }
  public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      return (int) nl;
  }
  public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    int d[] = new int[N];
    for(int i=0; i<N; i++) d[i] = sc.nextInt();
    Arrays.sort(d);
    out.println(d[N/2] - d[N/2-1]);
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

Measured memory_bytes: 24632
#include<bits/stdc++.h>
    using namespace std;
    int main(){
     int n;
     cin>>n;
     vector<pair<int,int> >v[n+1];
     
     for(int i=0;i<n-1;i++){
     int a,b,w;
     cin>>a>>b>>w;
     
     v[a].push_back(make_pair(b,w));
     v[b].push_back(make_pair(a,w));
     }
     int ans[n+1];
     queue<int>q;
     q.push(1);
     int vis[n+1]={0};
     vis[1]=true;
       ans[1]=0;
       while(!q.empty()){
          int p=q.front();
          q.pop();
          for(int i=0;i<v[p].size();i++)
            if(vis[v[p][i].first]==false){
              vis[v[p][i].first]=true;
              ans[v[p][i].first]=(ans[p]+v[p][i].second)%2;
              q.push(v[p][i].first);
            }
       }
       for(int i=1;i<=n;i++)
       cout<<ans[i]<<"\n";
    }

Measured memory_bytes: 7168
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
const int MOD = 1000000007;
int N, M;
int X[100005];
int Y[100005];
int Left[100005], Right[100005];
map <pair <int, int>, int> A;
int Inv[100005];
int Arb[100005];
int len;
vector <pair <int, int> > V;
vector <int> P;
void Read()
{
    cin >> N >> M;
    for(int i = 1; i <= N; i++)
        cin >> X[i];
    for(int i = 1; i <= M; i++)
        cin >> Y[i];
}
inline bool cmp(pair <int, int> a, pair <int, int> b)
{
    if(a.first == b.first)
        return Inv[a.second] > Inv[b.second];
    return a.first < b.first;
}
void precalcLeftRight()
{
    int point = 0;
    Y[M + 1] = 2000000000;
    for(int i = 1; i <= N; i++)
    {
        while(point <= M && Y[point] < X[i])
            ++point;
        --point;
        if(point != 0)
            Left[i] = X[i] - Y[point];
        else
            Left[i] = 2000000000;
        if(point != M)
            Right[i] = Y[point + 1] - X[i];
        else
            Right[i] = 2000000000;
        A[make_pair(Left[i], Right[i])] = i;
    }
    for(int i = 1; i <= N; i++)
    {
        if(A[make_pair(Left[i], Right[i])] == i && Left[i] != 2000000000 && Right[i] != 2000000000)
        {
            V.push_back(make_pair(Left[i], i));
        }
    }
    sort(V.begin(), V.end());
    int cnt = 1;
    for(int i = 0; i < V.size(); i++)
    {
        if(i == 0 || V[i].first != V[i - 1].first)
            ++cnt;
        Inv[V[i].second] = cnt;
    }
    for(int i = 0; i < V.size(); i++)
    {
        V[i].first = Right[V[i].second];
    }
    sort(V.begin(), V.end(), cmp);
    for(int i = 0; i < V.size(); i++)
        P.push_back(Inv[V[i].second]);
    len = cnt;
}
inline void Add(int& x, int y)
{
    x += y;
    if(x >= MOD)
        x -= MOD;
}
void Upd(int pos, int val)
{
    while(pos <= len)
    {
        Add(Arb[pos], val);
        pos += (pos & (-pos));
    }
}
int Sum(int pos)
{
    int ret = 0;
    while(pos >= 1)
    {
        Add(ret, Arb[pos]);
        pos -= (pos & (-pos));
    }
    return ret;
}
void Solve()
{
    Upd(1, 1);
    for(int i = 0; i < P.size(); i++)
    {
        int sum = Sum(P[i] - 1);
        Upd(P[i], sum);
    }
    int ans = Sum(len);
    cout << ans << "\n";
}
int main()
{
    Read();
    precalcLeftRight();
    if(len == 0)
    {
        cout << "1\n";
        return 0;
    }
    Solve();
    return 0;
}


Measured memory_bytes: 10232
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class CColon {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      double a, b, h, m; cin >> a >> b >> h >> m;

      double rad1 = m/60*2*PI;
      double rad2 = (h*60+m)/720*2*PI;
      double rad = rad1-rad2;
      debug(rad2);

      double ret = a*a+b*b-2*a*b*cos(rad);
      cout << setprecision(10) << fixed;
      cout << sqrt(ret) << endl;
    }
};

signed main() {
  CColon solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 4236