akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Set;

public class Main {
	public static void main(String args[]) throws IOException {
		FastScanner fs = new FastScanner();
		double  page = fs.nextInt();
		System.out.println((int)Math.ceil(page / 2) );
	}
}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}



Measured memory_bytes: 21204
#include<stdio.h>
int main(void)
{
	int A,B,C;
	scanf("%d %d %d",&A,&B,&C);
	if(A==B&&A!=C) printf("Yes\n");
	else if(A==C&&A!=B) printf("Yes\n");
	else if(B==C&&C!=A) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 1604
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split();
            var stack = new Stack<int>();

            foreach(var elem in input) {
                if(elem == "+") {
                    var val1 = stack.pop();
                    var val2 = stack.pop();
                    stack.push(val1 + val2);
                }
                else if(elem == "-") {
                    var val1 = stack.pop();
                    var val2 = stack.pop();
                    stack.push(val2 - val1);
                }
                else if(elem == "*") {
                    var val1 = stack.pop();
                    var val2 = stack.pop();
                    stack.push(val1 * val2);
                }
                else {
                    stack.push(int.Parse(elem));
                }
            }
            Console.WriteLine(stack.pop());
        }

    }

    class Stack<T>
    {
        private Element<T> top;

        public void push(T data)
        {
            this.top = new Element<T>(this.top, data);
        }

        public T pop()
        {
            var result =  this.top.data;
            this.top = this.top.next;
            return result;
        }

        private class Element<Tdata>
        {
            public Element<Tdata> next;
            public Tdata data;
            public Element(Element<Tdata> next, Tdata data)
            {
                this.next = next;
                this.data = data;
            }
        }
    }
}



Measured memory_bytes: 15988
# 少ないときは総当たりゲーミング

N, C = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(C)]
E = [list(map(int, input().split())) for _ in range(N)]

g = [[0]*C for _ in range(3)]
for y, e in enumerate(E):
    for x, e_i in enumerate(e):
        g[(x+y)%3][e_i-1] += 1
# print(g)

min_cost = 10**18
for c0 in range(C):
    for c1 in range(C):
        for c2 in range(C):
            if len({c0, c1, c2}) < 3:
                continue
            colors = [c0, c1, c2]
            # print(colors)
            cost = 0
            for i, g_i in enumerate(g):
                for j, g_j in enumerate(g_i):
                    # print(i, (j, colors[i]), D[j][colors[i]])
                    cost += D[j][colors[i]]*g_j
            min_cost = min(min_cost, cost)

print(min_cost)

            

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

using namespace std;

typedef long long ll;

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int red = 0;
	int blue = 0;
	for(int i = 0; i < (int)s.size(); i++){
		if(s[i] == 'R')red++;
		else blue++;
	}
	if(red > blue)cout << "Yes" << endl;
	else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> 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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};



int main(){
    LL x;cin >> x;
    vector<P> p;
    for (int i = 0; ; i++) {
        LL t = i;
        for (int j = 0; j < 4; j++) {
            t *= i;
        }
        if(t >= 1e18) break;
        p.pb(mp(t, i));
        p.pb(mp(-t, -i));
    }
    for (int i = 0; i < p.size(); i++) {
        for (int j = 0; j < p.size(); j++) {
            if(p[i].fs - p[j].fs == x){
                cout << p[i].sc << " " << p[j].sc << endl;
                return 0;
            }
        }
    }
    assert(false);
    return 0;
}


Measured memory_bytes: 3756
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define F first
#define S second
#define pi acos(-1)
using ll = long long;
using namespace std;
using namespace __gnu_pbds;
using vl = vector<ll>;
using pll =  pair<ll,ll>;
const ll mod = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


ll power(ll x,ll y){
    ll res = 1;
    while(y){
        if(y&1)
            res = (res*x)%md;
        x = (x*x)%md;
        y = y/2;
    }
    return res;
}

void solve(){
    int n;
    cin>>n;
    vl a(n);

    for(int i=0;i<n;i++)
    	cin>>a[i];
    ll ans=1;
    sort(a.rbegin(),a.rend());
    int num = n - 1;

    for(int i=0;i+1<n;i+=2){
    	//cout<< a[i] << " " << a[i+1] << " " << num<< endl;
    	if(a[i] == num && a[i+1] == num)
    		ans = (ans * 2)%mod;
    	else{
    		cout<<0;
    		return;
    	}
    	num -= 2;
    }

    if (n % 2 == 1&&a[n-1] != 0)
    {
    	cout<<0;
    }
    else
    	cout<<ans;
}
 
int main()
{
    


    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //int n; cin>>n; for (int i = 0; i < n; ++i)
    solve();
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; cin >> n;
    int ans = 0;
    int cnt[10][10] = {};
    FOR(i,1,n+1){
        string s = to_string(i);
        int fi = s.front() - '0';
        int la = s.back() - '0';
        cnt[fi][la]++;
    }
    rep(i,10){
        rep(j,10){
            ans += cnt[i][j] * cnt[j][i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# ABC146 D - Insertion
n=int(input())
s=input()
ss=s
l_cnt=0
r_cnt=0
if s.count('()')>0:
    # ss=ss.replace('()','')
    while ss.count('()')>0:
        ss=ss.replace('()','')
    l_cnt=ss.count('(')
    r_cnt=ss.count(')')
    s+=')'*l_cnt
    s='('*r_cnt+s

    print(s)
else:
    l_cnt=s.count('(')
    r_cnt=s.count(')')
    s+=')'*l_cnt
    s='('*r_cnt+s
    print(s)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;
ll mod = 1e9 + 7;

ll pow(ll a,ll b){
    if(b == 0)
        return 1;
    ll res = pow(a * a % mod, b / 2);
    if(b&1)
        res = res * a % mod;
    return res;
}

int main(){
    ll N,a,b;
    cin >> N >> a >> b;
    ll ans = pow(2, N) - 1;
    ll c = 1, d = 1;
    for (int i = 0; i < a;i++){
        c = c * (N - i) % mod;
        d = d * (i + 1) % mod;
    }
    ans -= c * pow(d, 1e9 + 5) % mod;
    c = 1, d = 1;
    for (int i = 0; i < b;i++){
        c = c * (N - i) % mod;
        d = d * (i + 1) % mod;
    }
    ans -= c * pow(d, 1e9 + 5) % mod;
    while(ans < 0)
        ans += mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}





    
void test_case() {

        double d, t , s;
        cin>>d>>t>>s;

        double temp = d/s;

        if( temp <= t) {
            yes;
        } else {
            no;
        }
        


}


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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);


    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}

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

typedef long long ll;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x){return fabs(x-(int)round(x))<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll x){stringstream ss;ss<<x;return ss.str();}
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)

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

  while (cin >> s) {
    int cnt = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'o') {
        cnt++;
      }
    }
    cout << 700 + cnt * 100 << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <climits>

using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    vector<int> times;
    REP(i, 5) {
        int a;
        cin >> a;
        times.push_back(a);
    }
    
    ll m = 123ll*123ll*123ll*123ll*123ll;
    do {
        ll n = 0;
        REP(i, 5) {
            n += times[i];
            if (i != 4 && n%10>0) n = (n/10+1)*10;
        }
        m = min(m, n);
    } while (std::next_permutation(times.begin(), times.end()));
    cout << m << endl;
}


Measured memory_bytes: 256
N,K = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
idx = x.index(1)
l,r = idx,idx
ans = 0
while l > 0
  l -= K-1
  ans += 1
end
r += l.abs if l < 0
while r < N-1
  r += K-1
  ans += 1
end
p ans


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

using int64 = long long;
using uint64 = unsigned long long;

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

    int N, A, B;
    std::cin >> N >> A >> B;

    int64 ans = 0;

    std::vector<int64> X(N);
    for (int i = 0; i < N; i++) {
        std::cin >> X[i];

        if (i > 0) {
            ans += std::min(A * (X[i] - X[i - 1]), (int64)B);
        }
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 1024
#abc096d

P = [11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381]
print " ".join(map(str, P[:input()]))


Measured memory_bytes: 2692
import fractions
n,m=map(int,input().split())
s=str(input())
t=str(input())
f=fractions.gcd(n,m)
f2=n*m//f
#print(f2)
for i in range(f2,n*m+1,f2):
    z2=(i//n)*(i//m)//fractions.gcd(i//n,i//m)
    for j in range(1,i+1,z2):
        #print(i,j)
        if s[-(-j//(i//n))-1]!=t[-(-j//(i//m))-1]:
            break
    else:
        print(i)
        break
else:
    print(-1)

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

int main(){

    int N;
    cin>>N;
    vector<int> X(N),Y(N),H(N);
    for(int i=0;i<N;i++){
        cin>>X.at(i)>>Y.at(i)>>H.at(i);
    }
    bool check=false;
    for(int x=0;x<=100;x++){
        for(int y=0;y<=100;y++){
            for(int h=max(H.at(0)-200,1);h<=H.at(0)+200;h++){
                bool ans=true;
                for(int i=0;i<N;i++){
                    if(!(max(h-abs(x-X.at(i))-abs(y-Y.at(i)),0)==H.at(i))) ans=false;
                }
                if(ans){cout<<x<<" "<<y<<" "<<h<<endl;
                    check=true;
                    break;
                }
            }
            if(check) break;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

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

  int ans = 0;
  if (a * c <= b) {
    ans = c;
  }
  else {
    ans = b / a;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define int                      long long
#define MOD                     1000000007
#define inf                     9e18
#define ld                      long double
#define countbit                __builtin_popcount
#define loop(i,a,n)				for(int i=a;i<n;i++)
#define pb                      push_back
#define pf                      push_front
#define mp                      make_pair
#define f                       first
#define s                       second
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define boost                   ios_base::sync_with_stdio();cin.tie(0);cout.tie(0);
#define cases                   int tests;cin>>tests;while(tests--)
#define all(s)                  s.begin(),s.end()
#define line                    cout<<endl;
#define watch(x)                cout<<(#x)<<" is "<<x<<endl
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rich_set;
bool isprime(int n){if(n==1)return false;if(n==2)return true;for(int i=2;i<=sqrt(n);i++){if(n%i==0){ return false;}}return true;}
int poww(int b,int e){if(e==0)return 1;else if(e%2==0){int a=pow(b,e/2);return a*a;}else {int a=pow(b,e/2);return b*a*a;}}
int powm(int x,int y,int m=MOD){x=x%m;int res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
int modInverse(int a, int m=MOD) { return powm(a, m-2, m);}
void print(vector<int>v){for(int i=0;i<v.size();i++){cout<<v[i]<<" ";}}
void print(int arr[]){int size = *(&arr + 1) - arr; for(int i=0;i<size;i++){cout<<arr[i]<<" ";}}
string to_bin(int n){string res="";int i=0;while(n>0){if(n%2==1){res=res+'1';}else{res=res+'0';}n/=2;i++;}reverse(all(res));return res;}
int to_dec(string s){int n=s.size(),ans=0,temp=1;for(int i=n-1; i>=0; i--){int x=s[i]-'0';ans+=x*temp;temp*=2;}return ans;}
void result(bool f){if(f)cout<<"YES"<<endl;else cout<<"NO"<<endl;}
 
 
 
void solve(){
	int n;
    cin>>n;
    int w;
    cin>>w;
    int wt[n+1];
    int val[n+1];
    loop(i,0,n){
        cin>>wt[i]>>val[i];
    }
    int dp[n+1][w+1];
    loop(i,0,n+1){
        loop(j,0,w+1){
            if(i==0 || j==0)dp[i][j]=0;
            else if(wt[i-1]<=j){
                dp[i][j]= max(dp[i-1][j], val[i-1] + dp[i-1][j-wt[i-1]]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][w];line
 
}
int32_t main(){
	boost
  //cases
	solve();	
	
	//return 0;
}

Measured memory_bytes: 79104
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;

    int dx = tx-sx;
    int dy = ty-sy;

    cout << "L";
    REP(i,dy+1){
        cout << "U";
    }
    REP(i,dx+1){
        cout << "R";
    }
    cout<<"D";

    REP(i,dx){
        cout << "L";
    }
    REP(i,dy){
        cout << "D";
    }

    cout<<"D";
    REP(i,dx+1){
        cout << "R";
    }
    REP(i,dy+1){
        cout << "U";
    }
    cout<<"L";

    REP(i,dy){
        cout << "D";
    }
    REP(i,dx){
        cout << "L";
    }




    cout<<endl; 

	return;
}

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

Measured memory_bytes: 256
#![allow(unused_imports)]

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

use std::{i32, i64, u32, u64, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};

fn main() {
    input! {
        n: usize,
        p: i64,
        arr: [i64; n],
    }
    let o = arr.iter().filter(|&a| a % 2 == 1).count();
    if o == 0 { println!("{}", (1 - p) << n); }
    else { println!("{}", 1u64 << (n - 1)); }
}


Measured memory_bytes: 4352
#include <stdio.h>
int main (){
  char s[5];
  int k=0;
scanf ("%s",s);
if (s[0]==s[1] && s[2]==s[3]){
k++;
}
  else if (s[0]==s[2] && s[1]==s[3]){
  k++;
  }
  else if (s[0]==s[3] && s[1]==s[2]){
  k++;
  }
  if (s[0]==s[1] && s[0]==s[2] && s[0]==s[3]){
  k=0;
  }
  if (k>0){
  printf ("Yes");
  }
 else {
 printf ("No");
 }
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    // 魔法をi回
    // j番目はmin(a[j-i+1], …, a[j-1], a[j])かかる
    vector<vector<ll>> mi(n, vector<ll>(n, INF));
    REP(i, n) mi[0][i] = a[i];
    FOR(i, 1, n) {
        REP(j, n) {
            // [j-i, j] = [j-i+1, j] + [j-i]
            mi[i][j] = min(mi[i-1][j], a[(j-i+n)%n]);
        }
    }

    ll ans = INF;
    REP(i, n) {
        ll val = i*k;
        REP(j, n) val += mi[i][j];
        chmin(ans, val);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 31616
primes :: Integral a => [a]
primes = map fromIntegral $ [2, 3] ++ primes'
  where
    -- primes' :: Integral a => [a]
    primes' = [5] ++ f 1 7 primes'
    -- f :: Integral a => a -> a -> [a] -> [a]
    f m s (p:ps) = [n | n <- ns , gcd m n == 1] ++ f (m * p) (p * p) ps
      where
        ns = [x + y | x <- [s, s + 6 .. p * p - 2], y <- [0, 4]]

main :: IO ()
main = do
  n <- readLn :: IO Int
  print $ head $ filter (n <= ) primes

Measured memory_bytes: 5684
//xtwakioi! xtwddYnoi(双重含义)!
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=1000010, Mod=1e9+7;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int S,dp[N];
signed main()
{
    S=read();
    if(S<3) puts("0");
    else if(S==3) puts("1");
    else
    {
        dp[3]=dp[4]=dp[5]=1, dp[6]=2;
        for(ri int i=7;i<=S;i++)
        {
            dp[i]=1;
            for(ri int k=3;k+3<=i;k++)
            (dp[i]+=dp[k])%=Mod;
        }
        printf("%lld\n",dp[S]);
    }
    return 0;
}

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

int main() {
  int n;
  cin >> n;

  int ans = 0;
  for (int i = 1; i <= n; i = i+2) {
    int cnt = 0;
    for (int j = 1; j <= i; j++) {
      // 奇数 i について 1〜i までの数字で剰余を求める
      // 割り切れたら約数なのでインクリメント
      if (i % j == 0) { cnt++; }
    }
    if (cnt == 8) { ans++; }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

int main() {
    int N; cin >> N;
    vector<int> b(N + 1);
    repp(i, 1, N) cin >> b[i];
    vector<int> order(N + 1, -1);
    for(int i = N; i > 0; --i) {
        int idx = 0, cnt = 1;
        while(cnt <= b[i] && idx <= N) {
            if(order[idx++] == -1) ++cnt;
        }
        if(idx > N) {
            cout << "-1\n";
            return 0;
        }
        order[idx - 1] = b[i];
    }
    rep(i, N) cout << order[i] << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define 	pb	push_back 
#define 	ff	first 
#define 	ss	second 
using namespace std;
typedef long long ll;
inline void debug() {
	#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin); 
	freopen("output.txt", "w", stdout);
	#endif
	}
ll const u_bound=4*(1e7)+7LL;
int main(){
	ll n,m,k;
	cin>>n>>m>>k;
	
	ll arr1[n+1]={0};	ll arr2[m+1]={0};
	ll ind=0;
	for(int i=1;i<=n;i++){
		cin>>arr1[i];
		arr1[i]+=arr1[i-1];
		if(arr1[i]<=k)
			ind=i;
	}
	
	for(int i=1;i<=m;i++){
		cin>>arr2[i];
		arr2[i]+=arr2[i-1];
	}
	ll ans=0;
	ll j=0;
	ll i=ind;
	while(i>=0&&j<=m){
		if(arr1[i]+arr2[j]>k){
			i--;
		}else{
		ans=max(ans,i+j);
		j++;
		}
	}
		
	cout<<ans;
}


Measured memory_bytes: 6768
#include <bits/stdc++.h>
#define ull unsigned long long
using namespace std;
ull jc[46], n, i, k;
multiset<ull> v;
void init()
{
	jc[0] = 1;
	for (int i = 1; i < 46; i ++) jc[i] = jc[i - 1] * 2;
}
int main() 
{
	init();
	cin >> n;
	ull ans = 0;
	for (i = 0; i < n; i ++) cin >> k, v.insert(k);
	multiset<ull>::iterator iter;
	while (!v.empty())
	{
		iter = v.end();
		iter --;
		ull sum = *iter;
		v.erase(iter);
		for (i = 0; jc[i] <= sum; i ++);
		if (v.find(jc[i] - sum) != v.end())
		{
			ans ++;
			v.erase(v.find(jc[i] - sum));
		}
	}
	cout << ans << endl;
}

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

int main() {
  int A, B;
  cin >> A >> B;

  if (A <= 5) {
    cout << 0 << endl;
  } else if (6 <= A && A <= 12) {
    cout << B / 2 << endl;
  } else {
    cout << B << endl;
  }

  return 0;
}


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

int main()
{
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;

	int x = 0, y = 0;
	for (int i = 0; i < n; i++) {
		if (x * a < n)
			x++;
		if (y * c < n)
			y++;
	}

	cout << ((x * b < y * d) ? x * b : y * d) << endl;

	return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<cstdlib>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int maxn=1e5+5;
int n,k;
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll maxx=0;
    ll a1=a*c;
    ll b1=a*d;
    ll c1=b*c;
    ll d1=b*d;
    cout<<max(max(a1,b1),max(c1,d1))<<endl;
	system("pause");
    return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define pb push_back
#define LL long long
#define x first
#define y second
#define pii pair<int,int>
#define mp make_pair
#define MEM(x) memset(x,0,sizeof(x))
#define pi acos(-1)
using namespace std;
int mod=1e9+7;	
LL f_pow(LL a,LL b){
	LL res=1,temp=a;
	while(b){
		if(b&1)res=res*temp%mod;
		temp=temp*temp%mod;
		b>>=1;
	}
	return res;
}
int main(){
	int n;
	scanf("%d",&n);
	int a[500005];
	int tot=0;
	for(int i = 0;i<n;i++){
		scanf("%d",&a[i]);
		tot^=a[i];
	}
	int cnt=0;
	int now=0;
	map<int,int> m;
	//v.pb(map<int,int>());
	int lev=0;
	map<int,vector<pii> > ans;
	for(int i = 0;i<n;i++){
		now^=a[i];
		m[now]++;
		if(now==tot){
			cnt++;
			now=0;
			lev++;
			//v.pb(map<int,int>());
			for(auto it:m){
				if(it.x==0)
				continue;
				ans[it.x].pb(mp(it.y,lev));
			}
			m.clear();
		}
	}
//	printf("%lld\n",tot);
	if(tot==0){
		LL myans=0;

		for(auto it:ans){
			LL lastlev = 0;
			LL last=0;
			LL sum = 0;
			for(auto p :it.y){
				sum+=(p.y-lastlev-1)*last%mod;
				sum%=mod;
				last = ((sum+1)*p.x%mod + last)%mod;
				lastlev = p.y;
				sum+=last;
			}
			sum--;
			myans+=last;
		}
		//assert(0);
		printf("%lld\n",((f_pow(2,cnt-1)+myans)%mod+mod)%mod);
	}
	else{
		/*LL temp[500005];
		temp[0]=1;
		LL odd=0,even=1;
		for(int i =1;i<=cnt;i++){
			if(i&1){
				temp[i]=even;
				odd+=temp[i];
				odd%=mod;
			}
			else{
				temp[i]=odd;
				even+=temp[i];
				even%=mod;
			}
		}*/
		LL odd=0,even=1;
		vector<int> v;
		int now = 0;
		for(int i = 0;i<n;i++){
			now^=a[i];
			if(now==0){
				v.pb(0);
				even+=odd;
				even%=mod;
			}
			if(now==tot){
				v.pb(1);
				odd+=even;
				odd%=mod;
			}
			//printf("%lld %lld\n",odd,even);
		}
		printf("%lld\n",even);
	}
	return 0;
}
/*
n = x*m+x=x*(m+1);



*/

Measured memory_bytes: 43008
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back
const ll mod = 1000000007;
// const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void sayNo() {
	cout << "NO" << endl;
}

void sayYes() {
	cout << "YES" << endl;
}


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

	ll len = S.size();

	vi rem(len);
	ll m = 1;
	for (ll i = len - 1; i >= 0; i--) {
		rem[i] = m;
		m *= 10;
		m %= 13;
	}
	/*
	for (auto r : rem) {
		cout << r << ", ";
	}
	cout << endl;
	*/

	m = 0;
	vvi dp(len + 1, vi(13, 0));
	dp[0][0] = 1;
	for (ll i = 0; i < len; i++) {
		if (S[i] == '?') {
			for (ll j = 0; j < 13; j++) {
				for (ll k = 0; k < 10; k++) {
					dp[i + 1][(j + k * rem[i]) % 13] += dp[i][j];
					dp[i + 1][(j + k * rem[i]) % 13] %= mod;
				}
			}
		}
		else {
			ll num = S[i] - '0';

			for (ll j = 0; j < 13; j++) {
				dp[i + 1][(j + num * rem[i]) % 13] = dp[i][j];
			}
		}
	}
	/*
	for (auto a : dp[len]) {
		cout << a << ", ";
	}
	cout << endl;
	*/

	cout << dp[len][5] << endl;

	return 0;
}

Measured memory_bytes: 14464
#include <stdio.h>

int main(void) {
	int n; scanf("%d",&n);
	int ary[n+1]; for(int i=1; i<=n; i++) scanf("%d",&ary[i]);
	int bry[n+1]; for(int i=1; i<=n; i++) scanf("%d",&bry[i]);
	int cry[n+1]; for(int i=1; i<=n; i++) scanf("%d",&cry[i]);
	int ex_dish = n;
	int satis = 0;
	for(int i=1; i<=n; i++) {
		satis += bry[ary[i]];
		if (ary[i] - 1 == ex_dish) {
			satis += cry[ex_dish];
		}
		ex_dish = ary[i];
	}
	printf("%d",satis);
	
	return 0;
}


Measured memory_bytes: 128
N=int(input())
P=[(0,0) for i in range(N)]
for i in range(N):
    x,l=map(int,input().split())
    P[i]=(x-l,x+l)
P.sort(key=lambda y:y[1])
#print(P)
ans=1
t=P[0][1]
for i in range(1,N):
    if t<=P[i][0]:
        ans+=1
        t=P[i][1]
print(ans)


Measured memory_bytes: 18260
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<stack>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
#define MAX 510000
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
using namespace std;


int main(){
  ll N,A,B;
  cin>>N>>A>>B;
  ll T=N/(A+B);
  cout<<T*A+min(A,N-(A+B)*T)<<endl;
}

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

using namespace std;

int main() {
	int64_t N, K;
	set<int64_t> visited;
	
	cin >> N >> K;
	
	int64_t value = N % K;
	while(visited.find(value) == visited.end()) {
		visited.insert(value);
		value = abs(value - K);	
	}
	
	cout << *visited.begin() << endl;
}

Measured memory_bytes: 256
# 入力
H,W=map(int,input().split())

# 最上段
l=['#'*(W+2)]

for i in range(H):
  s=input()
  l.append('#'+s+'#')

# 最下段
l.append('#'*(W+2))

# 出力
for x in l:
  print(x)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

typedef long long ll;

using namespace std;


int main(){
    int num[200][3],n,sum;
    int a[101][3]={0};
    
    scanf("%d",&n);
    
    for(int i=0;i<n;i++)
        for(int j=0;j<3;j++)
            scanf("%d",&num[i][j]);
    
    for(int i=0;i<3;i++)
        for(int j=0;j<n;j++)
            a[num[j][i]][i]++;
    
    for(int i=0;i<n;i++){
        sum=0;
        for(int j=0;j<3;j++)
            if(a[num[i][j]][j]<2)sum+=num[i][j];
        printf("%d\n",sum);
    }
    
    return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const ll MOD = 1e9+7;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int n, l;
    cin >> n >> l;

    int sum = n * (l + (l+n-1)) / 2;

    if (l <= 0 && l+n-1 >= 0) {
        std::cout << sum << '\n';
    } else {
        if (abs(l) < abs(l+n-1)) {
            std::cout << sum - l << '\n';
        } else {
            std::cout << sum - (l+n-1) << '\n';
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
     
int main(){
  int N;
  std::cin >> N;
  int x0=0,x1,y0=0,y1,t0=0,t1;
  for(int i=0;i<N;i++){
    std::cin >> t1 >> x1 >> y1;
    int sum=x0-x1+y0-y1;
    if(t1-t0<abs(sum)){
      std::cout << "No" <<std::endl;
      return 0;
    }

    if((t1-t0)%2!=abs(sum)%2){
      std::cout << "No" <<std::endl;
      return 0;
    }
  }
      std::cout << "Yes" <<std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

struct edge { int to; int cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int n,m,s,t;
vector<int> g[300010];
int d[300010];

int main() {
	cin >> n >> m;
	rep(i,m){
		int u,v;
		cin >> u >> v;
		g[u*3].push_back(v*3+1);
		g[u*3+1].push_back(v*3+2);
		g[u*3+2].push_back(v*3);
	}
	cin >> s >> t;
	for(int i = 0; i < 300010; i++) d[i] = INF; d[s*3] = 0;
	queue<int> que; que.push(s*3);
	while(que.size()){
		int p = que.front(); que.pop();
		for(auto a : g[p]){
			if(d[p]+1 < d[a]){
				d[a] = d[p]+1;
				que.push(a);
			}
		}
	}
	if(d[t*3] != INF){
		cout << d[t*3]/3 << endl;
	}else{
		cout << -1 << endl;
	}
	return 0;
}

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


# 約数の計算
def count_yakusuu(n):
    c = 0
    for j in range(1, n+1):
        if n % j == 0:
            #print("n % j ==0", n, j)
            c += 1
    return c


cnt = 0
for i in range(1,N+1,2):
    c = count_yakusuu(i)
    #print("i,c:",i,c)
    if count_yakusuu(i) == 8:
        #print(i, "is 8")
        cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7;
char s[N][5];
int main(){
    int n,a,b,c;
    cin>>n>>a>>b>>c;
    for(int i=1;i<=n;i++)    scanf("%s",s[i]+1); 
    string ans="";
    
    for(int i=1;i<=n;i++){
        if(s[i][1]=='A'&&s[i][2]=='B'){
            if(a>b){
                a--;b++;
                ans+='B';
            }
            else if(a<b){
                a++;b--;
                ans+='A'; 
            }
            else {
                if(s[i+1][1]=='A'){
                    a++;b--;
                    ans+='A';
                }
                else{
                    a--;b++;
                    ans+='B';
                }
            }
        }
        else if(s[i][1]=='A'&&s[i][2]=='C'){
            if(a>c){
                a--;c++;
                ans+='C';
            }
            else if(a<c){
                a++;c--;
                ans+='A'; 
            }
            else {
                if(s[i+1][1]=='A'){
                    a++;c--;
                    ans+='A';
                }
                else{
                    a--;c++;
                    ans+='C';
                }
            }
        }
        else {
            if(b>c){
                b--;c++;
                ans+='C';
            }
            else if(b<c){
                b++;c--;
                ans+='B'; 
            }
            else {
                if(s[i+1][2]=='C'){
                    b--;c++;
                    ans+='C';
                }
                else{
                    b++;c--;
                    ans+='B';
                }
            }
        } 
        if(a<0||b<0||c<0) return cout<<"No"<<endl,0;
    }
    puts("Yes");
    int t=ans.size();
    for(int i=0;i<t;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 4320
using System;

public class ALDS1_1_D{
    public static void Main(){
        var n = int.Parse(Console.ReadLine());
        var tmp_min = int.Parse(Console.ReadLine());
        
        var profit = -1000000001;
        n--;
        
        for (var i = 0; i < n; i++)
        {
            var R_i = int.Parse(Console.ReadLine());
            
            if (R_i - tmp_min > profit)
            {
                profit = R_i - tmp_min;
            }
            
            if (R_i < tmp_min)
            {
                tmp_min = R_i;
            }
        }
        
        Console.WriteLine(profit);
    }
}


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

const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int dx2[20] = {0,0,1,1,1,1,-1,-1,-1,-1,2,2,2,2,2,-2,-2,-2,-2,-2};
const int dy2[20] = {2,-2,1,2,-1,-2,1,2,-1,-2,0,1,2,-1,-2,0,1,2,-1,-2};
const int INF = 1000000;

int main(){
  int h,w;
  cin >> h >> w;
  int maze[h][w];
  // 魔法使い
  int x_mgc,y_mgc;
  cin >> x_mgc >> y_mgc;
  x_mgc--; y_mgc--;
  // ゴール
  int x_gl,y_gl;
  cin >> x_gl >> y_gl;
  x_gl--; y_gl--;
  rep(i,0,h){
    string s;
    cin >> s;
    rep(j,0,w){
      if(s[j]=='.') maze[i][j] = INF;
      else maze[i][j] = -1;
    }
  }
  queue<P> que;
  queue<P> que2;
  P s = make_pair(x_mgc,y_mgc);
  que.push(s);
  maze[x_mgc][y_mgc] = 0;
  int wp = 0;
  int end = 0;
  while(1){
    while(!que.empty()){
      P z = que.front();
      que2.push(z);
      que.pop();
      int x = z.first;
      int y = z.second;
      rep(i,0,4){
        if(x+dx[i]>=0&&y+dy[i]>=0&&x+dx[i]<h&&y+dy[i]<w){
          if(maze[x+dx[i]][y+dy[i]]==INF){
            maze[x+dx[i]][y+dy[i]] = maze[x][y];
            if(x+dx[i]==x_gl&&y+dy[i]==y_gl){
              end = 1;
              break;
            }
            que.push(make_pair(x+dx[i],y+dy[i]));
          }
        }
      }
      if(end) break;
    }
    int flag = 0;
    while(!que2.empty()){
      P z = que2.front();
      que2.pop();
      int x = z.first;
      int y = z.second;
      rep(i,0,20){
        if(x+dx2[i]>=0&&y+dy2[i]>=0&&x+dx2[i]<h&&y+dy2[i]<w){
          if(maze[x+dx2[i]][y+dy2[i]]==INF){
            if(flag==0){
              flag = 1;
              wp++;
            }
            maze[x+dx2[i]][y+dy2[i]] = wp;
            if(x+dx2[i]==x_gl&&y+dy2[i]==y_gl){
              end = 1;
              break;
            }
            que.push(make_pair(x+dx2[i],y+dy2[i]));
          }
        }
      }
    }
    if(flag==0){
      end = 1;
      break;
    }
    if(end) break;
  }

  if(maze[x_gl][y_gl]==INF) cout << -1 << endl;
  else cout << maze[x_gl][y_gl] << endl;

  return 0;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

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

	fx(T.size()) {
		if (T[x]!='?') {
			continue;
		}
		if (x == 0) {
			if (T[1]=='D'||T[1]=='?') {
				T[0] = 'P';
			}
			else {
				T[0] = 'D';
			}
		}
		else if (x==T.size()-1) {
			T[x] = 'D';
		}
		else {
			if (T[x-1]=='P') {
				T[x] = 'D';
			}
			else if (T[x+1]=='D' || T[1] == '?') {
				T[x] = 'P';
			}
			else {
				T[x] = 'D';
			}
		}
	}
	ce(T)
    return 0;
}



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

#define FOR(i, j, k) for(int i=j ; i<k ; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

    int N; cin >> N;
    int ans = 0;

    REP(i, N + 1) {
        if (i%2 == 0) continue;
        int x = 0;
        REP(j, i + 1) {
            if (j%2 == 0) continue;
            if (i % j == 0) x++;
        }
        if (x == 8)  ans++;

    }

    cout << ans << endl;

    return 0;
}


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

int a[5];

int main(){
	scanf("%d%d%d",&a[1],&a[2],&a[3]);
	sort(a+1,a+4);
	if(a[1]==a[3]) printf("No\n");
	else if(a[1] == a[2] || a[2] == a[3]) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
price = 0
c = 0
b = 0
a = 0

def sum_price(a, b, c):
    return a*500 + b*100 + c*50

while c <= C:
    if sum_price(a, b, c) == X:
        cnt += 1
        break
    while b <= B:
        if sum_price(a, b, c) == X:
            cnt += 1
            break
        while a <= A:
            if sum_price(a, b, c) == X:
                cnt += 1
                break
            a += 1
        a = 0
        b += 1
    b = 0
    c += 1

print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <deque>
 
using namespace std;
using ll = long long;
 
void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << endl; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }
 
#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)
 
constexpr int MOD = 1e9+7;

constexpr int COMB_MAX = 510000;
ll fac[COMB_MAX], finv[COMB_MAX], inv[COMB_MAX];

void initComb(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COMB_MAX; 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] * finv[n - k] % MOD) % MOD;
}

int main(void){
    initComb();
    Cin(int, n, m);
    ll ans = 0;
    for(int s = 1, sign = 1; s <= n; s ++, sign *= -1){
        ans = (ans + sign * comb(n, s) * comb(m-s, n-s) % MOD * fac[n-s] % MOD) % MOD;
    }
    ans = (comb(m, n) * fac[n] % MOD + MOD - ans) % MOD;
    Cout(ans * comb(m, n) % MOD * fac[n] % MOD);
}



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

int main() {

    int N,M;
    cin >> N >> M;
    
    int sum = 0;
    int x;
    
    rep (i,M) {
        cin >> x;
        sum += x;
    }
    
    if (N - sum <= 0) {
        cout << "Yes" << endl;
    }
    
    else {cout << "No" << endl;
         }
    
}


Measured memory_bytes: 256