akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//#include<iostream>
using namespace std;

typedef long long ll;

const int N = 200005;
const int INF = 100000000;
int n,m;
string s;

int dst[N];
bool vstd[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin>>n>>m;
	cin>>s;
	
	reverse(s.begin(),s.end());
	
	for(int i=0;i<n+1;i++){
		if(s[i] == '1'){
			vstd[i] = true;
			dst[i] = INF;
		}
	}
	
	priority_queue<pair<int,int> > pq;
	pq.push({0,0});
	dst[0] = 0;
	for(int i=1;i<=n;i++){
		if( i - m - 1 >= 0 ){
			vstd[i-m-1] = true;
		}
		if(vstd[i]){
			continue;
		}
		while(!pq.empty() && vstd[pq.top().second])pq.pop();
		if(pq.empty()){
			dst[i] = INF;
			continue;
		}
		dst[i] = -pq.top().first + 1;
		pq.push({-dst[i],i});
	}
	
	if(dst[n] == INF){
		cout<<-1;
		return 0;
	}
	/*
	for(int i=0;i<=n;i++){
		cout<<dst[i]<<" ";
	}cout<<endl;
	*/
	vector<int> sol;
	sol.clear();
	int lst = dst[n],idx = n;
	for(int i=n;i>=0;i--){
		if(dst[i] < lst){
			sol.push_back(idx-i);
			lst = dst[i];
			idx = i;
		}
	}
	
	//reverse(sol.begin(),sol.end());
	for(int x: sol){
		cout<<x<<" ";
	}
	
	return 0;
}


Measured memory_bytes: 4824
#include<iostream>
#include <vector>
#include<algorithm>
typedef long long int ll;
using namespace std;
const ll INF = 2000000;
int main()
{
	long long h, w; cin >> h >> w; int goi;
	long long ans = INF;
	if (h*w % 3 == 0) { cout << 0; }
	else {
		for (int i = 0; i < 2; i++)
		{
			for (int j = 0; j <= w; j++)
			{
				vector<long long> v(3);
				v[0] = j*h;
				v[1] = (w - j)*(h / 2);
				v[2] = h*w - v[0] - v[1];
				goi = min(ans, max(v[0], v[2]) - min(v[0], v[1]));
				if (goi)ans = goi;
				v[0] = j*h;
				v[1] = (w - j) / 2 * h;
				v[2] = w*h - v[0] - v[1];
				goi = min(ans, (max(v[0], v[2]) - min(v[0], v[1])));
				if (goi)ans = goi;
			}
			swap(h, w);
		}
		ans = min(w, ans); ans = min(ans, h);
		cout << ans << endl;
		return 0;
	}
}


Measured memory_bytes: 256
n = int(input())
a = ["AC"] * n
c = [0]*4

for i in range(n):
  a[i] = input()
  if(a[i]=="AC"):
    c[0] += 1
  if(a[i]=="WA"):
    c[1] += 1
  if(a[i]=="TLE"):
    c[2] += 1
  if(a[i]=="RE"):
    c[3] += 1

print("AC x " +str(c[0]))
print("WA x " +str(c[1]))
print("TLE x " +str(c[2]))
print("RE x " +str(c[3]))



Measured memory_bytes: 16016
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
#define PI 3.1415926535897932384626433832795028
#define INF (1<<29)
#define LINF (1LL<<60)
using namespace std;
using INT = long long;
using P = pair<int,int> ;

int main(){
    int n,ans=0;
    cin >> n;
    int p[n];
    rep(i,n) cin >> p[i];
    for(int i=1; i+1<n ;i++){
        if((p[i]>p[i-1]&&p[i]<p[i+1])||(p[i]<p[i-1]&&p[i]>p[i+1])){
            ans++;
        }
    }
    cout << ans << endl;
	return 0;
}



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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 1 << 20;
const lli mod = 1000000007;
const lli e3 = 1 << 13;
const lli INF = 1ll << 62;

lli n;
lli p[e5];
lli ans;

lli solve(lli i,lli j,lli k){
  if(i == j || i == k || j == k) return 0;
  if(p[i] < 2) return 0;
  if(p[j] < 4) return 0;
  if(p[k] < 4) return 0;
  return 1;
}

lli solve2(lli i,lli j){
  if(i == j) return 0;
  if(p[i] < 14) return 0;
  if(p[j] < 4) return 0;
  return 1;
}

lli solve3(lli i,lli j){
  if(i == j) return 0;
  if(p[i] < 24) return 0;
  if(p[j] < 2) return 0;
  return 1;
}

int main(){
  cin >> n;
  for(lli i = 1;i <= n;i++){
    lli x = i;
    lli j = 2;
    while(x != 1){
      while(x%j != 0) j++;
      x /= j;
      p[j]++;
    }

  }
  for(lli i = 0;i <= n;i++){
    cerr << p[i] << endl;
  }
  for(lli i = 0;i <= n;i++){
    for(lli j = 0;j <= n;j++){
      for(lli k = j+1;k <= n;k++){
        ans += solve(i,j,k);
      }
    }
  }
  for(lli i = 0;i <= n;i++){
    for(lli j = 0;j <= n;j++){
      ans += solve2(i,j);
      ans += solve3(i,j);
    }
  }
  for(lli i = 0;i <= n;i++){
    if(p[i] >= 74) ans++;
  }
  cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6;
const ll LINF = 1e18;
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl

ll n, cnt, ans, a[ohara], b, c, d, tmp, tmpp, m, h, w, x, y, sum, pos, k;
ld doua;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
bool fl;
struct edge
{
    int to, cost;
};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin >> n >> x;
    rep(i, n) cin >> a[i];
    rep(i, n - 1)
    {
        sum = a[i] + a[i + 1];
        if (sum <= x)
            continue;
        ll her;
        her = sum - x;
        ans += her;
        a[i + 1] -= her;
        if (a[i + 1] < 0)
        {
            ll maina;
            maina = a[i + 1];
            a[i + 1] = 0;
            a[i] += maina;
        }
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    int n,q,a[100000]={0},i;
    string s;
    cin >> n >> q >> s;
    for(i=1;i<n;i++){
        if(s[i-1]=='A' and s[i]=='C') a[i] = a[i-1]+1;
        else a[i]=a[i-1];
    }
    for(i=0;i<q;i++){
        int x,y;
        cin >> x >> y;
        cout << a[y-1]-a[x-1] << endl;;
    }
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	auto func = [](int y){
		if(!(y%400)) return true;
		else if(!(y%100)) return false;
		else if(!(y%4)) return true;
		return false;
	};

	for(int N=0;;N++){
		int a=in(),b=in();
		if(!a && !b) break;
		if(N) out();
		int flag = false;
		for(int i=a;i<=b;i++){
			if(func(i)){
				flag = true;
				out(i);
			}
		}
		if(!flag) out("NA");
	}
	return 0;
}


Measured memory_bytes: 3132
#include <iostream>
using namespace std;
int main() {
  int a ,b,coast;
  cin >> a >> b;
  if (a >=13){
    coast = b;
    }
  else if (a>=6 && a <= 12 ){
    coast = b/2;
  }
  else{
    coast =0;
  }
    
cout << coast;

return 0;
 }

Measured memory_bytes: 256
w,h,n = map(int,input().split())
a1 = [0]
a2 = [w]
a3 = [0]
a4 = [h]

for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        a1.append(x)
    elif a == 2:
        a2.append(x)
    elif a == 3:
        a3.append(y)
    else:
        a4.append(y)
        
xl = max(a1)
xh = min(a2)
yl = max(a3)
yh = min(a4)

if xh - xl < 0:
    ansx = 0
else:
    ansx = xh - xl
if yh - yl < 0:
    ansy = 0
else:
    ansy = yh - yl
print(ansx * ansy)

Measured memory_bytes: 3064
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void run() {
		boolean[] primes = new boolean[10001];
		primes[0] = primes[1] = true;
		for (int i = 2; i <= 10000; i++) {
			if (primes[i]) continue;
			for (int j = i+i; j <= 10000; j += i)
				primes[j] = true;
		}
		while (sc.hasNext()) {
			int n = sc.nextInt();
			int res = 0;
			for (int i = 1; i <= n/2; i++) {
				if (!primes[i] && !primes[n-i+1]) res++;
			}
			int r = (n%2!=0 && !primes[n/2+1]) ? 1 : 0;
			out.println(2*res+r);
		}
		
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 24164
from fractions import gcd

A, B, C, D = map(int, input().split())

if A % C == 0:
    cc = B // C - A // C + 1
else:
    cc = B // C - A // C
if A % D == 0:
    dd = B // D - A // D + 1
else:
    dd = B // D - A // D

E = int(C * D / gcd(C, D))
if A % E == 0:
    cd = B // E - A // E + 1
else:
    cd = B // E - A // E
print(int((B - A + 1) - cc - dd + cd))

Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
#define PI acos(-1)
typedef long long ll;
int main()
{
    int x,y500,n,y5,ans;
    cin >> x;
    y500 = 1000*(x/ 500);
    n = x % 500;
    y5 = 5 * (n / 5);
    ans = y500 + y5 ;
    cout << ans<< endl;

    return 0;

}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

int main(int argc, char ** argv) {
	ll n;
	cin >> n;
	vi a(n,0);
	vi pre(n,0);
	for(ll i=0; i<n; i++) {
		cin >> a[i];
		if(i == 0) pre[i] = a[i];
		else pre[i] = pre[i-1]+a[i];
	}
	ll ans = abs(pre[n-1]-pre[0]-pre[0]);
	for(ll i=0; i<n-1; i++) {
		ans = min(ans, abs((pre[n-1] - pre[i]) - pre[i]));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>

int main(){
  int num,i;
  int f[50];

  scanf("%d",&num);

  f[0]=f[1]=1;

  for(i=2;i<=num;i++){
    f[i]=f[i-1]+f[i-2];
  }
  printf("%d\n",f[num]);

  return 0;
}



Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <cmath>

int main() {
  int N, X;
  std::cin >> N >> X;

  int mn = 1<<30, sm = 0;

  for (int i = 0; i < N; i++) {
    int m;
    std::cin >> m;

    mn = std::min(mn, m);
    sm += m;
  }

  std::cout << N + (X - sm) / mn << std::endl;
}


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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cerr << #a << " = " << a << endl

//const int inf = 1001001001;
//const int mod = (int)1e9+7;
const ll inf = 1e15;
const ll mod = 1e9+7;

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

int main() {
    ll X;
    cin >> X;

    ll balance = 100;
    REP(i, inf) {
        balance *= 1.01;
        if (balance >= X) {
            cout << i+1 << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3624
package main

import (
  "fmt"
)

func main() {
  var n int 
  var m uint
  fmt.Scan(&n, &m)
  res := 1 << m - 1
  for i := 0; i < n; i++ {
    var k int 
    fmt.Scan(&k)
    like := 0
    for j := 0; j < k; j++ {
      var a uint 
      fmt.Scan(&a); a--
      like |= 1 << a
    }
    res &= like 
  }
  cnt := 0
  for i := uint(0); i < m; i++ {
    if res >> i & 1 == 1 {cnt++}
  }
  fmt.Println(cnt)

}

Measured memory_bytes: 512
// https://onlinejudge.u-aizu.ac.jp/beta/room.html#KUPC2020Spring/problems/A
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<int> v(4);
    for (auto &x : v) {
        cin >> x;
    }
    sort(ALL(v));
    cout << abs(v[0] + v[3] - v[1] - v[2]) << endl;
    return 0;
}



Measured memory_bytes: 3212
n, m = map(int, input().split())
s_list = []
c_list = []

is_err = False
def has_err(seq):
    if 1 != len(set(seq)):
        return True
    else:
        return False

for _ in range(m):
    s, c = map(int, input().split())
    s_list.append(s)
    c_list.append(c)
    if (s, c) == (1, 0) and n != 1:
        is_err = True
    if s in s_list:
        ix_list = [i for i, x in enumerate(s_list) if x == s]
        if has_err([x for i, x in enumerate(c_list) if i in ix_list]):
            is_err = True

if is_err:
    print('-1')
    quit()

if (n, m) == (1, 0):
    print(0)
    quit()

int_dict = {}
for s, c in zip(s_list, c_list):
    int_dict.update({"{}".format(s):c})

for i in range(1,n+1):
    if str(i) not in int_dict.keys() and i == 1:
        int_dict.update({"{}".format(i):1})
    elif str(i) not in int_dict.keys() and i != 1:
        int_dict.update({"{}".format(i):0})

ans = 0
for k, v in int_dict.items():
    ans += 10**(n-int(k))*v

print(ans)

Measured memory_bytes: 3064
#
# abc042 a
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5 5 7"""
        output = """YES"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """7 7 5"""
        output = """NO"""
        self.assertIO(input, output)


def resolve():
    L = list(input().split())
    if L.count("5") == 2 and L.count("7") == 1:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16020
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
const int MOD = (int)1e9 + 7;
const int INF = 1LL << 60;
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; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
struct mint {
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime MOD
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> &P){
    os << P.first;
    os << " ";
    os << P.second;
    os << "\n";
    return os;
}
mint dfs(int now,int from);
//fixed<<setprecision(10)<<ans<<endl;
int N,K;
vector<vector<int>> edge;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K ;
    edge.resize(N);
    REP(i,N-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    mint ans = dfs(0,-1)*K;

    cout << ans.x << endl;
}

mint dfs(int now,int from){
    if (edge[now].size() >=K) return 0;
    int can_color_num; //nowの子に使える色の種類
    if(from==-1){//親がいないならnowに使った色以外使える
        can_color_num = K-1;
    }else{//nowとnowの親以外の色を使える
        can_color_num = K-2;
    }

    mint res = 1;
    for(auto to:edge[now]){
        if(to==from) continue;
        res*=can_color_num--;
        res*=dfs(to,now);
    }
    return res;
}

Measured memory_bytes: 11648
#include <bits/stdc++.h>
#define int long long int
#define gif(a,b) (a/b +(a%b?1:0))
#define pi 3.14159265358
#define watch(x) cout<<(#x)<<" is "<<(x)<<"\n";
#define float long double
using namespace std;

int32_t main()
{   
    cin.tie(NULL);
    std::ios::sync_with_stdio(false);
    int m;
	cin >> m;
	int a[m-1], b[m];
	for(int i = 0; i < m; ++i)
		b[i] = 0;
	for(int i = 0; i < m - 1; ++i)
	{
		cin >> a[i];
		b[a[i]-1]++;
	}
	for(int i = 0; i < m; ++i)
		cout << b[i] << "\n";
    return 0;
}


Measured memory_bytes: 6732
S = input()
ue2 = int(S[0:2])
sita2 = int(S[2:4])
ue2_month_flag = False
sita2_month_flag = False

if ue2 < 13 and ue2 != 0:
    ue2_month_flag = True
if sita2 < 13 and sita2 != 0:
    sita2_month_flag = True

if ue2_month_flag and sita2_month_flag:
    print('AMBIGUOUS')
elif ue2_month_flag:
    print('MMYY')
elif sita2_month_flag:
    print('YYMM')
else:
    print('NA')


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


def is_loadable(pack: list, k: int, P: int):
    _tmp = 0
    counter = 1
    for w in pack:
        if _tmp + w > P:
            _tmp = w
            counter += 1
        else:
            _tmp += w
        if counter > k or w > P:
            return False
    return True


n, k = [int(i) for i in input().strip().split()]
pack = [None] * n
for i in range(n):
    pack[i] = int(input())

right = sum(pack)
left = max(pack)

while left < right:
    mid = (left + right) // 2
    if is_loadable(pack, k, mid):
        right = mid
    else:
        left = mid + 1

print(left)



Measured memory_bytes: 9416
n = int(input())
da = [list(map(int,input().split())) for i in range(n)]

now = da[0]
for i in range(1,n):
    co = max((now[0] - 1)// da[i][0], (now[1] - 1)// da[i][1])
    co += 1
    now[0] = da[i][0] * co
    now[1] = da[i][1] * co
print(now[0] + now[1])

Measured memory_bytes: 3188
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

vector<edge> G[5001*50];
vl d(5001*50,INF);

void dijkstra(ll s){
  d[s]=0;
  priority_queue<P,vP,greater<P>> pq;
  pq.push({0,s});
  while(pq.size()){
    P p=pq.top();
    pq.pop();
    ll v=p.second,c=p.first;
    if(c>d[v]){
      continue;
    }
    rep(i,(ll)G[v].size()){
      edge e=G[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        pq.push({d[e.to],e.to});
      }
    }
  }
}

int main() {
  ll n,m,s;
  cin >> n >> m >> s;
  if(s>5000){
    s=5000;
  }
  rep(i,m){
    ll u,v,a,b;
    cin >> u >> v >> a >> b;
    u--;v--;
    FOR(j,a,5001){
      G[5001*u+j].pb(edge{5001*v-a+j,b});
      G[5001*v+j].pb(edge{5001*u-a+j,b});
    }
  }
  rep(i,n){
    ll C,D;
    cin >> C >> D;
    if(C>5000){
      C=5000;
    }
    rep(j,5000){
      G[5001*i+j].pb(edge{min(5001*i+5000,5001*i+C+j),D});
    }
  }
  dijkstra(s);
  FOR(i,1,n){
    ll ans=INF;
    rep(j,5001){
      ans=min(ans,d[5001*i+j]);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 44432
#include <stdio.h>
#define MAX 100005
using namespace std;

int n,a[MAX],ans[MAX]; 
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		ans[a[i]]=i;
	}
	for(int i=1;i<=n;i++){
		if(i==1) printf("%d",ans[i]);
		else printf(" %d",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 1536
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
// it is a knapsack dummy
int knp(int wei[],int val[],int n,int mxl){
	int dp[n+1][mxl+1]; // consider items for all possible weight
	//for(int i=0;i<n;++i) cout<<wei[i]<<" "<<val[i]<<"\n";
	for(int i=0;i<=n;++i) for(int j=0;j<=mxl;++j){
		if(i==0 || j==0) dp[i][j]=0;
		else if(wei[i-1]<=j) {
			// consider the weight
			dp[i][j] = max(val[i-1]+dp[i-1][j-wei[i-1]],dp[i-1][j]);
			// either include or not
		}
		else {
			// now i cannot include it 
			dp[i][j]=dp[i-1][j];
		}
	}
	//for(int i=0;i<=n;++i){
	//	for(int j=0;j<=mxl;++j) cout<<dp[i][j]<<" ";
	//	cout<<"\n";
	//}
	return dp[n][mxl]; // all items considered
}
int knp2(int wei[],int val[],int n,int mxl,bool inc[]){
	int dp[n+1][mxl+1]; 
	for(int i=0;i<=n;++i) for(int j=0;j<=mxl;++j){
		if(i==0 || j==0) dp[i][j]=0;
		else if(wei[i-1]<=j) {
			dp[i][j] = max(val[i-1]+dp[i-1][j-wei[i-1]],dp[i-1][j]);
		}
		else {
			dp[i][j]=dp[i-1][j];
		}
	}
	// if it comes form top -> not include else include
	// for minimum we if include == not include then not include;
	int ans=dp[n][mxl];
	int curr_w=mxl;
	for(int i=n;i>0;--i){
		if(ans<=0) break; // no solution
		if(ans==dp[i-1][curr_w]) continue; // not include
		else{
			// include
			inc[i-1]=1;
			ans-=val[i-1]; curr_w-=wei[i-1];
		}
	}
	return dp[n][mxl]; 
}
vector<int> prime;
void seive(){
	int arr[200005]={0};
	for(int i=2;i<200005;++i){
		if(arr[i]==0){
			prime.push_back(i);
			for(int j=2*i;j<200005;j+=i)
				arr[j]=1;
		}
	}
}
int fx(int n){
	for(auto it : prime){
		if(n%it==0) return it;
	}
	return n;
}
int lcm(int a,int b){
	a/=__gcd(a,b);
	return a*b;
}
void solve(){
	int n,k; cin>>n>>k;
	int a[n],b[n];
	for(int i=0;i<n;++i) cin>>a[i];
	for(int i=0;i<n;++i) cin>>b[i];
	sort(a,a+n);
	sort(b,b+n);
	int i=0,j=n-1;
	while(i<n && a[i]<b[j]){
		a[i]=b[j];
		++i; --j;
	}
	int s=0;
	for(int i=0;i<n;++i) s+=a[i];
	cout<<s<<"\n";
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int k; cin>>k;
	string s; cin>>s;
	int n=s.size();
	if(n<=k) cout<<s;
	else{
		for(int i=0;i<k;++i) cout<<s[i];
			cout<<"...";
 	}
	return 0;
}



Measured memory_bytes: 3664
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for(int (i) = (n)-1; (i) >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define FI first
#define SE second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
}



int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int k;
  cin >> k;
  vector<int> r(8, -1);
  rep(i,k) {
    int y, x;
    cin >> x >> y;
    r[x] = y;
  }
  vector<int> ar(8);
  rep(i,8) ar[i] = i;
  do {
    bool ok = true;
    rep(i,8) if(r[i] >= 0 && r[i] != ar[i]) ok = false;
    if(!ok) continue;
    vector<vector<char>> f(8, vector<char>(8, '.'));
    rep(i,8) if(ar[i] >= 0) f[i][ar[i]] = 'Q';
    rep(i,8) {
      rep(j,8) if(j != i && ar[i] != ar[i]+(j-i)
      && ar[i]+(j-i) >= 0 && ar[i]+(j-i) < 8
      && f[j][ar[i]+(j-i)] == 'Q') ok = false;
      rep(j,8) if(j != i && ar[i] != ar[i]-(j-i)
      && ar[i]-(j-i) >= 0 && ar[i]-(j-i) < 8
      && f[j][ar[i]-(j-i)] == 'Q') ok = false;
    }
    if(ok) {
      rep(i,8) {
        rep(j,8) cout << f[i][j] << (j == 7 ? "\n" : "");
      }
      break;
    }
  } while(next_permutation(all(ar)));
  return 0;
}


Measured memory_bytes: 3220
def test():
    s = list(input())
    t = list(input())
    n = min(len(s),len(t))
    s.sort(); t.sort(reverse=True)
    for i in range(n):
        if s[i] < t[i]:
            print("Yes")
            return
        elif s[i] > t[i]:
            print("No")
            return
        elif s[i] == t[i]:
            pass
    if len(s) < len(t):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    test()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void DFS(vector<vector<int>>& Tree, vector<int>& C, vector<int>& D, int di, int& ci) {
	if (D[di] > 0) return;
	D[di] = C[ci];
	ci++;
	for (int dj : Tree[di]) DFS(Tree, C, D, dj, ci);
};

int main() {
	int N;
	cin >> N;
	vector<vector<int>> Tree(N);
	vector<pair<int, int>> Edges(N - 1);
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		Tree[a - 1].push_back(b - 1);
		Tree[b - 1].push_back(a - 1);
		Edges[i] = { a - 1,b - 1 };
	}
	vector<int> C(N), D(N,-1);
	for (int i = 0; i < N; i++) cin >> C[i];
	sort(C.begin(), C.end(), greater<int>());
	int ci = 0;
	DFS(Tree, C, D, 0, ci);
	int sum = 0;
	for (auto& p : Edges) sum += min(D[p.first],D[p.second]);
	cout << sum << endl;
	for (int d : D) cout << d << " ";
	cout << endl;
}

Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn=2e5+100;
int par[maxn],sum[maxn];
int N,K,p,tot;

void init(int n)
{
    for(int i=0;i<=n;i++)
        par[i]=i;
}

int find(int x)
{
    if(par[x]==x)
        return x;
    return par[x]=find(par[x]);
}
void unit(int x,int y)
{
    int fx=find(x),fy=find(y);
    if(fx!=fy)
        par[fx]=fy;
}
bool same(int x,int y)
{
    return find(x)==find(y);
}
int main()
{
    while(~scanf("%d%d",&N,&K))
    {
        int ans=0;
        memset(sum,0,sizeof(sum));
        memset(par,0,sizeof(par));
        tot=0;
        init(N);
        int t;
        scanf("%d",&t);
        sum[t]++;
        p=t;
        tot++;
        for(int i=2;i<=N;i++)
        {
            scanf("%d",&t);
            sum[t]++;
            if(!same(t,p))
            {
                tot++;
               // printf("%d %d\n",tot,t);
                unit(t,p);
            }
        }
        sort(sum,sum+N+1);
       // printf("tot=%d\n",tot);
        if(tot<=K)
            ans=0;
        else
        {
            int cnt=tot-K;
            int pos=lower_bound(sum,sum+N+1,1)-sum;
          //  printf("pos=%d\n",pos);
            while(cnt--)
                ans+=sum[pos++];
        }
        printf("%d\n",ans);
    }
    return 0;
}


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

//int _; 
 
string s;

int main()
{
	//for(scanf("%d",&_);_;_--)
	cin >> s;
	for(int i=0;i<s.size();i++)
		cout << 'x';
	puts("");
	return 0;
}

Measured memory_bytes: 256
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def r_sort(a) a.sort{|a,b|b<=>a} end

def search(x,d)
  return 1 if(d >= @memo[0].size)
  if(@memo[x][d] === false)
    p -1
    exit
  end
  return @memo[x][d] if(@memo[x][d] != nil)
  @memo[x][d] = false
  nx = @t[x][d]-1
  nd = @mem[nx][x]+1
  hyo = [search(nx,nd),search(x,d+1)].max + 1
  @memo[x][d] = hyo
  return hyo
end

n = inp[0]
@t= []
@memo = na2(n,n-1,nil)
@mem = na2(n,n,nil)
n.times do
  @t.push(inp)
end
n.times do |i|
  (n-1).times do|j|
    @mem[i][@t[i][j]-1] = j
  end
end

ans = 0
n.times do |i|
  ans = [ans,search(i,0)].max
end

p ans-1


Measured memory_bytes: 29180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

int main(){
  int A,B;
  cin >> A >> B;
  string s;
  cin >> s;
  rep(i,A+B+1){
    if(s[A]!='-'){
      cout << "No" << endl;
      return 0;
    }
    if(i!=A && (((int)s[i]-'0')>9 || ((int)s[i]-'0')<0)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" <<  endl;
  return 0;

}


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

#define fi first
#define se second
#define pb push_back
#define ll long long

const int N = 5e4 + 7;

using namespace std;

int n , m;
ll used[N];
int cnt  , sum  , a , x , y;
int main(){
    ios_base::sync_with_stdio(false);
   cin >> n >> m;
   for( int i = 0;i <= 100;i ++ ){
    for( int j = 0;j <= 100;j ++ ){
        if( i * 2 + j * 4 == m and i + j == n )
            return cout << "Yes" , 0;
    }
   }
   cout << "No";
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007

struct edge {
    int to; 
    int weight;
    edge(int t, int w) : to(t),weight(w) {}
};

using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<edge>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;


int main(){

    int n; cin >> n;
    Graph G(n);
    rep(i,n-1){
        int a,b,w; cin >> a >> b >> w;
        a--;b--;
        G.at(a).push_back(edge(b,w));
        G.at(b).push_back(edge(a,w));
    }

    vector<int> ans(n,-1);
    queue<edge> q;
    ans.at(0) = 0;
    q.push(edge(0,0));
    while(!q.empty()){
        edge v = q.front();
        q.pop();
        for(auto nv : G.at(v.to)){
            if(ans.at(nv.to) != -1) continue;
            ans.at(nv.to) = (ans.at(v.to)+nv.weight)%2;
            q.push(nv);
        }
    }
    rep(i,n) cout << ans.at(i) << endl;

    return 0;
}


Measured memory_bytes: 6784
#include <iostream>

int main() {
	int n, m, target[100];
	std::cin >> n >> m;
	for (int i = 0; i < m; i++) {
		std::cin >> target[i];
	}
	int score[100] = {}, d[100];
	for (int i = 0; i < m; i++) {
		//d[0] ~ d[j] をゲームごとに何度も流用する（1ゲーム終わったらjを初期化）が
		//スコアはしっかり保存してあげる
		for (int j = 0; j < n; j++) {
			std::cin >> d[j];
			if (target[i] == d[j]) {
				score[j] += 1;
			}else{
				score[target[i] - 1] += 1;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		std::cout << score[i] << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3088
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

alias Yoko = Tuple!(int, "h", int, "p", int, "q");

void main() {

    while (1) {
        int n, m, a;
        scan(n,m,a);

        if(!n) return;

        auto y = new Yoko[](m);

        foreach (i ; 0 .. m) {
            int hi, pi, qi;
            scan(hi,pi,qi);
            y[i] = Yoko(hi, pi, qi);
        }

        y.sort!"a > b"();

        auto am = iota(n + 1).array;

        foreach (yi ; y) {
            swap(am[yi.p], am[yi.q]);
        }

        writeln(am.countUntil(a));
    }
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 3476
// Last Change: 06/29/2019 21:08:11.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (auto &&e : p) {
    cin >> e;
  }

  int ans = 0;

  int maxP, minP, sumP;
  for (int i = 2; i < n; ++i) {
    maxP = max(p[i - 2], max(p[i - 1], p[i]));
    minP = min(p[i - 2], min(p[i - 1], p[i]));
    sumP = p[i - 2] + p[i - 1] + p[i];
    if (p[i - 1] == sumP - maxP - minP) {
      ++ans;
    }
  }

  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 888
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
    int a;
    long long int b, cost;
    scanf("%d %lld", &a, &b);
    if(a >= 13)
        cost = b;
    else if(a >= 6 && a <= 12)
        cost = b / 2;
    else
        cost = 0;
    printf("%d\n", cost);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(obj) (obj).begin(),(obj).end()
typedef long long llong;
llong mod=1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  llong h,to,n;
  cin>>h>>n;
  llong a[10000] ,b[10000],ck[10000];
  for(llong i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }

  for(llong i=0;i<=h;i++)ck[i]=mod;

  for(llong i=1;i<=h;i++){
    llong l;
    for(llong j=0;j<n;j++){
      if(i<=a[j]){
        l=0;
      }
      else{
        l=ck[i-a[j]];
      }
      if(ck[i]>(l+b[j])){
        ck[i]=l+b[j];
      }
    }
  }
  cout<<ck[h]<<endl;
  return 0;
  }


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

#define st first
#define nd second
typedef long long LL;
typedef pair <int, int> PII;
typedef pair <LL, LL> PLL;

const int N = 100, C = 26;
int C1[C + 1], C2[C + 1];
char Tab[N + 1];

int main()
{
    int n;
    scanf("%d %s", &n, Tab);
    string w = Tab;

    for (int i = 0; i < (int)w.size(); ++i)
        ++C1[(int)(w[i] - 'a')];
    
    int result = 0;
    for (int i = 0; i < (int)w.size(); ++i)
    {
        int l = (int)(w[i] - 'a'), counter = 0;
        --C1[l]; ++C2[l];
        for (int j = 0; j < C; ++j)
            if (C1[j] && C2[j])
                ++counter;
        result = max(result, counter);
    }

    printf("%d", result);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[228];
int main () {
    cin >> n;
    n *= 2;
    for ( int i = 0 ; i < n ; i ++ ){
        cin >> a[i];
    }
    sort( a, a+n );
    int ans = 0;
    for ( int i = 0 ; i < n ; i += 2 ) {
        ans += a[i];
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
    public static void main(String[] args) {
	try{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	while(true){
	    String line = reader.readLine();
	    int w = Integer.parseInt(line);
	    int s;
	    if(w==-1)break;
	    if(w<=10) {
		s = 1150;
	    }else if(w<=20) {
		s=1150+125*(w-10);
	    }else if(w<=30) {
		s=1150+1250+140*(w-20);
	    }else {
		s=1150+1250+1400+160*(w-30);
	    }
	    int x = 4280-s;
	    System.out.println(x);
	}
        }catch(IOException e){
	    System.out.println(e);
        }
    }
}

Measured memory_bytes: 16880
#include<cstdio>  
#include<cstring>  
#include<iostream>  
#include<algorithm>  
#define LL long long  
using namespace std;  
  
struct good  
{  
    int w,v;  
}g[110];  
  
bool cmp(good a,good b)  
{  
    return a.v > b.v;  
}  
good A[110],B[110],C[110],D[110];  
  
LL swa[110],swb[110],swc[110],swd[110];//重量的前缀和  
LL sva[110],svb[110],svc[110],svd[110];//价值的前缀和  
  
int main(void)  
{  
    int n,w,i,j,k,l;  
    int a,b,c,d;  
    while(scanf("%d%d",&n,&w)==2)  
    {  
        a = b = c = d = 0;  
        for(i=1;i<=n;i++)  
        {  
            scanf("%d%d",&g[i].w,&g[i].v);  
            if(g[i].w == g[1].w)  
                A[++a] = g[i];  
            if(g[i].w == g[1].w + 1)  
                B[++b] = g[i];  
            if(g[i].w == g[1].w + 2)  
                C[++c] = g[i];  
            if(g[i].w == g[1].w + 3)  
                D[++d] = g[i];  
        }  
        sort(A+1,A+a+1,cmp);  
        sort(B+1,B+b+1,cmp);  
        sort(C+1,C+c+1,cmp);  
        sort(D+1,D+d+1,cmp);  
        swa[0] = swb[0] = swc[0] = swd[0] = 0;  
        sva[0] = svb[0] = svc[0] = svd[0] = 0;  
        for(i=1;i<=a;i++)  
        {  
            swa[i] = swa[i-1] + A[i].w;  
            sva[i] = sva[i-1] + A[i].v;  
        }  
        for(i=1;i<=b;i++)  
        {  
            swb[i] = swb[i-1] + B[i].w;  
            svb[i] = svb[i-1] + B[i].v;  
        }  
        for(i=1;i<=c;i++)  
        {  
            swc[i] = swc[i-1] + C[i].w;  
            svc[i] = svc[i-1] + C[i].v;  
        }  
        for(i=1;i<=d;i++)  
        {  
            swd[i] = swd[i-1] + D[i].w;  
            svd[i] = svd[i-1] + D[i].v;  
        }  
        int sumv = 0;  
        int ans = 0;  
        for(i=0;i<=a;i++)  
        {  
            for(j=0;j<=b;j++)  
            {  
                for(k=0;k<=c;k++)  
                {  
                    for(l=0;l<=d;l++)  
                    {  
                        LL sum = swa[i] + swb[j] + swc[k] + swd[l];  
                        if(sum <= (LL)w)  
                        {  
                            ans = max((LL)ans,sva[i]+svb[j]+svc[k]+svd[l]);  
                        }  
                    }  
                }  
            }  
        }  
        cout << ans << endl;  
    }  
  
    return 0;  
}  

Measured memory_bytes: 256
import sys
import numpy as np
from fractions import gcd
from functools import reduce

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, M = rl()
A = np.array(rl())
B = A // 2

def merge(a, b):
    g = gcd(a, b)
    a //= g; b //= g
    if a%2 == 0 or b%2 == 0:
        return 0
    n = g * a * b
    if n > 10 ** 9:
        return 0
    return n

x = reduce(merge, B)
if x == 0:
    answer = 0
else:
    answer = M // x - M // (2*x)

print(answer)


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

int main()
{
	int n;
	cin >> n;
	auto p = vector<int>(n,0);
	for(int i=0;i<n;i++){
	    cin >> p[i];
	}
    auto _max = *max_element(p.begin(),p.end());
    
     cout << accumulate(p.begin(),p.end(),0) - _max/2;    
    
}

Measured memory_bytes: 256
class Trie
  def initialize
    @root = Hash.new
  end

  def build(str)
    node = @root
    str.each_char do |ch|
      node[ch] ||= Hash.new
      node = node[ch]
    end
    node[:end] = true
  end

  def find(str)
    node = @root
    str.each_char do |ch|
      return nil unless node = node[ch]
    end
    node[:end] && true
  end
end


def main
  n = gets.chomp.to_i
  trie = Trie.new
  (1..n).each do |ca|
    command, str = gets.chomp.split(/\s/)
    trie.build(str) if command == "insert"
    if command == "find"
      flag = trie.find str
      puts "yes"  if flag 
      puts "no" if not flag
    end
  end
end

main

Measured memory_bytes: 248860
/*
新图中(x, y)和(p, q)联通，当且仅当：存在一条长度为l的从x走到p的路径，和一条长度为l的从y走到q的路径
因为可以在一条边上来回走，所以只要判断是否存在两条长度奇偶性相同的从x走到p、从y走到q的路径 
(1)当a和b在一个是二分图的联通块中时，a到b所有路径长度奇偶性相同：进行二分图染色，同色点之间都是偶数、异色点之间都是奇数
(2)当a和b在一个存在奇环的联通块中时，a到b存在长度为奇数的路径、也存在长度为偶数的路径
(3)当(x, y)中有一个点是孤立点时，(x, y)单独成为一个联通块
根据(1)(2)(3)可以直接分类讨论计数
*/

#include <cstdio>

using namespace std;

namespace io
{
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush (){fwrite (obuf, 1, oS - obuf, stdout);oS = obuf;}
	inline void putc (char x){*oS ++ = x;if (oS == oT) flush ();}
	template <class I>
	inline void gi (I &x) {for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;}
	template <class I>
	inline void print (I x){
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;while(x) qu[++ qr] = x % 10 + '0',  x /= 10;while (qr) putc (qu[qr--]);}
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io::gi;
using io::putc;
using io::print;

typedef long long int LL;
const int Max_N(100050);
const int Max_M(200050);

int N, M, Head[Max_N], Total, To[Max_M << 1], Next[Max_M << 1];

inline void Add_Edge(int s, int t)
{
	++Total, To[Total] = t, Next[Total] = Head[s], Head[s] = Total;
}

int color[Max_N], A, B, C, V;
LL Ans;
bool qaq;

void dfs(int u)
{
	++V;
	for (int i = Head[u], v;i;i = Next[i])
		if (!color[v = To[i]])
			color[v] = 3 - color[u], dfs(v);
		else
			if (color[v] == color[u])
				qaq = true;
}

int main()
{
	gi(N), gi(M);
	for (int u, v;M--;)
		gi(u), gi(v), Add_Edge(u, v), Add_Edge(v, u);
	for (int u = 1;u <= N;++u)
	{
		if (color[u])
			continue;
		if (color[u] = 1, V = 0, qaq = false, dfs(u), qaq == false)
			if (V > 1)
				Ans += (A * 2 + B) * 2 + 2, ++A;
			else
				++C;
		else
			Ans += (A + B) * 2 + 1, ++B;
	}
	print(Ans + C * 1LL * N + N * 1LL * C - C * 1LL * C);
	return 0;
}

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

int main() {
    double a, b, C, d, S, c, h;
    cin >> a >> b >> C;
    
    d = acos(-1) * C / 180;
    S = 0.5 * a * b * sin(d);
    c = sqrt(a * a + b * b - 2 * a * b * cos(d));
    h = S * 2 / a;

    printf("%lf\n", S);
    printf("%lf\n", a +  b + c);
    printf("%lf\n", h);

    return 0;
}


Measured memory_bytes: 3480
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 6/14/2018
 
 12:40-13:27 1WA
 13:28-13:50 pause
 
 Editorials:
  - https://youtu.be/LMfovZuqBsg?t=985
 
 Summary:
  - X*dold+A[P[i]] vs A[P[i]] 😡
 
 */

// $ g++ -std=c++11 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
const int MAX_N=2e3+1;
int N,X;
LL A[MAX_N];
LL P[MAX_N];
const LL Inf=1e15;
int f(int from, int to) {
//  return (to-from+N)%N;
  return from<=to?to-from:N-(from-to);
}
void solve() {
  LL res=Inf;
  REP(i,N) P[i]=i;
  REP(d,N) {
    LL tot=0;
    REP(i,N) {
      LL dold=f(P[i],i);
      LL p=(i-d+N)%N;
//      LL a=1LL*X*dold+A[P[i]],b=1LL*X*d+A[p];
//      dump4(d,i,a,b);
      if(A[P[i]]>A[p]) P[i]=p;
      tot+=A[P[i]];
    }
//    dump3(d,tot,res);
    SMIN(res,tot+X*d);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N>>X;
  REP(i,N) cin>>A[i];
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define INF 1000000000000000
#define rep(i,N) for(int i=0;i<N;i++)
typedef long long ll;

ll dp[405][405];


int main(){
  int N;
  cin>>N;
  ll a[N];
  rep(i,N) cin>>a[i];

ll sum[N][N];
for(int l=0;l<N;l++){
  sum[l][l+1] = a[l];
  for(int r=l+2;r<=N;r++){
    sum[l][r] = sum[l][r-1] + a[r-1];
  }
}


for(int width = 2; width<=N; width++){
  for(int l=0; l+width<= N; l++){
    int r = l+width;
    dp[l][r] = INF;
    for(int m = l+1; m<r; m++){
      dp[l][r] = min(dp[l][r], dp[l][m] + dp[m][r] + sum[l][r]);
    }
  }
}

cout<< dp[0][N];

}


Measured memory_bytes: 2816
#!/usr/bin/perl

my ($x1,$y1,$x2,$y2) = map {$_ - 0} split(/\s+/o,<STDIN>);

my ($p,$q) = &r($x2-$x1, $y2-$y1);

my $x3 = $x2 + $p; 
my $y3 = $y2 + $q;

my ($p,$q) = &r($x3-$x2, $y3-$y2);

my $x4 = $x3 + $p;
my $y4 = $y3 + $q;

print "$x3 $y3 $x4 $y4\n";

exit(0);

sub r {
  my $xx = shift;
  my $yy = shift;
  return (-$yy,$xx);
}


Measured memory_bytes: 512
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

A,V=get_i
B,W=get_i
T=gets.to_i
if (V-W)*T>=(B-A).abs
    puts "YES"
else
    puts "NO"
end

Measured memory_bytes: 14392
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

int main(){
	fast;
	ll n,ans=0,f=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		ans=0;
		int p=i;
		while(p>0){
			ans++;
			p/=10;
		}
		if(ans%2==1)f++;
	}cout<<f<<endl;
	return 0;
}/*『你强归你强，我永不示弱』*/


Measured memory_bytes: 256