akhauriyash/Code-Regression huggingface dataset:
# 1マス移動するごとに周囲5*5を見て現在+1を書き込む? ◎
# それとも移動できるまで移動してから、次を探しに行く?
# 幅優先か、深さ優先か? 幅優先

# AGC033Aからコピペ

h, w = list(map(int, input().split()))

start = list(map(int, input().split()))
goal = list(map(int, input().split()))

masu = [input() for i in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

inf = 10 ** 7
distance = [[inf for _ in range(w)] for _ in range(h)]

from collections import deque

queue = deque([])
distance[start[0]-1][start[1]-1] = 0
queue.append((start[0]-1, start[1]-1, 0))

while True:
    if len(queue) == 0:
        break
    now = queue.popleft()
    now_h = now[0]
    now_w = now[1]
    now_distance = now[2]
    now_distance_matrix = distance[now_h][now_w]

    if now_distance > now_distance_matrix:
        # もう小さい数字がdistanceに書かれているので
        continue
    distance[now_h][now_w] = now_distance

    for hh in range(now_h - 2, now_h + 2+1):
        for ww in range(now_w - 2, now_w + 2+1):
            if not (0 <= hh <= h-1 and 0 <= ww <= w-1):
                continue
            if masu[hh][ww] == '#':
                continue
            if distance[hh][ww] <= now_distance:
                continue
            queue.append((hh, ww, now_distance + 1))

    for i in range(4):
        next_h = now_h + dx[i]
        next_w = now_w + dy[i]
        if not (0 <= next_h <= h-1 and 0 <= next_w <= w-1):
            continue
        if masu[next_h][next_w] == '#':
            continue
        if distance[next_h][next_w] <= now_distance:
            continue
        else:
            distance[next_h][next_w] = now_distance
            queue.appendleft((next_h, next_w, now_distance))

t = distance[goal[0]-1][goal[1]-1]
if t == inf:
    print(-1)
else:
    print(t)

# print(distance)


Measured memory_bytes: 234256
/*
   YOU CAN'T TAKE HELP FROM EDITORIAL               .m.
*/
#include "bits/stdc++.h"

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define pb push_back
#define all(ar) ar.begin(),ar.end() 
#define pii pair<int,int> 


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

const ll mod = 1e9 + 7;
const ll mxr = 1e6 + 10;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
/*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
/*/
    ll c = 0,n,d; cin>>n>>d;
    while(n--){
        ll x,y; cin>>x>>y;
        if((x * x) + (y * y) <= d * d){
            c++;
        }
    }
    cout<<c el;
    return 0;
}

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

int main() {
	int n; cin >> n;
	int sum = 0, ori = n;
	while (n) {
		sum += n%10;
		n /= 10;
	}
	if (ori%sum == 0) cout << "Yes\n"; 
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int w,a,b;
  cin >> w >> a >> b;
  if(a < b && a+w<b)
    cout << b-a-w << endl;
  else if(b < a && b+w<a)
    cout << a-b-w << endl;
  else
    cout << 0 << endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

//参考
//https://note.com/tak_nakamori/n/n00a17b49b69d
fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut sc: Vec<(u8,u8)> = Vec::new();

    for _i in 0..m {
        sc.push((read(),read()));
    }

    //Nごとに最小/最大+1の値を設定する
    //最大+1なのはループ範囲の設定のため
    let start:[usize;3] = [0, 10, 100];
    let end:[usize;3] = [10, 100, 1000];

    //Nに合わせて小さい数から全探索
    for i in start[n - 1]..end[n - 1]{

        //一文字ごとに判定するため文字列へ変換
        let str:String = i.to_string();

        //答えが存在するかのフラグ
        let mut flg = true;

        // 1桁ごと確認する。
        // 見ている桁とs_iが同じだったら、
        // その桁の値とc_iが同じかチェックする。
        // 値とc_iが異なると答えは存在しない。
        for j in 0..n {
            for k in 0..m {
                if (j as u8) + 1 == sc[k].0 {
                    if sc[k].1 != str[j..j+1].parse().unwrap() {
                        flg = false;
                    }
                }
            }
        }

        // flaがtrueのままfor文が終わった最初のiが答え。
        if flg == true {
            println!("{}", i);
            return;
        }
    }

    println!("-1");

}


Measured memory_bytes: 4352
def main():
    import numpy as np

    n, m = map(int, input().split())
    dp = np.full(2**n, 10**9, dtype=np.int64)
    dp[0] = 0
    opened = np.arange(2**n)

    for _ in range(m):
        cost, types = map(int, input().split())
        to_open = np.array(list(map(int, input().split())), dtype=np.int64)

        openable = np.left_shift(1, to_open-1).sum()
        new_indexes = opened | openable
        new_costs = dp + cost
        sort_index = np.argsort(new_costs)
        new_costs.sort()
        update_pattern, idx = np.unique(new_indexes[sort_index], return_index=True)
        update_cost = new_costs[idx]
        dp[update_pattern] = np.minimum(dp[update_pattern], update_cost)

    full_open = 2**n - 1
    ans = dp[full_open]
    if ans == 10 ** 9:
        ans = -1

    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<int>> a(n, vector<int>(m));
  vector<vector<int>> b(m, vector<int>(l));
  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < m; j ++) cin >> a[i][j];
  }
  for (int i = 0; i < m; i ++) {
    for (int j = 0; j < l; j ++) cin >> b[i][j];
  }

  vector<vector<LL>> c(n, vector<LL>(l));
  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < m; j ++) {
      for (int k = 0; k < l; k ++) {
        c[i][k] += a[i][j] * b[j][k];
      }
    }
  }

  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < l; j ++) {
      if (j) cout << " ";
      cout << c[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 3260
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
s = set()
s.add(0)
s.add(-1)
for i in range(n-1):
  if a[i] == a[i+1]:
    s.add(a[i])
m = max(s)
s.discard(m)
k = max(s)
if a.count(m) > 3:
  print(m**2)
else:
  print(m*k)

Measured memory_bytes: 14244
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, A, B;
	cin >> N >> A >> B;
	cout << min(N*A, B) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
priority_queue<int>Q;
int edgenum,vet[4005],nex[4005],head[4005],du[4005];
int n,a[2005];
bool adj[2005][2005],vis[4000005];
int gcd(int a,int b)
{
	return (b==0)?a:gcd(b,a%b);
}
void addedge(int u,int v)
{
	edgenum++,vet[edgenum]=v,nex[edgenum]=head[u],head[u]=edgenum,du[v]++;
}
void dfs(int u)
{
	for (int i=1;i<=n;i++)
		if (adj[u][i]==true && vis[i]==false) addedge(u,i),vis[i]=true,dfs(i);
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++)
			if (gcd(a[i],a[j])>1) adj[i][j]=adj[j][i]=true;
	for (int i=1;i<=n;i++)
		if (!vis[i]) vis[i]=true,dfs(i);
	for (int i=1;i<=n;i++)
		if (du[i]==0) Q.push(i);
	while (!Q.empty())
	{
		int u=Q.top();Q.pop();
		printf("%d ",a[u]);
		for (int i=head[u];i!=0;i=nex[i])
		{
			du[vet[i]]--;
			if (du[vet[i]]==0) Q.push(vet[i]);
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 6144
#include<cstdio>
inline void read(int&r)
{
	register char c;r=0;
	do c=getchar();while(c<'0'||c>'9');
	do r=r*10+c-'0',c=getchar();while(c>='0'&&c<='9');
}

typedef long long ll;
const int mod=1e9+7;
int x[100001],ans=1;

int main()
{
	int n,i;read(n);
	for(i=1;i<=n;i++)
	{
		read(x[i]);
		if(x[i]<=(i-1)<<1)
			ans=(ll)ans*i%mod,i--,n--;
	}
	do ans=(ll)ans*n%mod;while(--n);
	printf("%d\n",ans);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<cctype>
#include<cmath>
#include<queue>
#include<stack> 
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
//const int MAX_V=105;
const long double pi = 3.14159265;
const long long mod =1e9+7;


int main(){
    
    int N, count =1;
    cin >> N;
    int d[N];
    rep(i,N){
        cin >> d[i];
    }
    sort(d,d+N);
    rep(i,N-1){
        if(d[i]<d[i+1]){
            count++;
        }
    }
    cout << count << endl;


    return 0;
}
 

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

//Patience
public class Main{

	void run(){
		int[][] move = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while(T--!=0){
			String start = "";
			for(int i=0;i<5;i++)for(int j=0;j<4;j++)start+=sc.next();
			List<String> l = new ArrayList<String>();
			l.add(start);
			int step = 20;
			while(!l.isEmpty()){
				List<String> next = new ArrayList<String>();
				Set<String> u = new HashSet<String>();
				for(String s:l){
					char[] ch = s.toCharArray();
					for(int i=0;i<5;i++){
						for(int j=0;j<4;j++){
							char x = ch[i*4+j];
							if(x=='0')break;
							for(int k=0;k<8;k++){
								int ni = i+move[k][0];
								int nj = j+move[k][1];
								if(0<=ni&&ni<5&&0<=nj&&nj<4){
									if(x==ch[ni*4+nj]){
										String n = "";
										for(int a=0;a<5;a++){
											for(int b=0;b<4;b++){
												if(a==i&&b==j||a==ni&&b==nj)continue;
												n += ch[a*4+b];
											}
										}
										n += "00";
										if(!u.contains(n)){
											u.add(n); next.add(n);
										}
									}
								}
							}
						}
					}
				}
				if(next.isEmpty()){
					System.out.println(step);
				}
				step-=2;
				l = next;
			}
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll root (ll Arr[ ] ,ll i)
{
	ll j=i;
    while(Arr[ i ] != i)
    {
		i = Arr[ i ]; 
    }
    Arr[j]=i;
	return i;
}
void join(ll Arr[ ],ll size[ ],ll A,ll B)
{
    ll root_A = root(Arr,A);
    ll root_B = root(Arr,B);
    if(root_A==root_B) return;
    if(size[root_A] < size[root_B ])
    {
	Arr[ root_A ] = Arr[root_B];
	size[root_B] += size[root_A];
	}
    else
    {
	Arr[ root_B ] = Arr[root_A];
	size[root_A] += size[root_B];
	}
}
int main()
{
	ll i,j,k,m,n,t;
	cin>>n>>m;
	ll ar[n],size[n];
	for(i=0;i<n;i++)
	{
		ar[i]=i;
		size[i]=1;
	}
	for(i=0;i<m;i++)
	{
		cin>>j>>k;
		j--,k--;
		join(ar,size,j,k);
	}
	ll ans=0;
	for(i=0;i<n;i++)
	{
		ans=max(ans,size[i]);
		//cout<<root(ar,i)<<' ';
	}
	//cout<<endl;
	cout<<ans;
}

Measured memory_bytes: 6756
/*QAQ三连：以前的题都补了吗，今天的题都做了吗，不会的算法都会了吗*/
/*金桔退役三连：退役选手不学不会不练*/
#include <bits/stdc++.h>
#define LDQ 1000000007
#define QAQ 0x3f3f3f3f
#define PI 3.14159265358979323846
using namespace std;
map<long long,long long>mp;
long long f(long long n)
{
    if(mp[n]!=0)
    {
        return mp[n];
    }
    if(n<2)
    {
        return mp[n]=n+1;
    }
    else if(n%2==0)
    {
        return mp[n]=(2*f(n/2-1)+f(n/2))%LDQ;
    }
    else
    {
        return mp[n]=(f(n/2-1)+2*f(n/2))%LDQ;
    }
}
int main()
{
    long long n;
    scanf("%lld",&n);
    printf("%lld",f(n));
    return 0;
}


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

using namespace std;

bool expr(string &str, int &itr);

int main() {
    string str;
    cin >> str;
    int itr=0;
    if(expr(str,itr)&&itr==str.length()){
        cout << "Cat" << endl;
    } else {
        cout << "Rabbit" << endl;
    }
    return 0;
}

bool expr(string &str, int &i){
    if(str=="") return true;
    if(str[i]!='m') return false;
    i++; 
    if(str[i]!='e') if(!expr(str,i))return false;
    if(str[i]!='e') return false;
    i++;
    if(str[i]!='w') if(!expr(str,i))return false;
    if(str[i]!='w') return false;
    i++;
    return true;
}




Measured memory_bytes: 3156
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <fstream>

#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

ll GCD(ll a, ll b) {
    if(b==0) return a;
    else return GCD(b, a%b);
}

ll LCM(ll a, ll b) {
    return a/GCD(a,b)*b;
}

class AMultiplication1 {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll a,b;
        in>>a>>b;
        out<<a*b<<endl;
	}
};


int main() {
	AMultiplication1 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main() {
	int n ; 
	cin>>n;
	int a[101], b[101];
	
	for( int i =0 ; i<n ; i++)
	{
	    cin>>a[i];
	}
	for( int i =0 ; i<n ; i++)
	{
	    cin>>b[i];
	}

int as=0 , bs=0 ;
	for( int i =0 ; i<n ; i++){
	    if( a[i]>b[i])
	    {
	        as+=a[i];
	        bs+=b[i];
	    }
	    
	}
	
	cout<<as-bs<<endl;
	return 0;
}

Measured memory_bytes: 256
var
 ch1,ch2,ch3,ch4,ch5,ch6:char;
 n,m,i,j,k1,k2:longint;
begin
 readln(n,m);
 for i:=1 to n do
 begin
  for j:=1 to m-1 do
   begin
    read(ch1,ch2,ch3,ch4,ch5,ch6);
    if (ch1='s') and (ch2='n') and (ch3='u') and (ch4='k') and (ch5='e') then begin k1:=i;k2:=j;end;
   end;
    read(ch1,ch2,ch3,ch4,ch5);
    if (ch1='s') and (ch2='n') and (ch3='u') and (ch4='k') and (ch5='e') then begin k1:=i;k2:=j;end;
   readln;
   end;
   writeln(chr(k2+64),k1);
end.

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int n,k;
string s;
int countHappy(string t){
    int ret = 0;
    FOR(i,1,n){
        //DEBUG2(t[i],t[i-1]);
        if(t[i]==t[i-1]) ret++;
    }
    return ret;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n>>k;
    cin>>s;

    int ans = countHappy(s);

    cout << min(ans + 2*k, n-1) << endl;
    return 0;
}

Measured memory_bytes: 512
h,w,d = map(int,input().split())
a = [0]*h
for i in range(h):
    a[i] = list(map(int,input().split()))
num = [[] for i in range(w*h+1)]
for i in range(h):
    for j in range(w):
        num[a[i][j]].append([i,j])
s = [0]*(h*w+1)
for i in range(1,h*w-d+1):
    s[d+i] = s[i] + abs(num[d+i][0][0]-num[i][0][0]) + abs(num[d+i][0][1]-num[i][0][1])
q = int(input())
for i in range(q):
    L,R = map(int,input().split())
    print(s[R]-s[L])

Measured memory_bytes: 33024
/*   Abhijith  */
#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
#define lld long long int
#define ld long double
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b)	for(lld i=a;i<=b;i++)
#define repr(i,a,b) for(lld i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define	endl '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
     ios;
     lld n,we;
     cin>>n>>we;
     vector<lld> v(n+1),w(n+1);
     rep(i,1,n)
     {
         cin>>w[i]>>v[i];
     }
     vector<vector<lld> > dp(n+1,vector<lld>(we+1,0));
     lld ans=0;
     rep(i,1,n)
     {
         dp[i]=dp[i-1];
         rep(j,1,we)
         {
             if(j-w[i]>=0)
             {
                 dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
             }
         }
     }
     cout<<dp[n][we]<<endl;
    return 0;
}


Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000000000000000;
#define PI 3.1415926535
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;}
char upper(char c){
    if('a' <= c && c <= 'z'){
        c = c - ('a' - 'A');
    }
    return c;
}
char lower(char c){
    if('A' <= c && c <= 'Z'){
        c = c + ('a' - 'A');
    }
    return c;
}
int GetDigit(int num){
    int digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}
ll enum_divisors(ll N) {
    ll res = 0;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res++;
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res++;
        }
    }
    // 小さい順に並び替える
    return res;
}
//input



//processing
int cntW,cntR,cntWR;


//dpTable
//int dp[100050];
int main(){
    int N;
    string c;
    cin >> N >> c;
    /*vector<char> c(N);
    for (int i = 0; i < N; i++){
        c.at(i) = S.at(i);
    }*/
    for (int i = 0; i < N; i++){
        if (c.at(i) == 'W') {
            cntW++;
        }
        else {
            cntR++;
        }
    }
    for (int i = 0; i < cntR; i++){
        if (c.at(i) == 'W'){
            cntWR++;
        }
    }
    cout << min(cntWR,min(cntW,cntR)) << endl;
    return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 998244353;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    REP(i,n){
        cin >> p[i];
    }
    sort(all(p));
    int ans=0;
    REP(i,k){
        ans+=p[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3600
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert
#define fh(x,v) for(auto x:v)

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
unsigned XorShift(void){static unsigned x = 123456789;static unsigned y = 362436069;static unsigned z = 521288629;static unsigned w = 88675123;unsigned t;t = x ^ (x << 11);x = y; y = z; z = w;return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));}
//}

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

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int n,p,dp[55][2];

main(){
    cin>>n>>p;
    int a[n];rep(i,n)cin>>a[i];
    dp[0][0]=1;
    rep(i,n){
        if(a[i]%2==0){
            dp[i+1][0]=dp[i][0]*2;
            dp[i+1][1]=dp[i][1]*2;
        }else{
            dp[i+1][0]=dp[i][0]+dp[i][1];
            dp[i+1][1]=dp[i][0]+dp[i][1];
            
        }
    }
    dump(dp[n][p]);
}





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

using namespace std;

constexpr int MAX_N = 100100;
constexpr int INF = 1e9 + 5;

int n, k;
int arr[MAX_N];

int dp[MAX_N];

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

    dp[1] = 0;
    for (int i = 2; i <= n; ++i) {
        dp[i] = -1;
        for (int j = 1; j <= k; ++j) {
            if (i - j <= 0) continue;
            if (dp[i - j] == -1) continue;
            int cur = dp[i - j] + abs(arr[i] - arr[i - j]);
            if (dp[i] == -1 || cur < dp[i]) {
                dp[i] = cur;
            }
        }
    }

    printf("%d\n", dp[n]);

    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	int x,ans;
	vector<int>a;
	f(i, 3){
		scanf("%d", &x);
		a.push_back(x);
	}
	sort(a.begin(), a.end());
	ans = 0;
	x = (a[2] - a[0]) / 2;
	ans += x;
	a[0] += x * 2;
	x = (a[2] - a[1]) / 2;
	ans += x;
	a[1] += x * 2;
	x = a[2] * 2 - (a[0] + a[1]);
	if (x == 1)ans += 2;
	else if (x == 2)ans += 1;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 long long int a,b,c,d,e=10000000000000,i,k,j,l=0;
 vector<long long>v;
  cin>>a;
  for(i=1;i<=a;i++)
  {
  cin>>b;
  v.push_back(b);l+=b;
  }
  
  for(i=0;i<a-1;i++)
  {
    j+=v[i];
   k=l-j;
   e=min(e,abs(k-j));
  //cout<<e<<endl;
 
  }
cout<<e<<endl;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e5+5,M=1e6+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a) memset(a,0,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first 
#define se second
int n,m;
ll fac[N],inv[N];
ll ksm(ll a,ll n){
	ll ans=1;
	while(n){
		if(n&1) ans=ans*a%mod;
		a=a*a%mod;
		n>>=1;
	}
	return ans;
}
ll C(int m,int n){
	return fac[m]*inv[m-n]%mod*inv[n]%mod;
}
ll A(int m,int n){
	return fac[m]*inv[m-n]%mod;
}
int main(){
	scanf("%d%d",&n,&m); 
	fac[0]=1;
	for(int i=1;i<=m;i++) fac[i]=fac[i-1]*i%mod;//阶乘递推. 
	inv[m]=ksm(fac[m],mod-2);//费马小定理. 
	for(int i=m-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;//阶乘逆元递推. 
	ll ans=0;
	for(int i=0;i<=n;i++){
		ans+=C(n,i)*((i&1)?-1:1)*A(m-i,n-i)%mod;
	}
	ans=(ans%mod+mod)%mod;
	printf("%lld\n",ans*A(m,n)%mod);
	return 0;
}



Measured memory_bytes: 11536
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <string>

int R;
long double pi = 3.14159265358979323846;

int main() {
  std::cin >> R;
  std::cout << std::fixed << std::setprecision(10) << 2*R*pi << std::endl;
}


Measured memory_bytes: 3784
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int w,h,x,y,r;
int main()
{
	cin>>w>>h>>x>>y>>r;
        if(0<=x-r&&x+r<=w&&0<=y-r&&y+r<=h) puts("Yes");
else puts("No");
}

Measured memory_bytes: 1120
//c++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define sz(x) ((int)(x).size())

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
//const int MOD = 1000000007;
const int MOD = 998244353;
//int MOD = 1000000007;
double EPS = 1e-10;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A){printf("%.12lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


//コンビネーション
const int MAXcomb = 10000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

ll disit(ll s, ll base = 10){
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}

//約数の列挙O(√n)
vector<ll> divisor(ll n){
    vector<ll> res(0);
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n/i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int power[10000010];
void solve(){
  ll N;
  cin >> N;
  COMinit();
  power[0] = 1;
  for(ll i = 1; i <= N; i++) power[i] = power[i-1] * 2 % MOD;
  int ans = pow_mod(3, N);

  for(ll i = N/2 + 1; i <= N; i++){
    ans += MOD - comb(N, i) * power[N-i+1] % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  solve();
}


Measured memory_bytes: 275200
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define EQ(a,b) (abs((a)-(b))<EPS)
using namespace std;
typedef long double D;
typedef complex<D> P;
const D EPS = 1e-8;
const D PI = acos(-1);

int n,r,q;
P p[30];
int cur;

inline D dot(const P &x, const P &y){return real(conj(x)*y);}

inline P rotate(const P &v, const D &s){
  return P(real(v)*cos(s) - imag(v)*sin(s), real(v)*sin(s) + imag(v)*cos(s) );
}

inline D arg(const P &a,const P &b,const P &c){return acos(dot(b-a,c-a)/(abs(b-a)*abs(c-a)));}

inline D rot_seta(const int &end){
  D dis = abs(p[end]-p[cur]);
  D seta = acos( (2*r*r - dis*dis)/(2*r*r) );
  P nxt = rotate(p[cur],-seta);
  return arg(p[cur],p[end],nxt);
}

int main(){
  
  while(cin >> n >> r >> q, n){
    rep(i,n){
      D x,y;
      cin >> x >> y;
      p[i] = P(x,y);
      if(EQ(abs(p[i]),r))cur = i;
    }
    
    vector<int> nxt(n,-1);
    
    rep(i,q){
      int id = -1;
      D min_s = PI;
      if(nxt[cur]>=0)id = nxt[cur];
      else{
	rep(j,n){
	  if(cur==j)continue;
	  D s = rot_seta(j);
	  if(id<0 || s+EPS < min_s)id = j, min_s = s;
	}
	nxt[cur] = id;
      }

      D seta = rot_seta(id);
      rep(i,n){
	if(i==cur)continue;
	p[i] = rotate(p[i]-p[cur],seta) + p[cur];
      }
      cout << fixed << setprecision(10) << p[id].real() << " " << p[id].imag() << endl;
      cur = id;
    }
  }
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

template <typename T>
struct SegmentTree {
 private:
  ll n;            //最下段のサイズ
  T e;             //単位元
  vector<T> node;  //セグメント木を表現する配列
  typedef function<T(T, T)> Func;
  Func f;  //区間クエリで使う処理

 public:
  SegmentTree(vector<T> v, Func f_input, T e_input) {
    f = f_input;
    e = e_input;
    ll sz = SZ(v);
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1, e);
    REP(i, sz) node[i + n - 1] = v[i];
    IREP(i, n - 1) node[i] = f(node[2 * i + 1], node[2 * i + 2]);
  }

  // x番目(0-indexed)の要素をvalに更新する
  void update(ll x, T val) {
    x += (n - 1);
    node[x] = val;
    while (x > 0) {
      x = (x - 1) / 2;
      node[x] = f(node[2 * x + 1], node[2 * x + 2]);
    }
  }

  // [a, b) に対する区間クエリに答える
  // k := 自分がいるノードのインデックス
  // [l, r) : ノードkの対象区間
  T query(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return e;
    if (a <= l && r <= b) return node[k];
    T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
    T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return f(vl, vr);
  }

  // 添字でアクセス
  T operator[](ll i) { return node[i + n - 1]; }
};

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<bool>> a(n, vector<bool>(26, false));
  REP(i, n) {
    ll c = s[i] - 'a';
    a[i][c] = true;
  }
  SegmentTree<vector<bool>> sg(a,
                               [](vector<bool> x, vector<bool> y) {
                                 ll sz = SZ(x);
                                 vector<bool> z(sz);
                                 REP(i, sz) { z[i] = x[i] || y[i]; }
                                 return z;
                               },
                               vector<bool>(26, false));
  ll q;
  cin >> q;
  while (q--) {
    ll t;
    cin >> t;
    if (t == 1) {
      ll i;
      char c;
      cin >> i >> c;
      i--;
      vector<bool> b(26, false);
      ll idx = c - 'a';
      b[idx] = true;
      sg.update(i, b);
      continue;
    }
    ll l, r;
    cin >> l >> r;
    l--;
    vector<bool> b = sg.query(l, r);
    ll ans = 0;
    REP(j, SZ(b)) {
      if (b[j]) {
        ans++;
      }
    }
    cout << ans << endl;
  }
}

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

#define MATHPI acos(-1)

template<class T> void chmax(T &a, T b) {
    if (a < b) a = b;
}
template<class T> void chmin(T &a, T b) {
    if (b < a) a = b;
}

using Mat = vector<vector<ll>>;
using Column = vector<ll>;

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int A,B;cin>>A>>B;
    int price = -1;   
    for (size_t i = 1; i <= 1250; i++)
    {
        if(floor(i*0.08) == A && floor(i*0.1) ==B) {
            price=i;
            break;
        }
    }
    cout<<price<<"\n";
    
    return 0;
}

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define inn(x, y) int x,y;cin>>x>>y
#define innn(x, y, z) int x,y,z;cin>>x>>y>>z
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define outt(x,y) cout<<(x)<<" "<<(y)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;
#define errrr(x,y,z) cerr<<(x)<<" "<<(y)<<" "<<(z)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 200020
#define lim9 1000000002

#define deg(rad) (((rad)/2/M_PI)*360)
#define mid(min, max) ((min + max) / 2)

int main() {
	ll n, ans = 0;
	cin >> n;
	for(ll i = 1; i <= n; i++) {
		if(!(i % 3) || !(i % 5)) {
		} else {
			ans += i;
		}
	}
	out(ans);
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 2LL << 60;
using ll = long long;
using P = pair<ll, ll>;

int main(int argc, char const *argv[]) {
    int n, k;
    int ans=0;
    cin >> n >> k;
    vector<int> s(n,0);
    rep(i, k){
        int d;
        cin >> d;
        rep(j,d){
            int snk;
            cin >> snk;
            snk--;
            s[snk]++;
        }
    }
    rep(i, n){
        if(s[i]==0){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ESP 1e-5

int main(void){
    vector<int> a(5);
    for(int i = 0; i < 5; i++){
	cin >> a[i];
    }
    for(int i = 0; i < 5; i++){
	if(a[i] == 0){
	    cout << i + 1 << endl;
	    return 0;
	}
    }
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,k,ctn = 0;
	cin >> n >> k;
	if (k == 0 ){
		ctn = n * n ;
	} else {
		for (long long a=n;a<=n;a++){
			for (long long i=k;i<=n;i++){
				ctn += a/i * (i - k);
				if(a%i-k >= 0) ctn += a%i+1-k;
			}
		}
	}
	cout << ctn << endl;
}


Measured memory_bytes: 256
#include<stdio.h>


int main(){

  int height, max[3]={}, i;

  for(i=0;i<10;i++){
    scanf("%d", &height);
    if(max[0]<=height){
      max[2]=max[1];
      max[1]=max[0];
      max[0]=height;
    }else if(max[1]<=height){
      max[2]=max[1];
      max[1]=height;
    }else if(max[2]<=height) max[2]=height;
  }

  for(i=0;i<3;i++) printf("%d\n", max[i]);

  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <numeric>
#include <cmath>

using namespace std;
using int64 = long long;
using P = pair<int64,int64>;

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

int main() {
    int64 n;
    cin >> n;
    vector<int64> a(n);
    int64 _max = INT_MIN;
    int64 _min = INT_MAX;
    int64 uindex = 0;
    int64 lindex = 0;
    for (int64 i=0; i<n; i++) {
        cin >> a[i];
        if (chmin(_min, a[i])) lindex = i+1;
        if (chmax(_max, a[i])) uindex = i+1;
    }

    vector<P> ans;
    bool r = _max < 0;

    if (signbit(_max) != signbit(_min)) {
        int64 index = uindex;
        if (abs(_max) < abs(_min)) {
            index = lindex;
            r = true;
        }

        for (int64 i=1; i<=n; i++) {
            if (i == index) continue;
            ans.emplace_back(i, index);
        }
    }

    int64 k = ans.size();

    for (int64 i=1; i<n; i++) {
        ans.emplace_back(i+1, i);
    }

    if (r) reverse(ans.begin() + k , ans.end());

    cout << ans.size() << endl;
    for (int i=0; i<ans.size(); i++) {
        if (i>k-1 && r)
            cout << ans[i].first << " " << ans[i].second << endl;
        else
            cout << ans[i].second << " " << ans[i].first << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n=10,h,w,m,t,i,j,k,res=0;
  int d[10][10];
  cin >> h >> w;
  m=h*w;
  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      cin >> d[i][j];
  for(k=0;k<n;k++)
    for(i=0;i<n;i++)
      for(j=0;j<n;j++)
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
  for(i=0;i<m;i++){
    cin >> t;
    if(t>=0)
      res+=d[t][1];
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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(void) {
    int n;
    cin>>n;
    double v[n];
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v,v+n);
    double tmp=(v[0]+v[1])/2;
    
    for(int i=2;i<n;i++){
        tmp=(tmp+v[i])/2;
    }
    cout<<setprecision(10)<<tmp<<endl;
}

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

int main() {
  
  int N, K, X;
  cin >> N >> K;
  X = 1;
  for (int i = 0; i < N; i++) {
    if( X < K )
      X *= 2;
    else
      X += K;
  }
  cout << X << endl;
}

Measured memory_bytes: 256
#abc158c
import sys
a,b=map(int,raw_input().split())
s=[]
for i in range(1100):
 s.append([i,int(i*0.08),int(i*0.1)])
for i in range(1100):
 if s[i][1]==a and s[i][2]==b:
  print s[i][0]
  sys.exit()
print -1


Measured memory_bytes: 3204
// Submitted By Subhash Yadav
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Scanner;

import java.util.*;

public class Main {

	static int h, w;
	static char board[][];

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String first[] = br.readLine().split(" ");
		h = Integer.parseInt(first[0]);
		w = Integer.parseInt(first[1]);

		String strt[] = br.readLine().split(" ");
		int sx = Integer.parseInt(strt[0])-1, sy = Integer.parseInt(strt[1])-1;

		String end[] = br.readLine().split(" ");
		int ex = Integer.parseInt(end[0])-1, ey = Integer.parseInt(end[1])-1;
		board =new char[h][w];
		for (int i = 0; i < h; i++) {
			char c[] = br.readLine().toCharArray();
			for (int j = 0; j < w; j++)
				board[i][j] = c[j];
		}
		br.close();

		ArrayDeque<Integer> ax = new ArrayDeque<>(), ay = new ArrayDeque<>();
		ax.add(sx);
		ay.add(sy);

		int dis[][] = new int[h][w];
		for (int i = 0; i < h; i++)
			Arrays.fill(dis[i], Integer.MAX_VALUE);
		dis[sx][sy] = 0;
		int row[] = { -1, 0, 0,1};
		int col[] = { 0, -1, 1, 0 };

		while (!ax.isEmpty()) {
			int getx = ax.removeFirst(), gety = ay.removeFirst();

			for (int d = 0; d < 4; d++) {
				int newx = getx + row[d], newy = gety + col[d];
				if (!legal(newx, newy))
					continue;

				if (dis[newx][newy] > dis[getx][gety]) {
					dis[newx][newy] = dis[getx][gety];
					ax.addFirst(newx);
					ay.addFirst(newy);
				}

			}
			
			// show the magic
			
			for(int x1=getx-2;x1<=getx+2;x1++) {
				for(int y1=gety-2;y1<=gety+2;y1++) {
					if(!legal(x1, y1)) continue;
					if (dis[x1][y1] > dis[getx][gety]+1) {
						dis[x1][y1] = dis[getx][gety]+1;
						ax.addLast(x1);
						ay.addLast(y1);
					}
					
				}
			}
			

		}

		System.out.println(dis[ex][ey] != Integer.MAX_VALUE ? dis[ex][ey] : -1);

	}

	public static boolean legal(int x, int y) {
		return x >= 0 && x < h && y >= 0 && y < w && board[x][y] == '.';
	}

	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

}

Measured memory_bytes: 63180
A, B, C, D = map(int, input().split())

jumyo_t = A//D
jumyo_a = C//B
if A%D != 0:
    jumyo_t += 1
if C%B != 0:
    jumyo_a += 1

if jumyo_a > jumyo_t:
    print("No")
else:
    print("Yes")




Measured memory_bytes: 9112
#include<bits/stdc++.h>
#define inf 1<<29
#define linf 1e16
#define eps (1e-8)
#define mod 1000000007
#define pi acos(-1)
#define phi (1.0+sqrt(5))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int main()
{
  int a,b;
  cin>>a>>b;
  if(a==1)a+=13;
  if(b==1)b+=13;
  if(a==b)cout<<"Draw"<<endl;
  else if(a<b)cout<<"Bob"<<endl;
  else cout<<"Alice"<<endl;
  return 0;
}



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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

ll calc(ll n) {
  if (n % 2 == 0) {
    return 0;
  }
  ll a = 0;

  for (ll i = 1; i <= n; i++) {
    if (n % i == 0) {
      a += 1;
    }
  }
  return a;
}

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

  ll count = 0;
  for (ll i = 1; i <= N; i++) {
    ll n = calc(i);
    if (n == 8) {
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,i;
    for(i=0;i<50;i++)
    {
        scanf("%d %d %d",&a,&b,&c);
        if(a==-1 && b==-1 && c==-1)
        {
            break;
        }
        else if(a!=-1 && b!=-1)
        {
            if(a+b>=80)
            {
                printf("A\n");
            }
            else if(a+b>=65 && a+b<80)
            {
                printf("B\n");
            }
            else if((a+b>=50 && a+b<65) || c>=50)
            {
                printf("C\n");
            }
            else if(a+b>=30 && a+b<50)
            {
                printf("D\n");
            }
            else if(a+b<30)
            {
                printf("F\n");
            }
        }
    else if(a==-1 || b==-1)
    {
        printf("F\n");
    }
    }
    return 0;
}



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

ll n, m, x, res = 2e18;
vector<ll> c(15);
vector<vector<ll>> a(15, vector<ll>(15));

void dfs(vector<ll> t) {
  if (t.size() == n) {
    ll sum = 0;
    vector<ll> ans(m);
    rep(i, n) {
      if (t[i]) {
        sum += c[i];
        rep(j, m) {
          ans[j] += a[i][j];
        }
      }
    }
    bool f = true;
    rep(i, m) {
      if (ans[i] < x)
        f = false;
    }
    /*
    rep(i, m)
      cout << ans[i] << " ";
    puts(f ? "Yes" : "No");
    cout << endl;
      rep(i, t.size())
        cout << t[i] << " ";
      cout << endl;
      cout << "sum:" << sum << endl;
    */
    if (f)
      res = min(res, sum);
    return;
  }
  rep(i, 2) {
    t.push_back(i);
    dfs(t);
    t.pop_back();
  }
}


int main() {
  cin >> n >> m >> x;
  rep(i, n) {
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }
  dfs(vector<ll>(0));
  if (res == 2e18)
    cout << -1 << endl;
  else cout << res << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <tuple>
#include <functional>
using namespace std;
using S = tuple<int, int, int>;
template <class T>
struct segment_tree{
    using func = function< T(T, T) >;
    int size;
    T ide;
    vector<T> data, sub;
    func f = [](T a, T b){ return ((a<b)?a:b); };
    segment_tree(){}
    segment_tree(int n, T ide){
        init(n, ide);
    }

    void init(int n, T ide){
        size = 1;
        while(size < n) size *= 2;
        this->ide = ide;
        data.assign(size*2, ide);
        sub.assign(size*2, ide);
    }

    // data[x] <- y
    void update(int x, T y){
        x += size;
        data[x] = y;
        while(x > 0){
            x /= 2;
            data[x] = f(data[x*2], data[x*2+1]);
        }
    }

    // return the answer for [x, y]
    T query(int x, int y){
        T res = ide;
        x += size;
        y += size;
        while(x <= y){
            if(x%2 == 1) res = f(res, data[x++]);
            if(y%2 == 0) res = f(res, data[y--]);
            x >>= 1;
            y >>= 1;
        }
        return res;
    }
};

int main(void){
    int n;
    cin >> n;
    vector< int > pos(n+1, 0);
    segment_tree<int> st[2];
    st[0].init(n+1, n+1);
    st[1].init(n+1, n+1);
    for(int i=1;i<=n;i++){
        int p;
        cin >> p;
        st[i%2].update(i, p);
        pos[p] = i;
    }

    vector<int> ans;
    priority_queue<S, vector<S>, greater<S> > q;

    function< void(int, int) > ins = [&](int l, int r){
        int x = st[l%2].query(l, r);
        q.push(S(x, l, r));
    };

    ins(1, n);
    while(!q.empty()){
        S s = q.top();
        q.pop();
        int x = get<0>(s);
        int l = get<1>(s);
        int r = get<2>(s);
        int y = st[r%2].query(pos[x], r);
        ans.push_back(x);
        ans.push_back(y);
        if(l < pos[x]) ins(l, pos[x]-1);
        if(pos[x]+1 < pos[y]) ins(pos[x]+1, pos[y]-1);
        if(pos[y] < r) ins(pos[y]+1, r);
    }

    for(int v: ans) cout << v << " ";
    cout << endl;
}


Measured memory_bytes: 11944
N = input()
n = list(map(int,raw_input().split()))
print(" ".join(list(map(str,n))))
for i in range(1,int(N)):
    v = n[i]
    j = i - 1
    while j >= 0 and v < n[j]:
        n[j+1] = n[j]
        j = j - 1
    n[j+1] = v
    print(" ".join(list(map(str,n))))

Measured memory_bytes: 6440