akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
dice = np.arange(1, N+1, dtype=np.int32)
need = np.zeros(N, np.int32)

for i in range(20):
    target = dice < K
    need[target] += 1
    dice[target] <<= 1 #2倍

counter = np.bincount(need, minlength=20)
power = np.full(20, .5, dtype=np.float64)
power[0] = 1
np.cumprod(power, out=power)

answer = (counter * power).sum() / N
print(answer)
#

Measured memory_bytes: 13796
# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-
# # 問題：https://atcoder.jp/contests/abc126/tasks/abc126_f
# # 解説動画を見ながら実装

import sys

m, k = map(int, input().strip().split())
max_num = 2**m
if k >= max_num:
    print(-1)
    sys.exit()

# if m == 0:
#     print(0)
#     sys.exit()

if m == 1:
    if k == 0:
        print('0 0 1 1')
    else:
        print('-1')
    sys.exit()

res = []
for i in range(max_num):
    if i == k:
        continue
    res.append(i)
res.append(k)
for i in range(max_num):
    j = max_num - i - 1
    if j == k:
        continue
    res.append(j)
res.append(k)
for i in range(2**(m+1)):
    print(res[i], end=' ')


Measured memory_bytes: 19620
using System;
using System.Linq;

namespace ProblemC
{
    class Program
    {
        static void Main()
        {
            var temp = Console.ReadLine().Split(' ').ToArray();
            long A = long.Parse(temp[0]);
            decimal B = decimal.Parse(temp[1]);
            long LB = (long)(B * 100);
            long ans = LB * A ;
            Console.WriteLine(ans / 100);
        }
    }
}


Measured memory_bytes: 28016
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        boolean debug = false;
        if (debug != false) {
            return;
        }
        System.out.println(str);
    }

    public static void main(String[] args) {

        String  S;
        try (Scanner sc = new Scanner(System.in)) {
            S = sc.next();
        }
        char[] c = S.toCharArray();
        if(c[0] == c[1] && c[2] == c[3] &&c[0]!=c[2]){
            System.out.println("Yes");
        }else if(c[0] == c[2] && c[1] == c[3] &&c[0]!=c[1]){
            System.out.println("Yes");
        }else if(c[0] == c[3] && c[1] == c[2] && c[0]!=c[1]){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }


}



Measured memory_bytes: 23124
import java.util.*;

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();

    for (int i = 0; i < H; i++) {
      String line = sc.next();
      for (int j = 0; j < 2; j++) {
        System.out.println(line);
      }
    }
  }
}


Measured memory_bytes: 22612
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let v = read_vec::<u32>();
    let a = v[0];
    let b = v[1];

    let bigger = std::cmp::max(a, b);
    let ans = if a != b {
        bigger * 2 - 1
    } else {
        bigger * 2
    };
    println!("{}", ans);
}


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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

int N, M, A;
multiset<ll> a;

void solve() {
	cin >> N >> M;
	for (int i = 0; i < N; ++i) {
		cin >> A;
		a.insert(A);
	}
	for (int i = 0; i < M; i++) {
		ll cur = *a.rbegin();
		a.insert(cur / 2);
		a.erase(--a.end());
	}
	
	ll ans = 0;
	for (auto i : a) ans += i;
	cout << ans;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


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

int main(){
  int n;
  cin>>n;
  ll t1,a1,t2,a2;
  cin>>t1>>a1;
  rep(i,n-1){
    cin>>t2>>a2;
    ll d=(t1+t2-1)/t2;
    if(a1>d*a2){
      d=(a1+a2-1)/a2;
    }
    t1=d*t2;
    a1=d*a2;
  }
  cout<<t1+a1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(auto& v: a) scanf("%d", &v);

	int all = 0;
	for(auto v: a) all = all ^ v;

	for(auto v: a) printf("%d ", all ^ v);
	printf("\n");
	return 0;
}


Measured memory_bytes: 3968
import java.util.*;

public class Main {
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String str = sc.next();

		// W,Eのカウント。配列は何？
        int countW = 0;
        int arrW[] = new int[n];
        int countE = 0;
        int arrE[] = new int[n];
        for (int i = 0; i < n; i++) {
            char ch = str.charAt(i);
            if (ch == 'W') {
                countW++;
            } else {
                countE++;
            }
            arrW[i] = countW;
            arrE[i] = countE;
        }
        // 与えられた文字列について、W、Eの文字数をそれぞれカウント。
        // さらに各配列に「その位置でのW(E)の要素の数」を突っ込む。

        // こうすると、
        int min = 0;
        for (int i = 0; i < n; i++) {
            if (i == 0) {
                min = arrE[n - 1] - arrE[i];
            } else {
                int tmp = arrW[i - 1] + (arrE[n - 1] - arrE[i]);
                if (min > tmp) {
                    min = tmp;
                }
            }
        }
        System.out.println(min);
	}
}


Measured memory_bytes: 31068
// C - Mazimum Volume
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main(){
    double l;
    cin >> l;
    double ans = 1.0;
    ans = l/3*l/3*l/3;
    printf("%.20f\n", ans);
    return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)


void solve(long long H, long long A){
    cout << (H + A - 1) / A << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long H;
    scanf("%lld",&H);
    long long A;
    scanf("%lld",&A);
    solve(H, A);
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            #yield i
        if i != n // i:
            divisors.append(n//i)
            #yield n//i
    return divisors

def solve(N: int):
    divisors =  make_divisors(N)
    res = 0
    for i in divisors:
        t = i-1
        if t > 0 and N // t == N % t:
            res += t
    print(res)


# Generated by 1.1.4 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
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 42696
import java.util.Scanner;

/**
 * Created by zhangrunfeng on 2/16/20
 */
public class Main {
    private int N;
    private int[] arr;

    public Main(Scanner sc) {
        N = sc.nextInt();
        arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }
    }

    public void printArray() {
        for (int i = 0; i < N-1; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println(arr[N-1]);
    }

    public void selectionSort() {
        int count = 0;
        for (int i = 0; i < N-1; i++) {
            int minIx = i;
            for (int j = minIx+1; j < N; j++) {
                if (arr[j] < arr[minIx]) {
                    minIx = j;
                }
            }
            if (minIx != i) {
                count++;
                // swap arr[i] & arr[minIx]
                int tmp = arr[i]; arr[i] = arr[minIx]; arr[minIx] = tmp;
            }
        }
        printArray();
        System.out.println(count);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.selectionSort();
    }
}


Measured memory_bytes: 26344
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int a = sc.nextInt();
		
		// 計算
		int result = 0;
		result = n * n - a;
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 23124
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();

        S = S.replaceAll("eraser",  "-");
        S = S.replaceAll("erase",   "-");
        S = S.replaceAll("dreamer", "-");
        S = S.replaceAll("dream",   "-");
        S = S.replaceAll("-", "");
        if(S.length() == 0) System.out.println("YES");
        else System.out.println("NO");
    }
}

Measured memory_bytes: 43800
#include <stdio.h>
int a[200001],b[200001];

int main(){
    int n;scanf("%d",&n);
    for (int i=1;i<=n;++i)scanf("%d",&a[i]);

    int m=0;
    for (int i=n;i>0;--i){
        int tmp=0;
        for (int j=2;j*i<=n;++j){
            if (b[j*i]) tmp++;
        }
        if (tmp%2!=a[i]) b[i]=1,++m;
        else b[i]=0;
    }

    printf("%d\n",m);
    for (int i=1;i<=n;++i)
    if (b[i]) printf("%d ",i);

}


Measured memory_bytes: 2432
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long int lld;
typedef pair<int, int> pii;
typedef pair<int, lld> pil;
typedef pair<pii, int> piii;
int n, m;
int main()
{
	int i, j, k, l;
	int t = 1, tv = 0;
	while(t--)
	{
		lld a, b, c, d;
		lld res = 0;
		scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
		if (d > 0) {
			if (a > d) {
				a = a - d;
				res += d;
				d = 0;
			}
			else {
				res += a;
				d -= a;
				a = 0;
			}
		}
		if (d > 0) {
			if (b > d) {
				b = b - d;
				d = 0;
			}
			else {
				d -= b;
				b = 0;
			}
		}
		if (d > 0) {
			if (c > d) {
				c = c - d;
				res -= d;
				d = 0;
			}
			else {
				d -= c;
				res -= c;
				c = 0;
			}
		}
		printf("%lld\n", res);
	}
}

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

using namespace std;

void solve()
{
	string str;
	getline(cin, str);
	for(int i = 0; i < str.size(); ++i)
	{
		if('a' <= str[i] && str[i] <= 'z')
		{
			str[i] = str[i] - 'a' + 'A';
		}
		cout << str[i];
	}
	cout << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1168
import fractions

n=int(input())
a=list(map(int, input().split()))
count=0

if n%2==1:
    for i in range(n):
        if a[i]%4==0:
            count+=1
    if count>=n//2:
        print('Yes')
        exit()
count=0
    
for i in range(n):
    if a[i]%4==0:
        count+=2
    elif a[i]%2==0:
        count+=1
    else:
        continue

if count>=n:
    print('Yes')
else:
    print('No')


    
    


        
    

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

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

const int mod=998244353;
//const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

mint choose(int n,int a){
    mint x=1;
    mint y=1;
    for(int i = 0; i < a; i++) {
        x*=n-i;
        y*=i+1;
    }
    return x/y;
}

//#define int long long
//signed main(){
int main() {
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    int n;
    cin >> n;

    vector<int> d(n,0);
    vector<int> cnt(n,0);
    int m=0;
    for(int i = 0; i < n; i++) {
        cin >> d[i];
        cnt[d[i]]+=1;
        m=max(d[i],m);
        if(d[i]==0&&i!=0){
            cout << "0" << "\n";
            return 0;
        }
    }

    mint ans=1;
    for(int i = 1; i <= m; i++) {
        mint tmp=cnt[i-1];
        tmp=tmp.pow(cnt[i]);
        ans*=tmp;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int n,s,p;
int arr[3001];
long long memo[3001][3001][2],ans;
long long dp(int index,int left,bool take){
    if (left==0){
        return n-(index-1)+1;
    }
    if (left<0 || index>n) return 0;
    if (memo[index][left][take]!=-1){
        return memo[index][left][take];
    }
    long long one=dp(index+1,left,take);
    long long two=dp(index+1,left-arr[index],true);
    if (!take){
        //cout<<index<<' '<<two<<'\n';
        ans+=two*index;
        ans%=p;
    }
    return memo[index][left][take]=(one+two)%p;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>s;
    for (int i=1;i<=n;i++){
        cin>>arr[i];
    }
    memset(memo,-1,sizeof(memo));
    p=998244353;
    dp(1,s,false);
    cout<<ans;
}

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

#define ll long long

ll x;

int main(){
	scanf("%lld", &x);
	ll y = x / 11;
	x -= y * 11;
	y *= 2;
	if(1 <= x && x <= 6) ++ y;
	else if(6 < x) y += 2;
	printf("%lld\n", y);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1000000007;
const long long INF = 1LL << 60;
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s; cin >> s;
    if(s == "Sunny") cout << "Cloudy" << endl;
    else if(s == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
    
    return 0;
}


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

int main()
{

    int n,l,i,j;
    scanf("%d %d",&n,&l);
        char str1[n][l+1];
    for(i=0;i<n;i++)
    {
        scanf("%s",&str1[i]);

    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(strcmp (str1[i],str1[j])>0)
            {
                char str2[l+1];
                strcpy(str2,str1[i]);
                strcpy(str1[i],str1[j]);
                strcpy(str1[j],str2);

            }
        }
    }
    for(i=0;i<n;i++)
    {
        printf("%s",str1[i]);
    }

    return 0;
}



Measured memory_bytes: 1696
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;


int n;

int main() {
	cin >> n;
	map<string, LL>mp;
	for (int i = 0; i < n; ++i) {
		string t;
		cin >> t;
		sort(t.begin(), t.end());
		mp[t]++;
	}
	LL ans = 0;
	for (auto p : mp) {
		ans += p.second * (p.second - 1) / 2;
	}
	cout << ans << endl;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int ans[200000] = {};
vector<int> nodes[200000];

void dfs(int p, int s){
    rep(i, nodes[s].size()){
        int to = nodes[s][i];
        if(to == p) continue;
        ans[to] += ans[s];
        dfs(s, to);
    }
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, Q; cin >> N >> Q;
    rep(i, N-1){
        int a, b; cin >> a >> b;
        a--; b--;
        nodes[a].push_back(b);
        nodes[b].push_back(a);
    }
    rep(i, Q){
        int a, x; cin >> a >> x; a--;
        ans[a] += x;
    }
    dfs(-1, 0);
    rep(i, N){
        if(i == N-1) cout << ans[i] << endl;
        else cout << ans[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 26624
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  repp(i, 1, B) {
    if ((A * i) % B == C) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;


bool isPrime(int a) {
  int squared = sqrt(a);
  for (int i = 2; i <= squared; ++i) { // only need to test up to squareroot
    if (a % i == 0) {
      return false;
    }
  }
  return true;
}

int main() {

  int n; // number of inputs

  cin >> n;

  int prime_count = 0;
  
  for (int i = 0; i < n; ++i) {
    int input;
    cin >> input;
    if (isPrime(input)) ++prime_count;
  }
  
  cout << prime_count << endl;
  
}

Measured memory_bytes: 1160
L, R = map(int, input().split())

if not L // 2019 == R // 2019:
    print(0)
else:
    L %= 2019
    R %= 2019
    ans = 2020
    for i in range(L, R):
        for j in range(i+1, R+1):
            tmp = (i * j) % 2019
            if tmp < ans:
                ans = tmp
    print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName

template <typename T>ostream &operator<<(ostream &out,const vector<T> &v) {rep(i,(int)v.size()-1)cout<<v[i]<<" ";cout<<v[(int)v.size()-1];return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const map<T1, T2> &p) {out << "(" << p.first << ", " << p.second << ")";return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const pair<T1, T2> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template<class T>void debag(const T &obj){cout<<obj<<endl;}

bool solve(){
	rep(i,5){
		int x;cin>>x;
		if(x==0)cout<<i+1<<endl;
	}
  	return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(15);
  solve();
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(void){
    int n; cin>>n;
    vector <int> a(n),b(n+1);
    for(int i=0;i<n;i++){
      cin>>a[i];  
    }
    b[0]=0;
    for(int i=0;i<n;i++){
        b[i+1]=b[i]+a[i];
    }
    map <int,int> ma;
    for(int i=0;i<n+1;i++){
        ma[b[i]]++;
    }
    int ans = 0;
    sort(b.begin(),b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    for(int i=0;i<b.size();i++){
        int k = ma[b[i]];
        ans += k*(k-1)/2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
vector<string> v= {"AC", "WA", "TLE", "RE"};
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	map<string ,ll> m;
	for(ll i=0;i<n;i++){
		string s;
		cin>>s;
		m[s]++;
	}
	for(ll i=0;i<4;i++){
		cout<<v[i]<<" x "<<m[v[i]]<<"\n";
	}
	
	return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    ll n, k;
    cin >> n >> k;
    cout << n - k + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
#include <math.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 100;

ll a[maxn][maxn], ans[maxn][maxn];
ll n, k;
void mul(ll a[maxn][maxn], ll b[maxn][maxn]) {
    ll c[maxn][maxn];
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) { c[i][j] = 0;
            for (int k = 1; k <= n; k++) {
                c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % mod;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            a[i][j] = c[i][j];
        }
    }
}

int main() {
//    freopen("in.in", "r", stdin);
//    freopen("o2.out", "w", stdout);
    cin >> n >>k;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> a[i][j];
        }
        ans[i][i] = 1;
    }
    while (k) {
        if (k & 1) {
            mul(ans, a);
        }
        mul(a, a);
        k >>= 1;
    }
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            sum += ans[i][j];
            sum %= mod;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>

using namespace std;

int main()
{
    int n;
    int a[200010];
    int even[100010], odd[100010];
    int ecnt = 0, ocnt = 0;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if ((i+1)%2) {
            odd[ocnt] = a[i];
            ocnt++;
        }
        else {
            even[ecnt] = a[i];
            ecnt++;
        }
    }
    if (n%2) {
        for (int i = ocnt-1; i >= 0; i--) {
            cout << odd[i] << " ";
        }
        for (int i = 0; i < ecnt; i++) {
            cout << even[i] << " ";
        }
        cout << endl;
    }
    else {
        for (int i = ecnt-1; i >= 0; i--) {
            cout << even[i] << " ";
        }
        for (int i = 0; i < ocnt; i++) {
            cout << odd[i] << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3712
from itertools import accumulate

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

def calc_imos(arr):
  imos=[0]*(N+1)
  for i,a in enumerate(arr):
    l=max(0,i-a) #照らす範囲の左側インデックス、0が最小
    r=min(N-1,i+a) #照らす範囲右側インデックス,arrの長さ-1=Nが最大
    imos[l]+=1
    imos[r+1]-=1
  imos=list(accumulate(imos))
  return imos[:-1]

for k in range(min(50,K)):
  A=calc_imos(A)
print(*A,sep=" ")

Measured memory_bytes: 233248
#include<stdio.h>
int main(){
  long long n,i,j=2,ans=0;
  scanf("%lld",&n);
  for(i=1;(j*5)<=n;i++){
    j*=5;
    ans+=n/j;
  }
  printf("%lld\n",n%2?0:ans);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int i, j;

	int n, m;
	int a[100][100];
	int b[100];
	int c[100];

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

	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			scanf("%d", &a[i][j]);
		}
	}

	for (j = 0; j < m; j++)
	{
		scanf("%d", &b[j]);
	}

	for (i = 0; i < n; i++)
	{
		c[i] = 0;
		for (j = 0; j < m; j++)
		{
			c[i] += a[i][j] * b[j];
		}
		printf("%d\n", c[i]);
	}


	return 0;
}


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

int main()
{
    int n = 0;
    int d[200][2] = {};
    int count = 0;
    bool ret = false;

    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> d[i][0];
        cin >> d[i][1];
        if(d[i][0] == d[i][1]){
            ++count;
        }
        else{
            count = 0;
        }

        if(count >= 3){
            ret = true;
        }
    }

    if(ret){
        cout << "Yes";
    }else{
        cout << "No";
    }


    return 0;
}

Measured memory_bytes: 3568
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt();
		if(a == b && b == c && c == a && a % 2 == 0)
			System.out.println(-1);
		else{
			int count = 0;
			while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
				int temp_a = b / 2 + c / 2;
				int temp_b = c / 2 + a / 2;
				c = a / 2 + b / 2;
				a = temp_a;
				b = temp_b;
				count++;
			}
			System.out.println(count);
		}
	}
 
}

Measured memory_bytes: 23252
S=input()
if S[0]=='o':
  if S[1]=='o':
    if S[2]=='o':
      print('1000')
    else:
      print('900')
  else:
    if S[2]=='o':
      print('900')
    else:
      print('800')
else:
  if S[1]=='o':
    if S[2]=='o':
      print('900')
    else:
      print('800')
  else:
    if S[2]=='o':
      print('800')
    else:
      print('700')
  
    

Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        //Solve();
        return;
    }

    public static string Solve()
    {
        int[] input = ReadInts();
        int N = input[0];
        int K = input[1];
        int ans = 0;
        while (N > 0)
        {
            N /= K;
            ans++;
        }

        return ans.ToString();
    }

    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


Measured memory_bytes: 11220
use std::io::*;
use std::collections::{ HashMap, HashSet };

fn read(s: &mut StdinLock) -> i64 {
    s.by_ref().bytes().map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .skip_while(|c| c.is_whitespace())
        .fold(0, |a, x| (x as u8 - b'0') as i64 + a * 10)
}
fn read_line_split(s: &mut StdinLock, n: i64) -> Vec<i64> {
    (0..n).map(|_| read(s)).collect()
}

fn main() {
    let s = stdin();
    let mut s = s.lock();
    let n: i64 = read(&mut s);
    let a: Vec<i64> = read_line_split(&mut s, n);
    let mut cnt_map: HashMap<i64, i64> = 
        a.clone().into_iter()
            .collect::<HashSet<i64>>()
            .iter()
            .map(|&x| (x, 0))
            .collect::<HashMap<i64, i64>>();
    for i in &a {
        *cnt_map.get_mut(i).unwrap() += 1;
    }
    let tot: i64 = cnt_map.iter().fold(0, |acc, x| acc+(x.1*(x.1-1))/2);
    for i in &a {
        let ans: i64 = tot + 1 - cnt_map[i];
        println!("{}", ans);
    }
}

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

int main() {
  int N,D,X;
  cin >> N >> D >> X;
  
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  int sum = 0;
  int d = D - 1;
  for (int i = 0; i < N; i++) {
    sum += (d / A.at(i)) + 1;
  }
  cout << sum + X << endl;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <set>
using namespace std;

int main(){
    int x, t;
    cin >> x >> t;
    cout << max(0,x - t) << endl;
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

void main() {
    immutable x = readln.split.to!(int[]);
    (x.countUntil!"a == 0" + 1).writeln;
}

void scan(T...)(ref T args) {
    auto line = readln.split; // @suppress(dscanner.suspicious.unmodified)
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args)
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args)
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 2684
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int p = sc.nextInt();
    int q = sc.nextInt();
    int r = sc.nextInt();
    System.out.println(Math.min(Math.min(p + q, q + r), r + p));

  }
}

Measured memory_bytes: 35572
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    max1st = max(A)
    max1stIndex = A.index(max1st)

    for i in range(len(A)):
        if i == max1stIndex:
            tmp = A[i]
            A[i] = 0
            print(max(A))
            continue

        print(max1st)




if __name__ == '__main__':
    main()


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

const int N = 6000;
//const int N = 10;
bool block[N][5];


void output(){
  cout <<"Begin"<<endl;
  rep(i,10){
    rep(j,5){
      cout << block[9-i][j] << " ";
    }
    cout << endl;
  }
  cout <<"end"<<endl;
}

void all_fall(int y){
  rep(j,5)block[y][j]=false;

  
  REP(i,y,N-1){
    rep(j,5)block[i][j]=block[i+1][j];

  }
  
  rep(j,5)block[N-1][j]=false;
}

int getmax(int l,int r){
  int ret=0;
  REP(j,l,r){    
    int tmp = N-1;
    for(int i=N-1;i>=0;i--){
      if (block[i][j])break;
      tmp=i;
    }
    ret=max(ret,tmp);
  }
  return ret;
}

void fall(){
  rep(i,N){
    if (block[i][0]&block[i][1]&block[i][2]&block[i][3]&block[i][4]){
      all_fall(i);
      i--;
    }
  }
}

main(){
  int n;
  while(cin>>n && n){
    rep(i,N)rep(j,5)block[i][j]=false;
    rep(i,n){
      int d,p,q;
      int wid=1,hei=1,pos;
      cin>>d>>p>>q;
      q--;
      if (d == 1){//yoko
	pos = getmax(q,q+p);	
	wid=p;
      }else if (d == 2){//tate
	pos = getmax(q,q+1);
	hei=p;
      }

      rep(i,hei){
	rep(j,wid){
	  block[pos+i][q+j]=true;
	}
      }
      fall();
      //output();
    }

    cout << count(&block[0][0],&block[N][0],true) << endl;
    //    cout << cnt << endl;
  }
  
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

LL RSP[3];
string cs = "rsp";

LL calc(string s){
    dump(s)
    int len = s.length();
    vector<VL> dp(len+1,VL(3));
    
    for(int i = 1; i <= len; i++){
        REP(j,3){
            LL base = 0;
            REP(k,3){
                if(j == k) continue;
                chmax(base,dp[i-1][k]);
    
            }
            dp[i][j] = base + (s[i-1] == cs[(j+1)%3] ? RSP[j] : 0);
        }
    }
    LL res = 0;
    REP(i,3){
        chmax(res,dp[len][i]);
    }
    dump(res)
    return res;
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int N,K; cin >> N >> K;
    REP(i,3) cin >> RSP[i];
    string s; cin >> s;
    vector<string> vs(K);
    REP(i,N){
        vs[i%K] += s[i];
    }
    LL ans = 0;
    for(string x : vs){
        ans += calc(x);
    }
    cout << ans << endl;
    

}

Measured memory_bytes: 5968
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp(a,b) make_pair(a,b)
const long long mod = 1000000007;
const long long inf = 1ll<<61;
typedef pair<int, int> P;
typedef pair<int ,P> PP;
struct edge { int to; int to2; int cost; };

signed main() {
	string s; cin >> s;
	string N;
	rep(i, s.size()) {
		if (s[i] == 'A')N.push_back('A');
		else if (s[i] == 'B') {
			if (i != s.size() - 1 && s[i + 1] == 'C') {
				N.push_back('D');
				i++;
			}
			else N.push_back('Z');
		}
		else N.push_back('Z');
	}
	//cout << N << endl;
	int cnt = 0;
	int rw = 0;
	rep(i, N.size()) {
		if (N[i] == 'A')rw++;
		else if (N[i] == 'D')cnt += rw;
		else rw = 0;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  string s;
  cin>>s;
  int cnt[3];
  rep(i,0,3)cnt[i]=0;
  rep(i,0,3){
    
    if(s[i]=='a')cnt[0]=1;
    if(s[i]=='b')cnt[1]=1;
    if(s[i]=='c')cnt[2]=1;
  }
  if(cnt[0]==1&&cnt[1]==1&&cnt[2]==1)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    vector<vector<ll>> cnt(61,vector<ll>(n));
    rep(i,n){
        cin>>a[i];
        a[i]--;
        cnt[0][i]=a[i];
    }
    FOR(b,1,61){
        rep(i,n){
            cnt[b][i]=cnt[b-1][cnt[b-1][i]];
        }
    }
    ll now=0;
    rep(b,61){
        if(1ll<<b & k){
            now=cnt[b][now];
        }
    }
    cout<<now+1<<endl;
}

Measured memory_bytes: 101672
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

const int N_MAX = 1005;

int n, m;
vector<int> graph[N_MAX];
vector<P> edges;
vector<bool> used(N_MAX, false), in_history(N_MAX, true);
deque<int> history;

inline void show_history(){
	int l = history.size();
	cout << l << endl;
	rep(i,l) cout << history[i]+1 << endl;
}

inline bool check(){
	vector<int> indeg(N_MAX, 0), outdeg(N_MAX, 0);
	for(int i : history){
		for(int j : graph[i]){
			++outdeg[i];
			++indeg[j];
		}
	}
	for(int x : history){
		if(outdeg[x] != 1 || indeg[x] != 1) return false;
	}
	return true;
}

inline bool dfs(int v){
	used[v] = true;
	in_history[v] = true;
	history.push_back(v);
	for(int nv : graph[v]){
		if(in_history[nv]){
			while(history.front() != nv){
				in_history[history.front()] = false;
				history.pop_front();
			}
			return true;
		}
		if(dfs(nv)) return true;
	}
	history.pop_back();
	in_history[v] = false;
	return false;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	rep(i,m){
		int a, b;
		cin >> a >> b;
		--a; --b;
		graph[a].push_back(b);
		edges.emplace_back(a, b);
	}
	{
		int i = 0;
		for(; i < n; ++i){
			if(used[i]) continue;
			in_history = vector<bool>(N_MAX, false);
			if(dfs(i)) break;
		}
		if(i == n){
			cout << -1 << endl;
			return 0;
		}
	}
	while(!check()){
		rep(i,n) graph[i].clear();
		for(P e : edges){
			if(in_history[e.first] && in_history[e.second]){
				graph[e.first].push_back(e.second);
			}
		}
		vector<vector<bool>> selected(n);
		rep(i,n) selected[i].assign(graph[i].size(), false);
		int n_history = history.size();
		rep(i,n_history){
			int a = history[i], b = history[(i+1)%n_history];
			rep(j,graph[a].size()){
				if(graph[a][j] == b){
					selected[a][j] = true;
				}
			}
		}
		P e = {-1, -1};
		rep(i,n)rep(j,selected[i].size()){
			if(selected[i][j] == 0){
				e.first = i;
				e.second = graph[i][j];
				break;
			}
		}
		if(e.first != -1){
			while(history.front() != e.second){
				history.push_back(history.front());
				history.pop_front();
			}
			while(history.back() != e.first){
				in_history[history.back()] = false;
				history.pop_back();
			}
		}
	}
	show_history();
	return 0;
}

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

#define ll long long



int main()
{

    ll n;
    cin>>n;

    set<long long>s;
    set<long long>:: iterator it;

    for(int i=1;i<=n;i++){
        if((i%3==0 || i%5==0) ){
          //  s.insert(i);
            continue;
        }else{

          s.insert(i);
        }
    }

 
    ll sum=0;

    for(it=s.begin();it!=s.end();it++){
            //cout<<*it<<" ";
        sum+=*it;
    }

  cout<<sum<<endl;




 return 0;
}


Measured memory_bytes: 28552
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    deque<ll> q;
    rep(i, n) {
        ll a;
        cin >> a;
        int idx = lower_bound(q.begin(), q.end(), a) - q.begin();
        //cout << idx;
        if (idx == 0) {
            q.push_front(a);
        }
        else if (idx >= i) {
            q[q.size()-1] = a; 
        }
        else {
            q[idx-1] = a;
        }
        //cout << v.size() << endl;
    }
    cout << q.size() << endl;
    return 0;
}


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


int main()
{
    ll a,b,c,d,e,f,n,m,t;
    cin>>n;
    ll arr[n+5];
    for(int i=1;i<=n;i++) cin>>arr[i];
    c=0;
    
    ll cost[n+5]={0};
    cost[1]=0;
    cost[2]=abs(arr[2]-arr[2-1]);
    for(int i=3;i<=n;i++)
    {
        cost[i]=min(cost[i-1]+abs(arr[i]-arr[i-1]),cost[i-2]+abs(arr[i]-arr[i-2]));
    }
    
    
    
    
    
    
    cout<<cost[n];
    
    
    
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <bits/stdc++.h>
#define LEN 100010
using namespace std;

struct Node {
    int key;
    Node *prev, *next;
};

Node *nil;
void init () {
    nil = (Node *)malloc(sizeof(Node));
    nil->prev = nil;
    nil->next = nil;
}

void insert (int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->prev = nil;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
}

Node* listSearch(int key) {
    Node *cur = nil->next;
    while (cur != nil && cur->key != key) {
        cur = cur->next;
    }
    return cur;
}

void deleteNode(Node *t) {
    if (t == nil) return;
    t->next->prev = t->prev;
    t->prev->next = t->next;
    free(t);
}


void deleteKey (int key) {
    deleteNode(listSearch(key));
}

void deleteFirst () {
    deleteNode(nil->next);
}

void deleteLast () {
    deleteNode(nil->prev);
}

void printList () {
    Node *x = nil->next;
    if (x != nil) printf("%d", x->key); x = x->next;
    while (x != nil) {
        printf(" %d", x->key);
        x = x->next;
    }
    printf("\n");
}

int main(){
    int n, key;
    char command[20];
    cin >> n;
    init();
    for (int i=0; i < n; i++) {
        scanf("%s%d", command, &key);
        if (command[0] == 'i') insert(key);
        else if (command[0] == 'd') {
            if (strlen(command) > 6) { 
                if (command[6] == 'F') deleteFirst();
                else if (command[6] == 'L') deleteLast();
            }
            else deleteKey(key);
        }
        // printList();
    }
    printList();
    return 0;
} 


Measured memory_bytes: 34340