akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    while(!cin.eof()) {
        string s;
        cin >> s;
        if(s.size() <= 2) {
            break;
            cout << "0\n0\n";
            continue;
        }
        int a = 0, b = 0;
        for(int i = 0; i < s.size() - 3; ++i){
            if(s[i] == 'J' && s[i+1] == 'O' && s[i+2] == 'I') ++a;
            if(s[i] == 'I' && s[i+1] == 'O' && s[i+2] == 'I') ++b;
        }
        cout << a << "\n" << b << "\n";
    }
    return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b, c, d; cin >> n >> a >> b >> c >> d;
    --a; --b; --c; --d;
    string s; cin >> s;
    bool f = false;
    if(c < d){
        for(ll i = a; i < d; i++){
            if(s[i] == '#' && s[i+1] == '#'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    else{
        for(ll i = a; i < c; i++){
            if(s[i] == '#' && s[i+1] == '#'){
                cout << "No" << endl;
                return 0;
            }
            if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.' && b <= i && i <= d) f = true;
        }
        if(!(f)){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 592
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <bitset>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
//#define double long double
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch-'0'), ch=getchar();
    return s*w;
}
void print(int x) { if(x<0) x=-x, putchar('-'); if(x>9) print(x/10); putchar(x%10+'0'); }
int n,a[N],qz[N];
signed main()
{
    n=read();
    for(ri int i=1;i<=n;i++) a[i]=read(), qz[i]=qz[i-1]^a[i];
    for(ri int i=1;i<=n;i++)
    {
        printf("%lld ",qz[i-1]^qz[i]^qz[n]);
    }
    puts("");
    return 0;
}

Measured memory_bytes: 6884
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

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

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

int main() {
  string s;
  cin >> s;
  int anser = 0;
  REP(i, s.size() - 1) {
    if (s[i] != s[i + 1]) {
      anser++;
    }
  }
  cout << anser << endl;
  return 0;
}

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

int main() {
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;

    for(int i = 0; i < n; ++i){
        if(i == k - 1){
            cout << char(s[i] - 'A' + 'a');
        }else{
            cout << s[i];
        }
    }

    cout << endl;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    f = list(map(int, readline().split()))

    a.sort()
    f.sort(reverse=True)

    x = [p * q for p, q in zip(a, f)]
    mx = max(x)
    ng = -1
    ok = mx
    import math

    while abs(ok - ng) > 1:
        mid = (ng + ok) // 2
        rem = k
        for p, q in zip(a, f):
            r = math.floor(mid / q)
            h = max(0, p - r)
            rem -= h
        if rem >= 0:
            ok = mid
        else:
            ng = mid

    print(ok)


if __name__ == '__main__':
    main()


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

#define DIV 1000000007

using namespace std;

vector<int> adj[212345];
bool visited[212345];

int bfs(int x){
    if(visited[x])
        return 0;
    
    visited[x] = true;
    int resp = 1;
    for(auto it : adj[x])
        resp += bfs(it);
    
    return resp;
}

int main(){
    int n, m;

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

    for(int i = 0; i < m; i++){
        int a, b;

        scanf(" %d %d", &a, &b);

        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    int resp = 0;
    for(int i = 1; i <= n; i++){
        if(!visited[i]){
            resp = max(resp, bfs(i));
        }
    }

    printf("%d\n", resp);

    return 0;
}

Measured memory_bytes: 21396
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000001145
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int ans=INF;
int n,m,R;
int r[11];
int d[222][222];
void warshall_floyd(int n) {
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}
signed main(){
	
	cin>>n>>m>>R;
	rep(i,n)rep(j,n)d[i][j]=INF;
	rep(i,R){
		cin>>r[i];
		r[i]--;
	}
	rep(i,m){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		d[a][b]=c;
		d[b][a]=c;
	}
	warshall_floyd(n);
	sort(r,r+R);
	do{
		int sum=0;
		rep(i,R-1){
			sum+=d[r[i]][r[i+1]];
		}
		ans=min(ans,sum);
	}while(next_permutation(r,r+R));
	
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define sort stable_sort 
using namespace std; 

int _; 

int a,b,c,k; 
 
int main()
{
	//for(scanf("%d",&_);_;_--)
	scanf("%d%d%d%d",&a,&b,&c,&k);
	while(b <= a && k)
	{
		b <<= 1;
		k--;
	}
	while(c <= b && k)
	{
		c <<= 1;
		k--;
	}
	printf((b>a && c>b) ?"Yes\n":"No\n");
	return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	string S;
	cin >> S;

	int n = 0;
	for (int i = 0; i < 4; i++) {
		if (S.at(i) == '+') n++;
		else n--;
	}

	cout << n << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) x.begin(),x.end()
using namespace std;


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

    int n,x;
    cin >> n >> x;
    vector<int> l(n);
    vector<int> d(n);
    d[0]=0;
    int cnt=1;
    rep (i, n) cin >> l[i];
    for(int i=1; i<=n; ++i) {
        d[i]=d[i-1] + l[i-1];
        if (d[i] <= x) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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


int main() {
    int n;
    int k;
    cin >> n >> k;
    int d[k];
    rep(i, k) cin >> d[i];

    while(1){
        string s = to_string(n);
        bool check = true;
        rep(i, s.size()){
            bool acheck = true;
            rep(j, k){
                if(s[i]-'0' == d[j]){
                    acheck = false;
                } 
            }
            if(acheck == false){
                check = false;
                break;
            }
        }
        if(check) break;
        n++;
    }
    cout << n << endl;



    // rep(i, n.size()){
    //     bool kirai = [&](int a){
    //         bool check = true;
    //         rep(j, k){
    //             if(s[i]-'0' == d[j]){
    //                 check = false;
    //             } 
    //         }
    //         return check;
    //     }

    //     if(kirai(s[i]-'0')){
    //         rep(s[i]-'0', k){
    //             if(kirai(s[i]-'0'+1))
    //         }
    //     }
    // }

}

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
    ll N;
    cin >> N;
    ll ans = 0, x = N;
    while (x > 0) {
        ans += x % 10;
        x /= 10;
    }
    N /= 10;
    for (int i = 1; N > 0; i++) {
        ll s = 9 * i, x = N - 1;
        while (x > 0) {
            s += x % 10;
            x /= 10;
        }
        //cout << i << " " << s << "\n";
        ans = max(ans, s);
        N /= 10;
    }
    cout << ans << "\n";
}

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

int main() {
    string s, t;
    cin >> s >> t; 

    int ans = 1010;
    rep(i, s.size() - t.size() + 1){
        int error = 0;
        rep(j, t.size()){
            if(t.at(j) != s.at(i + j)){
                error++;
            }
        }
        ans = min(ans, error);
    }

    cout << ans << endl;
    return 0;
}
 
 //vector<int> a(3);
 //a.at(0);
 //a.size();
 //vector<vector<int>> a(3, vector<int>(3));
 //uint64_t sum = 0;
 //max(a, b);
 //min(a, b);
 //swap(a, b);
 //sort(vec.begin(), vec.end());  昇順
 //reverse(vec.begin(), vec.end());  降順

Measured memory_bytes: 3628
import java.util.*;

class Main{
	public static void main(String[] A){
		Scanner s=new Scanner(System.in);

		while(true){
			String a=s.next().replaceAll("\""," \"");
			if(a.equals("."))
				return;
			String b=s.next().replaceAll("\""," \"");

			String[] aa=a.split("\""),bb=b.split("\"");

			if(aa.length!=bb.length){
				System.out.println("DIFFERENT");
				continue;
			}
			int c=0;
			for(int i=0;i<aa.length;++i){
				if(!aa[i].equals(bb[i])) {
					if(i%2==0||c==1){
						c=2;
						break;
					}
					c=1;
				}
			}
			System.out.println(c==0?"IDENTICAL":c==1?"CLOSE":"DIFFERENT");
		}
	}
}



Measured memory_bytes: 33212
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

int main() {
    int n;
    cin >> n;
    vector<int> s(1 << n);
    REP(i, 1 << n) cin >> s[i];
    
    int mx = 0;
    multiset<int> st1, st2;
    REP(i, 1 << n) {
        st1.insert(-s[i]);
        mx = max(mx, s[i]);
    }
    st1.erase(st1.find(-mx));
    st2.insert(-mx);
    REP(i, n) {
        multiset<int> st;
        for (int x: st2) {
            auto iter = st1.upper_bound(x);
            if (iter == st1.end()) {
                cout << "No\n";
                return 0;
            }
            st.insert(*iter);
            st1.erase(iter);
        }
        for (int x: st) st2.insert(x);
    }
    
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 22704
#include <iostream>

using namespace std;

int main(void) {

	int n, cnt = 0;

	cin >> n;

	if (n / 10 == 9) cnt++;
	if (n - n / 10 * 10 == 9) cnt++;
	if (cnt != 0) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;

}

Measured memory_bytes: 256
<?php

$s = trim(fgets(STDIN));

$p = 'NA';

if ($s[0]*10+$s[1] >= 1 && $s[0]*10+$s[1] <= 12){
  $p = 'MMYY';
} 

if ($s[2]*10+$s[3] >=1 && $s[2]*10+$s[3] <= 12){
  if ($p == 'MMYY'){
    $p = 'AMBIGUOUS';
  } else {
    $p = 'YYMM';
  }
}

echo $p;

?>

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef pair<int, bool> ib;

#define FOR(a, b, c) for(int a = b; a < c; ++a)
#define RFOR(a, b, c) for(int a = b; a >= c; --a)
#define mp(a, b) make_pair(a, b)
#define all(v) v.begin(), v.end()

#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define vb vector<bool>
#define fst first
#define snd second
#define MAXN 100010
#define LOGMAXN 20
#define MAXM 44100
#define LOGMAXN 20
#define INF 1000000007
#define INFLL 1000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007LL

int n;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	int a, b;
	while(cin >> a >> b)
	{
		int ans = a*b;
		if(a > 9 || b > 9)
			ans = -1;
		printf("%d\n", ans);
	}
	return 0;
}


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

using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int m;
  cin >> m;
  cout << 24 + (24 - m) << '\n';
  return 0;
}


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

int main(void)
{
	int i,c_0=0,c_1=0,len;
	char s[100001];
	scanf("%s",s);
	len=strlen(s);
	
	for(i=0;i<len;i++){
		if(s[i]=='0')
			c_0++;
		if(s[i]=='1')
			c_1++;
	}
	if(c_0>=c_1)
		printf("%d",c_1*2);
	else
		printf("%d",c_0*2);
	return 0;
}
	

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int main() {
    int X;
    cin >> X;
    puts(X >= 30 ? "Yes" : "No");
}

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int main()
{
    int a, b;
    cin >> a >> b;

    cout << a - min(a, 2 * b) << '\n';
    return 0;
}


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

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

  sort(s, s+3);

  if (s[0]=='a' && s[1]=='b' && s[2]=='c')
  cout << "Yes" << endl;
  else
  cout << "No" << endl;
  
}

Measured memory_bytes: 3640
n=int(input())
aa=list(map(int,input().split()))
dic={}
ans=0
for i in range(n):
	x=i-aa[i]
	y=i+aa[i]
	if i>0:
		if x in dic:
			ans+=dic[x]
	if y in dic:
		dic[y]+=1
	else:
		dic[y]=1
print(ans)

Measured memory_bytes: 40296
n,x,y=map(int,input().split())
p=[0 for i in range(n-1)]
for i in range(1,n):
    for j in range(i+1,n+1):
        p[min([j-i-1,abs(i-x)+abs(j-y)])]+=1
for i in p:
    print(i)

Measured memory_bytes: 3444
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int M = cin.nextInt();
        int[] A = cin.ArrayInt(N);
        int[] B = cin.ArrayInt(M);
        Console.WriteLine(calc(A) * calc(B) % mod);
    }

    long mod = 1000000007;

    long calc(int[] A)
    {
        Array.Sort(A);
        long ans = 0;
        long sum = 0;

        for (int i = 0; i < A.Length; i++)
        {
            ans += A[i] % mod * i - sum;
            sum += A[i] % mod;
            ans %= mod;
            sum %= mod;
        }
        return (ans + mod) % mod;
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 33752
unittest
{
	assert( [ "2 2 4" ].parse.expand.solve == "45.000000" );
	assert( [ "12 21 10" ].parse.expand.solve == "89.783464" );
	assert( [ "3 1 8" ].parse.expand.solve == "4.236395" );
	
	assert( [ "10 10 1000" ].parse.expand.solve == "0.000000" );		// 追加ケース
}



import std.conv;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abx = input.front.split.to!( real[] );
	return tuple( abx[ 0 ], abx[ 1 ], abx[ 2 ] );
}

auto solve( real a, real b, real x )
{
	if( x == a * a * b ) return "0.000000";
	
	auto y = x / a;
	auto ans = 0.0L;
	if( a * a * b / 2 < x )
	{
		// 水筒の体積の半分以下のときは、傾けたときの水の形が四角柱になる（断面は台形）
		// 台形の端の部分を切って直角三角形に揃える
		auto f = y / ( a / 2 ) - b;
		b -= f;
		y -= f * a;
	}
	
	// 水筒の体積の半分以下のときは、傾けたときの水の形が三角柱になる（断面は直角三角形）
	auto c = y * 2 / b;							// 三角柱断面のbじゃないほうの辺の長さ
	auto d = ( b ^^ 2 + c ^^ 2 ) ^^ 0.5;		// 三角柱断面の斜辺の長さ
	auto e = y * 2 / d;							// 床から限界まで傾けた水筒の口までの高さ
	ans = 90 - asin( e / b ) * 180 / PI;
	
	return format( "%0.6f", ans );
}


Measured memory_bytes: 256
import heapq
import sys
input = sys.stdin.readline
from operator import itemgetter

def readlines(n):
    for _ in range(n):
        b, c = map(int, input().split())
        yield b, c

def main():
    _, M = map(int, input().split())
    A = list(map(int, input().split()))
    total = sum(A)
    heapq.heapify(A)

    for b, c in sorted(readlines(M), key=itemgetter(1), reverse=True):
        for _ in range(b):
            o = heapq.heappushpop(A, c)
            if o < c:
                total += c - o
            else:
                break
            
    print(total)

main()

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

using namespace std;

int main(void)
{
    string sa, sb, sc;
    int acount=0, bcount=0, ccount=0, an, bn, cn, turn=1;

    cin >> sa >> sb >> sc;

    an = sa.size();
    bn = sb.size();
    cn = sc.size();

    //while(an!=acount && bn!=bcount && cn!=ccount){
    while(1){
        if(turn==1 && acount>=an){
            cout << 'A' << endl;
            break;
        }
        if(turn==2 && bcount>=bn){
            cout << 'B' << endl;
            break;
        }
        if(turn==3 && ccount>=cn){
            cout << 'C' << endl;
            break;
        }  

        while(1){
            

            if(turn==1){
                if(sa[acount] == 'a'){
                    turn = 1;
                }
                else if(sa[acount] == 'b'){
                    turn = 2;
                }
                else{
                    turn = 3;
                }
                acount++;
                break;
            }
            else if(turn==2){
                if(sb[bcount] == 'a'){
                    turn = 1;
                }
                else if(sb[bcount] == 'b'){
                    turn = 2;
                }
                else{
                    turn = 3;
                }
                bcount++;
                break;
            }
            else{
                if(sc[ccount] == 'a'){
                    turn = 1;
                }
                else if(sc[ccount] == 'b'){
                    turn = 2;
                }
                else{
                    turn = 3;
                }
                ccount++;
                break;
            }
        }
    }

    /*if(an == acount){
        cout << 'A' << endl;
    }
    else if(bn == bcount){
        cout << 'B' << endl;
    }
    else{
        cout << 'C' << endl;
    }*/

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;


int main(){
	int a,b,c;
	cin >> a >> b >> c;
	cout << (b/a >= c ? c : b/a) << endl;
	
}

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

const int N = 200 * 1000 + 20;
int a[N], n;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int tmp = 0;
    for (int i = 0; i < n; i++)
        if (a[i] == tmp + 1)
            tmp++;
    return cout << (tmp? n - tmp: -1) << "\n", 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
using namespace std;

int n;
int t[10002];

int dp[2][5001][2];

int main(void){
  scanf("%d",&n);
  for(int i = 1; i < n; i++){
    scanf("%d",t+i);
  }

  for(int i = 0; i < 2; i++){
    for(int j = 0; j < 5001; j++){
      for(int k = 0; k < 2; k++){
	dp[i][j][k] = 1<< 25;
      }
    }
  }

  dp[1][0][0]=0;

  for(int i = n; i > 0; i--){
    for(int j = 0; j < 5000; j++){
      dp[i%2][j+1][0] = min(dp[(i+1)%2][j][0],dp[(i+1)%2][j][1]+t[i]);
      dp[i%2][j][1] = min(dp[(i+1)%2][j][1],dp[(i+1)%2][j][0]+t[i]);
      dp[(i+1)%2][j][0] = 1 << 25;
      dp[(i+1)%2][j][1] = 1 << 25;
    }
  }
  printf("%d\n",dp[1][n/2][0]);
}

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

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    string s, t; cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == t[i]) ans++;
    }
    cout << ans << '\n';

}



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

int main() {
  int X;
  cin >> X;
  if (400 <= X && X <= 599){
    cout << 8 << endl;
  }
  else if (600 <= X && X <= 799){
    cout << 7 << endl;
  }
  else if (800 <= X && X <= 999){
    cout << 6 << endl;
  }
  else if (1000 <= X && X <= 1199){
    cout << 5 << endl;
  }
  else if (1200 <= X && X <= 1399){
    cout << 4 << endl;
  }
  else if (1400 <= X && X <= 1599){
    cout << 3 << endl;
  }
  else if (1600 <= X && X <= 1799){
    cout << 2 << endl;
  }
  else if (1800 <= X && X <= 1999){
    cout << 1 << endl;
  }
}

    
    



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int64_t long long
constexpr int64_t MOD=1e9+7;

int main() {
    ios_base::sync_with_stdio(0);
    string s;
    cin>>s;
    vector<int>pos(s.size(),0);
    for(int i=0;i<s.size();){
        char c=s[i];
        int L=i;
        while(i<s.size()&&s[i]==c){
            ++i;
        }
        int R=i-1;
        int n=R-L+1;
        if(c=='R'){
            pos[R+1]+=n/2;
            pos[R]+=n-(n/2);
        }else{
            pos[L]+=n-(n/2);
            pos[L-1]+=n/2;
        }
    }
    for(int i:pos){
        cout<<i<<" ";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1104
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-01-26 20:28:13
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

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

  int h, n; cin >> h >> n;
  vector<int> a(n); cin >> a;
  if (accumulate(all(a), int()) >= h) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 640
/**
 * 
 */
//package AtCoder;
import java.util.*;
/**
 * @author Shivansh Singh
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int n,i;
		n=sc.nextInt();
		int []arr=new int[n];
		for (i=0;i<n;i++)
			arr[i]=sc.nextInt();
		int []dp=new int[n+1];
		dp[0]=dp[1]=0;
		dp[2]=(int)Math.abs(arr[1]-arr[0]);
		for (i=3;i<=n;i++)
			dp[i]=(int)Math.min(dp[i-1]+Math.abs(arr[i-1]-arr[i-2]),dp[i-2]+Math.abs(arr[i-1]-arr[i-3]));
		System.out.println(dp[n]);
		sc.close();
	}

}


Measured memory_bytes: 59464
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n,m;
    cin >> n >> m;
    if(m==1){
        cout << "0" << endl;
        return 0;
    }
    vector<int>x(m);
    vector<int>dist(m-1);
    for(int i=0;i<m;i++){
        cin >> x.at(i);
    }
    sort(x.begin(),x.end());
    for(int i=0;i<m-1;i++){
        dist[i]=x[i+1]-x[i];
    }
    sort(dist.begin(),dist.end());
    for(int i=0;i<n-1;i++){
        dist.pop_back();
    }
    int ans=0;
  int size=dist.size();
    for(int i=0;i<size;i++){
        ans+=dist[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3980
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef pair<int,int> PII;
#define X first
#define Y second
inline int read()
{
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int L,R,d,cnt;
int main()
{
	L=read();R=read();d=read();
	for(int i=L;i<=R;i++)if(i%d==0)cnt++;
	printf("%d\n",cnt);
	return 0;
}
/*

*/


Measured memory_bytes: 3176
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

const int N=55;
const int MAX_S=2451;
vector<tuple<int,int,int>>edges[N];
int n,m,S;
vector<pair<int,int>>_exchange;

void dijkstra(int s)
{
  vector<vector<ll>>dist(n,vector<ll>(MAX_S,1e15));
  dist[s][S]=0;
  priority_queue< pair<ll,pair<int,int>>, vector<pair<ll,pair<int,int>>>,greater< pair<ll,pair<int,int>> > >pq; //{dist,{src,silver_coins}}
  pq.push({0,{s,S}});

  while(!pq.empty()){
    int curr_dist=pq.top().first;
    int node=pq.top().second.first;
    int silver=pq.top().second.second;
    pq.pop();
    if(dist[node][silver]<curr_dist)  continue;

    for(auto x:edges[node]){
      if(get<1>(x)<=silver){
        if( dist[get<0>(x)][silver-get<1>(x)] > dist[node][silver]+get<2>(x) ){
          dist[get<0>(x)][silver-get<1>(x)] = dist[node][silver]+get<2>(x);
          pq.push({dist[get<0>(x)][silver-get<1>(x)],{get<0>(x),silver-get<1>(x)}});
        }
      }
    }
    int new_s=min(MAX_S-1,silver+_exchange[node].first);
    if(dist[node][new_s]>dist[node][silver]+_exchange[node].second){
      dist[node][new_s]=dist[node][silver]+_exchange[node].second;
      pq.push({dist[node][new_s],{node,new_s}});
    }
  }

  for(int i=1;i<n;i++){
    int ans=1e15;
    for(int k=0;k<MAX_S;k++){
      ans=min(ans,dist[i][k]);
    }
    cout<<ans<<"\n";
  }
}
signed main(){
  fastio
  cin>>n>>m>>S;
  S=min(S,MAX_S-1);  //check with bigger limits
  for(int i=0;i<m;i++){
    int u,v,cost_req,time_req;cin>>u>>v>>cost_req>>time_req;
    u--;v--;
    edges[u].emplace_back(v,cost_req,time_req);
    edges[v].emplace_back(u,cost_req,time_req);
  }
  for(int i=0;i<n;i++){
    int silver,time;cin>>silver>>time;
    _exchange.emplace_back(silver,time);
  }
  dijkstra(0);
  return 0;
}

Measured memory_bytes: 7288
n = int(input())
h = list(map(int, input().split()))
dp = [0] * n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
	dp[i] = dp[i-1] + abs(h[i]-h[i-1])
	dp[i] = min(dp[i],dp[i-2] + abs(h[i] - h[i-2]))
print (dp[n-1])

Measured memory_bytes: 13980
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define SZ(x) ((ll)(x).size())
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

template<typename T>
T gcd(T u, T v) {
    if(u==0)return v;
    if(v==0)return u;
    T r;
    while (v) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    REP(i,n){
        cin >> a[i];
        b[i] = a[i];
    }
    reverse(all(b));
    vector<int> sa(n+1);
    vector<int> sb(n+1);
    sa[0] = 0;
    sb[0] = 0;
    REP(i,n){
        sa[i+1] = gcd(a[i],sa[i]);
    }
    REP(i,n){
        sb[i+1] = gcd(b[i],sb[i]);
    }
    int res = 0;
    REP(i,n){
        chmax(res,gcd(sa[i],sb[n-i-1]));
    }
    put(res);
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<ll, int>Pair;
#define MAX 1e9
struct edge { int to, cost; };
typedef pair<int, int>P;

//union_find木テンプレ
//問いに応じて最大の頂点数を定めること
#define MAXN 100100
long int par[MAXN];//親番号
long int rank[MAXN];//木の深さ
long int siz[MAXN];//属する集団のサイズ
//初期化関数
void init(int n) {
    rep(i, n) { par[i] = i; ::rank[i] = 0; siz[i] = 1; }
}
//木の根を求める関数
int find(int x) {
    if (par[x] == x) { return x; }
    else { return par[x] = find(par[x]); }
}
//xとｙの集合を併合する関数
void unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y)return;
    if (::rank[x] < ::rank[y]) {
        par[x] = y;
        siz[y] += siz[x];
    }
    else {
        par[y] = x;
        siz[x] += siz[y];
        if (::rank[x] == ::rank[y])::rank[x]++;
    }
}
//同じかどうかとサイズがいくらか。
bool same(int x, int y) { return find(x) == find(y); }
int size(int x) { return siz[find(x)]; }

int main(){
  int N,M;
  cin>>N>>M;
  init(N);
  rep(i,M){
    int x,y,z;
    cin>>x>>y>>z;
    x--;y--;
    unite(x,y);
  }
  set<int>S;
  int ans=0;
  rep(i,N){
    if(!S.count(find(i))){
      S.insert(find(i));ans++;
    }
  }
  cout<<ans;
}




Measured memory_bytes: 10548
#include<bits/stdc++.h>
using namespace std;
int a[200005];
long long b[200005];
int main()
{
	int n;long long sum=0;
	cin>>n;
	memset(b,0,sizeof(b));
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
		if(i==0)
			b[i]=a[i];
		else
			b[i]=b[i-1]+a[i];
	}
	long long ans=2*1e14+1;
	for(int i=0;i<n-1;i++)
	{
		ans=min(ans,abs(sum-2*b[i]));
	}
	cout<<ans;
	return 0;
}	

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

int main(){
    int n;
    cin >> n;
    int Adj[n][n];
    int A[n][n];
    int g1, g2;

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            Adj[i][j] = 0;
            A[i][j] = 0;
        }
    }

    for(int i=0;i<n;i++){
        cin >> g1 >> g2;
        for(int j=0;j<g2;j++){
            cin >> Adj[i][j];
            A[i][Adj[i][j]-1] = 1;
        }
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j==n-1){
                cout << A[i][j];
            } else {
                cout << A[i][j] <<" ";
            }   
        }
        cout << endl;
    }
}


Measured memory_bytes: 3092
import math

N,M=map(int,input().split())

if abs(N-M)>=2:
    print(0)
elif abs(N-M)==1:
    print((math.factorial(N)*math.factorial(M))%(10**9+7))
else:
    print(((math.factorial(N) * math.factorial(M))*2) % (10 ** 9 + 7))

Measured memory_bytes: 5184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1e9+7;

int main(){

    int x[5] = {};
    int ans;
    for (int i = 0; i < 5; i++){
        cin>>x[i];
        if (x[i] == 0){
        ans = i+1;

        }
    }    cout << ans <<" ";

}




Measured memory_bytes: 3528
// CODE FESTIVAL 2017 qual A
// B - fLIP

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;


int N, M, K;

bool can() {
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= M; j++) {
            if (i * M + j * N - 2 * i * j == K) {
                return true;
            }
        }
    }
    return false;
}

int main() {

    cin >> N >> M >> K;

    cout << (can() ? "Yes" : "No") << endl;

    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 repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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 long long INF = 1LL << 60;

int main(){
  int a, b, h;
  cin >> a >> b >> h;

  cout << (a+b) * h/2 << endl;

  return 0;
}


Measured memory_bytes: 256
import numpy as np

N = int(input())
R = []
for i in range(N):
    s, p = input().split()
    R.append([i+1, s, -int(p)])
    
R_sort = sorted(R, key=lambda x : (x[1], x[2]))

for city in R_sort:
    print(city[0])

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

using namespace std;

signed main()
{
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    int a[n];
    int g = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        g = __gcd(g, a[i]);
    }
    int m = *max_element(a, a + n);
    if(k % g == 0 && k <= m)
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 640
s = "abcdefghijklmnopqrstuvwxyz"

def fA(N):
  if N <= 26: return s[N-1]
  a = (N-1) // 26
  b = N % 26

  return fA(a) + fA(b)

N = int(input())
print(fA(N))
# for N in range(710):
#   print(N, fA(N))





Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n, k, a[N], dp[N];
int main() {
    scanf("%d%d", &n, &k);
    for(int i=0; i<n; ++i)
        scanf("%d", a+i);
    for(int i=1; i<n; ++i)
        dp[i] = 1e9+1;
    for(int i=0; i<n; ++i){
        for(int j=1; j<=k && (i+j) < n; ++j)
            dp[i+j] = min(dp[i+j], dp[i] + abs(a[i] - a[i+j]));
    }
    cout << dp[n-1];
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<deque>
#include<algorithm>
#define maxn 100005
using namespace std;
typedef deque<int>::iterator diter;
deque<int> q;
int n,m,cnt;
bool vis[maxn];
struct node { int v; node *nxt; } edge[maxn*2],*head[maxn],*ncnt;
void addedge(int u,int v)
{
	ncnt++;
	ncnt->v=v,ncnt->nxt=head[u];
	head[u]=ncnt;
}
int check(int u)
{
	for(node *p=head[u];p;p=p->nxt)
		if(!vis[p->v]) return p->v;
	return 0;
}
int main()
{
	scanf("%d%d",&n,&m);
	ncnt=&edge[0];
	int u,v;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		addedge(u,v); addedge(v,u);
	}
	vis[u]=vis[v]=true;
	q.push_front(u); q.push_back(v);
	while(!q.empty())
	{
		u=q.front();
		v=check(u);
		if(!v) break;
		q.push_front(v); vis[v]=true;
	}
	while(!q.empty())
	{
		u=q.back();
		v=check(u);
		if(!v) break;
		q.push_back(v); vis[v]=true;
	}
	printf("%d\n",q.size());
	for(diter it=q.begin();it!=q.end();it++)
		printf("%d%c",*it,it==q.end()?'\n':' ');
}

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


int n, k;
priority_queue<int> que;
set<int> st ={0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

void dfs(int now){
    if(now>=n) que.push(-now);
    else {
        for(auto p : st){
            int tmp =  now*10 + p;
            dfs(tmp);
        }
    }
}
 
int main(void){
    cin>>n>>k;
    rep(i, k){
        int a;
        cin>>a;
        st.erase(a);
    }
    for(auto p : st){
        if(p != 0) dfs(p);
    }
    cout<<-que.top()<<endl;
    
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){

  char **A,**B,**C,b[2];int k,i,j,n,x,y,minj,r,f=0;

  scanf("%d",&n);

  A=(char **)malloc(n*sizeof(char *));
  for(i=0;i<n;i++){
    
 A[i]=(char *)malloc(2*sizeof(char ));
  }
   B=(char **)malloc(n*sizeof(char *));
  for(i=0;i<n;i++){
    
 B[i]=(char *)malloc(2*sizeof(char ));
  }
   C=(char **)malloc(n*sizeof(char *));
  for(i=0;i<n;i++){
    
 C[i]=(char *)malloc(2*sizeof(char ));
  }
  for(i=0;i<n;i++){
  scanf("%s",A[i]);
  strcpy(C[i],A[i]);
  strcpy(B[i],A[i]);
  }

   for(i=0;i<n-1;i++){
   for(j=n-1;j>i;j--){
    x=atoi(&B[j][1]);
    y=atoi(&B[j-1][1]);
    if(x<y){
  	strcpy(b,B[j]);
     
  	strcpy(B[j],B[j-1]);
  	strcpy(B[j-1],b);
  	}
   
  }
  }

  
  for(i=0;i<n;i++){
    printf("%s",B[i]);
    if(i !=n-1)printf(" ");
  }printf("\n");
  
   printf("Stable\n");
  
   for(i=0;i<n;i++){
    minj=i;
    for(j=i+1;j<n;j++){
      x=atoi(&C[j][1]);y=atoi(&C[minj][1]);
      if(x<y){
	
	minj=j;
      }
      for(r=i+1;r<n;r++){
	if(atoi(&C[r][1])==atoi(&C[i][1])){
	if(r<minj)f++;


      }}
   
    }
   
    if(i !=minj){
      strcpy(b,C[i]);
      strcpy(C[i],C[minj]);
      strcpy(C[minj],b);}
   
      }
    for(i=0;i<n;i++){
    printf("%s",C[i]);
    if(i !=n-1)printf(" ");
  }printf("\n");
   
    if(f !=0)printf("Not stable\n");
  else printf("Stable\n");
  
  return 0;
}



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

using namespace std;

int n, cnt[1005], in[1005], out[1005], par[1005], ta, tb, tc, td;
bool o[1005];

int find(int a) {
	if (par[a] == a)
		return a;
	return par[a] = find(par[a]);
}

int main() {
	scanf("%d%d", &n, &ta);
	for (int i = 0; i < 1005; i++)
		par[i] = i;
	while (n--) {
		scanf("%d%d%d%d", &ta, &tb, &tc, &td);
		if (tc == 0)
			ta = 500 + ta;
		else
			ta = 500 - tc;
		if (td == 0)
			tb = 500 - tb;
		else
			tb = 500 + td;
		if (find(ta) != find(tb))
			par[par[ta]] = par[tb];
		out[ta]++;
		in[tb]++;
	}
	for (int i = 0; i < 1005; i++)
		if (in[i] * out[i] == 0 || in[i] != out[i])
			o[i] = o[find(i)] = 1;
	for (int i = 0; i < 1005; i++)
		if ((i > 500 && out[i] < in[i]) || (i < 500 && out[i] > in[i]) || !o[find(i)]) {
			printf("NO\n");
			return 0;
		}
	printf("YES\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  string *s = new string[n];
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  map<string, int> maps;
  for(int i=0;i<n;i++){
    auto itr = maps.find(s[i]);
    if(itr != maps.end()){
      ++maps[s[i]];
      continue;
    }else{
      maps[s[i]] = 1;
    }
  }
  int max = 0;
  vector<string> vec;
  for(auto i=maps.begin(); i!=maps.end();i++){
    if(i->second >= max) {
      max = i->second;
    }
  }
  for(auto i=maps.begin();i!=maps.end();i++){
    if(i->second == max){
      vec.emplace_back(i->first);
    }
  }
  sort(vec.begin(), vec.end());
  for(auto& val:vec){
    cout << val << endl;
  }

  return 0;
}

Measured memory_bytes: 28528
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    string s; cin >> s;
    int k; cin >> k;
    bool flag = true;
    rep(i,s.size()){
        if (i >= k){
            cout << 1 << endl;
            return 0;
        }
       else if( s[i] != '1'){
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int (i) = (a);(i) < (b);(i)++)
#define Rep(i,n) For(i,0,n)
#define All(a) (a).begin(),(a).end()
#define sp " "
#define Rev(s,a,b) reverse((s).begin()+(a),(s).begin()+(b)+1)//s[a]....s[b] rev

vector<char> boin = {'a','i','u','e','o'};
typedef long long ll;

ll min(ll x,ll y){
    if(x > y)return y;
    else return x;
}

int main(){
    int n;
    ll ans = 0;
    ll length;
    cin >> n;
    vector<ll> a(n);
    vector<ll> l(n); 
    Rep(i,n){
        cin >> a[i];
        if(i == 0)l[i] = a[i];
        else l[i] = a[i] + l[i-1];
    }
    if(l[n-1] % 2 == 1)length = l[n-1] - 1;
    else length = l[n-1];
    ll m = lower_bound(All(l),length/2)-l.begin();

    ans += min(abs(l[n-1]-2*l[m]),abs(l[n-1]-2*l[m-1]));
    cout << ans << endl;
    //cin >> n;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    long long n,a,b;
    cin>>n>>a>>b;
    long long x1,x2;
    long long ans=0;
    cin>>x1;
    for(int i=1;i<n;i++){
        cin>>x2;
        ans+=min((x2-x1)*a,b);
        x1=x2;
        
    }
 cout<<ans<<endl;   
}


Measured memory_bytes: 256
s = input()

for i in range(len(s) - 1):
    if len(set(s[i: i + 2])) == 1:
        print(i + 1, i + 2)
        exit()
for i in range(len(s) - 2):
    if len(set(s[i: i + 3])) <= 2:
        print(i + 1, i + 3)
        exit()

print('-1 -1')

Measured memory_bytes: 3188
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
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;
}
const int MOD = 1000000007;
int rui(int a, int b) {
    if(b == 0) {
        return 1;
    }
    return rui(a, b - 1) * a;
}
int main() {
    int res = 10000000;
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A);
    vector<int> b(B);

    int mina = 10000000;
    rep(i, 0, A) {
        cin >> a[i];
        chmin(mina, a[i]);
    }
    int minb = 10000000;
    rep(i, 0, B) {
        cin >> b[i];
        chmin(minb, b[i]);
    }
    chmin(res, mina + minb);
    vector<int> x(M);
    vector<int> y(M);
    vector<int> c(M);
    rep(i, 0, M) {
        cin >> x[i] >> y[i] >> c[i];
        x[i]--;
        y[i]--;
        chmin(res, (a[x[i]] + b[y[i]] - c[i]));
    }
    cout << res << endl;
}

Measured memory_bytes: 2304