akhauriyash/Code-Regression huggingface dataset:
while True:
    s = input().rstrip().split()
    if '+' in s:
        print(int(s[0])+int(s[2]))
    elif '-' in s:
        print(int(s[0])-int(s[2]))
    elif '*' in s:
        print(int(s[0])*int(s[2]))
    elif '/' in s:
        print(int(s[0])//int(s[2]))
    elif '?' in s:
        break



Measured memory_bytes: 5592
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i, n) for(int i=1;i<=n;i++)
using namespace std;
int main(){
	int a;
	cin>>a;
	int b=a%100, c=a/100;
	if(c*5<b)
		cout<<0<<endl;
	else
		cout<<1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline int read()
{int x=0;
char c=getchar();
while (c<'0'||c>'9') c=getchar();
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x;
}
int main (){
	int a,b;
	a=read();b=read();
	int c=a+b;
	if (a%3==0||b%3==0||c%3==0) {printf ("Possible\n");}
	else {printf ("Impossible\n");}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort()
score = 0
for f in range(n-2):
	for s in range(f+1,n-1):
		for t in range(s+1,n):
			if a[f]+a[s]>a[t] and a[f] != a[s] and a[f]!=a[t] and a[s]!=a[t]:
				score += 1
print(score)

Measured memory_bytes: 9192
n, m = list(map(int, input().split()))
a = [input() for i in range(m)]
b = []
c = []
total_act = 0
total_act2 = 1
total = 1
if m == 0:
    for i in range(n + 1):
        if str(i) in a:
            total *= total_act
            total_act = 0
            total_act2 = 1
        else:
            total_act3 = total_act2 + total_act
            total_act2 = total_act
            total_act = total_act3
    total *= total_act
    print(total % 1000000007)
else:
    b.append(int(a[0]))
    for i in range(len(a) - 1):
        b.append(int(a[i + 1]) - int(a[i]) - 1)
        if int(a[i + 1]) - int(a[i]) - 1 == 0:
            print(0)
            exit()
    b.append(n - int(a[-1]))

    for i in range(max(b)):
        total_act3 = total_act2 + total_act
        total_act2 = total_act
        total_act = total_act3
        c.append(total_act)

    for i in b:
        total *= c[i - 1]
    print(total % 1000000007)


Measured memory_bytes: 9380
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main(){
    int w,h,n;
    
    cin >> w >> h >> n;
    
    int x[1005],y[1005];
    for(int i=0; i<n; i++){
        int a,b;
        cin >> a>> b;
        x[i] = a;
        y[i] = b;
    }
    int sum=0,dx[1005],dy[1005];
    for(int i=0; i<n-1; i++){
        dx[i] = x[i+1]-x[i];
        dy[i] = y[i+1]-y[i];
        if(dx[i]*dy[i]>=0) sum += max(abs(dx[i]),abs(dy[i]));
        else sum += (abs(dx[i]) + abs(dy[i]));
    }
    cout << sum << endl;
}

Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>
using namespace std;
long mod=1e9+7,N;
long cumsum[1<<20];
long c2[1<<20];
main()
{
	cin>>N;
	long ans=0;
	cumsum[0]=1;
	for(int i=0;i<N;i++)
	{
		long t=(cumsum[i]+c2[i])%mod;
		(c2[i+3]+=t)%=mod;
		if(i+1<N)(ans+=t*(N-1)%mod*(N-1)%mod+t*(N-max(N-i-1,2L)+1)%mod)%=mod;
		else(ans+=t*N)%=mod;
		(c2[i+1]+=c2[i])%=mod;
		(cumsum[i+1]+=t)%=mod;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 16640
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;
 
 ll mod=1e9 +7;
 
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

const ll M=200006;
ll f[M],inv[M];

void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2,mod);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

ll func(ll tot,ll given)
{
  ll res=0;
  for(ll i=0;i<=30;i++)
  {
    if((1<<i) & tot)
    {
      if(!((1<<i) & given))
      {
        res+=expo(2,i,mod);
      }
    }
    else
    {
      if((1<<i) & given)
        res+=expo(2,i,mod);
    }
  }
  return res;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // compute();
    // Sieve();
    ll tests=1;
    // cin>>tests;
    while(tests--)
    {
      ll i,j,n,tot=0;
      cin>>n;
      vector<ll>a(n),ans(n);
      rep(i,0,n-1)
      {
        cin>>a[i];
        tot^=a[i];
      }

      rep(i,0,n-1)
      {
        cout<<func(tot,a[i])<<" ";
      }


    }
    return 0;
   }

Measured memory_bytes: 17412
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    s = "##" + s + "##";
    a++; b++; c++; d++;
    if(c < d){
        int ok = 1;
        while(b < d){
            if(s[b+1] == '.') b++;
            else if(s[b+2] == '.') b += 2;
            else {
                ok = 0;
                break;
            }
        }
        while(a < c){
            if(s[a+1] == '.') a++;
            else if(s[a+2] == '.') a += 2;
            else {
                ok = 0;
                break;
            }
        }
        if(ok == 0){
            puts("No");
        }else {
            puts("Yes");
        }
    }else {
        int ok = 1;
        while(b < d){
            if(s[b-1] == '.' && s[b+1] == '.') break;
            if(s[b+1] == '.') b++;
            else if(s[b+2] == '.') b += 2;
            else {
                ok = 0;
                break;
            }
            if(s[b-1] == '.' && s[b+1] == '.') break;
        }
        s[b] = '#';
        while(a < c){
            if(s[a+1] == '.') a++;
            else if(s[a+2] == '.') a += 2;
            else {
                ok = 0;
                break;
            }
        }
        while(b < d){
            if(s[b+1] == '.') b++;
            else if(s[b+2] == '.') b += 2;
            else {
                ok = 0;
                break;
            }
        }
        if(ok == 0){
            puts("No");
        }else {
            puts("Yes");
        }
    }
    return 0;
}

Measured memory_bytes: 772
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

// Driver program
void Main(){

  int N;
  cin>>N;

  int A[2][N];

  rep(i,N){
    cin>>A[0][i];
  }
  rep(i,N){
    cin>>A[1][i];
  }

  int ans=0;
  rep(i,N){
    int buff=0;
    rep(j,i+1){
      buff+=A[0][j];
    }
    reps(j,i,N){
      buff+=A[1][j];
    }
    maxi(ans,buff);
  }


  cout<< ans<<"\n";

}


//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        x: usize, y: usize, z: usize
    }
    let mut rest = x - z;
    let mut count = 0;
    while rest >= y + z {
        rest -= y + z;
        count += 1;
    }
    println!("{}", count);
}


Measured memory_bytes: 4352
a, = [list(map(int, s.split())) for s in open(0)][0]
tf = False
for i in range(1,10):
    for j in range(1,10):
        if i*j == a:
            tf = True
            break
    if tf:
        break

if tf:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265359
using namespace std;

int main()
{
  int s, w;
  cin >> s >> w;

  cout << ((s<=w) ? "unsafe" : "safe") << endl;
  return 0;
}


Measured memory_bytes: 3628
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}

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

    int N;
    int a[100];
    cin >> N;
    REP(i, N) cin >> a[i];

    sort(a, a+N);
    int x = 0, y = 0;
    for(int i=0; i<N; i+=2) {
        x += a[i];
    }
    for(int i=1; i<N; i+=2) {
        y += a[i];
    }
    cout << max(x, y)  - min(x, y) << endl;
}


Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        a: usize,
        b: usize,
    }

    println!("{}", (((a as f64)+(b as f64))/2.0).ceil());

}


Measured memory_bytes: 2688
n,x,y = map(int,input().split())
ans = [0]*(n)

for i in range(1,n):
    for j in range(i+1,n+1):
        d = min(j-i,abs(x-i)+abs(y-j)+1)
        ans[d] += 1
for i in ans[1:]:
    print(i)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
 
int main(void){
  
  vector<vector<int>> a(3, vector<int>(3));
  
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++ ) {
      cin >> a.at(i).at(j);
    }
  }
  
  vector<int> x(3);
  vector<int> y(3);
  
  int a1 = 0;
  
  for (int i = 0; i < 3; i++) {
    y.at(i) = a.at(0).at(i);
  }
  
  for (int i = 1; i < 3; i++) {
    x.at(i) = a.at(i).at(0) - y.at(0);
  }
  
  
  bool flag = true;
  
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (x.at(i) + y.at(j) != a.at(i).at(j)) {
        flag = false;
      }
    }
  }
  
  if (flag){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}

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

int N;
vector<long long> A, B;

void solve() {
	A.clear();
	B.clear();
	cin >> N;
	A.resize(N);
	for (int n = 0; n < N; n++)cin >> A[n];
	sort(A.begin(), A.end(), greater<int>());
	int p = 0;
	while (p < N - 1) {
		if (A[p] != A[p + 1])p++;
		else {
			B.push_back(A[p]);
			p += 2;
		}
	}
	if (B.size() < 2)cout << 0 << endl;
	else cout << B[0] * B[1] << endl;
	return;
}

//////////////////////////////
//////////////////////////////

int main() {
#ifdef DEBUGTIME
	for (int time = 0; time < DEBUGTIME; time++) {
		solve();
		cout << "####################" << endl;
	}
#else
	solve();
#endif
	return 0;
}


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

int main()
{
    long long n,m,k,ans=0;
    cin>>n>>m>>k;
    long long A[n],B[m],a[n+1],b[m+1];
    for(int i=0;i<n;i++) cin>>A[i];
    for(int i=0;i<m;i++) cin>>B[i];
    a[0]=0;b[0]=0;
    for(int i=1;i<n+1;i++) a[i]=a[i-1]+A[i-1];
    for(int i=1;i<m+1;i++) b[i]=b[i-1]+B[i-1];
    for(int i=0;i<n+1;i++){
        while(m>=0 && (a[i]+b[m])>k) m--;
        if(m>=0)
            if((i+m)>ans)
                ans=i+m;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 9884
import sys
input = sys.stdin.readline

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

from collections import Counter
from itertools import accumulate
import bisect

C=Counter(A)

LIST=sorted(C.values())
LEN=len(LIST)
SUM=[0]+list(accumulate(LIST))
MIN=0
MAX=SUM[-1]

for k in range(1,N+1):
    MIN=0
    while MIN!=MAX:
        mid=(MIN+MAX+1)//2
        x=bisect.bisect_right(LIST,mid)

        if SUM[x]+(LEN-x)*mid>=mid*k:
            MIN=mid
        else:
            MAX=mid-1

    print(MIN)

Measured memory_bytes: 123924
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    vector<vector<int>> v(8);
    v[0] = {1, 4, 1, 4, 1, 2, 1, 2};
    for (int i = 1; i < 8; ++i) {
        v[i] = v[i-1];
        rotate(v[i].begin(), v[i].begin()+1, v[i].end());
    }
    sort(v.begin(),v.end());
    vector<int> a(8);
    while(scanf("%d", &a[0]) != EOF){
        for (int i = 1; i < 8; ++i) scanf("%d", &a[i]);
        int ans = 0, val = INF<int>;
        for (int i = 0; i < 8; ++i) {
            int p = 0;
            for (int j = 0; j < 8; ++j) {
                p += max(0, a[j]-v[i][j]);
            }
            if(p < val) ans = i, val = p;
        }
        for (int i = 0; i < 8; ++i) {
            if(i) printf(" ");
            printf("%d", v[ans][i]);
        }
        puts("");
    }
    return 0;
}


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

using namespace std;

int main() {
    int num=0;
    string s;
    cin >> s;
    for(int i=0; i<3; i++) {
        if(s[i] == '1') num++;
    }
    cout << num << endl;
    return(0);
}

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

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define REP(i,n) FOR(i,0,n)

int A, B, C;
int X;

int main() {
  scanf("%d%d%d%d", &A, &B, &C, &X);

  int count = 0;
  REP(a,A+1) REP(b,B+1) REP(c,C+1) {
    if (500 * a + 100 * b + 50 * c == X) ++count;
  }

  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i, j, n, k, a, b;
  int A[100][100];

  scanf("%d", &n);

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

  for(i = 0; i < n; i++){
    scanf("%d%d", &a, &k);

    if(k != 0){
      for(j = 0; j < k; j++){
        scanf("%d", &b);
        A[a - 1][b - 1] = 1;
      }
    }
  }

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      printf("%d", A[i][j]);
      
      if(j != n - 1) printf(" ");
    }
    
    printf("\n");
  }
  
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

int main(){
	int n, a, b, time;
	cin >> n;
	vector<pair<int, int>> v(n);
	for(int i=0; i<n; i++){
		cin >> a >> b;
		v[i].first = b;
		v[i].second = a;
	}

	sort(v.begin(), v.end());

	time = 0;
	for(int i=0; i<n; i++){
		time += v[i].second;
		if(time > v[i].first){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main()
{
  int W, H, N;
  cin >> W >> H >> N;

  int left = 0, right = W, bottom = 0, top = H;
  int x, y, a;
  for (int i = 0; i < N; i++)
  {
    cin >> x >> y >> a;
    if (a == 1)
      left = max(left, x);
    if (a == 2)
      right = min(right, x);
    if (a == 3)
      bottom = max(bottom, y);
    if (a == 4)
      top = min(top, y);
  }
  cout << max((right - left), 0) * max((top - bottom), 0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

bool hantei(int mask, int pos){
	if(mask & (1 << pos))return true;
	else return false;
}
int board[11][10010];
int main(void){
	int r, c;
	while(1){
		cin >> r >> c;
		if(r == 0 && c == 0) return 0;
		rep(i, r) rep(j, c) cin >> board[i][j];
		long long ans = 0;
		for (int mask = 0; mask < (1 << r); ++mask){
			vector<int> sum(c, 0);//v[i] := i?????????0????????°
			for (int pos = 0; pos < r; ++pos){
				if(hantei(mask, pos)){//?????¢
					for (int i = 0; i < c; ++i){
						if(board[pos][i] == 1) sum[i]++;//0?????°?????????
					}
				}else{//????????????
					for (int i = 0; i < c; ++i){
						if(board[pos][i] == 0) sum[i]++;
					}
				}
			}
			long long tmp = 0;
			for (int i = 0; i < c; ++i){
				if(sum[i] < (double)r / 2.0) tmp += (r - sum[i]);
				else tmp += sum[i];
			}
			ans = max(ans, tmp);
		}
		printf("%lld\n", ans);
	}
}

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

int main(){
    
    string s;
    cin>>s;
    
    
    for(int i=0;i<s.size();i++){
        if(s[i]=='?'){
            s[i]='D';
        }
    }
    cout<<s<<"\n";
    
    return 0;
}

Measured memory_bytes: 3752
import sys
sys.setrecursionlimit(10**6)

N, W = map(int, input().split())
w, v = [], []
dp = [[0] * (W+1) for _ in range(N+1)]

for i in range(N):
    t1, t2 = map(int, input().split())
    w.append(t1)
    v.append(t2)

for idx in range(1, N+1):
    for weight in range(W+1):
        if weight - w[idx - 1] < 0:
            dp[idx][weight] = dp[idx - 1][weight]
            continue

        # Select
        # v1 = dp[idx - 1][weight - w[idx]] + v[idx]
        v1 = dp[idx - 1][weight - w[idx - 1]] + v[idx - 1]

        # Not Select
        v2 = dp[idx - 1][weight]

        dp[idx][weight] = max(v1, v2)

# for i in range(N+1):
#     print(dp[i])
print(dp[N][W])

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

d = dict()
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

M = 0
N = 0
for x in d.items():
    if x[1] >= 4 and x[0] > M:
        M = x[0]
        N = x[0]
    elif x[1] >= 2 and x[0] > M:
        N = M
        M = x[0]
    elif x[1] >= 2 and x[0] > N:
        N = x[0]

print(M*N)






Measured memory_bytes: 18060
import math
A, B, H, M = map(int,input().split()) 

KakudoA = 2*math.pi*(H+M/60)/12
KakudoB = 2*math.pi*M/60

kakudobetween = min(abs(KakudoA-KakudoB), abs(2*math.pi+KakudoB-KakudoA))

if kakudobetween < 0.00000000000000000001:
	print(abs(B-A))
elif abs(kakudobetween - math.pi) < 0.000000000000000001:
	print(A+B)
else:
	print(math.sqrt(A**2+B**2-2*A*B*math.cos(kakudobetween)))

Measured memory_bytes: 9576
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; }

const int MAXN = 100005;
int vis[MAXN], sz[MAXN], dep[MAXN], val[MAXN], n, m, s, t;
vector<int> gra[MAXN];
LL ans;

void dfs(int u, int fa) {
	vis[u] = 1;
	for (int v : gra[u]) if (v != fa) {
		if (vis[v]) { s = u, t = v; continue; }
		dep[v] = dep[u] ^ 1;
		dfs(v, u);
	}
}

void dfs1(int u, int fa) {
	for (int v : gra[u]) if (v != fa) {
		if ((s == u && t == v) || (s == v && t == u)) continue;
		dfs1(v, u);
		sz[u] += sz[v], val[u] += val[v];
	}
	if (!val[u]) ans += abs(sz[u]);
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++) {
		int u, v; scanf("%d%d", &u, &v);
		gra[u].push_back(v);
		gra[v].push_back(u);
	}
	dfs(1, 0);
	int d = 0, odd = dep[s] == dep[t];
	for (int i = 1; i <= n; i++)
		d += (sz[i] = dep[i] ? -1 : 1);
	if (m == n && odd) {
		if (d & 1) return puts("-1"), 0;
		sz[s] -= d / 2, sz[t] -= d / 2;
		ans += abs(d / 2);
	} else if (m == n && !odd) {
		if (d) return puts("-1"), 0;
		val[s] = 1, val[t] = -1;
	} else if (d) return puts("-1"), 0;
	
	dfs1(1, 0);
	if ((m == n && odd) || m < n)
		return printf("%lld\n", ans), 0;
	int cnt = 0;
	for (int i = 1; i <= n; i++) if (val[i])
		vis[++cnt] = -val[i] * sz[i];
	vis[++cnt] = 0;
	nth_element(vis + 1, vis + 1 + cnt / 2, vis + cnt + 1);
	int x = vis[1 + cnt / 2];
	for (int i = 1; i <= cnt; i++)
		ans += abs(vis[i] - x);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 13568
N,M = map(int,input().split())

RES = []

for i in range(M):
    RES.append(list(input().split()))

WA = [0]*(M+N)
ACed = [0]*(N+M)
tmp_num = [0]*(M+N)
tmp = 0
for i in range(M):
    num = int(RES[i][0])
    if RES[i][1] == "WA" and not ACed[num]:
        tmp_num[num] += 1
    elif RES[i][1] == "WA" and ACed[num]:
        tmp += 1
    else:
        ACed[num] = 1
        WA[num] = tmp_num[num]

print(sum(ACed),end=" ")
print(sum(WA))

Measured memory_bytes: 30520
#include<stdio.h>
#include<math.h>

int main(){
    int A1, A2, A3;
    int S1, S2, S3;

    scanf("%d %d %d", &A1, &A2, &A3);
    S1 = abs(A1-A2);
    S2 = abs(A2-A3);
    S3 = abs(A3-A1);

    if(S1<=S3 && S2<=S3){
        printf("%d", S1+S2);
    }else if(S2<=S1 && S3<=S1){
        printf("%d", S2+S3);
    }else{
        printf("%d", S1+S3);
    }

    return 0;
}

Measured memory_bytes: 128
#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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	for(ll b = 1; b <= n; ++b){
		ans += (n/b) * max(b-k, 0LL);
		ans += max(n%b-k+1, 0LL);
	}
	if(k == 0) ans -= n;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
using namespace std;
vector<long> memo;
vector<int> vc;
int dp(int num)
{
    if(memo[num] != -1) 
        return memo[num];
    memo[num] =  min(dp(num-1)+abs(vc[num]-vc[num-1]),dp(num-2)+abs(vc[num]-vc[num-2]));
    return memo[num];
}


int main()
{
    int N;
    cin >> N;
   
    int temp;
    
    for (int i = 0; i < N; i++)
    {
        cin >> temp;
        vc.push_back(temp);
        memo.push_back(-1);
    }
    
    memo[0]=0;
    memo[1] = abs(vc[0]-vc[1]);

    cout << dp(N-1) << endl;
    
}

Measured memory_bytes: 3952
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <bitset>
using namespace std;

#define X first
#define Y second
#define N 100010
#define M 
#define maxn 1000

typedef long long ll;
const int INF=1ll<<30;

vector<int> E[N], ans1, ans2, ans;
bool vis[N];

void Dfs1(int x)
{
	vis[x] = true;
	ans1.push_back(x);
	for (int i = 0; i < E[x].size(); ++i)
	{
		int y = E[x][i];
		if (!vis[y])
		{
			Dfs1(y);
			break;
		}
	}
}


void Dfs2(int x)
{
	vis[x] = true;
	ans2.push_back(x);
	for (int i = 0; i < E[x].size(); ++i)
	{
		int y = E[x][i];
		//cout << x <<" " <<y<<" "<<vis[y]<<endl;
		if (!vis[y])
		{
			Dfs2(y);
			break;
		}
	}
}

int main()
{
	//freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
	
	int n, m; scanf("%d%d", &n, &m);
	
	while (m--)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		E[x].push_back(y);
		E[y].push_back(x);
	}
	Dfs1(1); Dfs2(1);
	printf("%d\n",(int)(ans1.size() + ans2.size() - 1));
	for (int i = ans1.size() - 1; i >= 0; --i) ans.push_back(ans1[i]);
	for (int i = 1; i < ans2.size(); ++i) ans.push_back(ans2[i]);
	for (int i = 0; i < ans.size(); ++i) printf("%d%c", ans[i], i == ans.size() - 1? '\n':' ');
	return 0;
}

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

typedef long long ll;

ll occurances[26];

ll trueMOD(ll x)
{
    ll MOD = 1e9 + 7;
    return ((x % MOD) + MOD) % MOD;
}

int main()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < 26; i++)
    {
        occurances[i] = 0;
    }
    for (int i = 0; i < s.length(); i++)
    {
        occurances[s.at(i) - 'a']++;
    }
    ll result = 1;
    for (int i = 0; i < 26; i++)
    {
        result *= (occurances[i] + 1);
        result = trueMOD(result);
    }
    result--;
    result = trueMOD(result);
    cout << result << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>

int main()
{
  /* 10進数のNをk進数で表示 */
  int n,k,i;
  int s[2000];

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

  for(i=0; n > 0; i++)
  {
    s[i] = n%k ;
    n = n/k ;
  }

  printf("%d",i);
  return 0;
}


Measured memory_bytes: 1716
#!/usr/bin/python
# AOJ
# 0015

for i in range(int(input())):
    n1 = list(input())
    n2 = list(input())
    if len(n2) > len(n1):
        n1, n2 = n2, n1

    ans = []
    for i in range(len(n1)):
        a = int(ans.pop(0)) if len(ans) == i + 1 else 0
        c1 = int(n1.pop(-1))
        c2 = int(n2.pop(-1)) if len(n2) != 0 else 0
        ans = list(str(a + c1 + c2)) + ans
    if len(ans) > 80:
        print('overflow')
    else:
        print(''.join(ans))

Measured memory_bytes: 6720
#include<stdio.h>

int main(void)
{
  int r, c, i, j, sum = 0, total = 0;

  scanf("%d %d",&r, &c);

  int hyo[r][c];

  for(i = 0; i < r; i++) {
    for(j = 0; j < c; j++) {
      scanf("%d", &hyo[i][j]);
    }
  }

  for(i = 0; i < r; i++) {
    for(j = 0; j < c; j++) {
      printf("%d ", hyo[i][j]);
      sum += hyo[i][j];
    }
    printf("%d\n", sum);
    total += sum;
    sum = 0;
  }

  for(j = 0; j < c; j++) {
    for(i = 0; i < r; i++) {
      sum += hyo[i][j];
    }
    printf("%d ", sum);
    sum = 0;
  }
  printf("%d\n", total);

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
const long long MOD = 1000000007;
long long x[200010] ;
 
ll fst(ll a, ll b){
    if (!b) {
        return 1;
    }
 
    ll sq=fst(a, (b>>1LL));
    sq*=sq;
 
    if (b&1) {
        sq%=MOD;
        sq*=a;
    }
 
    return sq%MOD;
}
 
long long inv (long long n){
    return fst (n,MOD-2) ;
}
 
long long c(long long n, long long k) {
    return x[n]*inv(x[k])%MOD *inv(x[n-k])%MOD;
}
 
int main ()
{
int n , k ;
cin >> n >> k ;
x[0]=1;
for (int i = 1 ; i <= n ; i ++)
    x[i]= (i*x[i-1])%MOD ;
int l;
if (k>n) l = n;
else l=k+1;
long long ans =0 ;
for (int i = 0 ; i < l ; i++){
    ans += c(n,i)*c(n-i+(i-1),i)%MOD ;
    ans %=MOD;
}
cout << ans ;
}

Measured memory_bytes: 1792
N=int(input())
HN=list(map(int,input().split()))

rtn=0
btm=0
top=0
for Hi in HN:
  if top<Hi:
    top=Hi
  elif top==btm and btm>Hi:
    top=Hi
    btm=Hi    
  elif top>Hi:
    rtn+=top-btm
    top=Hi
    btm=Hi
rtn+=top-btm
print(rtn)
    

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

int main()
{
    int n, m; cin >> n >> m;
    int maxL = INT_MIN, minR = INT_MAX, L, R;

    for(int i = 0; i < m; i++)
    {
        cin >> L >> R;
        if(L > maxL) maxL = L;
        if(R < minR) minR = R;
    }
    int res = minR - maxL + 1;
    if(res < 0) res = 0;
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <iostream>
#include <queue>
#include <stack>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <cctype>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define UNIQUE(v) do{ (v).erase( unique(begin(v), end(v)), end(v) ); } while(0)

namespace std {
	template<class S, class T> pair<S, T> operator + (const pair<S, T> &a, const pair<S, T> &b) {return mp<S, T>(a.first + b.first, a.second + b.second);}
	template<class S, class T> pair<S, T> operator - (const pair<S, T> &a, const pair<S, T> &b) {return mp<S, T>(a.first - b.first, a.second - b.second);}
	template<class S, class T> pair<S, T>& operator += (pair<S, T> &a, const pair<S, T> &other) {return a = a + other;}
	template<class S, class T> pair<S, T>& operator -= (pair<S, T> &a, const pair<S, T> &other) {return a = a - other;}
	template<class S, class T> ostream& operator << (ostream& ost, pair<S, T> p) {ost << "(" << p.first << ", " << p.second << ")";return ost;}
	template<class T> ostream& print_iterable_container(ostream& ost, T& container) {
		for (auto&& iter = begin(container); iter != end(container); ++iter) ost << (iter == begin(container) ? " [ " : ", ") << (*iter);
		return ost << " ]";
	}
#	define APPLY_PRINT_ITERABLE_CONTAINER(container_type)\
	template<class T> ostream& operator << (ostream& ost, container_type<T>& container) {\
		return print_iterable_container(ost, container);\
	}
	APPLY_PRINT_ITERABLE_CONTAINER(vector);
	APPLY_PRINT_ITERABLE_CONTAINER(list);
	APPLY_PRINT_ITERABLE_CONTAINER(deque);
}

template<class T> inline bool CHMAX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool CHMIN(T &l,const T &r){return l>r?l=r,1:0;}

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

using ld = long double;

template<class T> using VV = vector<vector<T> >;
template<class T> using maxPQ = priority_queue<T>;
template<class T> using minPQ = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> using uomap = unordered_map<T, U>;
template<class T> using uoset = unordered_set<T>;

const ll INF = 1001001001;
const ll INFll = (ll)INF * INF;
const ll MOD = 1000000007;
const ll MOD_FFT = 998244353;
const ld EPS = 1e-15;

//function<void(int,int)> tensi_no_3p=[&](int v,int d){
//};

int main() {
	ios_base::sync_with_stdio(false);
	int N, K; cin >> N >> K;
	cout << (N - 1 + K - 2) / (K - 1) << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] arr = br.readLine().split(" ");

		int a = Integer.parseInt(arr[0]);
		int b = Integer.parseInt(arr[1]);

		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a == b");
		}

	}
}

Measured memory_bytes: 17088
//
//  main.cpp
//  CoderWork
//
//  Created by Minoru Hayashi on 2020/02/29.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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


//const ll INF = 1LL<<60;
const int INF = 1LL<<29;

//#define __DBG__


void solve(void){

  int N;
  cin >> N;
  
  vector<int> DP(N+10,INF);
  
  vector<int> C;
  
  C.push_back(1);
  REP2(i,1,7){
    C.push_back(pow(6,i));
    C.push_back(pow(9,i));
  }
  
  sort(ALL(C));
  
  DP[0]=0;
  
  for(int i=1; i<=N; i++){
    REP(j,13){
      if(i>=C[j]){
        chmin(DP[i], DP[i-C[j]]+1);
      }
    }
  }
  
  cout << DP[N] << endl;
  
  return;
}


int main(int argc, const char * argv[]) {


    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    solve();
 
    return 0;
}



Measured memory_bytes: 640
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import re

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
H = map(int, raw_input().split()) + [INF]

ans = 0
pre = -INF
cnt = 0
for num in H:
    if num <= pre:
        cnt += 1
    else:
        ans = max(ans, cnt)
        cnt = 0
    pre = num

print ans

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

template <typename T>
void print(const T &v);

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    ll ans = 0;
    ans += a[0];
    int idx = 1;
    int cnt = 0;
    for (int i = 0; i < n - 2; i++)
    {
        ans += a[idx];
        cnt++;
        if (cnt == 2)
        {
            cnt = 0;
            idx++;
        }
    }
    cout << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int mod;

inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
	int x = 1 % mod;
	while(b){
		if(b & 1) x = mul(x, a);
		a = mul(a, a);
		b >>= 1;
	}
	return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

const int N = 306;
int C[N][N], f[N][N], g[N][N];

int main(){
	int n, k, m;
	cin >> n >> k >> m;
	mod = m;

	for(int i = 0; i < N; i++){
		C[i][0] = 1;
		for(int j = 1; j <= i; j++)
			C[i][j] = add(C[i - 1][j], C[i - 1][j - 1]);
	}
	f[0][0] = 1;	
	for(int i = 0; i < N; i++) g[0][i] = f[0][i];

	for(int i = 1; i <= k; i++){
		f[i][0] = 1;
		for(int j = 1; j <= n; j++){
			for(int y = 0; y < j; y++){
				f[i][j] = add(f[i][j], mul(C[j - 1][y], mul(f[i][y], g[i - 1][j - 1 - y])));
			}
		}
		for(int j = 0;  j <= n; j++)
			g[i][j] = add(g[i - 1][j], f[i][j]);
	}
	cout << f[k][n];
}

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

int main() {
    string S, T;
    cin >> S;
    cin >> T;
    map<char, int> Sn, Tn;

    for(int i = 0; i < S.size(); i++) {
       Sn[S[i]] += 1;
    }

    for(int i = 0; i < T.size(); i++) {
        Tn[T[i]] += 1;
    }

    vector<int> A(26);
    vector<int> B(26);
    int t = 0;
    for(char i = 'a'; i <= 'z'; i++) {
        
        A[t] = Sn[i];
        B[t] = Tn[i];
        t++;
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    bool ok = true;
    for(int i = 0; i < 26; i++) {
        if(A[i] != B[i]) ok = false;
    }

    if(ok) cout << "Yes";
    else cout << "No"; 
    return 0;

}

Measured memory_bytes: 776
#include<stdio.h>
int main(){
  int A,B,C,D;
  scanf("%d%d%d%d",&A,&B,&C,&D);
  
  while(1){
    C=C-B;
    if(C<=0)break;
    A=A-D;
    if(A<=0)break;
    }
 if(C<=0) printf("Yes");
  else printf("No");
    }

Measured memory_bytes: 1736
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int r,g,b;

	cin >> r >> g >> b;

	if (r<=b&&b<=g) {
		cout << "Yes" << endl;
	}

	else{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

ll comb3(ll a) {
	ll res = a * (a - 1ll) * (a - 2ll);
	res /= 6;
	return res;
}

ll comb2(ll a) {
	ll res = a * (a - 1ll);
	res /= 2;
	return res;
}


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> roma(5,0);
	rep(i, n) {
		string S; cin >> S;
		if (S[0] == 'A') roma[0]++;
		if (S[0] == 'C') roma[1]++;
		if (S[0] == 'H') roma[2]++;
		if (S[0] == 'M') roma[3]++;
		if (S[0] == 'R') roma[4]++;
	}
	ll res = 0;

	rep(i, 5) {
		res += roma[i];
	}

	ll ans = comb3(res);

	ll ans_minus = 0;

	rep(i, 5) {
		if (roma[i] >= 2) {
			if (roma[i] >= 3) {
				ans_minus += comb3(roma[i]);
				ans_minus += comb2(roma[i]) * (res - roma[i]);
				continue;
			}
			ans_minus += res - roma[i];
		}
	}
	ans -= ans_minus;

	dunk(ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;
 
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
 
template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}
 
// ------------------------------------------------------------------------------------------

map<vector<int>, int> mp;

void init() {
   vector<int> v(8);
   iota(all(v), 0);
   mp[v] = 0;
   queue<vector<int>> que;
   que.push(v);

   while (que.size()) {
      vector<int> cur = que.front(); que.pop();
      int idx = find(all(cur), 0) - cur.begin();
      int y = idx / 4, x = idx % 4;
      rep (i, 4) {
         int ny = y + dy[i], nx = x + dx[i];
         if (ny < 0 || ny >= 2 || nx < 0 || nx >= 4) continue;
         vector<int> next = cur;
         int nc = 4 * ny + nx;
         swap(next[idx], next[nc]);
         if (mp.count(next)) continue;
         mp[next] = mp[cur] + 1;
         que.push(next);
      }
   }
}

int main() {
   init();
   vector<int> vs(8);
   while (cin >> vs[0]) {
      repp (i, 1, 8) cin >> vs[i];
      cout << mp[vs] << endl;
   }

   return 0;
}


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

// 人を頂点とし，友達関係を辺とするグラフにおいて，連結成分のサイズから友達||ブロック関係を除く

struct UnionFind
{
    vector<int> d;
    UnionFind(int n) : d(n, -1) {}
    int root(int x)
    {
        if (d[x] < 0)
            return x;
        return d[x] = root(d[x]);
    }
    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (d[x] > d[y])
            swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -d[root(x)]; }
};

int main()
{
    int N, M, K;
    cin >> N >> M >> K;
    UnionFind graph(N);
    vector<int> friendship(N, 0);
    vector<vector<int>> block(N);
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        friendship[a]++;
        friendship[b]++;
        graph.unite(a, b);
    }
    for (int i = 0; i < K; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        block[a].push_back(b);
        block[b].push_back(a);
    }

    for (int i = 0; i < N; i++)
    {
        int ans = graph.size(i) - friendship[i] - 1;
        for (int u : block[i])
        {
            if (graph.same(i, u))
                ans--;
        }
        printf("%d%c", ans, i == N - 1 ? '\n' : ' ');
    }
    return 0;
}

Measured memory_bytes: 6784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, ml, mr, ans, a[100005], b[100005];
multiset<ll> l, r;

multiset<ll>::iterator last (multiset<ll> &S) {
	auto it = S.end(); it--;
	return it;
}

int main()
{
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++) {
		scanf("%lld%lld",&a[i],&b[i]);
	}
	l.insert(0);
	r.insert(0);
	ml = b[1]; mr = b[1];
	for(ll i=2;i<=n;i++) {
		ml -= b[i-1] - a[i-1];
		mr += b[i] - a[i];
		if(ml <= b[i] && b[i] <= mr) {
			ll GL = b[i] - ml, GR = mr - b[i];
			l.insert((*last(l))+GL);
			r.insert((*last(r))+GR);
			ml = b[i]; mr = b[i];
		}
		else if(b[i] < ml) {
			ll G = ml - b[i];
			ans += G;
			r.insert((*last(r))+mr-ml);
			auto it = last(l);
			ll V = (*it);
			l.erase(it);
			l.insert(V - G);
			l.insert(V - G);
			mr = ml; ml = mr - (V - (*last(l)));
		}
		else {
			ll G = b[i] - mr;
			ans += G;
			l.insert((*last(l))+mr-ml);
			auto it = last(r);
			ll V = (*it);
			r.erase(it);
			r.insert(V - G);
			r.insert(V - G);
			ml = mr; mr = ml + (V - (*last(r)));
		}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 11136
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 30000000000000LL
#define GOLD 1.61803398874989484820458
const long long MAX_MOD = 1e6 + 3;
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
long long powering(long long now,long long now_go){
	long long ans = 1;
	while (now_go != 0) {
		if (now_go % 2 == 1) {
			ans *= now;
			ans %= MAX_MOD;
		}
		now *= now;
		now %= MAX_MOD;
		now_go /= 2;
	}
	return ans;
}
long long inv(long long now) {
	return powering(now, MAX_MOD - 2LL);
}
long long d;
long long geko[32] = {};
long long bobo[30] = {};
long long solve(long long now, long long now_digit, long long L) {
	if (L / 2 == now_digit) {
		if (L % 2 == 0) {
			if (d == now) {
				return 1;
			}
			else {
				return 0;
			}
		}
		else {
			if (d == now) {
				return 10LL;
			}
			else {
				return 0LL;
			}
		}
	}
	long long ans = 0;
	for (long long i = -9; i <= 9; ++i) {
		long long tea = geko[L - now_digit - 1] - geko[now_digit];
		tea *= i;
		tea += now;
		if (tea >= 0) {
			if (tea % geko[now_digit + 1] == d % geko[now_digit + 1]) {
				//ok
				long long geko = solve(tea, now_digit + 1, L);
				if (geko == 0) continue;
				if (now_digit == 0) {
					bobo[i + 9]--;
				}
				ans += geko * bobo[i+9];
				if (now_digit == 0) {
						bobo[i + 9]++;
				}
			}
		}
		else {
			tea += geko[18];
			if (tea % geko[now_digit + 1] == d % geko[now_digit + 1]) {
				long long geko = solve(tea - bobo[18], now_digit + 1, L);
				if (geko == 0)continue;
				if (now_digit == 0) {
						bobo[i + 9]--;
				}
				ans += geko * bobo[i + 9];
				if (now_digit == 0) {
						bobo[i + 9]++;
				}
			}
			tea -= geko[18];
		}
	}
	return ans;
}
int main() {
	for (int i = 0; i <= 9; ++i) {
		for (int q = 0; q <= 9; ++q) {
			bobo[i - q + 9]++;
		}
	}
	geko[0] = 1;
	for (int i = 1; i <= 18; ++i) {
		geko[i] = 10LL * geko[i-1];
	}
	cin >> d;
	if (d % 9 != 0) {
		cout << 0 << endl;
		return 0;
	}
	int len = to_string(d).length();
	long long ans = 0;
	for (long long digit = len; digit <= len * 2; ++digit) {
		ans += solve(0, 0, digit);
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
/*
ID: little_10
LANG: C++
TASK: frac1
*/
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <map>

using namespace std;

#define gc() getchar()
#define digit(x) ('0' <= x && x <= '9')

int read()
{
	int x=0, f=1;char c=gc();
	while(!digit(c)){if(c == '-') f=-1;c=gc();}
	while(digit(c))x=(x<<3)+(x<<1)+x-'0', c=gc();
	return x*f;
}

const int N = 160;

int a, b;

int main()
{
	scanf("%d", &a);
	for(register int i=1; i<=9; i++)
	{
		if(a%i) continue;
		if(a/i>=1 && a/i<=9)
		{
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  each(x,vec) is >> x;
  return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  rep(i,vec.size()) {
    if (i) os << " ";
    os << vec[i];
  }
  return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
  rep(i,vec.size()) {
    if (i) os << endl;
    os << vec[i];
  }
  return os;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m; cin >> n >> m;
  string str; cin >> str;
  vector<vector<ll>> G(n);
  rep(i, m) {
    ll a, b; cin >> a >> b; --a, --b;
    G[a].pb(b);
    G[b].pb(a);
  }
  vector<P> cnt(n, P(0, 0));
  rep(i, n) each(to, G[i]) {
    if (str[to] == 'A') {
      cnt[i].first++;
    }
    else {
      cnt[i].second++;
    }
  }
  vector<bool> used(n, false);
  queue<ll> Q;
  rep(i, n) {
    if (cnt[i].first == 0 || cnt[i].second == 0) {
      Q.push(i);
      used[i] = true;
    }
  }
  while (!Q.empty()) {
    ll v = Q.front(); Q.pop();
    each(to, G[v]) {
      if (str[v] == 'A') {
        if (--cnt[to].first == 0 && !used[to]) {
          Q.push(to);
          used[to] = true;
        }
      }
      else {
        if (--cnt[to].second == 0 && !used[to]) {
          Q.push(to);
          used[to] = true;
        }
      }
    }
  }
  if (*min_element(all(used)) == false) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 15568