akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
template <char d = ' ', class T>
ostream& operator << (ostream& out, vector<T>& v){ for(auto& e : v){ out << e << d; } return out; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int ans = M;
    ans = min(ans, a * x + b * y);
    prints(ans);
    ans = min(ans, 2 * c * max(x, y));
    prints(ans);
    ans = min(ans, a * max(0, x - y) + 2 * c * y);
    prints(ans);
    ans = min(ans, b * max(0, y - x) + 2 * c * x);
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include<cstdio>
#include<set>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN=500005;

int N,K,A[MAXN];
int pos[MAXN];
vector<int> adj[MAXN];
set<int> L,R; //L存储pos上，比当前数小，绝对值差<K的下标；R存储比当前数大的下标
priority_queue<int,vector<int>,greater<int> > Q;
vector<int> stk;
int pri[MAXN];
int deg[MAXN];

int main()
{
    scanf("%d%d",&N,&K);
    for(int i=1;i<=N;i++)
        scanf("%d",&A[i]),pos[A[i]]=i;
    for(int i=1;i<=K;i++)
        R.insert(A[i]);
    set<int>::iterator x,y;
    for(int i=1;i<=N;i++)
    {
        x=L.upper_bound(A[i]);
        y=R.upper_bound(A[i]);
        if(x!=L.end())
        {
            adj[i].push_back(pos[*x]);
            deg[pos[*x]]++;
        }
        if(y!=R.end())
        {
            adj[i].push_back(pos[*y]);
            deg[pos[*y]]++;
        }
        L.insert(A[i]);
        if(i-K+1>0)
            L.erase(A[i-K+1]);
        if(i+K<=N)
            R.insert(A[i+K]);
        R.erase(A[i]);
    }

    for(int i=1;i<=N;i++)
        if(deg[i]==0)
            Q.push(i);
    while(!Q.empty())
    {
        int u=Q.top();
        Q.pop();
        stk.push_back(u);
        for(int i=0;i<(int)adj[u].size();i++)
        {
            deg[adj[u][i]]--;
            if(deg[adj[u][i]]==0)
                Q.push(adj[u][i]);
        }
    }
    for(int i=0;i<N;i++)
        pri[stk[i]]=i+1;
    for(int i=1;i<=N;i++)
        printf("%d\n",pri[i]);

    return 0;
}


Measured memory_bytes: 64240
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;

signed main(){
char c;
cin>>c;
if(c=='A')cout<<"T"<<endl;
if(c=='T')cout<<"A"<<endl;
if(c=='G')cout<<"C"<<endl;
if(c=='C')cout<<"G"<<endl;
}

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


public class Main {
	
	public static void main(String[] args)throws IOException{
	
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] intAry = new int[51];
		
		for (int i = 0; i <= 9; i++) {
			for (int j = 0; j <= 9; j++) {
				for (int k = 0; k <= 9; k++) {
					for(int l = 0; l <= 9; l++){
						intAry[i+j+k+l]++;
					}
				}
			}
		}
		
		String input;
		while((input = br.readLine()) != null){
			System.out.println(intAry[Integer.parseInt(input)]);
		}
	}
}

Measured memory_bytes: 17056
//Abhishek Bansal
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)
#define TR(v,it) for( LET(it,v.begin()) ; it != v.end() ; it++)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define si(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define all(a) a.begin(),a.end()
#define bitcount(n) __builtin_popcount(n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

//#define TRACE

using namespace std;
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
typedef long long int lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< ii > vii;
lli modpow(lli a,lli n,lli temp){lli res=1,y=a;while(n>0){if(n&1)res=(res*y)%temp;y=(y*y)%temp;n/=2;}return res%temp;}
//***********************************END OF TEMPLATE*********************************************************************
int A[100003];
int main(){
	int N,x;si(N);si(x);
	lli ans = 0;
	for(int i=0;i<N;++i) si(A[i]);
	for(int i=0;i<N-1;++i){
		if(A[i]+A[i+1]<=x) continue;
		ans+=A[i]+A[i+1]-x;
		A[i+1] = max(0,x-A[i]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

int main(void) {

	int n, k, l[50], num = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> l[i];
	}

	sort(l, l + n, greater<int>());

	for (int i = 0; i < k ;i++)
	{
		num += l[i];
	}

	cout << num << "\n";

	return 0;
}

Measured memory_bytes: 256
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    ll n;
    ll k;
    ll ans =0;
    cin >> n >> k;
    REP(i,n){
        ll tmp;
        cin >> tmp;
        if(tmp >= k){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int x, n;
    cin >> x >> n;
    int p[105] = {0}, a;
    for(int i = 0; i < n; ++i) {
        cin >> a;
        p[a] = 1;
    }
    if(p[x] == 0) {
        cout << x << '\n';
        return 0; 
    }
    int i = 1;
    while(1) {
        if(p[x-i] == 0) {
            cout << x-i << '\n';
            return 0; 
        } else if(p[x+i] == 0) {
            cout << x+i << '\n';
            return 0; 
        }
        i++;
    }
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
long long combi(int n,int k){
    k = min(k,n-k);
    long long p = 1;
    for(int i = n;i>=n-k+1;i--){
        p*=i;
        p%=MOD;
    }
    for(int i = 0;i<k;i++){
        p*=modinv(i+1,MOD);
        p%=MOD;
    }
    return p;
}
int main(){
    long long n,k;
    cin >> n >> k;
    long long ans[k];
    long long tmp,tmp2;
    for(int i = 1;i<=k;i++){
        tmp = combi(k-1,i-1);
        tmp%=MOD;
        //cout << tmp << endl;
        if(n-k+1>=i) tmp2=combi(n-k+1,i);
        else tmp2 = 0;
        //cout << tmp2 << endl;
        tmp2%=MOD;
        tmp*=tmp2;
        tmp%=MOD;
        ans[i-1] = tmp;
        if(ans[i-1]<0) ans[i-1]+=MOD;
    }
    rep(i,k){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main (){
	int n;
	scanf ("%d", &n);
	char str[n + 1]; // untk null terminator
	scanf ("%s", str);
	
	if (n % 2 == 1){
		puts ("No");
	}	
		
	else {
		int half = 1;
		// 1 == benar
		// 0 == salah
		for (int i = 0; i < n / 2; i++){
			if (str[i] != str[i + n / 2]){
				half = 0;
			}
		}
		if (half){
			puts ("Yes");
		}
		else {
			puts ("No");
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 1660
fun main(args: Array<String>) {
    val (_, k) = readLine()!!.split(" ").map { it.toInt() }
    val aa = readLine()!!.split(" ").map { it.toInt() }
    val sum = mutableListOf(0)
    for (a in aa) {
        sum.add((sum.last() + a - 1) % k)
    }
    var indices = mutableMapOf<Int, MutableList<Int>>()
    for (i in 0 until sum.size) {
        if (!indices.containsKey(sum[i])) {
            indices[sum[i]] = mutableListOf()
        }
        indices[sum[i]]!!.add(i)
    }
    var ret = 0L
    for (l in indices.values) {
        var s = 0
        var e = 0
        while (s < l.size) {
            while (e < l.size) {
                if (l[e] - l[s] >= k) {
                    break
                }
                e += 1
            }
            ret += e - s - 1
            s += 1
        }
    }
    println(ret)
}


Measured memory_bytes: 85760
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>
#include <cctype>
#include <ctype.h>
#include <ios>
#include <iomanip>

#define INF 200000000
#define MOD 1000000007

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a == b)
        cout << a + b << endl;
    else
        cout << max(a, b) + max(a, b) - 1 << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 0
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 110
#define MAX_T 40010
#define MAX_V 110

ll N;
ll T[MAX_N] = {};
ll V[MAX_N] = {};
ll Limit[MAX_T] = {};   // i 秒での限界速度
ll EndTime = 0;
double dp[MAX_T][MAX_V];

// i 秒時点で、現在の速度が j m/s のときの最大値
double dfs(int i = 0, int j = 0) {
    if(EndTime <= i) {
        if(j != 0) { dp[i][j] = -DINF; }
        else { dp[i][j] = 0; }
        return dp[i][j];
    }

    double& res = dp[i][j];
    if(res != DINF) { return res; }
    res = -DINF;

    if(j > Limit[i]) {
        // 条件違反
        return res;
    }
    if(j < Limit[i]) {
        // 速度を上げる
        double dist = static_cast<double>(j) + 0.5;
        res = max(res, dfs(i+1, j+1) + dist);
        // 速度を上げて戻す
        dist = static_cast<double>(j) + 0.25;
        res = max(res, dfs(i+1, j) + dist);
    }
    if(j > 0) {
        // 速度を下げる
        double dist = static_cast<double>(j-1) + 0.5;
        res = max(res, dfs(i+1, j-1) + dist);
    }
    // 速度維持
    res = max(res, dfs(i+1, j) + static_cast<double>(j));
    return res;
}

signed main()
{
    cin >> N;
    REP(i, N) { cin >> T[i]; }
    REP(i, N) { cin >> V[i]; }

    // EndTime と Limit の作成
    REP(i, N) {
        for(int j = EndTime; j < EndTime + T[i]; ++j) { Limit[j] = V[i]; }
        EndTime += T[i];
    }

    REP(i, MAX_T) { REP(j, MAX_V) { dp[i][j] = DINF; } }

    printf("%.10f\n", dfs());
    return 0;
}


Measured memory_bytes: 36096
#include <bits/stdc++.h>
#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x,y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
void dfs(int idx,vector<int>*tree,vector<int>&visited)
{
    for(auto c:tree[idx])
    {
        if(visited[c]==-1)
        {
            visited[c]=visited[idx]+1;
            dfs(c,tree,visited);
        }
    }
}
int32_t main()
{
    nitin;
    int n;
    cin>>n;
    int k;
    cin>>k;
    vector<int>tree[n];
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        --a;
        --b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<int>irritation[n];
    set<pair<int,int>>s;
    vector<int>cnt_irri(n,0);
    for(int i=0;i<n;i++)
    {
        vector<int>visited(n,-1);
        visited[i]=0;
        dfs(i,tree,visited);
        for(int j=0;j<n;j++) {
            if (visited[j] > k) {
                irritation[i].push_back(j);
                cnt_irri[j]++;
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        if(cnt_irri[i]!=0)
        s.insert({cnt_irri[i],i});
    }
    int cnt=0;
    vector<int>visited(n,0);
    while(!s.empty())
    {
        auto it=prev(s.end());
        int idx=it->second;
        int its_irri=it->first;
        visited[idx]=1;
        cnt_irri[idx]=0;
        cnt++;
        s.erase(it);
        for(auto c:irritation[idx])
        {
            if(visited[c]!=1)
            {
                s.erase({cnt_irri[c],c});
                cnt_irri[c]--;
                if(cnt_irri[c]>=1)
                {
                    s.insert({cnt_irri[c],c});
                }
            }
        }
    }
    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 35976
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;


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

ll a,b,c,k;
cin >> a >> b >> c >> k;

if(k % 2 == 0) cout << a - b << endl;
else cout << b - a << endl;



return 0;
}

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

int main(){
    long long n, m;
    cin >> n >> m;

    vector<long long> x(n), y(n), z(n);

    for(long long i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i];

    bool plus[3];
    vector<long long> sum;

    long long ans = 0;
    for(long long bit = 0; bit < (1 << 3); bit++){
        for(long long mask = 0; mask < 3; mask++){
            if(bit & (1 << mask)) plus[mask] = true;
            else plus[mask] = false;
        }

        sum.assign(n, 0);
        for(long long i = 0; i < n; i++){
            if(plus[0] == true) sum[i] += x[i];
            else sum[i] -= x[i];

            if(plus[1] == true) sum[i] += y[i];
            else sum[i] -= y[i];

            if(plus[2] == true) sum[i] += z[i];
            else sum[i] -= z[i];
        }

        sort(sum.begin(), sum.end(), greater<long long>());

        long long cnt = 0;
        for(long long i = 0; i < m; i++) cnt += sum[i];

        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

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

flag = 1
count = 0
while flag:
    flag = 0
    for i in range(0, N-1, 1):
        if A[i] > A[i+1]:
            A[i], A[i+1] = A[i+1], A[i]
            flag = 1
            count = count + 1

A_str = map(str, A)
print(' '.join(A_str))
print(count)



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

string s;
int main() {
	int i;
	cin >> s;
	for(i=0; i<s.size() && s[i]!='C'; i++);
	for(; i<s.size() && s[i]!='F'; i++);
	cout << (i<s.size() ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 3568
#include <iostream>
using namespace std;
int gcd(int a,int b){
    int temp,c;
    if(a<b){
        temp=a;
        a=b;
        b=temp;
    }
    c=a%b;
    temp=a;
    a=b;
    b=c;
    if(b==0){
        return a;
    }else{
        return gcd(a,b);
    }
    
}
int main(void){
    int a,b;
    cin>>a>>b;
    cout<<gcd(a,b)<<endl;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int N,A,B;
    cin>>N>>A>>B;
    cout <<min(N*A,B)<<endl;
}

Measured memory_bytes: 256
/*
利益が出たら（最小値が更新された時点で）、利益max-minをprof[]に入れおき、
prof[]の中で最大のものを最終的な答えとする。
（入力値が２つだった場合は少し挙動が違うので、例外としてある）
 */


#include<stdio.h>
int main(){
  int max=-1000000000,tmp=-1000000000,min=1000000000,n,i,j=0,a[200000],prof[100000];
    
  scanf("%d",&n);
    
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
    
  if(n==2){
       
    prof[0]=a[1]-a[0];
    j++;
        
  }else{
        
    for(i=0;i<n;i++){
        
      if(a[i]>max){
	max=a[i];
      }
        
      if(a[i]<min){
            
	prof[j]=max-min;
	j++;
	min=a[i];
	max=-1000000000;
      }
    }
    
    prof[j]=max-min;
    j++;
  }
    
  for(i=0;i<j;i++){
    if(prof[i]>tmp)tmp=prof[i];
  }
  printf("%d\n",tmp);
    
}


Measured memory_bytes: 2568
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
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;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

//最大公約数をを返す関数
long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

//nCkを求める関数
long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    long long h,w;
    cin >> h >> w;
    long long ans = 0;
    if((h*w) % 2 == 0) {
        ans = h*w/2;
    }else {
        ans = h*w/2 + 1;
    }
    if((h == 1 || w == 1) && h+w >= 4) {
        ans = 1;
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 888
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
//        sc.useDelimiter(",");
//        DecimalFormat df = new DecimalFormat("0.00000000");
        int n = Integer.parseInt(sc.next());
        int a[] = new int[6];
        Dice dice[] = new Dice[n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 6; j++) {
                a[j] = Integer.parseInt(sc.next());
            }
            dice[i] = new Dice(a);
        }
        boolean isDifferent = true;
        Outer:
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                if (dice[i].equals(dice[j])) {
                    isDifferent = false;
                    break Outer;
                }
            }
        }
        out.println(isDifferent ? "Yes" : "No");

        out.flush();
    }
}
class Dice {
    private int top, front, back, left, right, bottom, temp;
    Dice(int[] a) {
        this.top = a[0];
        this.front = a[4];
        this.back = a[1];
        this.left = a[3];
        this.right = a[2];
        this.bottom = a[5];
    }
    void rollWest() {
        this.temp = this.left;
        this.left = this.top;
        this.top = this.right;
        this.right = this.bottom;
        this.bottom = this.temp;
    }
    void rollEast() {
        this.temp = this.right;
        this.right = this.top;
        this.top = this.left;
        this.left = this.bottom;
        this.bottom = this.temp;
    }
    void rollSouth() {
        this.temp = this.back;
        this.back = this.top;
        this.top = this.front;
        this.front = this.bottom;
        this.bottom = this.temp;
    }
    void rollNorth() {
        this.temp = this.front;
        this.front = this.top;
        this.top = this.back;
        this.back = this.bottom;
        this.bottom = this.temp;
    }
    int getTop() {
        return this.top;
    }
    int getFront() {
        return this.front;
    }
    int getBack() {
        return this.back;
    }
    int getRight() {
        return this.right;
    }
    int getLeft() {
        return this.left;
    }
    int getBottom() {
        return this.bottom;
    }
    boolean equals(Dice d) {
        boolean result = false;
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 3; j++) {
                if (this.back == d.getBack()) break;
                d.rollSouth();
            }
            d.rollEast();
        }
        for (int i = 0; i < 3; i++) {
            if (this.top == d.getTop()) break;
            d.rollEast();
        }
        if (this.back == d.getBack()
                && this.top == d.getTop()
                && this.right == d.getRight()
                && this.left == d.getLeft()
                && this.front == d.getFront()
                && this.bottom == d.getBottom()) {
            result = true;
        }
        return result;
    }
}


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

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

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

int main(){
	int n; scanf("%d",&n);

	mint ans=1;
	int hist[100000]={3};
	rep(i,n){
		int a; scanf("%d",&a);
		ans*=hist[a];
		hist[a]--;
		hist[a+1]++;
	}
	printf("%d\n",ans.to_int());

	return 0;
}


Measured memory_bytes: 640
n = int(input())
a =[' 0',' 0',' 0',' 0',' 0',' 0',' 0',' 0',' 0',' 0']
A_1 = a.copy()
A_2 = a.copy()
A_3 = a.copy()
B_1 = a.copy()
B_2 = a.copy()
B_3 = a.copy()
C_1 = a.copy()
C_2 = a.copy()
C_3 = a.copy()
D_1 = a.copy()
D_2 = a.copy()
D_3 = a.copy()
ren1 = [A_1,A_2,A_3]
ren2 = [B_1,B_2,B_3]
ren3 = [C_1,C_2,C_3]
ren4 = [D_1,D_2,D_3]
for i in range(n):
    b = input()
    c = b.split(' ')
    ren = int(c[0])
    kai = int(c[1])
    banme = int(c[2])
    nin = int(c[3])
    if nin < 0:
        if ren == 1:
            ren1[kai-1][banme-1] = ' %s'%(int(ren1[kai-1][banme-1])+nin)
        elif ren == 2:
            ren2[kai-1][banme-1] = ' %s'%(int(ren2[kai-1][banme-1])+nin)
        elif ren == 3:
            ren3[kai-1][banme-1] = ' %s'%(int(ren3[kai-1][banme-1])+nin)
        elif ren == 4:
            ren4[kai-1][banme-1] = ' %s'%(int(ren4[kai-1][banme-1])+nin)
    elif ren == 1:
        ren1[kai-1][banme-1] = ' %s'%(int(ren1[kai-1][banme-1])+nin)
    elif ren == 2:
        ren2[kai-1][banme-1] = ' %s'%(int(ren2[kai-1][banme-1])+nin)
    elif ren == 3:
        ren3[kai-1][banme-1] = ' %s'%(int(ren3[kai-1][banme-1])+nin)
    elif ren == 4:
        ren4[kai-1][banme-1] = ' %s'%(int(ren4[kai-1][banme-1])+nin)
print(''.join(A_1))
print(''.join(A_2))
print(''.join(A_3))
print('####################')
print(''.join(B_1))
print(''.join(B_2))
print(''.join(B_3))
print('####################')
print(''.join(C_1))
print(''.join(C_2))
print(''.join(C_3))
print('####################')
print(''.join(D_1))
print(''.join(D_2))
print(''.join(D_3))

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

int main(){
  string s; cin>>s;
  int x=s.size();
  char a[x],b[x];
  for(int i=0;i<x;i++){
    a[i]=s[i];
    cin>>b[i];
  }int count=0;
  while(true){
    for(int i=0;i<x;i++){
      if(a[i]!=b[i]){
        char s=a[x-1];
        for(int j=0;j<x;j++){
          char s2=a[j];
          a[j]=s;
          s=s2;
        }break;
      }if(i==x-1){
        cout<<"Yes"<<endl;
        return 0;
      }
    }count++;
    if(count>x+2){
      cout<<"No"<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
using System;

namespace ALDS1_4_D {
    class Problem {
        private int n, k, totalWeights;
        private int[] weights;

        public Problem(int n, int k) {
            this.n = n;
            this.k = k;
        }

        public void Read() {
            weights = new int[n];
            for (int i = 0; i < n; i++) {
                int weight = int.Parse(Console.ReadLine());
                weights[i] = weight;
                totalWeights += weight;
            }
        }

        public int Run() {
            return SearchCapacity(totalWeights);
        }

        private int SearchCapacity(int totalWeights) {
            int left = 0;
            int right = totalWeights;
            while (left < right) {
                int mid = (left + right) / 2;
                if (IsAllGainOn(mid))
                    right = mid;
                else
                    left = mid + 1;
            }
            return right;
        }

        private bool IsAllGainOn(int capacity) {
            int nextCargo = 0;
            for (int i = 0; i < k; i++) {
                if (nextCargo == n)
                    return true;
                int sumWeights = 0;
                for (int j = nextCargo; j < n; j++) {
                    sumWeights += weights[j];
                    if (sumWeights > capacity)
                        break;
                    nextCargo++;
                }
            }
            return nextCargo == n;
        }
    }

    class Program {
        static void Main(string[] args) {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);

            Problem p = new Problem(n, k);
            p.Read();
            Console.WriteLine(p.Run());
        }
    }
}

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

int		main(void)
{
	vector<int> abc(3);

	cin >> abc.at(0) >> abc.at(1) >> abc.at(2);
	sort(abc.begin(),abc.end(),greater<int>());
		cout << ((abc.at(0) == abc.at(1) + abc.at(2)) ? "Yes" : "No") << endl;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>

using namespace std;

const int N=1e5;

int n,sum;
int a[N+5];
int ans[N+5];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum += a[i];
		a[i] *= 2;
	}
	int k=0;
	for(int i=1;i<=n;i+=2)
		k += a[i];
	ans[1] = k-sum;
	ans[n] = a[n]-ans[1];
	for(int i=n-1;i>=2;i--)
		ans[i] = a[i]-ans[i+1];
	for(int i=1;i<n;i++)
		printf("%d ",ans[i]);
	printf("%d\n",ans[n]);
	return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> p(n), p2(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p2[i] = p[i];
    }
    sort(p2.begin(), p2.end());
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        cnt += (p[i] != p2[i]);
    }
    cout << (cnt <= 2 ? "YES" : "NO") << endl;
    return 0;
}

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

int main(void){

    string S; cin>>S;
    set<char> st;
    for (int i = 0; i < S.size(); ++i) {
        st.insert(S[i]);
    }
    for (char i = 'a'; i <= 'z'; ++i) {
        if(!st.count(i)) {
            cout << i << endl;
            return 0;
        }
    }
    cout<<"None"<<endl;
    return 0;
}

Measured memory_bytes: 512
from _collections import deque
n,m=map(int,input().split())
M=[[] for _ in range(n)]
ANS=[-1]*n
ANS[0]=0
for i in range(m):
    a,b=map(int,input().split())
    M[b-1].append(a-1)
    M[a-1].append(b-1)

q=deque([0])

while q:
    s=q.popleft()
    for x in M[s]:
        if ANS[x]!=-1:
            continue
        q.append(x)
        ANS[x]=s
print('Yes')
for ans in ANS[1:]:
    print(ans+1)

Measured memory_bytes: 34704
#include <iostream>
using namespace std;
bool t[999999] = {false};
int main()
{
	int n, c, i, j, d;
	t[0] = true;
	for (i = 2; i * i <= 999999; i++)
	{
		if (!t[i-1])
		{
			for (j = i+i; j <= 999999; j+=i)
				t[j-1] = true;
		}
	}
	while (cin >> n, n)
	{
		c = 0;
		d = 1;
		for (i = 1; d <= n; i++)
		{
			if (!t[i])
			{
				c += i+1;
				d++;
			}
		}
		cout << c << endl;
	}
}

Measured memory_bytes: 0
// abc122_b
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void) {
	string S;
	cin >> S;
	string t = "ACGT";
	int max = 0;
	for (int i = 0; i < S.length(); i++) {
		string res;
		for (int j = i; j < S.length(); j++) {
			if (t.find(S[j]) == std::string::npos) {
				break;
			}
			res += S[j];
		}
		if (max < res.length()) {
			max = res.length();
		}
	}
	cout << max << endl;

	return 0;
}

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

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


Measured memory_bytes: 256
import math
x = int(input())

m = math.ceil((x / 2) ** (1 / 5))
M = int(x ** (1 / 5))
for i in range(m, M + 1):
    n = int((x - i ** 5) ** (1 / 5))
    if n ** 5 == x - i ** 5:
        print(str(int(i)) + ' ' + str(int(-n)))
        break

l = M
L = math.ceil((x / 5) ** (1 / 4) + 1)
for i in range(l + 1, L):
    n = int((i ** 5 - x) ** (1 / 5))
    if n ** 5 == i ** 5 - x:
        print(str(int(i)) + ' ' + str(int(n)))
        break


Measured memory_bytes: 9284
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int A;
  cin >> N >> A;
  if (A >= 0 && N % 500 <= A){
    cout << "Yes" << endl;
  }
  else if (A >= 0 && N % 500 > A){
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main(){
    int h, w, n;
    cin >> h >> w >> n;
    int x = max(h, w);
    cout << (n + x - 1) / x << endl;

    return 0;
}

Measured memory_bytes: 764
#include <iostream>
using namespace std;
int main(){
  long long a = 0;
  cin >> a;
  long long kotae = 0;
  long long ima = 0;
  long long amari = 0;
  long long keisann = 0;
  long long syou = 0;
  keisann = a / 2;
  amari = a % 5;
  if(a % 2 == 1){
    kotae = 0;
  }
  else{
    while(1){
      if(keisann >= 5){
        keisann = keisann / 5;
        kotae += keisann;
      }
      else{
        break;
      }
    }
  }
  cout << kotae << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n, m, l, p[13];
char s[13][13]; bool flag;
bool IsMat(int u, int v) {
	for (int i = 1; i <= m; i++)
		if (s[u][i] ^ s[v][p[i]]) return false;
	return true;
}
bool chk() {
	bool used[13], pal = n&1;
	memset(used, false, sizeof used);
	for (int u = 1, v; u <= n; u++) if (!used[u]) {
		for (v = u+1; v <= n; v++)
			if (!used[v] && IsMat(u, v)) break;
		if (v <= n) used[u] = used[v] = true;
		else if (!IsMat(u, u)) return false;
		else if (!pal) return false;
		else used[u] = true, pal = false;
	}
	return true;
}
void DFS(int u, bool odd) {
	if (u > m) {flag |= chk(); return;}
	if (p[u]) {DFS(u+1, odd); return;}
	if (odd) p[u] = u, DFS(u+1, odd^1), p[u] = 0;
	for (int v = u+1; !flag && v <= m; v++) if (!p[v])
		p[u] = v, p[v] = u, DFS(u+1, odd), p[u] = p[v] = 0;
}
int main() {
	read(n), read(m);
	for (int i = 1; i <= n; i++) scanf("%s", s[i]+1);
	return DFS(1, m&1), puts(flag ? "YES" : "NO"), 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define int long long
#define double long double
#define INF LLONG_MAX/1000
#define P pair<int,int>
#define prique priority_queue
using namespace std;
string s;
signed main() {
	cin >> s;
	int ans = INF;
	rep(i, s.size() - 1) {
		if (s[i] != s[i + 1]) {
			ans = min(ans, max(i + 1, (int)s.size() - i - 1));
		}
	}
	if (ans != INF)cout << ans << endl;
	else cout << s.size() << endl;
	return 0;
}

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

int k = 0;
struct val_pos{
	int val;
	int pos;
};

void Merge(val_pos a[], int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	val_pos* L = new val_pos[n1+1];
	val_pos* R = new val_pos[n2+1];
	for ( int i = 0; i < n1; i++) L[i] = a[left + i];
	L[n1].val = INT_MAX;
	for (int i = 0; i < n2; i++) R[i] = a[mid + i];
	R[n2].val = INT_MAX;
	int i = 0;
	int j = 0;
	while(i < n1 || j < n2){
		if (L[i].val <= R[j].val){
			a[left + i + j] = L[i];
			i++;
		}
		else{
			a[left + i + j] = R[j];
			j++;
		}
	}
}

void MergeSort(val_pos a[], int left, int right){
	if (left + 1 < right){
		int mid = (left + right) / 2;
		MergeSort(a, left, mid);
		MergeSort(a, mid, right);
		Merge(a, left, mid, right);
	}
}

void MinCost(val_pos a[], int n, int min){
	for (int i = 0; i < n; i++){
		if (i != a[i].pos){
			int k_st = 0;
			int k_ex = 2 * (min + a[i].val);
			while(i != a[i].pos){
				k_st += a[i].val + a[a[i].pos].val;
				k_ex += min + a[a[i].pos].val;
				int tmp = a[a[i].pos].pos;
				a[a[i].pos].pos = a[i].pos;
				a[i].pos = tmp;
			}
			k += k_st < k_ex ? k_st : k_ex;
			break;
		}
		if (i == n-1) return;
	}
	MinCost(a, n, min);
	return;
}

int main(){
	int n = 0;
	scanf("%d", &n);
	val_pos a[1000];
	int min = INT_MAX;
	for (int i = 0; i < n; i++) {
		a[i].pos = i;
		scanf("%d", &a[i].val);
		if (a[i].val < min) min = a[i].val;
	}
	MergeSort(a, 0, n);
	MinCost(a, n, min);
	printf("%d\n", k);
}


Measured memory_bytes: 2888
table = [["light fly", 0, 48.0], ["fly", 48.0, 51.0], ["bantam", 51.0, 54.0],
         ["feather", 54.0, 57.0], ["light", 57.0, 60.0],
         ["light welter", 60.0, 64.0], ["welter", 64.0, 69.0],
         ["light middle", 69.0, 75.0], ["middle", 75.0, 81.0],
         ["light heavy", 81.0, 91.0], ["heavy", 91.0, Float::INFINITY]]
$<.readlines.map(&:to_f).each do |w|
  table.each {|name, bottom, top| puts name if bottom < w and w <= top}
end


Measured memory_bytes: 6872
n=int(input())

ab = []
for _ in range(n):
    a, b, c = (int(x) for x in input().split())
    ab.append([a, b, c])

dp = [[0 for i in range(3)] for j in range(n+1)]

for i in range(n):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i+1][k] = max([dp[i+1][k], dp[i][j]+ab[i][k]])

print(max(dp[n]))

Measured memory_bytes: 44100
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
int a[7] = {1,3,5,7,8,10,12};
int b[4] = {4,6,9,11};
int c[1] = {2};
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m)){
        int sum = 0, cnt = 0,flag = 0;
        if(n == m) printf("Yes\n");
        else{
            for(int i = 0; i < 7; i++)
                if(a[i] == n || a[i] == m) cnt++;
            for(int i = 0; i < 4; i++)
                if(b[i] == n || b[i] == m) sum++;
            if(cnt == 2 || sum == 2) printf("Yes\n");
            else flag = 1;
        }
        if(flag == 1) printf("No\n");
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int inf=0x3f3f3f3f;
char Map[1005][1005];
int dist[1005][1005];
bool vis[1005][1005];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int n,m;
int sx,sy,ex,ey;
void bfsDeque() {
	memset(dist,0x3f,sizeof(dist));
	memset(vis,0,sizeof(vis));
	dist[sx][sy]=0;
	deque<pair<int,int> > q;
	q.push_back(make_pair(sx,sy));
	while(!q.empty()) {
		pair<int,int> u=q.front();
		q.pop_front();
		if(vis[u.x][u.y]) {
			continue;
		}
		vis[u.x][u.y]=1;
		for(int i=0;i<4;i++) {
			int tx=u.x+dx[i];
			int ty=u.y+dy[i];
			if(!vis[tx][ty] && tx>=1 && tx<=n && ty>=1 && ty<=m && Map[tx][ty]!='#') {
				if(dist[tx][ty]>dist[u.x][u.y]) {
					dist[tx][ty]=dist[u.x][u.y];
					q.push_front(make_pair(tx,ty));
				}
			}
		}
		for(int i=-2;i<=2;i++) {
			for(int j=-2;j<=2;j++) {
				int tx=u.x+i;
				int ty=u.y+j;
				if(!vis[tx][ty] && tx>=1 && tx<=n && ty>=1 && ty<=m && Map[tx][ty]!='#') {
					if(dist[tx][ty]>dist[u.x][u.y]+1) {
						dist[tx][ty]=dist[u.x][u.y]+1;
						q.push_back(make_pair(tx,ty));
					}
				}	
			}
		}
	}
	
}

int main() {
	scanf("%d %d %d %d %d %d",&n,&m,&sx,&sy,&ex,&ey);
	for(int i=1;i<=n;i++) {
    	scanf("%s",Map[i]+1);
  	}
  	bfsDeque();
  	if(dist[ex][ey]==inf) {
  		printf("-1");
  		return 0;
	}
  	printf("%d",dist[ex][ey]);
  	return 0;
}

Measured memory_bytes: 9600
from collections import deque
h,w = map(int,input().split())
map_input = [list(input()) for i in range(h)]

score = [[10**10]*(w+1) for i in range(h+1)]
score[0][1] = 0
score[1][0] = 0

for i in range(h):
    for j in range(w):
        tmp1 = score[i][j+1] + (map_input[i][j]=='#' and (i==0 or map_input[i-1][j]=='.'))
        tmp2 = score[i+1][j] + (map_input[i][j]=='#' and (j==0 or map_input[i][j-1]=='.'))
        score[i+1][j+1]=min(tmp1,tmp2)
print(score[-1][-1])

Measured memory_bytes: 3436
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) {if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b) {if(a>b){a=b;return 1;}return 0;}

string s;
vector<bool> fore(26,false);
int pro(){
    REP(i,26){
        if(!fore[i]){
            fore[i]=true;
            return i;
        }
    }
    return 26;
}


int main(){
    cin >> s;
    int n = s.size();
    
    string res;
    if(s.size()!=26){
        REP(i,n){
            fore[s[i]-'a']=true;
            res.push_back(s[i]);
        }
        res.push_back((char)('a'+pro()));
        put(res);
        return 0;
    }else{
        int d=26;
        for(int i=25;i>0;--i){
            if(s[i]>s[i-1]){
                d=i;
                break;
            }
        }
        if(d==26){
            put(-1);
            return 0;
        }
        REP(i,d-1){
            fore[s[i]-'a']=true;
            res.push_back(s[i]);
        }
        REP(i,s[d-1]-'a'+1){
            fore[i]=true;
        }
        res.push_back((char)('a'+pro()));
        put(res);
        return 0;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int main()
{
	int num;
	string s;
	cin >> num >> s;
	int cnt = 0;
	for (int i = 0; i < s.size(); i++)cnt += s[i] == 'E';
	int mini = 1010101010;
	int now = 0;
	for (int i = 0; i < s.size(); i++)
	{
		cnt -= s[i] == 'E';
		mini = min(mini, cnt + now);
		now += s[i] == 'W';
	}
	printf("%d\n", mini);
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(2e5) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()


int main() {
    ll n, m;
    cin >> n >> m;
    priority_queue<ll> que;
    for(int i=0;i<n;i++){
        ll a;
        cin >> a;
        que.push(a);
    }
    for(int i=0;i<m;i++){
        ll a;
        a = que.top();
        que.pop();
        a /= 2;
        que.push(a);
    }
    ll ans = 0;
    while(!que.empty()){
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
/*
░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░
░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░
░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░
░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░
░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░
░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░
░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░
░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░
░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░
░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░
░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░
░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░
░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██
░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█
░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀
░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░
░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░
█▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░
█░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
#define L nod<<1
#define R ((nod<<1)|1)
#define mp make_pair
const ll mod = 1000000007;
const ll nmax=500003;
#define int ll
set<int> s;
int n, id[200002], ans;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i=1, x; i<=n; i++) cin>>x, id[x]=i;
    s.insert(0);
    s.insert(n+1);
    for(int i=n; i>0; i--){
        auto r=s.lower_bound(id[i]);
        auto l=r;
        l--;
        int cur=0;
        if(*l!=0){
            cur+=(*r-id[i])*(*l-*prev(l));
        }
        if(*r!=n+1){
            cur+=(*next(r)-*r)*(id[i]-*l);
        }
        ans+=cur*i;
        s.insert(id[i]);
    }
    cout<<ans;
}


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

// N : number of ppl who live in a line
// i:  coordinate Xi
// 
int main(){
  int N;
  cin >> N;
  int *x = new int[N];
  int sum=0;
  for(int i=0; i<N; i++){
	cin >> x[i];
	sum += x[i];
  }
  // 四捨五入
  double tmp = (double)sum / (double)N; // pは整数
  int tmp2 = tmp;
  int p;
  if(tmp - tmp2 > 0.5){
	p = tmp2+1;
  }
  else{
	p = tmp2;
  }
  int sum_power = 0;
  //cout << "p:" << p << endl;
  for(int i=0; i<N; i++){
	int k = x[i] - p;
	sum_power += pow(k, 2);
  }
  
  cout << sum_power << endl;
  /*
  for(int i=0; i<N; i++){
	cout << x[i] << endl;
  }
  */

  
  delete[] x;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())

rst = 0
for i in range(1, n+1):
    if i % 2 == 0:
        continue

    cnt = 0
    for j in range(1, i+1):
        cnt += 1 if i % j == 0 else 0

    if cnt == 8:
        rst += 1

print(rst)


Measured memory_bytes: 2940