akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
from collections import defaultdict, deque

graph = defaultdict(list)
for i in range(M):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    graph[u].append(v + N)
    graph[u + N].append(v + 2 * N)
    graph[u + 2 * N].append(v)
S, T = map(int, input().split())
S -= 1
T -= 1

dist = [-1] * (3*N)
dist[S] = 0
q = deque([S])
while q:
    v = q.popleft()
    d = dist[v]
    Vs = graph[v]
    for u in Vs:
        if dist[u] == -1:
            q.append(u)
            dist[u] = d + 1
if dist[T] != float("inf") and dist[T] % 3 == 0:
    print(dist[T] // 3)
else:
    print(-1)


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

const int INF = 1001001001;

int main() {
  int N,K;
  cin>>N>>K;
  int h[N], dp[N];
  for (int i=0; i<N; i++){
    cin>>h[i];
    dp[i]=INF;
  }
  dp[0]=0;
  
  for(int i=1; i<N; i++){
    for(int j=1; j<K+1; j++){
      if(i>=j){
        dp[i]=min(dp[i], abs(h[i]-h[i-j])+dp[i-j]);
//        cout<<dp[i]<<","<<abs(h[i]-h[i-j])<<endl;
      }
    }
  }
  cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
package main

import (
    "fmt"
    "os"
    "bufio"
    "strconv"
    // "sort"
)
var sc = bufio.NewScanner(os.Stdin)


func main() {
    sc.Split(bufio.ScanWords)
    // code goes here
    a, b := nextInt(), nextInt()
    ans := Max(a + b, Max(a + a-1, b + b-1))
    fmt.Println(ans);
}



func nextInt() int {
    sc.Scan()
    v, e := strconv.Atoi(sc.Text())
    if e != nil { panic(e) }
    return v
}
func nextInt64() int64 {
    sc.Scan()
    v, e := strconv.ParseInt(sc.Text(), 10, 64)
    if e != nil { panic(e) }
    return v
}
func nextString() string {
    sc.Scan()
    return sc.Text()
}
func nextFloat() float64 {
    sc.Scan()
    v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}
func Max(x, y int) int { if x > y { return x }; return y }
func Min(x, y int) int { if x < y { return x }; return y }
func Abs(x int) int { if x > 0 { return x }; return -x }



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

typedef long long ll;
using namespace std;

int main(){
     string a,b;
     cin >> a >> b;
     int n = a.size(),m = b.size();
     ll dp[n+1][m+1];
     for(int i=0;i<=n;i++) for(int j=0;j<=m;j++) dp[i][j] = 0;
     for(int i=1;i<=n;i++)
          for(int j=1;j<=m;j++)
               if(a[i-1] == b[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
               else dp[i][j] = max({dp[i][j],dp[i-1][j],dp[i][j-1]});
     string ans = "";
     int i = n ,j = m;
     while(i > 0 && j > 0){
          if(dp[i][j] == dp[i-1][j-1] + 1 && dp[i][j] == dp[i-1][j] +1 && dp[i][j] == dp[i][j-1] + 1){
            ans += a[i-1];
            i--;
            j--;
          }
          else if(dp[i][j-1] > dp[i-1][j]) j--;
          else i--;
          
     }
     reverse(ans.begin(),ans.end());
     cout << ans << endl;
     return 0;
}

Measured memory_bytes: 73972
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  const int N = 200005;


const int MOD = 1000000007;
int32_t main()
{



    IOS

    
    int n;
    cin >> n;

    vector<vector<int>> arr(n,vector<int>(n));

    vector<int> dp(1<<n);

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)cin >> arr[i][j];
    }


    dp[0] = 1;


    for(int mask = 0; mask < (1<<n)-1; mask++)
    {
        int x = __builtin_popcountll(mask);
        // pairing the xth men with jth women

        for(int j = 0;j < n; j++)
        {
            if((!arr[x][j]) or ((1<<j)&mask))
            {
                // if jth women is already assigned 
                // or if xth men and jth women are not compatible 
                continue;
            }

            int target = (mask |(1 << j));
            // target state is where jth bit is set

            dp[target] += dp[mask];
            dp[target] %= MOD;

        }
    }


    cout << dp[(1<<n)-1]%MOD;


















    
    return 0;
}



Measured memory_bytes: 16640
def s()
  gets()
end
def i()
  gets.to_i
end
def li()
  gets.split.map(&:to_i)
end
def ili()
  n = gets.to_i
  as = gets.split.map(&:to_i)
  [n, as]
end

n, y = li()

man = y/10000
gosen = (y- man*10000)/5000
sen = (y- man*10000-gosen*5000)/1000
min = (man+gosen+sen)

if n == min
  puts [man, gosen, sen].join(" ")
elsif n < min
  puts [-1, -1, -1].join(" ")
else
  res = [-1, -1, -1]
  0.upto(man){|i|
    diff = n - (min + i)

    if diff >= 0 && diff%4==0 && diff/4 <= gosen+2*i
      res = [man-i, gosen+2*i-diff/4, sen+diff/4*5]
    end
  }
  puts res.join(" ")
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    int n;
    double a,ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        ans+=1/a;
    }
    printf("%.10f",1/ans);
}


Measured memory_bytes: 256
import re

H,W,K = map(int,input().split())
grid = [[0 for i in range(W+1)]]
for i in range(H):
  S = input()
  grid.append([0]+[ int(S[i]) for i in range(W) ])

#累積和gridの作成
#行について
for i in range(H+1):
  for j in range(W):
    grid[i][j+1] += grid[i][j]
#列について
for j in range(W+1):
  for i in range(H):
    grid[i+1][j] += grid[i][j]   

min_cnt = (H-1)*(W-1)
#横の区切りを作る
for h in range(2**(H-1)):
  cnt = 0
  #二進数の文字列を取得
  bin_str = format(h,"0{}b".format(H-1)) 
  #区切りのインデックスリスト
  l_p =[1]+[ x.start()+2 for x in re.finditer("1",bin_str) ] +[H+1]

  #cntに区切りの分だけ付け加える
  cnt = cnt + len(l_p) - 2
  
  ws = 0
  for w in range(1,W+1):
    for k in range(len(l_p)-1):
      if grid[l_p[k+1]-1][w]-grid[l_p[k+1]-1][w-1] > K:
        min_cnt=(H-1)*(W-1)+1
      if grid[l_p[k+1]-1][w]- (grid[l_p[k]-1][w]+grid[l_p[k+1]-1][ws]-grid[l_p[k]-1][ws]) > K:
        cnt = cnt + 1
        ws = w-1
        break    
  min_cnt = min(min_cnt,cnt)

###
print(min_cnt)        

Measured memory_bytes: 45788
//
//  main.c
//  ITP1_11_B
//
//  Created by k16031kk on 2018/05/30.
//  Copyright © 2018年 AIT. All rights reserved.
//

#include <stdio.h>

void roll1(int a[]){
    int t=a[0];
    a[0]=a[4];
    a[4]=a[5];
    a[5]=a[1];
    a[1]=t;
}
void roll2(int a[]){
    int t=a[1];
    a[1]=a[2];
    a[2]=a[4];
    a[4]=a[3];
    a[3]=t;
}
void roll3(int a[]){
    int t=a[0];
    a[0]=a[2];
    a[2]=a[5];
    a[5]=a[3];
    a[3]=t;
}

int main(int argc, const char * argv[]) {
    // insert code here...
    int area[6],q,x,y;
    for(int i=0; i<6; i++) {
        scanf("%d", &area[i]);
    }
    scanf("%d",&q);
    while(q--) {
        scanf("%d %d",&x, &y);
        if(area[0]==x||area[1]==x||area[5]==x||area[4]==x){
            while(area[0]!=x)
                roll1(area);
            while(area[1]!=y)
                roll2(area);
        }
        else {
            while(area[0]!=x)
                roll3(area);
            while(area[1]!=y)
                roll2(area);
        }
        printf("%d\n",area[2]);
    }
    return 0;
}



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

#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;

int main(int argc, char *argv[]) {
    ll x, a, b;
    cin >> x >> a >> b;
    
    if (abs(x-a) < abs(x-b)) {
    	cout << "A" << endl;
    } else {
    	cout << "B" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
char p[310];
int w[310], n, m, U[310], K, Mod = 998244353, CC[310];
vector<int>D[310][310][310];
int main(){
    int i, c=0, j, k, l;
    scanf("%s",p+1);
    scanf("%d",&K);
    for(i=1;p[i];i++);
    n=i-1;
    for(i=1;i<=n;i++){
        if(p[i]=='0')c++;
        else U[++m] = c, CC[c]++;
    }
    for(i=0;i<=c;i++){
        for(j=0;j<=m;j++){
            for(k=0;k<=m;k++){
                D[i][j][k].resize(CC[i]+1);
            }
        }
    }
    D[0][0][0][0]=1;
    for(i=0;i<=c;i++){
        for(j=0;j<=m;j++){
            for(k=0;k<=m;k++){
                for(l=0;l<=CC[i];l++){
                    int t = D[i][j][k][l];
                    if(!t)continue;
                    if(i!=c){
                        D[i+1][j][k][0] = (D[i+1][j][k][0]+t)%Mod;
                    }
                    if(j!=m){
                        int tp = U[j+1];
                        if(tp < i)continue;
                        if(l==CC[i]){
                            D[i][j+1][k+1][l] = (D[i][j+1][k+1][l]+t)%Mod;
                        }
                        else{
                            D[i][j+1][k][l+1] = (D[i][j+1][k][l+1]+t)%Mod;
                        }
                    }
                }
            }
        }
    }
    long long res=0;
    for(i=0;i<=K&&i<=m;i++){
        for(j=0;j<=CC[c];j++)res+=D[c][m][i][j];
    }
    printf("%lld\n",res%Mod);
}


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

using namespace std;

int main()
{
    int n, a=0, b=0;
    cin>>n;
    string s, t;
    for (int i=0; i<n; i++)
    {
        cin>>s>>t;
        if (s<t) b+=3;
        else if (s>t) a+=3;
        else { a++; b++; }
    }
    cout<<a<<' '<<b<<'\n';
    return 0;
}



Measured memory_bytes: 3180
// ConsoleApplication1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;


int main()
{	
	int N, K;
	string S;
	cin >> N >> K >> S;
	for (int i = 0; i < N; i++) {
		if (i == K-1) {
			if (S[i] == 'A') {
				S[i] = 'a';
			}
			else if (S[i] == 'B') {
				S[i] = 'b';
			}
			else {
				S[i] = 'c';
			}
		}
	}
	for (int i = 0; i < N; i++) {
		cout << S[i];
	}
	
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこの,プロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define mod 1000000007;
#define my_mod 2019;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    ll n,k;
    cin >> n >> k;
    ll num[n];
    rep(i,n) cin >> num[i];
    sort(num,num+n);
    ll ans = 0;
    rep(i,n-k){
        ans += num[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
for i in range(n):
    a = list(map(int,input().split()))
    t = 0
    for j in range(m):
        t += a[j]*b[j]
    t += c
    if t>0: count+=1
print(count)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
typedef long long ll;
int N,K,A[110];
ll dp[110][100010] = {},inf = 1e9+7;


int main(){
	cin >> N >> K;
	for(int i=1;i<=N;i++){
		cin >> A[i];
	}
	ll ans = 0;
	dp[0][0] = 1;
	for(int i=1;i<=N;i++){
		ll sum[K+10] = {};
		for(int j=0;j<=K;j++){
			sum[j] += dp[i-1][j];
			if(j>0) sum[j] += sum[j-1];
			sum[j] %= inf;
		}
		for(int j=0;j<=K;j++){
			if(j-A[i]-1<0) dp[i][j] += sum[j];
			else dp[i][j] += (sum[j]-sum[j-A[i]-1]+inf)%inf;
			dp[i][j] %= inf;
		}
	}
	cout << dp[N][K]%inf << endl;
}

Measured memory_bytes: 80128
#include<iostream>
using namespace std;
int main(){
  int n,m;cin>>n>>m;

  int mm[100010] = {};  
  for(int i = 0; i < m; ++i){
    int x,y;cin>>x>>y;
    mm[x]++;
    mm[y+1]--;
  }
  int ans = 0;
  for(int i = 1; i< n+1; ++ i){
    mm[i]+=mm[i-1];
    if(mm[i] >= m)ans++;

  }
  cout<<ans<<endl;
  
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;


int main(){
    ll n, k;    cin >> n >> k;
    vector<ll> a(n);
    for(int i=0; i<n; i++){
        int x;  cin >> x;
        a.at(i) = x-1;
    }

    vector<ll> city;
    vector<bool> seen(n, false);
    int nv = a.at(0);
    //city[0] = 1;
    seen[0] = true;
    for(int i=0; i<n; i++){
        if(seen[nv]){
            int st = nv;
            while(1){
            //cout << nv << ' ';
                city.push_back(nv);
                nv = a[nv];               
               if(nv==st) break; 
            }
            //cout << endl;
            break;
        }
        seen[nv] = true;
        nv = a[nv];
        //cout << nv << endl;
    }  
    //for(int i=0; i<city.size(); i++) cout << i <<':' << city[i] << endl;
    nv = a.at(0); 
    for(int i=0; i<n; i++){
        k -= 1;
        if(nv==city[0]){
            //cout << k << ' ' << k%city.size() << endl;
            cout << city[k%(city.size())]+1 << endl; return 0;
        }
        //k -= 1;
        if(k==0){
            cout << nv+1 << endl; return 0;
        }
        nv = a[nv];
    }
}

Measured memory_bytes: 6960
t=gets.to_i


t.times{
    
a,b,c,d=gets.split.map(&:to_i)   
 
if a<b
    puts "No"
    next
end

if b>d
     puts "No"
    next
end
    
if b<=c+1
    puts "Yes"
    next
end


first=(a-b)%b


if (d-b).gcd(b)==1
  puts "No"
    next
end



left=(c+1)%b
right=(b-1)%b

if right<left
    right+=b
end



gcd=b.gcd(d-b)


aa=(left-first)/gcd

bb=first+aa*gcd


if bb<left && bb+gcd>right
    puts "Yes"
    
else
    puts "No"
end
    
    
}

Measured memory_bytes: 1788
#include <stdio.h>
#include <string.h>

#define A 1046527
#define NIL (-1)
#define B 14

char H[A][B];

int geChar(char ch) {
	if ( ch == 'A' ) return 1;
	else if ( ch == 'C') return 2;
	else if ( ch == 'G') return 3;
	else if ( ch == 'T') return 4;
	else return 0;
}

long long geKey(char str[]) {
	long long sum = 0, a = 1, i;
	for (i = 0; i < strlen(str); i++) {
		sum += a*(geChar(str[i]));
		a *= 5;
	}
	return sum;
}

int X1(int key) { return key % A; }
int X2(int key) { return 1 + (key % (A - 1)); }

int find(char str[]) {
	long long key, i, x;
	key = geKey(str);
	for (i = 0; ; i++) {
		x = (X1(key) + i * X2(key)) % A;
		if (strcmp(H[x], str) == 0 ) return 1;
		else if ( strlen(H[x]) == 0) return 0;
	}
	return 0;
}

int insert(char str[]) {
	long long key, i, x;
	key = geKey(str);
	for (i = 0; ; i++) {
		x = (X1(key) + i * X2(key)) % A;
		if ( strcmp(H[x], str) == 0 ) return 1;
		else if (strlen(H[x]) == 0 ) {
			strcpy(H[x], str);
			return 0;
		}
	}
	return 0;
}

int main() {
	int i, n, x;
	char str[B], cm[9];
	
	scanf("%d", &n);

	for (i = 0; i < n; ++i) {
		scanf("%s %s", cm, str);

		if (cm[0] == 'i') {
			insert(str);
		} else {
			if (find(str)) {
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}
	return 0;
}



Measured memory_bytes: 15956
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long t=(c-1)/b+1;
		long o=(a-1)/d+1;
		if(t<=o){
		System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

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

int main(){
  int n,m; cin >> n >> m;
  vector<int> a(n);
  int total =0;
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    total += a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  
  if(a.at(m-1)*4*m >= total ){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9
#define MOD 1000000007
using namespace std;
using ll = long long;
using pii = pair<int, int>;
 
int main(void) {
    string sdash, t;
    cin >> sdash;
    cin >> t;
 
    vector<string> strSet;
 
    int slen = sdash.size();
    int tlen = t.size();
 
    for (int j = 0; j <= slen - tlen; j++)
    {
        string s = sdash;
        bool match = true;
        for (int i = 0; i < tlen; i++)
        {
            if(s[j+i] != t[i]){
                if(s[j+i] == '?'){
                    s[j+i] = t[i];
                } else {
                    match = false;
                    break;
                }
            }
        }
        if(match) {
            for (int i = 0; i < slen; i++)
            {
                if(s[i] == '?') s[i] = 'a';
            }
            strSet.push_back(s);
        }
    }
 
    if(strSet.empty()){
        cout << "UNRESTORABLE" << endl;
    } else {
        sort(strSet.begin(), strSet.end());
        cout << *strSet.begin() << endl;
    }
    return 0;
}

Measured memory_bytes: 3640
M = 10 ** 9 + 7

def main():
    h, w, k = map(int, input().split())
    k -= 1

    init_fib(w)

    dp = [[None for _ in range(w)] for _ in range(h + 1)]
    for i in range(w):
        dp[0][i] = 0
    dp[0][k] = 1

    for i in range(1, h + 1):
        for j in range(w):
            x = 0
            if j != 0 and dp[i-1][j-1] != 0:
                left = j - 1
                right = w - j - 1
                t = fib(left) * fib(right) % M
                x += t * dp[i-1][j-1] % M
            if j + 1 < w and dp[i-1][j+1] != 0:
                left = j
                right = w - j - 2
                t = fib(left) * fib(right) % M
                x += t * dp[i-1][j+1] % M

            if dp[i-1][j] != 0:
                left = j
                right = w - j - 1
                t = fib(left) * fib(right) % M
                x += t * dp[i-1][j] % M
            
            dp[i][j] = x % M

    print(dp[h][0])

T = []
def init_fib(n):
    global T
    T.append(1)
    T.append(1)

    for i in range(2, n + 1):
        T.append(T[-1] + T[-2])

def fib(n):
    return T[n]

main()


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

#define fi first
#define se second
#define repl(i,a,b) for(long long i=(long long)(a);i<(long long)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

ll gcd(ll x,ll y){
  return y?gcd(y,x%y):x;
}

struct frac{
  ll m,d; // m/d
  frac():m(0),d(1){}
  frac(ll a,ll b):m(a),d(b){}
  frac& fix() { if(d<0)m=-m,d=-d; ll g=gcd(m<0?-m:m,d<0?-d:d); if(g!=0)m/=g,d/=g; return *this;}
  frac& operator+=(const frac& a){ ll mm=a.d*m+a.m*d; ll dd=d*a.d; m=mm; d=dd; fix(); return *this;}
  frac& operator-=(const frac& a){ ll mm=a.d*m-a.m*d; ll dd=d*a.d; m=mm; d=dd; fix(); return *this;}
  frac& operator*=(const frac& a){ ll mm=a.m*m; ll dd=a.d*d; m=mm; d=dd; fix(); return *this;}
  frac operator+(const frac& a)const{ return frac(*this) += a;}
  frac operator-(const frac& a)const{ return frac(*this) -= a;}
  frac operator*(const frac& a)const{ return frac(*this) *= a;}
  bool operator==(const frac& a)const{ return m*a.d==d*a.m; }
  bool operator<(const frac& a)const{ if(m*a.m>0){
                                        return m*a.d<a.m*d;
                                      }else{
                                        return m<=0;
                                      }
                                    }
  void show(){
    fix();
    printf("%lld/%lld\n", m,d);
  }
};

ll mem[55][55];

ll comb(ll n,ll r)
{
  if(mem[n][r]!=-1)return mem[n][r];
    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return mem[n][r]=(comb(n-1,r-1)+comb(n-1,r));
}

ll n,a,b;
ll v[66];
map<ll,ll> cnt;

int main(){
	cin.sync_with_stdio(false);
  memset(mem,-1,sizeof(mem));
  cin>>n>>a>>b;
  rep(i,n)cin>>v[i];
  rep(i,n){
    cnt[v[i]]++;
  }
  sort(v,v+n);
  reverse(v,v+n);
  frac maxx(-1,1); ll res=0;
  repl(i,a,b+1){
    frac ave;
    map<ll,ll> cntt;
    rep(j,i){
      ave+=frac(v[j],1);
      cntt[v[j]]++;
    }
    ave*=frac(1,i);
    ll ncnt=1;
    each(it,cntt){
      ncnt*=comb(cnt[it.fi],cntt[it.fi]);
    }
    if(ave==maxx){
      res+=ncnt;
    }else if(maxx<ave){
      maxx=ave;
      res=ncnt;
    }
  }
  printf("%.10f\n", (double)maxx.m/maxx.d);
  printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    gcd = fractions.gcd
    N, X = LI()
    A = LI()
    maxD = abs(A[0] - X)
    for a in A[1:]:
        maxD = gcd(maxD, abs(X-a))
    print(maxD)
main()



Measured memory_bytes: 16652
n=gets.to_i
s=gets.split.map &:to_i
c=0
M=->l,m,r{n1=m-l
n2=r-m
ll=s[l,n1]
rr=s[m,n2]
ll<<1e10
rr<<1e10
i=j=0
(l...r).map{|k|if ll[i]<=rr[j]
s[k]=ll[i]
i+=1
else
s[k]=rr[j]
j+=1
c+=n1-i
end}}
S=->f,l,r{if l+1<r
m=(l+r)/2
f[f,l,m]
f[f,m,r]
M[l,m,r]
end}
S[S,0,n]
p c

Measured memory_bytes: 51760
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(m)]

bc = sorted(bc, key=lambda x: -x[1])    
heapq.heapify(a)
for b, c in bc:
    for i in range(b):
        d = heapq.heappop(a)
        if d < c:
            heapq.heappush(a, c)
        else:
            heapq.heappush(a, d)
            break
print(sum(a))

Measured memory_bytes: 101016
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;



int main(){
  int n,i;
  cin >> n;
  int d[n];
  for(i=0;i<n;i++){
    cin >> d[i];
  }
  sort(d,d+n);
  int ans = d[n/2] - d[n/2-1];

  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 640
#!/usr/bin/env python3
import sys
import numpy as np

def solve(N: int, K: int, h: "List[int]"):
    h = np.array(h)
    f = np.array([0 for i in range(N)])
    for i in range(1, N):
        f[i] = np.min(f[max(0,i-K): i] + np.abs(h[max(0, i-K): i] - h[i]))
    print(f[N-1])
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 26580
#include<stdio.h>  
int main(void)
{
   int h, m, s;
   scanf("%d", &s);
   h = s / 3600;
   m = (s % 3600) / 60;
   s = s % 60;
   printf("%d:%d:%d\n", h, m, s);
   return 0;
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pb push_back
#define ll long long int
#define w(t) int t;cin>>t; while(t--)
#define mp make_pair
#define int128 __int128_t
#define pii pair<int,int>
#define fi first
#define se second
#define fr(n) for(int i=0;i<n;i++)
#define rep(j,n) for(int i=j;i<n;i++)
#define um unordered_map
#define M 1000000009
#define pq priority_queue
#define pqm priority_queue <int, vector<int>, greater<int> >
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin>>n;
	vi v(n);
	fr(n){
		cin>>v[i];
	}
	vi dp(n,INT_MAX);
	dp[0]=0;
	fr(n){
		if(i-1>=0){
			dp[i]=min(dp[i],dp[i-1]+abs(v[i]-v[i-1]));
		}
		if(i-2>=0){
			dp[i]=min(dp[i],dp[i-2]+abs(v[i]-v[i-2]));
		}
	}
	cout<<dp[n-1]<<"\n";
	return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    ll a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;
    
    if (w >= v){
        cout << "NO" << endl;
        return 0;
    }

    ll d1 = abs(a - b);
    ll v2 = abs(v - w);
    if (d1  <= t * v2) cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

using namespace std;

int main(){
    int N;
    while(cin >> N){
        vector<pair<int,int>> A, B;
        for(int i=0;i<N;i++){
            int t; cin >> t;
            A.emplace_back(t, i);
        }
        for(int i=0;i<N;i++){
            int t; cin >> t;
            B.emplace_back(t, i);
        }
        sort(A.begin(), A.end());
        sort(B.begin(), B.end());
        vector<int> next(N);
        bool ok = true;
        bool chk = true;
        for(int i=N-1;i>=0;i--){
            if(A[i].first > B[i].first) ok = false;
            else if(i-1 >= 0 && A[i].first <= B[i-1].first) chk = false;
            next[A[i].second] = B[i].second;
        }
        if(chk){
            int size = 0;
            vector<int> visit(N, 0);
            int s = 0;
            while(!visit[s]){
                visit[s] = 1;
                ++size;
                s = next[s];
            }
            if(size == N) ok = false;            
        }
        cout << (ok ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
int f(int m) {
    return m * (m - 1) / 2;
}

int id[500][500];
int cnt;
int get(int x, int y) {
    if (x > y) swap(x, y);
    if (id[x][y]) return id[x][y];
    return id[x][y] = ++cnt;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int m = 1; f(m) <= n; m++) {
        if (f(m) == n) {
            puts("Yes");
            printf("%d\n", m);
            for (int i = 0; i < m; i++) {
                printf("%d ", m - 1);
                for (int j = 1; j < m; j++) {                    
                    printf("%d%c", get(i,(i+j)%m), " \n"[j == m - 1]);
                }

            }

            return 0;
        }
    }
    puts("No");

}

Measured memory_bytes: 2304
def lcs(s1, s2):
    dp = []
    for s2_k in s2:
        bgn_idx = 0
        for i, cur_idx in enumerate(dp):
            chr_idx = s1.find(s2_k, bgn_idx) + 1
            if not chr_idx:
                break
            dp[i] = min(cur_idx, chr_idx)
            bgn_idx = cur_idx
        else:
            chr_idx = s1.find(s2_k, bgn_idx) + 1
            if chr_idx:
                dp.append(chr_idx)
    return len(dp)

n = int(input())
ans = []
for _ in range(n):
    x = input()
    y = input()
    ans.append(lcs(x, y))

for i in ans:
    print(i)


Measured memory_bytes: 5612
#include<iostream>
#include<algorithm>

struct Card{
    char suit;
    char value;
};

void bubble_sort(Card a[], int n)
{
    int cnt = 0;
    bool flag = true;
    for (int i = 0; flag; i++)
    {
        flag = false;
        for (int j = n - 1; j >= i + 1; j--)
        {
            if (a[j - 1].value > a[j].value)
            {
                std::swap(a[j - 1], a[j]);
                flag = true;
            }
        }
    }
}

void print_sequence(Card a[], int n)
{
    for (int i = 0; i < n; i++)
    {
        if (i != n - 1)
        {
            std::cout << a[i].suit << a[i].value << " ";
        }
        else
        {
            std::cout << a[i].suit << a[i].value << std::endl;
        }
    }
}

void selection_sort(Card a[], int n){
    for(int i = 0; i < n-1; i++){
        int mini = i;
        for(int j = i; j < n; j++){
            if(a[mini].value > a[j].value) mini = j;
        }
        std::swap(a[mini], a[i]);
    }
}

bool is_stable(Card c1[], Card c2[], int n){
    for(int i = 0; i < n; i++){
        if(c1[i].suit != c2[i].suit){
            return false;
        }
    }
    return true;
}

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

    Card C1[n], C2[n];

    for(int i = 0; i < n; i++){
        std::cin >> C1[i].suit >> C1[i].value;
    }
    for(int i = 0; i < n; i++){
        C2[i] = C1[i];
    }

    bubble_sort(C1, n);
    print_sequence(C1, n);
    std::cout << "Stable" << std::endl;

    selection_sort(C2, n);
    print_sequence(C2, n);

    if(is_stable(C1, C2, n)){
        std::cout << "Stable" << std::endl;
    }
    else{
        std::cout << "Not stable" << std::endl;
    }
}


Measured memory_bytes: 3120
#include <iostream>

using namespace std;

int A, B;



int main()
{

	cin >> A;
	cin >> B;

	if ((A + B) % 2 == 1) {
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		int ans = (A + B) / 2;
		cout << ans << endl;
	}


	return 0;
}


Measured memory_bytes: 256
n = int(input())

stm = [[] for i in range(n)]

def possible(honest):
    #print(honest)
    for i in range(n):
        if honest[i] == '0':
            continue
        for j in range(len(stm[i])):
            #print(stm[i][j])
            #print(honest[stm[i][j][0]-1])
            if stm[i][j][1] == 1 and honest[stm[i][j][0]-1] == '0':
                return False
            elif stm[i][j][1] == 0 and honest[stm[i][j][0]-1] == '1':
                return False
    return True

            

for i in range(n):
    a = int(input())
    for _ in range(a):
        x,y = map(int, input().split())
        stm[i].append([x,y])
   
count = 0
for k in range(2**n):
    hon = list(bin(k)[2:])
    hon = ['0']*(n-len(hon)) + hon
    if possible(hon):
        count = max(count, sum([int(x) for x in hon]))
print(count)            

Measured memory_bytes: 47708
<?php

class Simulator
{
    public $word = array();
    public $n_operations;
    public $operations2;

    public function __construct()
    {
        fscanf(STDIN, '%d', $this->n_operations);
        $operations = new \SplDoublyLinkedList();
        while ($this->n_operations > 0) {
            $word = trim(fgets(STDIN));
            if ($word[0] === 'i') {
                $operations->unshift(substr($word, 7));
            } elseif ($word[6] === 'F') {
                $operations->shift();
            } elseif ($word[6] === 'L') {
                $operations->pop();
            } else {
                foreach ($operations as $key => $element) {
                    if ($element === substr($word, 7)) {
                        $operations->offsetUnset($key);
                        break;
                    }
                }
            }
            $this->n_operations -= 1;
        }
        $this->dll2 = $operations;
    }

    public function getAnswer()
    {
        $str = array();
        $operations = $this->dll2;
        while (true) {
            try {
                $element = $operations->shift();
                $str[] = $element;
            } catch (Exception $e) {
                echo implode(' ', $str), PHP_EOL;
                break;
            }
        }
    }
}

$answer = new Simulator();
$answer->getAnswer();



Measured memory_bytes: 136144
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

ll N, M;

ll f( ll x )
{ return std::min( N+x, (M-2*x)/2 ); }

int main()
{
  scanf( "%lld%lld", &N, &M );

  ll mid = std::max( (M/2-N)/2, 0ll );

  ll ans = 0, ansx;
  repi( d, -10000, 10001 ) if( 2*(mid+d) >= 0 && 2*(mid+d) <= M )
    chmax( ans, f( mid+d ) );

  printf( "%lld\n", ans );

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = 998244353;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;


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;
}

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


void solve() {
	ll n;
	cin >> n;
	Array a(n),b(n);
	REP(i, n) cin >> a[i];
	REP(i, n) cin >> b[i];

	ll pow2 = 2;
	ll ans = 0;
	REP(i, 30) {
		Array aa(n),bb(n);
		REP(i, n) aa[i] = a[i] % pow2;
		REP(i, n) bb[i] = b[i] % pow2;
		sort(all(bb));
		ll t = pow2 / 2;
		ll con = 0;
		REP(j, n) {
			con += lower_bound(all(bb), 2 * t - aa[j]) - lower_bound(all(bb), t - aa[j]);
			con += lower_bound(all(bb), 4 * t - aa[j]) - lower_bound(all(bb), 3 * t - aa[j]);
		}

		if (con % 2 == 1) ans += (1LL << i);

		pow2 *= 2;
	}

	cout << ans << en;
}

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

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}


Measured memory_bytes: 6572
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--)
using namespace std;


/* Mathematical Functions */
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);

const int inf = (int)1e17;
const int N = (int)3e5+5;
vector<int>P(N,0),dp(N,0);
vector<int>L;
int32_t main(){

	FASTIO;
	string str;
	cin >> str;
	REP(i,0,str.size()){
		L.pb(str[i]-'0');
	}
	int n = L.size(),M = 2019,ans = 0;
	RER(i,n-1,0){
		P[i] = P[i+1] + mpower(10,n-i-1,M)*L[i];
		P[i] %= M; 
		dp[P[i]]++;
	}
	dp[0]++;
	REP(i,0,2019){
		ans += dp[i]*(dp[i]-1)/2;
	}
	cout << ans << endl;
    return 0;

}
int modInv(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
int res = (x%m + m) % m;
return res;
}
 
int gcdExtended(int a, int b, int *x, int *y)
{
if (a == 0){
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b%a, a, &x1, &y1);
  *x = y1 - (b/a) * x1;
  *y = x1;
  return gcd;
}
 
int mpower(int x, int y, int p)
{
int res = 1;
x = x % p;
while(y > 0){
    if(y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
    }
    return res;
}
int power(int x, int y)
{
int res = 1;
while (y > 0){
    if (y & 1) res = res*x;
      y = y>>1;
      x = x*x;
    }
    return res;
}
 
bool isPrime(int n)
{
if (n <= 1)  return false;
  if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
      int p=sqrt(n);
      for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
          return false;
      return true;
}

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

int main() {
  int N,A ;
  cin >> N ;
  cin >> A ;
  
  int a,b ;
    a = N / 500;
  b = N - a*500 ;
    if (b <= A) {
      cout << "Yes" << endl;
                }
  else{
    cout << "No" << endl;
                   
  }
  
  
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long ans = 0;
        long low = (a/c)*c;
        long hi = (b/c)*c;
        ans += (hi-low)/c;
        if(low==a) ans++;
        System.out.println(ans);
    }
}


Measured memory_bytes: 23124
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
	int i,n,x;
	vector<int> a;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x;
		a.push_back(x);
	}
	sort(a.begin(),a.end());
	cout<<a[n-1]-a[0]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
ll x[210000];
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    rep(i, 0, n) cin >> x[i];
    vector<ll> y(x, x+n);
    sort(y.begin(), y.end());
    ll s = y[(n-1)/2], t = y[(n-1)/2+1];
    rep(i, 0, n) {
        if (x[i] <= s) cout << t << endl;
        else cout << s << endl; 
    }
    return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n;
    cin>>n;
    if(n<6)
    {
        for(int i=0; i<n; i++)
            cout<<0<<endl;
    }
    else
    {
        int w[10001]= {0};
        int ma=sqrt(n-2)+1;
        for(int x=1; x<=ma; x++)
        {
            for(int y=1; y<=ma; y++)
            {
                for(int z=1; z<=ma; z++)
                {
                    int o=x*x+y*y+z*z+x*y+y*z+z*x;
                    if(o>n)
                        break;
                    w[o]++;
                }
            }
        }
        for(int i=1; i<=n; i++)
            cout<<w[i]<<endl;
    }
    return 0;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n, m;
    cin >> n >> m;
    Graph G(n);
    for (int i=0; i<m; ++i) {
        int a, b;
        cin >> a >> b;
        G.at(a-1).push_back(b-1);
        G.at(b-1).push_back(a-1);
    }

    deque<int> res;
    vector<bool> used(n, false);
    int cur = 0;
    while (true) {
        used.at(cur) = true;
        res.push_back(cur);
        bool end = true;
        for (int nx : G.at(cur)) {
            if (!used.at(nx)) {
                used.at(nx) = true;
                cur = nx;
                end = false;
                break;
            }
        }
        if (end) break;
    }

    auto check = [&used, &G](int s) -> int {
        for (int nx : G.at(s)) {
            if (!used.at(nx)) {
                return nx;
            }
        }
        return -1;
    };
    int s = 0;
    while ((s = check(s)) != -1) {
        used.at(s) = true;
        res.push_front(s);
    }

    cout << res.size() << '\n';
    for (int i=0; i<(int)res.size(); ++i) {
        cout << res.at(i) + 1;
        if (i == (int)res.size()-1) cout << '\n';
        else cout << ' ';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


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

using namespace std ; 

const int N = 1e5 + 7 ; 

int n , m ;

string s ; 

long long dp[50][11][2][2];

int get(int i , int l, int res , int p){
//    if(dp[i][l][res][p]!=-1ll)return dp[i][l][res][p] ; 
    if(i==m)return 1 ; 
    long long ret = 0 ;
    for(int j = 0 ; j < 10 ; j++){
        if(res && j > s[i]-'0')continue ; 
        if(abs(j - l) < 2 || !p){
            int nres = 0 ;
            if(res)nres = (j==s[i]-'0'); 
            ret+=get(i+1 , j , nres , (p|(!!j)) ) ; 
        }
    }   
    return ret ; 
}

void make(long long x){
    s = "" ; 
    while(x){
        s+=char( x%10 + '0') ; 
        x/=10 ; 
    }
    reverse(s.begin() , s.end()) ;
    m = s.size() ; 
}

int main(){
    memset(dp , -1ll , sizeof dp) ; 
    ios_base::sync_with_stdio(0) ; 
    cin.tie(0) ; 
  //  freopen("in.in" , "r" , stdin) ; 
    cin>>n ; 
    long long l  = 1 , r = 3234566668 , ans = 0; 
    while(l <=r ){
        long long mid = (l+r) /2 ; 
        make(mid) ; 
        long long  k = get(0 , 0 , 1 , 0) -1; 
        if(k >= n){
            r = mid-1 ; 
            ans = mid ; 
        }
        else{
            l = mid+1 ; 
        }
    }
    cout<<ans;
    return 0 ; 
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.nextLine();

        n = n.replaceAll("1","a");
        n = n.replaceAll("9","b");
        n = n.replaceAll("a","9");
        n = n.replaceAll("b","1");

        System.out.println(n);

    }
}

Measured memory_bytes: 23380
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var MOD = 1000000000 + 7

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	var sum, ans int
	N := nextInt()
	A := make([]int, N)
	for i := range A {
		A[i] = nextInt()
		sum += A[i]
		sum %= MOD
	}
	for _, a := range A {
		sum -= a
		sum %= MOD
		if 0 > sum {
			sum += MOD
		}
		ans += (a * sum) % MOD
		ans %= MOD
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5848
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var (
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
)

func main() {
	defer writer.Flush()
	var Ns string
	fmt.Fscanf(reader, "%s", &Ns)
	NsArray := strings.Split(Ns, "")
	for _, N := range NsArray {
		if N == "9" {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define For(I,N)   for(int I=1;I<=(N);I++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A,B) (*max_element(A,B))
#define MINEL(A,B) (*min_element(A,B))
#define ROPEN(X) freopen(X,"r",stdin)
#define WOPEN(X) freopen(X,"w",stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int,int>
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int a,b,k;
	cin>>a>>b>>k;
	if(b-a+1>=2*k){
		for(int i=0;i<k;i++){
			cout<<a+i<<endl;
		}
		for(int i=k-1;i>=0;i--){
			cout<<b-i<<endl;
		}
	}else{
		for(int i=a;i<=b;i++){
			cout<<i<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
  int H, W; cin >> H >> W; string S[H];
  rep(i, H) cin >> S[i];
  int ans[H][W] = {};
  int cnt = 0;
  rep(i, H){
    rep(j, W){
      if(S[i][j]=='.'){
        int begin = j; 
        while(S[i][j]=='.'){
          cnt++; j++;
          if(S[i][j]=='#' || j==W){
            for(int k=begin; k<j; k++){
              ans[i][k]+=cnt;
            }
            cnt = 0;
            break;
          }
        }
      }
    }
  }
  rep(j, W){
    rep(i, H){
      if(S[i][j]=='.'){
        int begin = i; 
        while(S[i][j]=='.'){
          cnt++; i++;
          if(S[i][j]=='#' || i==H){
            for(int k=begin; k<i; k++){
              ans[k][j]+=cnt;
            }
            cnt = 0;
            break;
          }
        }
      }
    }
  }
  int maxans = 0;
  rep(i, H){
    rep(j, W){
      maxans = max(maxans, ans[i][j]);
    }
  }
  cout << maxans-1 << endl;
}

Measured memory_bytes: 19968
N = int(input())

counter = 0
current = 11
flag = False
while N > 0:
    tmp = N % 10
    if tmp == current:
        counter += 1
    else:
        counter = 0
        current = tmp
    if counter > 1:
        flag = True
    N = N // 10
if flag is True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060