akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<numeric>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define chmin(a,b) (a>(b)?a=(b),1:0)
#define abs(n) max((n),-(n))
#define dist(a,b) max((a)-(b),(b)-(a))
#define chmax(a,b) (a<(b)?a=(b),1:0)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000000
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  // ここでストリームに obj を書き込みます。
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}


int main(){
  li n; cin >>n;
  vector<li> vec(n);
  rep(i,n) cin >>vec[i];
  li m=vec[0];
  rep(i,n) chmax(m,vec[i]);
  printf("%ld ",m);
  li h=m*2,k=0;
  rep(i,n)
    if(vec[i]==m) continue;
    else if(chmin(h,dist(m/2,vec[i]))) k=i;
  print(vec[k]);
}




Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;

int main()
{
    int n;
	int ans=100000;
	cin >> n;
	for(int i=0;i<n;i++){
		ans=ans*21/20;
		if(ans%1000!=0){
			ans+=(1000-ans%1000);
		}
	}
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1144
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            int N = sc.nextInt();
            int M = sc.nextInt();
            int[] data = new int[M];
            int[] dd = new int[M - 1];
            for (int i = 0; i < M; i++) {
                int input = sc.nextInt();
                data[i] = input;
            }
            Arrays.sort(data);
            for (int i = 1; i < M; i++) {
                dd[i-1] = data[i] - data[i-1];
            }
            Arrays.sort(dd);
            if (M <= N) {
                System.out.println(0);
                return;
            }
            int sum = 0;
            for (int i = 0; i < N - 1 ; i++) {
                sum += dd[M-2-i];
            }
            System.out.println(data[M-1] - data[0] - sum);


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 34996
import numpy as np
from numba import njit

@njit('i8(i8,i8,i8[:],i8[:],i8)', cache=True)
def get_max_score(N, K, plist, slist, max_score):
    for start in range(N):

        total_score_in_loop = 0
        score_loop = []
        now = start
        while True:
            now = plist[now]
            total_score_in_loop += slist[now]
            score_loop.append(slist[now])
            if now == start:
                break
        
        rem_score, loop_score = 0, 0
        for idx in range(1, len(score_loop)+1):
            rem_score += score_loop[idx-1]
            if total_score_in_loop > 0:
                loop_score = ((K - idx) // len(score_loop)) * total_score_in_loop
            max_score = max(max_score, rem_score + loop_score)
    return max_score

def main():
    N, K = map(int, input().split())
    plist = np.array([i-1 for i in map(int, input().split())], dtype='int64')
    slist = np.array([i for i in map(int, input().split())], dtype='int64')
    max_score = -10**15
    max_score = get_max_score(N, K, plist, slist, max_score)
    print(max_score)

if __name__ == '__main__':
    main()


Measured memory_bytes: 105260
#include <stdio.h>

typedef struct {

	int pelotas = 1;
	int roja = 0;
}cajas;


int main (){

	cajas A[300000];
	A[0].roja = 1;

	int n, m;
	scanf ("%d %d", &n, &m);

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

		A[i].pelotas = 1;
		A[i].roja = 0;
	}

	while (m--){


		int x, y;
		scanf ("%d %d", &x, &y);

		A[y-1].pelotas +=1;
		A[x-1].pelotas -= 1;

		//printf("%d %d\n", A[x-1].pelotas, A[y-1].pelotas);
		if (A[x-1].roja == 1){

			A[y-1].roja = 1;

			if (A[x-1].pelotas == 0){
				A[x-1].roja = 0;
			}
		}
	}
	int contador = 0;

	for (int i = 0; i < n; i++){

		if (A[i].roja == 1)
			contador++;
	}
	printf("%d\n",contador);
	return 0;
}

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

using namespace std;

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

  int n; cin >> n;
  vector < pair < string, int > > vec(n);

  for(auto &p : vec) cin >> p.first >> p.second;

  string w; cin >> w;

  int flag = 0, ans = 0;
  for(auto &p : vec) {
    ans += p.second * flag;
    flag |= (p.first == w);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import * as fs from 'fs';

const inputs = fs.readFileSync('/dev/stdin', 'utf8').split(/\n/);

const isBeautifulString = (str: string): boolean => {
  const counts = {};
  Array.from(str).forEach((c) => {
    counts[c] = counts[c] === undefined ? 1 : counts[c] + 1;
  });
  return Object.values(counts).filter((v: number) => v % 2 === 1).length === 0;
};

if (isBeautifulString(inputs[0])) {
  console.log('Yes');
} else {
  console.log('No');
}


Measured memory_bytes: 29644
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;
 
using namespace std;


int main()   {
    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, 1000);   // rand_gen(rng) gets the rand no

//    auto start = chrono::steady_clock::now();

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readstring(s);
        if ((s[0]>='A') && (s[0]<='Z')) {
            cout << "A" << endl;
        } else {
            cout << "a" << endl;
        }
    }

//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;

    return 0;
}

Measured memory_bytes: 3624
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------

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

    vector<int> x(n), y(n), h(n);

    int one = -1;

    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> h[i];
    }

    for(int i = 0; i < n; i++){
        if(h[i] > 0){
            one = i;
        }
    }

    for(int i = 0; i <= 100; i++){
        for(int j = 0; j <= 100; j++){
            bool ok = true;
            int H = h[one] + abs(i - x[one]) + abs(j - y[one]);
            for(int k = 0; k < n; k++){
                if(h[k] > 0){
                    if(H != h[k] + abs(i - x[k]) + abs(j - y[k])){
                        ok = false;
                        break;
                    }
                }
                if(h[k] == 0){
                    if(H > abs(i - x[k]) + abs(j - y[k])){
                        ok =false;
                        break;
                    }
                }
            }

            if(ok){
                cout << i << " " << j << " " << H << endl;
                return 0;
            }
        }
    }

}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>
#include <bitset>
#include <queue>

using namespace std;

// O(N)
template <typename T>
std::vector<T> createPrimeList(T max)
{
	if (max < 2)
		throw std::invalid_argument("max must be gteq 2");

	std::vector<bool> table(max + 1, true);
	table[0] = false;

	for (int i = 2; i <= max; i++)
	{
		if (table[i])
		{
			for (int j = i + 1; j <= max; j++)
			{
				if (table[j] && (j % i == 0))
				{
					table[j] = false;
				}
			}
		}
	}

	std::vector<T> result;
	for (int i = 2; i <= max; i++)
	{
		if (table[i])
			result.push_back(i);
	}

	return result;
}

using ll = long long;
template <typename T>
void primeFactorize(std::vector<T> &primes, unordered_map<int, int> &mp, T num)
{

	if (num == 0)
	{
		throw std::invalid_argument("num must be gt 0");
	}

	for (int i = 0; i < primes.size(); i++)
	{
		ll p = primes[i];
		if (p > num)
			break;

		T tmp = num;

		while (tmp % p == 0)
		{
			mp[p]++;
			tmp = tmp / p;
		}
	}
}

int main()
{
	int n;
	cin >> n;
	unordered_set<ll> divs;

	vector<int> primes = createPrimeList(10000);
	std::unordered_map<int, int> mp;
	for (int i = 1; i <= n; i++)
	{
		primeFactorize(primes, mp, i);
	}

	ll ans = 1;
	ll mod = 1000000007;
	for (auto kv : mp)
	{
		ans = (ans * (kv.second + 1)) % mod;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
S = input()
hug = 0
if len(S) % 2 == 0:
  for i in range(int(len(S)/2)):
    if not S[i] == S[-i-1]:
      hug += 1
    else:
      pass
else:
  for i in range(int((len(S)+1)/2)):
    if not S[i] ==S[-i-1]:
      hug += 1
    else:
      pass
print(hug)

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

int main() {
	int n,i,ans=0;
	cin >> n;
	string s;
	cin >> s;
	i=0;
	while(i<n-1){
		if(s[i]!=s[i+1]){
			i+=2; ans++;
		}else{
			i++;
		}
		
	}
	cout << ans << endl;
}


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

using namespace std;

int main()
{
	
	int a, p;
	cin >> a >> p;
	int x = a * 3 + p;
	cout << x / 2 << endl;

}

Measured memory_bytes: 256
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
for j in range(min(K,int(2*(math.log2(N)))+10)):
	B = [0]*N
	for i in range(N):
		l = max(0,i-A[i])
		r = min(N-1,i+A[i])
		B[l] += 1
		if r < N-1:
			B[r+1] -= 1
	for i in range(1,N):
		B[i] += B[i-1]
	A = B
print(' '.join(map(str,A)))


Measured memory_bytes: 162052
# -*- coding: utf-8 -*-
from itertools import accumulate
def inpl(): return map(int, input().split())

N = int(input())
A = list(inpl())
l = 0
r = 0
S = 0
ans = 0

while l < N and r < N:
    while r < N:
        if S + A[r] == S ^ A[r]:
            S += A[r]
            ans += (r-l+1)
            r += 1
        else:
            break
    if r > l:
        S -= A[l]
        l += 1
        
    else:
        r += 1
        l += 1

print(ans)

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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++){
        cin >> h.at(i);
    }

    int high = 0;
    int ans = 0;

    for (int i = 0; i < n; i++){
        if (high <= h[i]){
            high = h[i];
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int N;
  cin>>N;
  string w[100];
  map<string,int> s;
  rep(i,N) {
    cin>>w[i];
    s[w[i]]++;
    if (s[w[i]] != 1){
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i(0);i<N-1;i++){
    if (w[i][int(w[i].size()-1)] != w[i+1][0]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int x = sc.nextInt();
		if (k * 500 >= x) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21716
/*
 * hoge.cpp
 *
 *  Created on: 2014/09/30
 *      Author: eiichi
 */
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<list>
using namespace std;

vector<int> split(string s,char c){
	vector<int> v;string tmp;
	for(int i=0;i<s.size();i++){
		if(s[i]==c){
			v.push_back(stoi(tmp));
			tmp ="";
		}
		else tmp += s[i];
	}
	if(tmp!="")v.push_back(stoi(tmp));
	return v;
}

int main(void){
	for(int i=0;;i++){
		int m,f,r;
		cin >> m >> f >> r;
		if(m==-1 && f==-1 && r==-1)break;
		if(m==-1 || f==-1)cout << "F" << endl;
		else if(m+f>=80)cout << "A" << endl;
		else if(m+f>=65)cout << "B" << endl;
		else if(m+f>=50)cout << "C" << endl;
		else if(m+f>=30){
			if(r>=50)cout << "C" << endl;
			else cout << "D" << endl;
		}
		else cout << "F" << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
program r20628a
 
implicit none
integer :: c(1:26)
integer, allocatable :: interval(:, :)
integer, allocatable :: s(:, :)
integer, allocatable :: t(:), v(:)
integer :: i, j, d, m, h
integer, allocatable :: smalld(:)
integer, allocatable :: q(:)


read *, d

allocate(s(1:26, 1:d))
allocate(interval(1:26, 0:d))
allocate(t(1:d))
allocate(v(0:d))

interval(:, :) = 0 !interval(i,d) = d - last(d,i)
v(0) = 0
m = 0

read *, c(1:26)

do i = 1, d
 read *, s(:, i)
  
  do j = 1, 26
  if (s(j, i) > m) then
  m = s(j, i)
  h = j
  end if
  end do
  
 print *, h
end do

end program r20628a

Measured memory_bytes: 2948
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

int n;

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

bool isinrange(int y, int x) {
	return 0 <= y&&y < n && 0 <= x&&x < n;
}

signed main() {
	int c = 1;
	while (cin >> n&&n) {
		int y = 0, x = 0, idx = 1;

		for (int i = 0; i < n * 2 - 1; i++) {
			A[y][x] = idx++;
			while (isinrange(y + dy[i % 2], x + dx[i % 2])) {
				y += dy[i % 2];
				x += dx[i % 2];
				A[y][x] = idx++;
			}
			if (i < n - 1) {
				if (i % 2 == 0)x++;
				else y++;
			}
			else {
				if (i % 2 == 1)x++;
				else y++;
			}
		}

		A[n - 1][n - 1] = n*n;

		cout << "Case " << c++ << ":" << endl;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++)
				printf("%3d", A[i][j]);
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3184
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int max = 1000000007;
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[m];
		int[] step = new int[n+1];
		for(int i=0;i<n+1;i++) step[i]=0;
		for(int i = 0;i<m;i++){
			a[i] = sc.nextInt();
			step[a[i]] = -1;
		}
		for(int i = 1;i<=n;i++){
			if(i>2&&step[i]!=-1){
				if(step[i-1]!=-1) step[i]+=step[i-1];
				if(step[i-2]!=-1&&(max-step[i]>step[i-2])) step[i]+=step[i-2];
				else if(step[i-2]!=-1) {
					step[i] = step[i-2]-max;
					step[i] += step[i-1];
				}
			}else if(i==1&&step[1]!=-1){
				step[1]=1;
			}else if(i==2&&step[2]!=-1){
			   if(step[1]!=-1)	step[2]=2;
			   else step[2]=1;
			}
		}
		System.out.println(step[n]%max);
	}
}
				


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

using namespace std;

typedef long long ll;
const ll mod = 1000000007;

ll dp[100005];

ll fast_pow(ll val, ll pw){
	if(pw == 0)
		return 1;
	ll tmp = fast_pow(val, pw/2), ans;
	ans = (tmp*tmp)%mod;
	if(pw%2==1)
		ans = (ans*val)%mod;
	return ans;
}

ll num_div(int n, int maxi, int pw){
	ll prod;
	int tmp = maxi/n;
	prod = fast_pow(tmp, pw);
	return prod;
}

int main(){
	int n, k;
	ll sum = 0;
	cin>>n>>k;
	memset(dp, 0, sizeof dp);
	for(int x=k;x>=1;x--){
		dp[x] = num_div(x, k, n)%mod;
		for(int div=2;div*x<=k;div++){
			dp[x] = (dp[x]-dp[x*div])%mod;
			while(dp[x] < 0){
				dp[x] += mod;
			}
		}
		sum = (sum+(x*dp[x])%mod)%mod;
		//cout<<x<<" "<<dp[x]<<"\n";
	}
	cout<<sum<<"\n";
	return 0;
}

Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const int inf = int(1e10);
//const ll inf = inf(1e19);
const int mod = int(1e9) + 7;

int h, n, ab[1000][2];
int dp[10000 + 1];
int main(){
    cin >> h >> n;
    rep(i, n){
        int a, b; cin >> a >> b;
        ab[i][0] = a;
        ab[i][1] = b;
    }

    rep(i, h + 1) dp[i] = inf;
    dp[0] = 0;
    rep(i, h){
        if(dp[i] == inf) continue;
        rep(j, n){
            if(i + ab[j][0] <= h){
                dp[i + ab[j][0]] = min(dp[i + ab[j][0]], dp[i] + ab[j][1]);
            }
            else dp[h] = min(dp[h], dp[i] + ab[j][1]);
        }
    }
    cout << dp[h] << endl;
}

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

#define DIV 1000000007

string S;
long long dp[100005][20];

void update(int idx, int num){
	for(int i = 0; i < 13; i++){
		dp[idx+1][(i*10+num)%13] += dp[idx][i];
		dp[idx+1][(i*10+num)%13] %= DIV;
	}
}

int main(){
	cin >> S;
	dp[0][0] = 1;
	for(long long i = 0; i < S.size(); i++){
		if(S[i] == '?'){
			for(int num = 0; num < 10; num++){
				update(i, num);
			}
		}else{
			int num = S[i] - '0';
			update(i, num);
		}
	}
	cout << dp[S.size()][5] << endl;
}


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

int main(){
    string s1, t;
    cin >> s1 >> t;
    int s1_size = s1.size();
    int t_size = t.size();
    string mins = s1;
    mins[0] = '~';
    for(int i=0; i < s1_size - t_size + 1; i++){
        bool b=true;
        for(int j=0; j<t.size(); j++){
            if(t[j] != s1[i+j] && s1[i+j] != '?'){
                b=false;
                break;
            }
        }
        if(b){
            string s = s1;
            for(int j=0; j<t.size(); j++){
                if(s[i+j] == '?') s[i+j] = t[j];
            }
            for(int j=0; j<s.size(); j++){
                if(s[j] == '?') s[j] = 'a';
            }
            mins = min(mins, s);
        }
    }
    if(mins[0] == '~') cout << "UNRESTORABLE" << endl;
    else cout << mins << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

vector<vector<ll>> warshall_floyd(int n, vector<vector<ll>> &dist){
    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    return dist;
}

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

    int n, m, l; cin>>n>>m>>l;
    vector<vector<ll>> dist(n, vector<ll>(n, INF));
    for(int i=0; i<n; i++) dist[i][i] = 0;
    for(int i=0; i<m; i++){
        int a, b, c; cin>>a>>b>>c;
        a--, b--;
        dist[a][b] = dist[b][a] = c;
    }

    auto dist1 = warshall_floyd(n, dist);

    vector<vector<ll>> dist2(n, vector<ll>(n, INF));
    for(int i=0; i<n; i++) dist2[i][i] = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(dist1[i][j] <= l){
                dist2[i][j] = dist2[j][i] = 1;
            }
        }
    }

    auto fidist = warshall_floyd(n, dist2);

    int q; cin>>q;
    while(q--){
        int s, t; cin>>s>>t;
        s--, t--;
        if(fidist[s][t] == INF) cout << -1 << endl;
        else cout << fidist[s][t] - 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3456
open Printf
open Scanf

let flip f x y = f y x
                   
let () =
  let n = scanf "%d " (fun x -> x) in
  let rec read x ls =
    if x = 0 then ls
    else let p = scanf "%d %d " (fun a b -> (a, b)) in
         read (x - 1) (p :: ls) in
  let ps = read n [] in
  List.sort (flip compare) ps |> List.hd |> (fun (a, b) -> printf "%d\n" (a + b))


Measured memory_bytes: 13696
#include<bits/stdc++.h>
using namespace std;
const int INF=2E9;

int main(){
    int N;
    char c;
    int W[300010]={};
    int E[300010]={};
    cin >> N;
    for(int i=1;i<=N;i++){
        cin >> c;
        if(c=='W'){
            W[i]=W[i-1]+1;
            E[i]=E[i-1];
        }
        if(c=='E'){
            E[i]=E[i-1]+1;
            W[i]=W[i-1];
        }
    }
    int ans=INF;
    for(int i=1;i<=N;i++){
        ans=min(ans,E[N]-E[i]+W[i-1]);
    }
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 2560
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

// input に使うやつ
var rdr = bufio.NewReaderSize(os.Stdin, 10000)

func readLine() string {
	buf := make([]byte, 0, 10000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

// string から int へ
func atoi(s string) int {
	i, _ := strconv.Atoi(s)
	return i
}

// 一つの文字を int として読み込み
func readInt() int {
	return atoi(readLine())
}

// 複数の文字を int のスライスとして読み込み
func readInts() []int {
	in := readLine()
	ins := strings.Split(in, " ")
	out := make([]int, len(ins))
	for i, v := range ins {
		out[i] = atoi(v)
	}
	return out
}

// sortしたスライスを返す
func sorted(a []int) []int {
	sort.Ints(a)
	b := a
	return b
}

// 逆順のsort
func reverse(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	b := a
	return b
}

func main() {
	n := readInts()
	a := n[0]
	b := n[1]
	var k int
	if a > b {
		if (a-b)%2 == 0 {
			k = (a - b) / 2
			if a+k == b-k {
				fmt.Println(int(math.Abs(float64(a + k))))
			} else {
				fmt.Println(int(math.Abs(float64(a - k))))
			}
		} else {
			fmt.Println("IMPOSSIBLE")
		}
	} else {
		if (b-a)%2 == 0 {
			k = (b - a) / 2
			if b+k == a-k {
				fmt.Println(int(math.Abs(float64(b + k))))
			} else {
				fmt.Println(int(math.Abs(float64(b - k))))
			}
		} else {
			fmt.Println("IMPOSSIBLE")
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
 
using namespace std;
 
int main() {
  vector<int> A = {111, 222, 333, 444, 555, 666, 777, 888, 999};
  int N;
  cin >> N;
  for(int i = 0; i < A.size(); i++) {
    if (N <= A[i]) {
      cout << A[i] << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import bisect
s = input()
len_s = len(s)
t = input()

ind_dict = {i : [] for i in t}
for i, _s in enumerate(s):
    if _s in t:
        ind_dict[_s] += [i]

def get_least(last, s, dic):
    ls = dic[s]
    ind = bisect.bisect_right(ls, last)
    if ind >= len(ls):
        return ls[0]
    else:
        return ls[ind]

if -1 in [s.find(_t) for _t in t]:
    print(-1)
else:
    cnt = 0
    last = get_least(-1, t[0], ind_dict)
    _next = last
    for _t in t[1:]:
        _next = get_least(last, _t, ind_dict)
        if _next <= last:
            cnt += 1
        last = _next
    print(cnt * len(s) + _next + 1)

Measured memory_bytes: 11508
from itertools import permutations
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for _ in range(n):
    name = input()
    d[name[0]] += 1

prefix = list('MARCH')
path = []
for i in range(5):
    for j in range(i + 1, 5):
        for k in range(j + 1, 5):
            path.append((prefix[i], prefix[j], prefix[k]))
ans = 0
for a, b, c in path:
    ans += d.get(a, 0) * d.get(b, 0) * d.get(c, 0)
print(ans)

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define INF (int)1e9+7

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;
typedef pair<ll,ll> Pl;
typedef vector<ll> vl;
typedef vector<Pl> vpl;

ll gcd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b <= 0) return -1;
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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


int main() {
    int N;
    cin >> N;

    vi A(N);
    rep(i, N) cin >> A[i];

    ll ans = 0;
    int negcnt = 0, absmin = INF;
    rep(i, N) {
        ans += abs(A[i]);
        absmin = min(absmin, abs(A[i]));

        if(A[i] < 0) negcnt++;
    }

    if(negcnt%2 == 1) ans -= absmin*2;

    //string ans = ( flag ? "Yes" : "No" );
    //printf("%.8lf\n", ans);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int maxn=1000009;
const int P=1000000007;

int H,L;
int p[maxn];

long long f[maxn];
vector<int>V;
void pre(int x,long long now){
	if(x>=L){
		x=p[x-L+1]+L-1;now=now*x%P;
		while(x){
			V.push_back(x);
			f[x]=(f[x]+now)%P;
			x>>=1;now=now*x%P;
		}
		return;
	}
	pre(x<<1,now*(x<<1)%P);
	pre(x<<1|1,now*(x<<1|1)%P);
}
long long ans;
void solve(int x,long long now){
	if(x>=L){
		x=p[x-L+1]+L-1;now=now*x%P;int y=0;
		for(y=x,x=x>>1;x;y=x,x=x>>1){
			ans=(ans+now*f[x])%P;
			ans=(ans-now*f[y]%P*x%P+P)%P;
			now=now*x%P;
		}
		return;
	}
	solve(x<<1,now*(x<<1)%P);
	solve(x<<1|1,now*(x<<1|1)%P);
}
void work(int o){
	pre(o<<1|1,o<<1|1);
	solve(o<<1,1LL*o*(o<<1)%P);
	
	for(int i=0;i<V.size();++i)f[V[i]]=0;
	V.clear();
}
int main(){
	scanf("%d",&H);L=1<<(H-1);
	for(int i=1;i<=L;++i)scanf("%d",&p[i]);
	for(int i=1;i<L;++i)work(i);
	
	printf("%lld\n",ans);
	
	return 0;
}

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

int main(){
    string s;
    int ans=-4;
    cin >> s;
    for(int i=0;i<4;i++){
        if(s[i]=='+'){
            ans += 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int n;
    cin >> n;
    vi ans(n+1);
    rep(i, n+1){
        ans[i] == 0;
    }
    for(int x=1; x <=100; x++){
        for(int y=1; y <=100; y++){
            for(int z=1; z <=100; z++){
                if(x*x+y*y+z*z+x*y+y*z+z*x<=n)
                    ans[x*x+y*y+z*z+x*y+y*z+z*x]++;
            }
        }
    }
    rep(i,n){
        cout << ans[i+1] << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }    
  struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

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

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

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

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
  int main(){
     lint n,m;
     cin>>n>>m;
     lint p[n];
     rep(i,n){
         cin>>p[i];
         --p[i];
     }
     UnionFind uf(n);
     rep(i,m){
         lint a,b;
         cin>>a>>b;
         --a;--b;
         uf.unite(a,b);
     }
     vector<vector<lint>> x(n);
     rep(i,n){
         x[uf.root(i)].push_back(i);
     }
     lint ans=0;
     rep(i,n){
         rep(j,x[i].size()){
             if(binary_search(all(x[i]),p[x[i][j]]))ans++;
         }
     }
     cout<<ans;
  }
  
  
     
  

Measured memory_bytes: 6912
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
}
// ----------------------------------------------------------------------------

void call(int n){
  for(int i=1; i<=n; i++){
    if(i%3 == 0){
      cout << " " << i;
      continue;
    }
    int x = i;
    while(x){
      if(x%10 == 3){
        cout << " " << i;
        break;
      }
      x /= 10;
    }
  }
  cout << endl;
}

int main(){
  int N;
  cin >> N;
  call(N);
  return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef vector<int > vecint;
typedef vector<ll > vecll;
typedef vector<vector<int > > vec2int;
typedef vector<bool > vecbool;
typedef vector<string > vecstr;
////////////////////////////////////////////////
int main()
{
  int n; cin >> n;
  vecll t(n), a(n);
  ll nt = 1;
  ll na = 1;
  REP(i,n){
    cin >> t[i] >> a[i];
    ll t1 = (nt + t[i] - 1)/t[i];
    ll a1 = (na + a[i] - 1)/a[i];
    ll k = max(t1, a1);
    nt = k*t[i];
    na = k*a[i];
  }
  cout << nt + na << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int lcm(int a,int b){return a/__gcd(a,b)*b;}
main(){
  int n,x,ans=1;
  cin>>n>>ans;
  r(i,n-1){
    cin>>x;
    int p=__gcd(ans,x);
    ans=lcm(ans,x);
  }
  cout<<ans<<endl;
}

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

int main() {
    int availableSocket, neededSocket, usedSocket = 1, ans = 0;
    cin >> availableSocket >> neededSocket;
    while(usedSocket < neededSocket) {
        usedSocket--;
        usedSocket += availableSocket;
        ans++;
    }
    cout << ans << endl;
    return 0;
} 




Measured memory_bytes: 256
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

from math import log10

n,k=nm()
a=nl()
b=[1]*(n+1)

for i in range(n):
  b[i+1] = log10(a[i])+b[i]

for i in range(n-k):
  if b[i+k+1]-b[i+1] > b[i+k]-b[i]:
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 33020
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define inputv(arr,n) for(ll i=0;i<n;i++){ll value;cin>>value;arr.pb(value);}
#define sz(a) ((ll)(a).size())
#define len(a) ((ll)(a).length())
#define precise cout<<fixed<<setprecision(0); 
#define F first
#define S second
#define vi vector <int> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define YES cout<<"Yes\n"
#define NO cout<<"No\n"
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
inline ll max(ll a,ll b)
{return ((a>b)?a:b);}
inline ll min(ll a,ll b)
{return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b)
{if(b==0) return a;a%=b;return gcd(b,a);}
#define nl cout<<"\n"
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
// hashing for pairs
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};
//sort in reverse order
bool compare(ll x, ll y){
    return x>y;
}
void solve()
{
  ll d,t,s;
  cin>>d>>t>>s;
  if(d<=s*t)
  {
    cout<<"Yes";nl;
  }
  else
  {
    cout<<"No";nl;
  }
  return;
}
int main()
{
    IOS;
    int T=1;
  //  cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int               long long
#define endl              '\n'
#define ff                first
#define ss                second
#define mp                make_pair
#define pb                push_back
#define vii               vector<int> 
#define mii                          map< int, int >
#define msi                          map< string, int > 
#define mib                          map< int, bool > 
#define pii               pair<int,int>
#define vpii              vector< pii >
#define all(v)            v.begin(),v.end()
#define loop(i,s,e)       for(int i=s;i<e;i++)
#define rloop(i,e,s)      for(int i=e;i>=s;i--)
#define mset(a,f)              memset(a,f,sizeof(a))
#define M                 1000000007
#define fastio            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define prvec(v)          loop(i_u_j,0,v.size())cout << v[i_u_j] <<" "; cout << endl;
#define prarr(arr,n)      loop(i_u_j,0,n)cout << arr[i_u_j] << " "; cout << endl;
#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)


template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //
const int N = 3e5 + 7;
int n;
int arr[N];
int dp[3001][3001];
int getans(int s, int e, bool f, int ans)
{           
      int &mafia = dp[s][e];
      if( mafia != -1 ) return mafia;
      if( s > e ) return ans;
      if(f)
      {
            int a = arr[s] + getans(s+1, e, !f, ans);
            int b = arr[e] + getans(s, e-1, !f, ans);
            return mafia = max(a,b);
      }
      else
      {
            int a = getans(s+1, e, !f, ans) - arr[s];
            int b = getans(s, e-1, !f, ans) - arr[e];
            return mafia = min(a,b);
      }
}

void solve()
{
      cin >> n;
      loop(i,0,n) cin >> arr[i]; 
      mset(dp,-1);
      cout << getans(0,n-1, 1, 0);
}

int32_t main() {
    fastio;

  
  int t = 1; 
  //cin>>t;
  
  while(t--) solve();
  
  


}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //















Measured memory_bytes: 72064
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair<int, int> pii;  // pair<int, int> に pii という別名を付ける
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  for(int i=0; i<S.size(); i++){
    S.at(i) = 'x';
  }
  cout << S << endl;
}

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

int main() {
  while(1) {
    int H, W;
    cin >> H >> W;
    if (H==0 && W==0) {
      break;
    }
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (i == 0 || i == H - 1 || j== 0 || j==W - 1) {
          cout << "#";
        }
        else {
          cout << ".";
        }
      }
      cout << endl;
    }
    cout << endl;
  }
}


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

using namespace std;

using ll = long long;

struct Edge {
  int src, dst;
  Edge(int src, int dst) : src(src), dst(dst) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

bool visited[100000];
vector<int> ans1;
void sweep1(int v, const Graph &g) {
  visited[v] = true;
  for (const auto &e : g[v]) {
    if (!visited[e.dst]) {
      sweep1(e.dst, g);
      ans1.push_back(v);
      return;
    }
  }
  ans1.push_back(v);
  return;
}

vector<int> ans2;
void sweep2(int v, const Graph &g) {
  visited[v] = true;
  for (const auto &e : g[v]) {
    if (!visited[e.dst]) {
      sweep2(e.dst, g);
      ans2.push_back(v);
      return;
    }
  }
  ans2.push_back(v);
  return;
}

int main() {
  int n, m;
  cin >> n >> m;
  Graph g(n);
  for (int i = 0; i < m; ++i) {
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    g[s].emplace_back(s, t);
    g[t].emplace_back(t, s);
  }
  sweep1(0, g);
  sweep2(0, g);
  ans2.pop_back();
  reverse(ans2.begin(), ans2.end());
  cout << ans1.size() + ans2.size() << endl;
  for (const auto &x : ans1) {
    cout << x + 1 << " ";
  }
  for (const auto &x : ans2) {
    cout << x + 1 << " ";
  }
}


Measured memory_bytes: 9720
// "It's impossible" said Pride.
// "It's risky" said Experience.
// "It's pointless" said Reason.
// "Give it a try" whispered the heart".
 
#include<bits/stdc++.h>//works like magic, but at cost
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define int long long
#define mod 100000009
int gcd(int a, int b) {
    return b ? gcd(b, a%b): a;
}
void solve() {
    string s;
    cin>>s;
    
    if(s[2]==s[3] && s[4]==s[5])
         cout<<"Yes"<<endl;    
    else
        cout<<"No"<<endl;
    
}
    
int32_t main() {
    fastio;
    int t=1;
    // cin>>t;
    while(t--)solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

const int SIZE=17;

const int MOD=1e9+7;

inline void add(int &lhs,int rhs){
    lhs=(lhs+rhs);
    if(lhs>=MOD) lhs-=MOD;
}
int dp[41][1<<SIZE];
int isAccept[1<<SIZE];
int mypow10[40];

int main(){
    int n;
    cin>>n;
    int xyz[3];
    for(int i=0;i<3;i++) cin>>xyz[i];

    
    dp[0][(1<<SIZE)-1]=1;

    

    for(int bit=0;bit<(1<<SIZE);bit++){
        int st=0;
        int buf=0;
        for(int i=0;i<SIZE;i++){
            buf++;
            if(!((bit>>i)&1) && xyz[st]==buf){
                st++;
                buf=0;
                if(st==3){
                    isAccept[bit]=true;
                    break;
                }
            }
        }
    }

    
    mypow10[0]=1;
    for(int i=0;i+1<n;i++) mypow10[i+1]=ll(mypow10[i])*10%MOD;

    int res=0;
    int mask=(1<<SIZE)-1;
    for(int i=0;i<n;i++){
        res=res*10LL%MOD;
        for(int bit=0;bit<(1<<SIZE);bit++){
            if(dp[i][bit]==0) continue;
            for(int v=1;v<=7;v++){
                int nex=(bit<<v)+(1<<(v-1))-1;
                nex&=mask;
                add(dp[i+1][nex],dp[i][bit]);
            }
            add(dp[i+1][mask],dp[i][bit]);
            add(dp[i+1][mask],dp[i][bit]);
            add(dp[i+1][mask],dp[i][bit]);
        }
        for(int bit=0;bit<(1<<SIZE);bit++){
            if(isAccept[bit]){
                add(res,dp[i+1][bit]);
                dp[i+1][bit]=0;
            }
        }
    }

    cout<<res<<endl;
    
    
    return 0;
}


Measured memory_bytes: 20352
//#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define WAIT system ("pause")
#define rt0 return 0
using namespace std;
int main()
{
 //   WAIT;
 string a,b,c;
 cin>>a>>b>>c;
 cout<<a[0]<<b[1]<<c[2];
    rt0;
}

Measured memory_bytes: 256
import numpy as np
i8 = np.int64
i4 = np.int32


def solve(A, F, K):
    min_ = 0
    max_ = 10 ** 12
    while min_ < max_:
        mid = (min_ + max_) // 2
        count = A - mid // F
        sum_ = count[count > 0].sum()
        if sum_ <= K:
            max_ = mid
        else:
            min_ = mid + 1
    return min_

def main():
    stdin = open('/dev/stdin', 'rb')
    pin = np.fromstring(stdin.read(), i8, sep=' ')
    N, K = pin[:2]
    A = pin[2: N + 2]
    F = pin[N + 2: 2 * N + 2]
    A = np.sort(A)[::-1]
    F.sort()
    ans = solve(A, F, K)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 23600
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).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; }


ll gcd(ll a, ll b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}

	return b ? gcd(b, a % b) : a;
}

int main()
{	
	int N;
	cin >> N;

	vector<ll> A(N);
	rep(i, N) cin >> A[i];

	//left[i] := gcd(A[0],...,A[i])
	vector<ll> left(N);
	left[0] = A[0];
	repl(i, 1, N)
	{
		left[i] = gcd(left[i - 1], A[i]);
	}

	//right[i] := gcd(A[N - 1],...,A[N - 1 - i])
	vector<ll> right(N);
	right[0] = A[N - 1];
	repl(i, 1, N)
	{
		right[i] = gcd(right[i - 1], A[N - 1 - i]);
	}

	ll max_gcd = 0;
	rep(i, N)
	{
		if (i == 0)
		{
			max_gcd = max(max_gcd, right[N - 2]);
		}
		else if (i == N - 1)
		{
			max_gcd = max(max_gcd, left[N - 2]);
		}
		else
		{
			max_gcd = max(max_gcd, gcd(left[i - 1], right[N - 2 - i]));
		}
	}


	cout << max_gcd << endl;


	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll n,m;
    cin >> n >> m;
    queue<ll> que;
    ll i;
    vector<ll> v[n];
    ll par[n];
    ll a,b;
    for(i=0;i<n;i++){
        par[i]=-1;
    }
    for(i=0;i<m;i++){
        cin >> a >> b;
        v[a-1].push_back(b);
        v[b-1].push_back(a);
    }
    par[0]=0;
    que.push(1);
    ll t;
    while(!que.empty()){
        t=que.front();
        que.pop();
        for(auto itr=v[t-1].begin();itr!=v[t-1].end();++itr){
            if(par[*itr-1]==-1){
                par[*itr-1]=t;
                que.push(*itr);
            }
        }
    }
    cout << "Yes"<<endl;
    for(i=1;i<n;i++){
        cout << par[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 12548