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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int H, W;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> H >> W;
  int ans = min((H+2)/3*W-H/3*W, (W+2)/3*H-W/3*H);
  for(int w = 1; w < W; w++) {
    int a = H*w;
    int b = ((H+1)/2)*(W-w);
    int c = (H/2)*(W-w);
    chmin(ans, max(a, b)-min(a, c));
    /*
    int a = (W-w)*H;
    int b = (a%2 ? (a-w)/2 : a/2);
    int c = (a%2 ? (a+W-w)/2 : a/2);
    int d = (a%2 ? (a-H)/2 : a/2);
    int e = (a%2 ? (a+H)/2 : a/2);
    if(H*w >= max(b,c)) chmin(ans, H*w - min(b,c));
    if(c >= max(b,H*w)) chmin(ans, c - min(b,H*w));
    if(H*w >= max(d,e)) chmin(ans, H*w - min(d,e));
    if(e >= max(d,H*w)) chmin(ans, e - min(d,H*w));
    */
    //cout<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<ans<<endl;
  }
  for(int h = 1; h < H; h++) {
    int a = h*W;
    int b = ((W+1)/2)*(H-h);
    int c = (W/2)*(H-h);
    chmin(ans, max(a, b)-min(a, c));
    /*
    int a = (H-h)*W;
    int b = (a%2 ? (a-W)/2 : a/2);
    int c = (a%2 ? (a+W)/2 : a/2);
    int d = (a%2 ? (a-h)/2 : a/2);
    int e = (a%2 ? (a+H-h)/2 : a/2);
    if(h*W >= max(b,c)) chmin(ans, h*W - min(b,c));
    if(c >= max(b,h*W)) chmin(ans, c - min(b,h*W));
    if(h*W >= max(d,e)) chmin(ans, h*W - min(d,e));
    if(e >= max(d,h*W)) chmin(ans, e - min(d,h*W));
    //cout<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<ans<<endl;
    */
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  string s;
  ll q;
  cin >> s >> q;


  ll p = 0;

  deque<char> d;
  for (auto&& i : s) {
    d.push_back(i);
  }

  rep(i, q) {
    ll t;
    cin >> t;
    if (t == 1) {
      p ^= 1;
    } else {
      ll f;
      char c;
      cin >> f >> c;
      f--;

      f ^= p;

      if (f == 0) {
        d.push_front(c);
      } else {
        d.push_back(c);
      }
    }
    cerr << p << endl;
  }

  if (p) {
    while (d.size()) {
      cout << d.back();
      d.pop_back();
    }
  } else {
    while (d.size()) {
      cout << d.front();
      d.pop_front();
    }
  }
  cout << endl;
}


Measured memory_bytes: 976
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int R,G;

int main(){
    cin>>R>>G;
    out(G*2-R);
}


Measured memory_bytes: 380
#include <stdio.h>
 
int main(void)
{
    long long int N, K;
    long long int temp1, temp2;
 
    // input
    scanf("%lld %lld", &N, &K);
 
    temp1 = N % K;
    if (temp1 < 0) {
        temp1 *= -1;
    }
    temp2 = temp1 - K;
    if(temp2 < 0) {
        temp2 *= -1;
    }
    // printf("%lld, %lld\n", temp1, temp2);
    if (temp1 > temp2) {
        printf("%lld\n", temp2);
    } else {
        printf("%lld\n", temp1);
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
  ll n, a, b;cin >> n >> a >> b;
  if((b-a)%2LL==0){
    cout << (b-a)/2LL << endl;
    return 0;
  }
  ll ans = 0;
  if(a-1<n-b){
    ans = a;
    b-=a;
    ans+=(b)/2LL;
  }
  else{
    ans= n-b;
    a+=n-b;
    ans+=(n-a+1)/2LL; 
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Main {
    private void topThreeHills() {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> hlist = new ArrayList<Integer>(10);
        while (sc.hasNext()) {
            hlist.add(sc.nextInt());
        }
        Collections.sort(hlist, Collections.reverseOrder());
        for (int i = 0; i < 3; i++) {
            System.out.println(hlist.get(i));
        }
    }

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

Measured memory_bytes: 12000
/*
* @Author: kabbo
* @Date:   2020-05-11 23:37:49
* @Last Modified by:   kabbo
* @Last Modified time: 2020-05-11 23:47:30
*/
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define endl '\n'
#define ull unsigned long long
#define ll long long
const int mod = 1e9 + 7;
using u64 = uint64_t;
using u128 = __uint128_t;
const int mx = 1e3;
char grid[mx + 3][mx + 3];
void solve() {
	int n, m;
	cin >> n >> m;
	for (int i(1); i <= n; ++i) {
		for (int j(1); j <= m; ++j) {
			cin >> grid[i][j];
		}
	}

	int dp[n + 2][m + 2] = {0};
	dp[n][m] = 1;
	for (int i(n); i >= 1; --i) {
		for (int j(m); j >= 1; --j) {

			if (i == n && j == m)
				continue;
			if (grid[i][j] == '#')
				dp[i][j] = 0;
			else {
				auto right = (j == m ? 0 : dp[i][j + 1]) % mod;
				auto down = (i == n ? 0 : dp[i + 1][j]) % mod;
				//cout << right << " " << down << endl;
				dp[i][j] = (right + down) % mod;
			}
		}
	}
	cout << dp[1][1] % mod << endl;
}
int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;/*
	cin >> t;
	for (int i(1); i <= t; ++i) {
		printf("Case %d: ", i);
	*/	solve();
	//}
#ifndef LOCAL_DEFINE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif
	return 0;
}

Measured memory_bytes: 5120
x = int(input())
a = 0
while True:
    po = pow(a, 5)
    b = po - x
    c = x - po
    if b > 0:
        ans = int(pow(b, 0.2))
    else:
        ans = - int(c ** 0.2)
    ans_p = pow(ans, 5)
    if ans_p == b or ans_p == c: 
        print(a, ans)
        break
    else:
        a += 1

Measured memory_bytes: 9456
#include<bits/stdc++.h>                                    
using namespace std;
int main()
{
  string O,E;
  cin >> O >> E;
  int N=(O.size()+E.size())/2;
  for(int i=0; i<N; i++){
    cout << O.at(i) << E.at(i);
  }
  if(O.size()>E.size())
    cout << O.at(O.size()-1);
  else if(E.size()>O.size())
    cout << E.at(E.size()-1);
  cout << endl;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
H=list(map(int,input().split()))
flg=[1]*N


for m in range(M):
  a,b =map(int,input().split())
  if H[a-1]<H[b-1]:
    flg[a-1]=0
  elif H[a-1]>H[b-1]:
    flg[b-1]=0
  else:
    flg[a-1]=flg[b-1]=0
  
print(flg.count(1))
 
  

Measured memory_bytes: 20112
#include <bits/stdc++.h>
using namespace std;
#define LOCAL
#pragma region Macros
typedef long long ll;
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K; cin >> N >> K;
    vector<ll> A(N); cin >> A;
    for (int i=K;i<N;++i){
        cout << (A[i]>A[i-K]?"Yes":"No") << '\n';
    }
}

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

int main(){
    int n, m;   cin >> n >> m;
    vector<pair<bool, int> >q(n, pair<bool, int>(false, 0));
    rep(i, m){
        int p;
        string s;
        cin >> p >> s;
        p--;
        if(!q[p].first){
            if(s == "WA"){
                q[p].second++;
            }else{
                q[p].first = true;
            }
        }
    }
    int ans = 0;
    int pen = 0;
    rep(i, n){
        if(q[i].first){
            ans++;
            pen += q[i].second;
        }
    }
    printf("%d %d\n", ans, pen);
}


Measured memory_bytes: 1024
sx, sy, tx, ty = map(int, input().split())

ans = ''
ans += 'R' * (tx - sx)
ans += 'U' * (ty - sy)
ans += 'L' * (tx - sx)
ans += 'D' * (ty - sy)
ans += 'D' + 'R' * (tx - sx + 1)
ans += 'U' * (ty - sy + 1) + 'L'
ans += 'U' + 'L' * (tx - sx + 1)
ans += 'D' * (ty - sy + 1) + 'R'

print(ans)


Measured memory_bytes: 3060
#include"bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long INT;
double PI = 3.14159265;

const long long INF = 1LL << 60;


int main() {
    int n, m,mx=0;
    map<string, int> map = {};
    string s;

    cin >> n;

    rep(i, n) {
        cin >> s;
        map[s]++;
    }

    cin >> m;

    rep(i, m) {
        cin >> s;
        map[s]--;
    }

    for (auto it = map.begin(); it != map.end(); it++) {
        mx = max(mx, it->second);
    }

    cout << mx << endl;

  return 0;
}

Measured memory_bytes: 256
def main():
    from operator import itemgetter
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

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

    AP = []
    for i in range(N):
        AP.append((A[i], i))
    AP.sort(key=itemgetter(0), reverse=True)

    # dp[i][l][r]
    # 大きい方からi個まで左右を決めて
    # 左をl回、右をr回使ったときの最大値
    # r = i - l
    dp = [[0]*(N+1) for _ in range(N+1)]
    for i in range(N):
        ai, pi = AP[i]
        for l in range(i+1):
            r = i - l
            # 左
            if dp[i+1][l+1] < dp[i][l] + (pi-l)*ai:
                dp[i+1][l+1] = dp[i][l] + (pi-l)*ai
            # 右
            if dp[i+1][l] < dp[i][l] + ((N-r-1)-pi)*ai:
                dp[i+1][l] = dp[i][l] + ((N-r-1)-pi)*ai

    print(max(dp[N]))

main()

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

string s;
int a = 0, b = 0;
int main()
{
    cin >> s;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] == '1')
        {
            a++;
        }
        else
        {
            b++;
        }
    }
    cout << min(a, b) * 2 << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    string s;
    cin >> n >> s;
    
    vl v(26, 1);
    rep(i, n) {
        v[s[i] - 'a']++;
    }

    ll ans = 1;
    rep(i, 26) {
        ans *= v[i];
        ans %= mod;
    }
    ans = (ans + mod - 1)%mod;

    out(ans);
    re0;
}

Measured memory_bytes: 512
/*input
6 727202214173249351
6 5 2 5 3 2
*/

//sometimes it's the people who no one imagines anything of 
//who do the things that no one can imagine.

//code author: iamxlr8

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

#define ll long long
#define endl "\n"
#define pb push_back
#define all(c) c.begin(),c.end()
#define hell 1000000007
#define inf 100000000000001
#define F first
#define S second
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

void solve()
{
	ll n,k;
	cin>>n>>k;
	vector<ll>v(n+1);
	set<ll>s;
	s.insert(1);
	for(ll i=1;i<=n;i++)
		cin>>v[i];
	ll now=1;
	vector<ll>w;
	w.pb(1);
	for(ll i=1;i<=n+10;i++)
	{
		now=v[now];
		if(s.find(now)!=s.end())
			break;
		s.insert(now);
		w.pb(now);
	}
	// for(auto p:w)
	// 	cout<<p<<" ";
	// cout<<endl;
	ll ind=-1;
	for(ll i=0;i<w.size();i++)
	{
		if(w[i]==now)
		{
			ind=i;
			break;
		}
	}
	if(k<=ind)
	{
		cout<<w[k];
		return;
	}
	k-=ind;
	k%=w.size()-ind;
	cout<<w[ind+k];
}

int main() 
{
    off;
    ll tests=1;
    // cin>>tests;
    while(tests--)
    {
        solve();
    }
    return 0;
}

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

int main() {
    int n;
    int h[110000];
    long long dp[110000];

    cin >> n;
    rep(i,n) cin >> h[i];
    dp[0] = 0;
    dp[1] = dp[0] + abs(h[1] - h[0]);
    for (int i = 2; i < n; ++i) {
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]),
                    dp[i-2] + abs(h[i] - h[i-2]));
    }
    cout << dp[n-1] << "\n";
    return 0;
}


Measured memory_bytes: 4800
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using vvpi = vector<vpi>;
const ull MOD = 998244353;
#ifdef LOCAL
#include "../../pp.hpp"
#define debug pp::debug
#else
#define debug(args...)
#endif

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

    int N, W; cin >> N >> W;
    vi w(N); vector<long long> v(N);
    for (int i = 0; i < N; ++i) cin >> w[i] >> v[i];
    
    vector<vector<long long>> dp(N, vector<long long>(W+1, 0));
    for (int cap = 0; cap <= W; ++cap) {
        if (cap >= w[0]) dp[0][cap] = v[0];
    }
    for (int i = 1; i < N; ++i) {
        for (int cap = 0; cap <= W; ++cap) {
            dp[i][cap] = dp[i-1][cap];
            if (cap >= w[i]) dp[i][cap] = max(dp[i][cap], dp[i-1][cap - w[i]] + v[i]);
        }
    }

    long long ans = 0;
    for (int cap = 0; cap <= W; ++cap) ans = max(ans, dp[N-1][cap]);

    cout << ans << '\n';
}


Measured memory_bytes: 79488
#f = open("input.txt")
#N, K = [int(x) for x in f.readline().split(' ')]
#lines = f.readlines()
#f.close()
from sys import stdin
N, K = [int(x) for x in stdin.readline().split(' ')]
lines = stdin.readlines()

schedule = [0]*N
for line in lines:
    strs = line.split(' ')
    schedule[int(strs[0])-1] = int(strs[1])

number = [1]*9
for i in range(9):
    l1 = i // 3
    l2 = i % 3
    if   schedule[0]!=l2+1 and schedule[0]!=0:
        number[i] = 0
    elif schedule[1]!=l1+1 and schedule[1]!=0:
        number[i] = 0

for s in schedule[2:]:
    tmp = [0]*9
    for i in range(9):
        l1 = i // 3
        l2 = i % 3
       	tmp[i] = [number[l2*3+j] for j in range(3) \
         if (s==0 or s==l1+1) and  not (l2==j and l1==j)]
    for i in range(9):
         number[i] = sum(tmp[i])
print(sum(number) % 10000)

Measured memory_bytes: 6752
import statistics
n = int( input() )
a = []
b = []
for _ in range( n ):
    a_i, b_i = map( int, input().split() )
    a.append( a_i )
    b.append( b_i )

m_a = statistics.median( a )
m_b = statistics.median( b )

if n % 2 == 1:
    print( int( m_b - m_a + 1 ) )
else:
    print( int( ( m_b - m_a ) * 2 + 1 ) )

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

bool is_prime(int n) {
  if (n == 2) return true;
  if (n % 2 == 0 || n == 1) return false;
  for (int i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0) return false;
  }
  return true;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n, ans = 0;
  while (cin >> n) {
    if (is_prime(n)) ans++;
  }
  cout << ans << "\n";
}


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

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

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    string s; cin>>s;
    int n=s.size();

    if(n%2 == 0){
        for(int i=n/2; i<n; i++){
            if(s[n-i-1] != s[i]){
                cout << i << endl;
                return 0;
            }
        }
    }
    else{
        if(s[n/2] != s[n/2+1]){
            cout << n/2+1 << endl;
            return 0;
        }

        for(int i=n/2+1; i<n; i++){
            if(s[n-i-1] != s[i]){
                cout << i << endl;
                return 0;
            }
        }
    }

    for(int i=0; i<n-1; i++){
        if(s[i] != s[i+1]){
            cout << n-i-1 << endl;
            return 0;
        }
    }
    cout << n << endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

// greatest common divisor and least common multiple
// gcd is calculated by Euclidean Algorithm
// lcm = m * n / gcd(m,n)
template <typename T = int>
T gcd(T a, T b) {
    if (a < b)
        return gcd(b, a);
    if (b == 0)
        return a;
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template <typename T = int>
T lcm(T m, T n) {
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

int main() {
    ll n, m;
    cin >> n >> m;
    vl a(n);
    vi twoes(35, 0);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i] /= 2;
        ll t   = a[i];
        int ts = 0;
        while (t % 2 == 0) {
            ts++;
            t /= 2;
        }
        twoes[ts]++;
        // if (a[i] % 2 == 0) {
        //     if (even == -1)
        //         even = a[i];
        //     else if (even != a[i]) {
        //         cout << 0 << "\n";
        //         return 0;
        //     }
        // }
    }
    int cnt = 0;
    for (int i = 0; i < 35; ++i) {
        if (twoes[i] != 0)
            cnt++;
    }
    if (cnt > 1) {
        cout << 0 << "\n";
        return 0;
    }
    ll l = a[0];
    for (int i = 1; i < n; ++i) {
        l = lcm(l, a[i]);
    }
    ll ret = m / l;
    cout << (ret + 1) / 2 << "\n";
    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 RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;


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

    // ifstream in("in.txt");
    // cin.rdbuf(in.rdbuf());

    int H, W; cin >> H >> W;
    vector<string> S(H);
    REP(i, H) cin >> S[i];

    ll ans = 0;

    REP(c, W-1) {
        vector<vector<int>> cost1(H+1), cost2(H+1);
        REP(k, H+1) {
            cost1[k].resize(H-k+1);
            cost2[k].resize(H-k+1);
            for (int i = 0; i + k < H; ++i) {
                cost1[k][i+1] = cost1[k][i] + (S[i][c] == S[i+k][c+1]);
                cost2[k][i+1] = cost2[k][i] + (S[i+k][c] == S[i][c+1]);
            }
        }
        vector<vector<int>> dp(H+1, vector<int>(H+1, INF));
        dp[0][0] = 0;
        REP(i, H+1) {
            REP(j, H+1) {
                if (dp[i][j] == INF) continue;
                // assert(abs(i - j) < H);
                int cost;
                if (i > j) {
                    cost = cost1[i - j][SZ(cost1[i - j]) - 1 - j];
                } else {
                    cost = cost2[j - i][SZ(cost2[j - i]) - 1 - i];
                }
                if (i < H) {
                    chmin(dp[i+1][j], dp[i][j] + cost);
                }
                if (j < H) {
                    chmin(dp[i][j+1], dp[i][j] + cost);
                }
            }
        }
        ans += dp[H][H];
    }

    cout << ans << endl;

    return 0;
}


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

class Proc{
public:
  string nam;
  int tim;
  Proc(){
    nam = "";
    tim = 0;
  }
};

Proc Q[100001];

class Queue{
private:
  int fp;
  int rp;
public:
  Queue(){
    fp = 0;
    rp = 0;
  }
  int next(int p) const{
    return (p+1)%100001;
  }
  bool isFull() const{
    return (next(rp) == fp);
  }
  bool isEmpty() const{
    return (rp == fp);
  }
  void push(Proc d){
    if(isFull()){
      return;
    }
    Q[rp] = d;
    rp = next(rp);
  }
  Proc front(){
    if(isEmpty()){
      Proc er;
      er.tim = -1;
      return er;
    }

    return Q[fp];
  }
  void pop(){
    if(isEmpty()){
      return;
    }
    fp = next(fp);
  }
};

int main(){
  Queue que;

  int n,q;
  cin >> n >> q;

  for(int i=0;i<n;i++){
    Proc p;
    cin >> p.nam >> p.tim;

    que.push(p);
  }

  int total_tim = 0;

  while(!que.isEmpty()){
    Proc p = que.front();
    que.pop();

    if(p.tim <= q){
      total_tim += p.tim;

      cout << p.nam << ' ' << total_tim << endl;
    }else{
      total_tim += q;
      p.tim -=q;

      que.push(p);
    }
  }

  return 0;
}



Measured memory_bytes: 6960
/*  */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000")

#define sti				set<int>
#define stpii			set<pair<int, int> >
#define mpii			map<int,int>
#define vi				vector<int>
#define pii				pair<int,int>
#define vpii			vector<pair<int,int> >
#define rep(i, a, n) 	for (int i=a;i<n;++i)
#define per(i, a, n) 	for (int i=n-1;i>=a;--i)
#define clr				clear
#define pb 				push_back
#define mp 				make_pair
#define fir				first
#define sec				second
#define all(x) 			(x).begin(),(x).end()
#define SZ(x) 			((int)(x).size())
#define lson			l, mid, rt<<1
#define rson			mid+1, r, rt<<1|1
#define getBits(x)		__builtin_popcount(x)
#define getBitIdx(x)	__builtin_ffs(x)

typedef long long LL;
const int maxn = 105;
const int inf = 0x3f3f3f3f;
int g[maxn][maxn];
vector<pair<pii,int> > ve;
int n, m;

void floyd() {
	rep(i, 1, n+1) g[i][i] = 0;
	rep(k, 1, n+1) {
		rep(i, 1, n+1) {
			rep(j, 1, n+1) {
				g[i][j] = min(g[i][j], g[i][k]+g[k][j]);
			}
		}
	}
}

void solve() {
	int ans = 0;
	
	floyd();
	
	rep(i, 0, m) {
		int a = ve[i].fir.fir, b = ve[i].fir.sec, w = ve[i].sec;
		int flag = (g[a][b]==w) ? 0:1;
		
		// if (flag) {
			// rep(u, 1, n+1) {
				// rep(v, 1, n+1) {
					// if (g[u][a]+w+g[b][v] == g[u][v]) {
						// flag = 0;
						// goto _outside;
					// }
				// }
			// }
		// }
		
		_outside:
		ans += flag;
	}
	
	printf("%d\n", ans);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// #ifndef ONLINE_JUDGE
		// freopen("data.in", "r", stdin);
		// freopen("data.out", "w", stdout);
	// #endif
	
	int u, v, w;
	pair<int,int> p;
	
	scanf("%d %d", &n, &m);
	memset(g, inf, sizeof(g));
	rep(i, 0, m) {
		scanf("%d %d %d", &u, &v, &w);
		g[u][v] = min(g[u][v], w);
		g[v][u] = min(g[v][u], w);
		ve.push_back(mp(mp(u, v), w));
	}
	solve();
	
	// #ifndef ONLINE_JUDGE
		// printf("time = %ldms.\n", clock());
	// #endif
	
	return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define d  long double
//#define d long double
#define pii pair<int,int>
#define pb push_back
#define N 200003
#define inf (int)1e18
#define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
vector<int> adj[200003];

 int siz[200001];
 bool arr1[200001];
 int c=0;
 vector<int> curr;
 
 
 
 
  stack<int> s;

void dfs(int z)
{
    s.push(z);
    arr1[z]=true;
    while(!s.empty())
    {
        int k=s.top();
        c++;
        curr.pb(k);
        //cout<<k<<" ";
        s.pop();
       // cout<<a[1].size()<<endl;
        for(int i=0;i<adj[k].size();i++)
        {
//cout<<3<<endl;

            if(arr1[adj[k][i]]==false)
            {

                s.push(adj[k][i]);
                arr1[adj[k][i]]=true;
            }
        }




    }
}


int rootx(int arr[],int  n,int x)
{
    while(x!=arr[x])
    {
        arr[x]=arr[arr[x]];
        x=arr[x];
    }
    return x;


}

void unionx(int arr[],int n,int a,int b)
{
    int roota=rootx(arr,n,a);
     int rootb=rootx(arr,n,b);

    if(siz[roota]>=siz[rootb])
    {

        arr[rootb]=arr[roota];
        siz[roota]+=siz[rootb];
    }
    else
    {
         arr[roota]=arr[rootb];
        siz[rootb]+=siz[roota];


    }
}

    bool findx(int arr[],int n,int a,int b)
    {

        if(rootx(arr,n,a)==rootx(arr,n,b))
            return true;
        else
            return false;
    }



 
signed main()
{
    haha
    int n,m,k;
    cin>>n>>m>>k;
    
    int gh[n];
    memset(gh,0,sizeof(gh));
    int arr[n];
    pair<int,int> fri[m];
    pair<int,int> block[k];
    for(int i=0;i<n;i++)
    {
        siz[i]=1;
        arr[i]=i;
    }
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        x--;
        y--;
        fri[i]={x,y};
        adj[x].pb(y);
        adj[y].pb(x);
        unionx(arr,n,x,y);
    }
    for(int i=0;i<m;i++)
    {
        if(rootx(arr,n,fri[i].first)==rootx(arr,n,fri[i].second))
        {
            gh[fri[i].first]--;gh[fri[i].second]--;
            
        }
    }
   

  
    
    for(int i=0;i<n;i++)
    {
        if(!arr1[i])
        {
            dfs(i);
        }
        for(auto x:curr)
        gh[x]+=c-1;
        
        c=0;
        curr.clear();
        
    }
    for(int i=0;i<k;i++)
    {
        int x,y;
        cin>>x>>y;
        x--;
        y--;
        if(rootx(arr,n,x)==rootx(arr,n,y))
        {
            gh[x]--;
            gh[y]--;
        }
    }
   for(int i=0;i<n;i++)
   cout<<gh[i]<<" ";
    
    
    
    
}

Measured memory_bytes: 16756
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        final Integer[] HonPT = new Integer[] {2, 4, 5, 7, 9};
        final Integer[] PonPT = new Integer[] {0, 1, 6, 8};
        Scanner scan = new Scanner(System.in);
        char[] n = scan.nextLine().toCharArray();
        Integer num = Integer.parseInt(String.valueOf(n[n.length - 1]));
        //System.out.println(num);
        
        if (Arrays.asList(HonPT).contains(num)) {
            System.out.println("hon");
        } else if (Arrays.asList(PonPT).contains(num)) {
            System.out.println("pon");
        } else {
            System.out.println("bon");
        }

        scan.close();
    }
}


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


def f(n):
    if n == 0:
        return "0"

    if n % 2 == 0:
        return f(n // (-2)) + "0"
    else:
        return f((n - 1) // (-2)) + "1"


ans = f(N)
if ans[0] == "0" and len(ans)>=2:
    ans = ans[1:]
print(ans)


Measured memory_bytes: 2940
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	int a, b;
	cin >> a >> b;
	if (a + b >= 10) {
		cout << "error" << endl;
	}
	else {
		cout << a + b << endl;
	}

	return 0;
}

Measured memory_bytes: 256
from collections import Counter

n,m=map(int,input().split())
a=[int(i)%m for i in input().split()]

s=[0]
for i in range(1,n+1):
	s.append((s[i-1]+a[i-1])%m)
c=Counter(s)
ans=0
for i in c.keys():
	ans+=c[i]*(c[i]-1)//2
print(ans)


Measured memory_bytes: 16588
import sys
import copy
sys.setrecursionlimit(9**9)
H,W=map(int,input().split())
M=[list(input()) for _ in range(H)]
N=copy.deepcopy(M)
m=x=y=0
def d(c,P):
    global m,x,y
    Q=[]
    for p in P:
        h=p[0]
        w=p[1]
        if h!=H-1 and M[h+1][w]=='.':
            M[h+1][w]='#'
            Q.append([h+1,w])
        if h!=0 and M[h-1][w]=='.':
            M[h-1][w]='#'
            Q.append([h-1,w])
        if w!=W-1 and M[h][w+1]=='.':
            M[h][w+1]='#'
            Q.append([h,w+1])
        if w!=0 and M[h][w-1]=='.':
            M[h][w-1]='#'
            Q.append([h,w-1])
    if len(Q)!=0:
      c+=1
      return d(c,Q)
    else:
        m=max(m,c)
f=False
for i in range(H):
    for j in range(W):
        if M[i][j]=='.':
            M[i][j]='#'
            d(0,[[i,j]])
            M=copy.deepcopy(N)
print(m)

Measured memory_bytes: 3700
n=int(input())
s=input()
ans=0
for i in range(1,n):
    A=s[:i]
    B=s[i:]
    asu=[]
    cnt=0
    for a in A:
        if a in B and a not in asu:
            cnt+=1
        asu.append(a)
    ans=max(ans,cnt)
print(ans)


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

using namespace std;

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

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

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

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n; cin >> n;
  ll prv = -1;
  ll ans = 0;
  rep(i, n) {
    ll x; cin >> x;
    if (x == prv) {
      ++ans;
      x = -1;
    }
    prv = x;
  }
  cout << ans << endl;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

int main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n),b(n - 1);
	for (int i = 0; i < n - 1; i++) {
		std::cin >> b[i];
	}
	a[0] = b[0];
	for (int i = 1; i < n - 1; i++) {
		a[i] = std::min(b[i - 1], b[i]);
	}
	a.back() = b.back();
	std::cout << std::accumulate(a.begin(), a.end(), 0) << "\n";
	return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys
from itertools import chain


def cut_count(A, m):
    """最長の長さ(切り上げ)がm以下になるような切断回数"""
    total = 0
    for a in A:
        n = (a - 1) // m
        total += n
    return total


def solve(N: int, K: int, A: "List[int]"):
    r = max(A)
    l = 0
    while l + 1 < r:
        m = (r + l) // 2
        if cut_count(A, m) <= K:
            r = m  # r は K回以下の切断回数で到達できる長さ
        else:
            l = m  # l は K回より多いの切断回数で到達できる長さ
    # print(l, r)
    return r


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N, K, A = map(int, line.split())
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    answer = solve(N, K, A)
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 31160
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		A[i] -= i + 1;
	}
	sort(A.begin(), A.end());
	for (int i = 0; i < N; i++) {
		res += abs(A[i] - A[i / 2]);
	}
	cout << res << endl;
}

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

char field[14][14]; //3~10

void bomb(int y,int x)
{
    field[y][x] = '0';
    for(int i=-3;i<=3;i++){
        if(field[y][x+i] == '1')
            bomb(y,x+i);
        if(field[y+i][x] == '1')
            bomb(y+i,x);
    }
}
int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        for(int j=0;j<14;j++){
            for(int k=0;k<14;k++){
                field[j][k] = '0';
            }
        }
        for(int j=3;j<=10;j++){
            for(int k=3;k<=10;k++){
                cin >> field[j][k];
            }
        }

        int x,y;
        cin >> x >> y;
        bomb(y+3-1,x+3-1);
        cout << "Data " << i << ":" << endl;
        for(int j=3;j<=10;j++){
            for(int k=3;k<=10;k++){
                cout << field[j][k];
            }
            cout << endl;
        }
    
    }
    return 0;    
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
string m[21][21];

vector<vector<int>> dxy = {{1,0},{-1,0},{0,-1},{0,1}};
deque<pair<int,int>> dq;

int main() {
  int h,w;
  cin >> h>>w;
  string s;
  for (int i = 1;i<h+1;i++){
    cin >> s;
    for(int j = 1;j< w+1;j++){
      m[i][j] = s[j-1];
      //cout << i << " " << j << " " << s[j-1] << endl;
    }
  }
  int mx = 0;
  int cx,cy,nx,ny;
  int tmx = 0;
  pair<int, int>tmp;
  for (int i = 1;i<h+1;i++){
    for(int j = 1;j< w+1;j++){
      //cout << "start" << i << " " << j << endl;
      if(m[i][j] == "."){
        //cout << "start" << i << " " << j << endl;
        tmx = 0;
        int p[21][21] ={};
        p[i][j] = 1;
        //cout << p[1][2] << endl;
        dq.push_front({j,i});
      
        while(!dq.empty()){
          tmp = dq.back();
          dq.pop_back();
          for(int k = 0;k<4;k++){
            nx = tmp.first + dxy[k][0];
            ny = tmp.second + dxy[k][1];
            //cout << nx << " " <<ny <<endl;
            //cout << nx << " " <<ny << " " << m[ny][nx] << " " <<p[ny][nx] << endl;
            if(nx > 0 && nx < w +1 &&ny > 0 && ny < h+1 && m[ny][nx] != "#" && p[ny][nx] == 0){
              //cout << nx << " " <<ny << " " << p[tmp.second][tmp.first] << " " <<p[ny][nx] << endl;
            
              p[ny][nx] = p[tmp.second][tmp.first]+1;
              tmx = max(p[ny][nx],tmx);
              //cout << tmx << endl;
              dq.push_front({nx,ny});
              //cout << nx << " " << ny << endl; 
            }
          }
        }
      }
      //cout <<tmx << " " <<mx << endl;
      mx = max(mx,tmx);
    }
  }
  cout << mx-1 << endl;
 }

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

int main(){
  int n,a[1000],minx=1000000,i;
  cin >> n;
  while(n!=0){
    minx=1000000;
    for(i=0;i<n;i++)
      cin >> a[i];
    sort(a,a+n);
    for(i=0;i<n-1;i++)
      if(minx>a[i+1]-a[i])
        minx=a[i+1]-a[i];
    cout << minx << endl;
    cin >> n;
  }
}


Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
//priority_queue<int> pque;
//priority_queue<int, vector<int>, greater<int>> pque;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;

struct abc{int a,b,c;};

int main(void){
    int N,Ma,Mb;
    cin >> N >> Ma >> Mb;
    vector<abc> ABC(N);
    for(int i = 0; i < N; i++){
        cin >> ABC.at(i).a >> ABC.at(i).b >> ABC.at(i).c;
    }
    
    int dp[N+1][500][500];
    
    for(int i = 0; i <= N; i++){
        for(int j = 0; j < 500; j++){
            for(int k = 0; k < 500; k++){
                dp[i][j][k] = INF;
            }
        }
    }
    
    
    for(int i = 0; i <= N; i++){
        dp[i][0][0] = 0;
    }
    
    for(int i = 1; i <= N; i++){
        for(int j = 0; j < 500; j++){
            for(int k = 0; k < 500; k++){
                dp[i][j][k] = dp[i-1][j][k];
                if(j - ABC.at(i-1).a >= 0 && k - ABC.at(i-1).b >= 0){
                   dp[i][j][k] = min(dp[i][j][k]  ,dp[i-1][j - ABC.at(i-1).a][k - ABC.at(i-1).b] +ABC.at(i-1).c);  
                }
            }
        }
    }
    
    
    
    int ans = INF;
    
    for(int i = 1; i < 450; i++){
        for(int j = 1; j < 450; j++){
            if(dp[N][i][j] < INF / 2){
                if(i * Mb == j * Ma){
                    ans = min(dp[N][i][j], ans);
                }
            }
        }
    }
    
    
    
    if(ans > INF / 4){
        ans = -1;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 40320
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

template<class T>
bool chmin(T &a, const T &b) {
    if(a>b) {
        a=b;
        return true;
    }
    return false;
}
struct Edge {
    int to,d,c;
    Edge(int to=0,int d=0,int c=0) :
        to(to),d(d),c(c) {}
};

struct State {
    int v,u;
    int spd;
    double t;
    State(int v=0,int u=0,int spd=0,double t=0) :
        v(v),u(u),spd(spd),t(t){}

    bool operator<(const State &rhs) const {
        return t>rhs.t;
    }
};
int s,g;
int n,m;
vector<Edge> G[40];

double dijk() {
    // v,u,spd;
    double d[40][40][40];
    rep(i,40) rep(j,40) rep(k,40) d[i][j][k]=INF;
    //rep(i,40) d[s][i][1]=1;
    d[s][s][0]=0;

    priority_queue<State> que;
    que.push(State(s,s,0));
    while(que.size()) {
        State s=que.top(); que.pop();

        rep(i,G[s.v].size()) {
            Edge e=G[s.v][i];
            if(e.to==s.u) continue;
            for(int k=-1;k<=1;k++) {
                if(!(0<=s.spd+k&&s.spd+k<=e.c)) continue;
                if(s.spd+k<=0) continue;
                if(chmin(d[e.to][s.v][s.spd+k],d[s.v][s.u][s.spd]+1.0*e.d/(s.spd+k))) {
                    que.push(State(e.to,s.v,s.spd+k,d[e.to][s.v][s.spd+k]));
                }
            }
        }
    }
    double ret=INF;
    rep(i,40) chmin(ret,d[g][i][1]);

    return ret;

}

void solve() {
    rep(i,40) G[i].clear();
    cin>>s>>g;
    s--,g--;
    rep(i,m) {
        int x,y,d,c;
        cin>>x>>y>>d>>c;
        x--,y--;
        G[x].push_back(Edge(y,d,c));
        G[y].push_back(Edge(x,d,c));
    }
    double ans=dijk();
    if(ans==INF) cout<<"unreachable"<<endl;
    else printf("%.10f\n",ans);
}

int main() {
    while(cin>>n>>m) {
        if(n==0) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 2256
numbers = list(map(int, input()))

for x in range(8):
    su = numbers[0]
    s = (str(numbers[0]))

    for i in range(3):
        if x & (1 << i):
            su += numbers[i+1]
            s += '+'
            s += str(numbers[i+1])
        else:
            su -= numbers[i+1]
            s += '-'
            s += str(numbers[i+1])

    if su == 7:
        print(s + '=7')
        break


Measured memory_bytes: 3060
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
vector<int> v;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);

    int N, M;
    cin >> N >> M;
    int ans = 0;
    int cnt = 0;
    for (int i = 0; i < M; ++i)
    {
        int a, b;
        cin >> a >> b;
        int t = 0;
        if (a >= N)
            t = 0;
        else
        {
            t = N - a;
        }
        v.push_back(t);
    }
    sort(v.begin(), v.end());

    for (int i = 0; i < M - 1; ++i)
        ans += v[i];
    cout << ans << endl;
    return 0;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<string>a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	vector<string>b(m);
	for (int i = 0; i < m; i++)cin >> b.at(i);
	for (int i = 0; i < n - m + 1; i++) {
		for (int j = 0; j < n - m + 1; j++) {
			bool ans = true;
			for (int k = 0; k < m; k++) {
				if (b.at(k) != a.at(k + i).substr(j, m))ans = false;
			}
			if (ans) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
from itertools import accumulate
import math
import bisect

n,d,a = map(int,input().split())
xh = [tuple(map(int,input().split())) for _ in range(n)]
xh.sort()
x = [xh[i][0] for i in range(n)]
h = [xh[i][1] for i in range(n)]
damage = [0]*(n+1)
point = 0

for i in range(n):
    if i != 0:
        damage[i] += damage[i-1]
    bi = bisect.bisect(x,2*d+x[i])
    count = max(math.ceil((h[i]-damage[i])/a),0)
    damage[i] += a*count
    damage[bi] -= a*count
    point += count
    
print(point)

Measured memory_bytes: 41852
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007LL
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  105
#define tmod             998244353LL
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll SUMD(ll n);
ll BS(vector<pair< ll ,ll > > &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
ll P[N+1];
void Sieve(int n=N);
ll Powb(ll b,ll n,ll m);

int main()
{
fast;
ll q=1,t;
//cin >> q; t = q;
while(q--)
{
    ll i,j,n,m,k,l,r,a=0,b=0,c=0,d=0,e,g=1,p,u,v,w,x,y,flag=1;
    //n=m=k=i=j=l=r=a=b=c=d=u=v=w=p=x=y=0;
     l = 1000000000000000000;
    cin >> n;
    vector<ll> V(n);
    for(i=0;i<n;i++)
    {
        cin >> V[i];
        if(V[i]==0) c++;
    }
    if(c!=0) {cout << 0; return 0;}
    ll ans = 1;
    for(i=0;i<n;i++)
    {
        if(l%V[i]==0 and ans > l/V[i])
            {cout << -1 ; return 0;}
        else if( l%V[i]!=0 and ans >= (l + V[i] - 1)/V[i])
            {cout << -1 ; return 0;}
        else ans *= V[i];
        if(ans > l) {cout << -1; return 0;}
    }
    if(ans>l) cout << -1;
    else cout << ans;

}
    return 0;
}

//*****************************************************************************************************************************************

ll Powb(ll b,ll n,ll m)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2,m);
    if(n%2==0){return (temp*temp)%m;}
    else{return (b*((temp*temp)%m))%m;}
}

ll SUMD(ll n)
{   ll sum=0;
    while(n>0){sum += n%10;n = n/10;}
    return sum;

}
ll BS(vector<pair<ll,ll> > &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid].F==ser)
    {
        return mid;
    }
    else if(PS[mid].F > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

void Sieve(int n)
{
    //memset(P,true,sizeof(P));
    //P[0] = false;
    //P[1]= false;
    for(int i=1;i<=n;i++) P[i] = i;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i]==i)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                if(P[j]==j)
                    P[j]=i;
            }
        }
    }

}



Measured memory_bytes: 3972