akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define SZ(a) ((int)a.size())
typedef long long ll;

int N, E, p[100100], ans;
pair<int, int> a[100100], b[100100];
tuple<int, int, int> e[200200];

int g (int i) { return p[i] == i ? i : p[i] = g(p[i]); }

int main () {
        scanf("%d", &N);
        fo(i, 0, N) {
                int x, y; scanf("%d %d", &x, &y);
                a[i] = MP(x, i);
                b[i] = MP(y, i);
                p[i] = i;
        }

        sort(a, a+N), sort(b, b+N);
        fo(i, 1, N) {
                int x,y,c;

                x = a[i-1].second, y = a[i].second, c = a[i].first-a[i-1].first;
                e[E++] = make_tuple(c,x,y);

                x = b[i-1].second, y = b[i].second, c = b[i].first-b[i-1].first;
                e[E++] = make_tuple(c,x,y);
        }

        sort(e, e+E);
        fo(i, 0, E) {
                int c,x,y; tie(c,x,y) = e[i];
                x = g(x), y = g(y);
                if (x != y) {
                        ans += c;
                        p[x] = y;
                }
        }

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



Measured memory_bytes: 5376
import copy

N = int(input())
lst = list(map(int, input().split()))
lst2 = sorted(lst)
sum = 0
for i in range(N):
  if (lst[i] != lst2[i]):
    sum += 1
if (sum == 0 or sum == 2):
  print('YES')
else:
  print('NO')


Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  string s,t;
  cin>>s;
  cin>>t;
  int ns=s.size(),nt=t.size();

  int q;
  cin>>q;

  int sa[ns+1]={},ta[nt+1]={};

  for(int i=1;i<=ns;i++){
    if(s[i-1]=='A') sa[i]=(sa[i-1]+1)%3;
    else sa[i]=(sa[i-1]+2)%3;
  }
  for(int i=1;i<=nt;i++){
    if(t[i-1]=='A') ta[i]=(ta[i-1]+1)%3;
    else ta[i]=(ta[i-1]+2)%3;
  }

  for(int i=1;i<=q;i++){
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    if((sa[b]-sa[a-1]+3)%3==(ta[d]-ta[c-1]+3)%3) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }

  return 0;
}


Measured memory_bytes: 1664
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		String x = sc.next();
		String y = sc.next();
		if(x.compareTo(y) == 0) {
			System.out.println("=");
		} else if(x.compareTo(y) > 0) {
			System.out.println(">");
		} else if(x.compareTo(y) < 0) {
			System.out.println("<");
		}
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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

}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int n;
	cin>>n;
	ll arr[n];
	int zero=0;
	for(int i=0;i<n;i++){
	    cin>>arr[i];
	    if(arr[i]==0)zero++;
	    
	}
	if(zero)cout<<0;
	else {
	    int status=1;
	    ll ans=1;
	    for(int i=0;i<n;i++){
	        if(((ll)1e18/ans)<arr[i]){
	            status=0;
	            cout<<-1;
	            break;
	        }
	        else ans=ans*arr[i];
	    }
	    if(status==1)cout<<ans;
	}

}


Measured memory_bytes: 4424
#include <stdio.h>

int main(void)
{
  int n, a, b;
  int ans=0, r, x;

  scanf("%d %d %d", &n, &a, &b);

  for (int i=0;i <= n; i++) {
    x = i;
    r = 0;
    
    for (;;) {
      r += x%10;
      x /= 10;
      if (x == 0){ break;}
    }

    if (r >= a && r <= b) {
      ans += i;
    }
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 128
import numpy as np

n = int(input())
m = [0]
m.extend(list(map(int, input().split())))
m.append(0)
k = []
l = []
a = 0

for i in range(n + 1):
    k.append(m[i + 1] - m[i])
    a += np.abs(m[i + 1] - m[i])

for i in range(n):
    l.append(np.abs(k[i + 1]) + np.abs(k[i]) - np.abs(k[i + 1] + k[i]))

for i in range(n):
    print(a - l[i])


Measured memory_bytes: 27480
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define all(x) x.begin(),x.end()
using namespace std;
void solve() {
   int a,b;
   cin>>a>>b;
   if(b+b>=a) cout<<0;
   else cout<<a-(b+b);
}
int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int t=1;
    //cin>>t;
    while(t--) solve();

}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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 main()
{
    int n, m, k; cin >> n >> m >> k;
    vector<int> v;
    rep(i, n+1) rep(j, m+1){
        v.push_back(i*m + j*n - 2*i*j);
    }
    sort(ALL(v));

    if(*lower_bound(ALL(v), k) == k){
        pr("Yes");
    }else {
        pr("No");
    }
    // prvec(v);
    return 0;}

Measured memory_bytes: 7432
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define   ull unsigned long long 
const int MAX=2e5+9;
const long long mod=1e9+7;
using namespace std;
vector<int>adj[MAX];
int dp[MAX][4];
ll pre[MAX][101];
int main(){
	int n , d;
	cin>>n>>d;
	vector<int>v[2000];
	for(int i=0;i<n;i++){
		int x;
		for(int j=0;j<d;j++){
		cin>>x;
		v[i].push_back(x);
	}
	}
	int cnt=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			int tot=0;
			for(int k=0;k<d;k++){
				tot=tot+(v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
			}
			int p=sqrt(1.0*tot);
			if(p*p==tot)
				cnt++;

		}

	}
	cout<<cnt;


}

Measured memory_bytes: 6144
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c); 
	for(int i=1;i<=100;i++)
		if((a*i)%b==c){
			printf("YES\n");
			return 0;
	}
	printf("NO\n");
	return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    string s,t; cin >> s >> t;
    int a,b;
    string u; cin >>a>>b;
    cin >> u;
    if(s==u) --a;
    if(u==t) --b;
    cout << a << ' ' << b <<  '\n';
    // cout << b << '\n'; 
}

Measured memory_bytes: 256
//In the name of God

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

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

const int N = 3e3+10 , mod = 1e9+7;

double dp[N][N] , p[N];

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   cout << fixed << setprecision(9);
   int n;
   cin >> n;
   dp[0][0] = 1;
   for(int i = 1 ; i <= n ; i++)
      cin >> p[i];
   for(int i = 1 ; i <= n ; i++){
      dp[i][0] = dp[i - 1][0] * double(1 - p[i]);
      for(int j = 1 ; j <= i ; j++)
         dp[i][j] = dp[i - 1][j] * (double)(1 - p[i]) + dp[i - 1][j - 1] * p[i];
   }
   double ans = 0;
   for(int i = 0 ; i <= n ; i++)
      if(i > n - i)
         ans += dp[n][i];
   cout << ans;
   return 0;
}


Measured memory_bytes: 69248
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>

long long gcd(long long a,long long b){
    return b?gcd(b,a%b):a;
    }
long long lcm(long long a,long long b){    
    return a/gcd(a,b)*b;
}

int main(void){
    long long a,b;
    scanf("%lld%lld",&a,&b);
    printf("%lld\n",lcm(a,b));
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{

    char c ;
    cin >> c;
    c += 1;
    cout << c << endl;

    return 0;
}

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

int main() {
  vector<int> v(5);
  for (int i = 0; i < 5; i++) cin >> v[i];

  int last = v[0];
  int last_idx = 0;
  for (int i = 0; i < 5; i++) {
    if (v[i] % 10 != 0 && v[i] % 10 < last % 10) {
      last = v[i];
      last_idx = i;
    }
  }

  int ans = 0;
  for (int i = 0; i < 5; i++) {
    ans += v[i];
    if (i != last_idx && v[i] % 10 != 0) {
      ans += (10 - v[i] % 10);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n, x = map(int, input().split())
A = list(map(int, input().split()))
count = 0
for i in range(1, n):
    diff = A[i] + A[i - 1] - x
    if diff <= 0:
        continue
    count += diff
    A[i] -= min(diff, A[i])
print(count)

Measured memory_bytes: 14576
macro_rules! read_line_to_tuple {
    ( $( $t:ty ),* ) => {{
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        let mut iter = input.split_whitespace();
        ( $( iter.next().unwrap().parse::<$t>().unwrap() ),* )
    }};
}

struct Dsu {
    n: usize,
    parent_or_size: Vec<usize>,
}

impl Dsu {
    fn new(n: usize) -> Dsu {
        Dsu { n, parent_or_size: vec![!1; n] }
    }

    fn merge(&mut self, a: usize, b: usize) -> usize {
        let (mut x, mut y) = (self.leader(a), self.leader(b));
        if x == y { return x; }
        if !self.parent_or_size[x] < !self.parent_or_size[y] {
            std::mem::swap(&mut x, &mut y);
        }
        self.parent_or_size[x] -= !self.parent_or_size[y];
        self.parent_or_size[y] = x;
        x
    }

    fn same(&mut self, a: usize, b: usize) -> bool {
        self.leader(a) == self.leader(b)
    }

    fn leader(&mut self, a: usize) -> usize {
        if self.parent_or_size[a] >= self.n { return a; }
        self.parent_or_size[a] = self.leader(self.parent_or_size[a]);
        self.parent_or_size[a]
    }

    fn _size(&mut self, a: usize) -> usize {
        let x = self.leader(a);
        !self.parent_or_size[x]
    }
}

fn main() {
    let (n, m) = read_line_to_tuple!(usize, usize);

    let mut count = n;
    let mut dsu = Dsu::new(n);
    for _ in 0..m {
        let (a, b) = {
            let (a, b) = read_line_to_tuple!(usize, usize);
            (a - 1, b - 1)
        };

        if !dsu.same(a, b) {
            dsu.merge(a, b);
            count -= 1;
        }
    }

    println!("{}", count - 1);
}

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

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

  switch (d) {
	case 25:
		cout << "Christmas";
		break;
	case 24:
		cout << "Christmas Eve";
		break;
    case 23:
		cout << "Christmas Eve Eve";
		break;
    case 22:
		cout << "Christmas Eve Eve Eve";
		break;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
int mon,day,i,t;

while(1){
	scanf("%d%d",&mon,&day);
	if(!mon&&!day)break;
	
	t=0;
	for(i=1;i<mon;i++){
		if(i==2)t+=29;
		else if(i==4||i==6||i==9||i==11)t+=30;
		else t+=31;
	}
	t+=day;
	
	switch(t%7){
	case 0:
		printf("Wednesday\n");
		break;
		
	case 1:
		printf("Thursday\n");
		break;
		
	case 2:
		printf("Friday\n");
		break;
		
	case 3:
		printf("Saturday\n");
		break;
	
	case 4:
		printf("Sunday\n");
		break;
	
	case 5:
		printf("Monday\n");
		break;
	
	case 6:
		printf("Tuesday\n");
		break;
	
	}
}
return 0;
}

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

int main(){
	/*input*/
	int n;	cin >> n;
	vector<int>p(n);
	for(int i = 0; i < n; i++){
		cin >> p[i];
	}
	/*calculaiton*/
	vector<int>tmp(n);
	tmp = p;
	sort(tmp.begin(), tmp.end());
	bool OK = false;	//true:YES false:NO
	int j = 0;
	for(int i = 0; i < n; i++){
		if(tmp[i] != p[i])j++;
	}
	if(j == 2||j == 0)OK = true;
	/*output*/
	if(OK){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll bit[100010]; int n0;
 
ll sum(int i){
	ll s=0;
	while(i>0){
		s+=bit[i];
      s%=MOD;
		i-=(i&(-i));
	}
	return s;
}
 
void add(int i, ll x){
	while(i<=n0){
		bit[i]+=x;
      bit[i]%=MOD;
		i+=(i&(-i));
	}
}
int main()
{
	int n, m;
  cin>>n>>m;
  map<int, vector<int> > mp;
  int x[100000], y[100000];
  map<int, int> mpy;
  for(int i=0; i<n; i++) cin>>x[i];
  for(int i=0; i<m; i++) cin>>y[i];
  for(int i=0; i<n; i++){
    int i1=lower_bound(y, y+m, x[i])-y;
    if(i1==0 || i1==m) continue;
    mp[x[i]-y[i1-1]].push_back(y[i1]-x[i]);
    mpy[y[i1]-x[i]]=0;
  }
  n0=1;
  for(auto& p:mpy){
    p.second=n0;
    n0++;
  }
  for(auto& p:mp){
    sort(p.second.begin(), p.second.end());
    p.second.erase(unique(p.second.begin(), p.second.end()), p.second.end());
    for(auto& x:p.second) x=mpy[x];
  }
  for(auto& p:mp){
    vector<int> v=p.second;
    for(int i=v.size()-1; i>=0; i--){
      add(v[i], (sum(v[i]-1)+1)%MOD);
    }
  }
  cout<<(sum(n0)+1)%MOD<<endl;
    return 0;
}

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

typedef long long ll;
typedef double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

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

    int n;
    cin >> n;

    string a, b, c;
    cin >> a >> b >> c;

    int ans = 0;
    for (int i = 0; i < n; i++) {
        set <char> s;
        s.insert(a[i]); s.insert(b[i]); s.insert(c[i]);
        ans += int(s.size()) - 1;
    }

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


Measured memory_bytes: 256
def resolve():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    aa = sorted(a)
    bb = sorted(b)
    ans = aa[0] + bb[0]

    for i in range(M):
        xx, yy, cc = map(int, input().split())
        tmp = a[xx - 1] + b[yy - 1] - cc
        ans = min(ans, tmp)

    print(ans)


resolve()

Measured memory_bytes: 18736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll w,h;cin>>w>>h;
  vector<ll> p(w),q(h);
  ll ans=0;
  for(ll i=0;i<w;i++){
    cin>>p[i];
    ans+=p[i];
  }
  sort(p.begin(),p.end());
  ll sum[w+1];
  sum[0]=0;
  for(ll i=0;i<w;i++){
    sum[i+1]=sum[i]+p[i];
  }
  for(ll i=0;i<h;i++){
    cin>>q[i];
    ans+=q[i];
    ll c=lower_bound(p.begin(),p.end(),q[i])-p.begin();
    ans+=sum[c]+q[i]*(w-c);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2688
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

#define int long long

struct edge {
    int to;
    int cost;
};

using namespace std;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vb = vector<bool>;
using qi = queue<int>;
using P = pair<int, int>;
using graph = vector<vector<edge>>;
// using graph = vector<vector<int>>;


#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define delim(i, n) cout << (i == n-1 ? "\n" : " ");

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

const int inf = 1LL << 60;
// const int inf = 100000000;
const int mod = 1000000007;

const int maxn = 300;
int n, m, k;

vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};

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

    cin >> n;
    int cnt = 0;
    FOR(i, 1, n) {
        cnt += (n-1)/i;
    }

    cout << std::fixed << std::setprecision(10) << cnt << "\n";
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using ll=long long;
using namespace std;

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main(){
    int N,D,A;
    cin>>N>>D>>A;

    vector<pair<int,int>> map;
    int a,b;
    for(int i=0;i<N;i++){
        cin>>a>>b;
        map.push_back({a,b});
    }
    map.push_back({1000000001,0});
    sort(map.begin(),map.end());

    BIT<int> bit(N+3);
    for(int i=0;i<N;i++){
        bit.add(i+1,i+2,map[i].second);
    }

    ll ans=0;
    int ed=0;

    for(int i=0;i<N;i++){
        if(bit.sum(i+1,i+2)>0){
            int range=map[i].first+2*D;
            int numBom=(bit.sum(i+1,i+2)+A-1)/A;
            ans+=numBom;
            int damage=numBom*A;
            while(ed<N && map[ed].first<=range){
                ed++;
            }
            bit.add(i+1,ed+1,-damage);
        }
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;

    return 0;
}

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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

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

int main(void){
    double a, b, x;
    cin >> a >> b >> x;
    if(x > a*a*b/2){
        double t = 2*(b*a*a-x)/(a*a*a);
        double tr = 180/M_PI;
        cout << fixed << setprecision(10) << atan(t)*tr <<endl;
    }else{
        double t = (a*b*b)/(2*x);
        double tr = 180/M_PI;
        cout << fixed << setprecision(10) << atan(t)*tr <<endl;
    }
    return 0;
}



Measured memory_bytes: 256
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, X = lr()
L = lr()
cnt = 1
cur = 0
for l in L:   
    cur += l
    if cur > X:
        break
    cnt += 1

answer = cnt
print(answer)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/twosat>
using namespace std;
using namespace atcoder;

int n, d;
int x[1000], y[1000];

int main() {
	int i;
	
	cin >> n >> d;
	for (i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	
	two_sat ts(n);
	
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (abs(x[i] - x[j]) < d) {
				ts.add_clause(i, false, j, false);
			}
			if (abs(x[i] - y[j]) < d) {
				ts.add_clause(i, false, j, true);
			}
			if (abs(y[i] - x[j]) < d) {
				ts.add_clause(i, true, j, false);
			}
			if (abs(y[i] - y[j]) < d) {
				ts.add_clause(i, true, j, true);
			}
		}
	}
	
	if (!ts.satisfiable()) {
		cout << "No" << endl;
		return 0;
	}
	
	cout << "Yes" << endl;
	auto answer = ts.answer();
	for (int i = 0; i < n; i++) {
		if (answer[i]) cout << x[i] << endl;
		else cout << y[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define rep(i,a,b,c)            for(int i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(int i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     3e18
#define vpii                    vector<pair<int,int>>
#define si                      set<int>
#define usi                     unordered_set<int>
#define vi                      vector<int>
#define vld                     vector<ld>
#define vvi                     vector<vector<int>>
#define vvld                    vector<vector<ld>>
#define pii                     pair<int,int>
#define vvpii                   vector<vector<pair<int,int>>>
#define pqi                     priority_queue<int>
#define mii                     map<int,int>
#define mic                     map<int,char>
#define um                      unordered_map
#define umii                    um<int,int>
#define umic                    um<int,char>
#define umci                    um<char,int>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define test                    int Testcases;cin>>Testcases;while(Testcases--)
#define input(a,n)              for(int i=0;i<n;++i) cin>>a[i];
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
    #endif
}

int32_t main()
{
	fastIO
	inp_out();
	int x;
	cin>>x;


	for(int i=-200;i<=200;++i)
	{
		for(int j=-200;j<=200;++j)
		{
			if((i*i*i*i*i)-(j*j*j*j*j)==x)
			{
				cout<<i<<" "<<j<<"\n";
				return 0;
			}
		}
	}


	return 0;
}

Measured memory_bytes: 3652
/*
[ ( ^ _ ^ ) ]
*/
// problem: atc/abc165_f
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000


const int nax = 200005;
vector<vector<int>> g(nax);
vector<int> a(nax), rs(nax), dp(nax, INF);
int n;


void dfs(int v, int p) {
    int idx = lower_bound(dp.begin(), dp.end(), a[v]) - dp.begin();
    int prev = dp[idx];
    dp[idx] = a[v];
    rs[v] = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
    for(int u: g[v]) {
        if(u==p) continue;
        dfs(u, v);
    }
    dp[idx] = prev;
}

void dfs2(int v, int p) {
    for(int u: g[v]) {
        if(u==p) continue;
        rs[u] = max(rs[u], rs[v]);
        dfs2(u, v);
    }
}

int main() {
    scanf("%d", &n);
    for(int i=1; i<=n; i++) {
        scanf("%d", &a[i]);
    }
    for(int i=0; i<n-1; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    dfs(1, -1);
    // dfs2(1, -1);
    for(int i=1; i<=n; i++) {
        printf("%d\n", rs[i]);
    }
    // printf("\n");
}


Measured memory_bytes: 27924
x,y=map(int,input().split())
if x==y==1:
    print(1000000)
else:
    a=0
    if x==1:
        a+=300000
    if x==2:
        a+=200000
    if x==3:
        a+=100000
    if y==1:
        a+=300000
    if y==2:
        a+=200000
    if y==3:
        a+=100000
    print(a)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll long long

int main()
{
        IO;
        ll i, j, n, m, k, l, r,t, q,sum,mod, lcm,mn1,mn2;
        cin>>n>>m>>k>>l;
        while(1){
            k-=m;
            if(k<=0)return cout<<"Yes"<<endl,0;
            n-=l;
            if(n<=0) return cout<<"No"<<endl,0;
        }
    return 0;
}


Measured memory_bytes: 3612
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
num = [0] * 100010
b = [0] * q
c = [0] * q
for i in range(q):
    b[i], c[i] = map(int, input().split())

for i in a:
    num[i] += 1

s = sum(a)

for i in range(q):
    s += (c[i]-b[i])*num[b[i]]
    num[c[i]] += num[b[i]]
    num[b[i]] = 0
    print(s)

Measured memory_bytes: 22144
#include "bits/stdc++.h"
using namespace std;

#define pb  push_back
#define mp  make_pair
#define ll  long long
#define itr iterator

typedef pair<ll,ll> pii;

const ll MAX=2e5+9;
const ll INF=1e12;

int N,M,X,Y,up[MAX],mark[MAX];

vector<int> vec[MAX];

signed main()
{
	ios_base::sync_with_stdio(false);

	cin>>N>>M;
	for(int A=1;A<=M;A++)
	{
		cin>>X>>Y;
		vec[X].pb(Y);
		vec[Y].pb(X);
	}
	set<pii> st;
	set<pii> ::iterator it;
	//{hei,node}
	st.insert({0,1});
	mark[1]=1;
	while(!st.empty())
	{
		it=st.begin();
		for(auto A:vec[it->second])
			if(!mark[A])
				st.insert({it->first+1,A}),
				up[A]=it->second,
				mark[A]=1;
		st.erase(st.begin());
	}
	for(int A=2;A<=N;A++)
		if(up[A]==-1)
			return cout<<"No",0;
	cout<<"Yes\n";
	for(int A=2;A<=N;A++)
		cout<<up[A]<<"\n";
	return 0;
}

Measured memory_bytes: 18772
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n, k, fruits[1005], ans=0; cin>>n>>k;

	for(int i=0; i< n;++i)
		{
			cin>>fruits[i];

		}
	sort(fruits, fruits+n);
	for(int i=0; i< k;++i)
	{
		ans+=fruits[i];
	}
	cout<<ans<<endl;





}

Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
int main(){
    unsigned long long int n;
    cin>>n;
    unsigned long long int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    unsigned long long int s=0;
    for(int i=1;i<n;i++){
        if(arr[i]<arr[i-1]){
            s+=arr[i-1]-arr[i];
            arr[i]=arr[i-1];
        }
    }
    cout<<s<<endl;
    return 0;
}

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

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

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

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

struct UnionFind {
  // parentの番号を格納する。親だった場合は-(その集合のサイズ)
  vector<int> Parent;

  //作成時は全て-1なので木が全て独立している状態
  UnionFind(int N) { Parent = vector<int>(N, -1); }

  // Aがどのグループに属しているか調べる
  int root(int A) {
    if (Parent[A] < 0)
      return A;
    else {
      return Parent[A] = root(Parent[A]);
    }
  }

  //自分のいるグループの頂点数を調べる
  int size(int A) { return -Parent[root(A)]; }

  // AとBをくっつける
  bool merge(int A, int B) {
    // AとBを繋げるのではなくroot(A)とroot(B)を繋げる
    A = root(A);
    B = root(B);
    if (A == B) {
      //すでに繋がれているので繋がない
      return false;
    }

    //大きい方（A）に小さい方（B）をくっつけたい
    if (size(A) < size(B)) swap(A, B);

    // Aのサイズを変更する
    Parent[A] += Parent[B];
    // Bの親をAに変更する
    Parent[B] = A;

    return true;
  }
};

int main() {
    int N,M;
    cin >> N >> M;
    vi X(M),Y(M),Z(M);

    REP(i,M){
        cin >> X[i] >> Y[i] >> Z[i];
        X[i]--,Y[i]--;
    }

    UnionFind uf(N);
    REP(i,M){
        uf.merge(X[i],Y[i]);
    }

    set<int> se;
    //setを使うという思考が抜けてる  

    REP(i,N){
        se.insert( uf.root(i) );
    }

    cout << se.size() << endl;

}



Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
#define int long long int

main() {
	int s;
	cin>>s;
	if(s==1000000000000000000){
		cout<<0<<" "<<0<<" "<<0<<" "<<1000000000<<" "<<1000000000<<" "<<0;
		return 0;
	}
	cout<<1000000000<<" "<<(1+(s/1000000000))<<" "<<0<<" "<<(s/1000000000)<<" "<<(s%1000000000)<<" "<<0;
	
	return 0;
}

Measured memory_bytes: 3596
const main = (inputs) => {
  var N = inputs[0]-0;
  var arr = [];
  var max1 = 0;
  var max2 = 0;
  for(var i=1;i<=N;i++){
    var num = inputs[i]-0;
    arr.push(num);
    if(max1<num){
      max2 = max1;
      max1 = num;
    }else if(max2<num){
      max2 = num;
    }
  }
  for(var i=0;i<N;i++){
    console.log(arr[i] == max1? max2: max1);
  }
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


Measured memory_bytes: 41496
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    k, n = MI()
    A = LI()
    for i in range(n):
        A.append(k+A[i])
    # A = A * 2
    # print(A)
    S = [0] * (2 * n)

    ans = INF
    for i in range(1, 2 * n):
        # print(i)
        # S[i-1] = A[i] - A[i-1]
        S[i] = S[i-1] + A[i] - A[i-1]
        if i >= (n - 1):
            # print(S[i], S[i-n+1])
            ans = min(ans, S[i] - S[i-n+1])

    # print(S)
    print(ans)


    # R
    # for i in range(k-1, 2 * n):






if __name__ == '__main__':
    solve()


Measured memory_bytes: 38504
#include <stdio.h>
  int main(){
   int l,n,a,b,i,j,k,c;
   int dp[101][4][4]; /*dp[a][b][c]とはa日間のパスタの作り方のうちa-1日目がbで、a日目はｃである場合の数。*/
   int x[101];
   scanf("%d %d",&n,&k);
   x[1] = 0;
   for(i=2;i<=n;i++){
	   for(j=1;j<4;j++){
		   for(l=1;l<4;l++){
			   dp[i][j][l] = 0;
			   x[i] = 0;
		   }
	   }
   }
   
   for(i=0;i<k;i++){
	   scanf("%d %d",&a,&b);
	     x[a] = b;
   }
   for(i=1;i<4;i++){
	   for(j=1;j<4;j++){
		   dp[2][i][j] = 1;
	   }
   }
   if(x[1] != 0){
	   for(i=1;i<4;i++){
		   if(i != x[1]){
		   dp[2][i][1]=0;
		   dp[2][i][2]=0;
		   dp[2][i][3]=0;
		   }
	   }
   }
   if(x[2] != 0){
	   for(i=1;i<4;i++){
		   if(i != x[2]){
		   dp[2][1][i]=0;
		   dp[2][2][i]=0;
		   dp[2][3][i]=0;
		   dp[3][i][1]=0;
		   dp[3][i][2]=0;
		   dp[3][i][3]=0;
		   }
	   }
   }
   for(i=2;i<n;i++){
	   dp[i+1][1][1]=(dp[i][2][1]+dp[i][3][1])%10000;
	   dp[i+1][1][2]=(dp[i][1][1]+dp[i][2][1]+dp[i][3][1])%10000;
	   dp[i+1][1][3]=(dp[i][1][1]+dp[i][2][1]+dp[i][3][1])%10000;
	   dp[i+1][2][1]=(dp[i][1][2]+dp[i][2][2]+dp[i][3][2])%10000;
	   dp[i+1][2][2]=(dp[i][1][2]+dp[i][3][2])%10000;
	   dp[i+1][2][3]=(dp[i][1][2]+dp[i][2][2]+dp[i][3][2])%10000;
	   dp[i+1][3][1]=(dp[i][1][3]+dp[i][2][3]+dp[i][3][3])%10000;
	   dp[i+1][3][2]=(dp[i][1][3]+dp[i][2][3]+dp[i][3][3])%10000;
	   dp[i+1][3][3]=(dp[i][1][3]+dp[i][2][3]);
	   
	   if(x[i+1] != 0){
	   for(j=1;j<4;j++){
		   if(j != x[i+1]){
		   dp[i+1][1][j]=0;
		   dp[i+1][2][j]=0;
		   dp[i+1][3][j]=0;
		   dp[i+2][j][1]=0;
		   dp[i+2][j][2]=0;
		   dp[i+2][j][3]=0;
		   } 
	   }
   }
	   
   }
   int sum = 0;
	for(i=1;i<4;i++){
		for(j=1;j<4;j++){
			sum += dp[n][i][j];
		}
	}
	printf("%d\n",sum%10000);
	scanf("%d",&i);
	return 0;
  }

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 1

int main()
{	
	ios_base::sync_with_stdio(0);
	string str;
	cin>>str;
	deque<char> dq;
	for(int i=str.size()-1; i>=0; i--){
		dq.push_front(str[i]);
	}
	int q,t,f;
	cin>>q;
	int rev = 0;
	for(int qr = 1; qr<=q; qr++){
		cin>>t;
		if(t==1){
			rev^=1;
		}else{
			cin>>f;
			char ch;cin>>ch;
			if(f==1){
				if(rev) dq.push_back(ch);
				else dq.push_front(ch);
			}
			else{
				if(rev^1) dq.push_back(ch);
				else dq.push_front(ch);
			}
		}
	}
	for(int i=dq.size()-1; i>=0 && rev; i--)
		cout<<dq[i];
	rev^=1;
	for(int i=0; i<dq.size() && rev; i++)
		cout<<dq[i];
}

Measured memory_bytes: 976
n, m, x = map(int, input().split())

book = []
for i in range(n):
    book.append(list(map(int, input().split())))

min_cost = 10**8

for i in range(2**n):
    a = [0] * m
    cost = 0
    for j in range(n):
        if (i >> j) & 1:
            cost += book[j][0]
            for k in range(m):
                a[k] += book[j][k+1]

    valid = True
    for j in range(m):
        if a[j] < x:
            valid = False
            break

    if valid:
        min_cost = min(min_cost, cost)

if min_cost == 10**8:
    print(-1)
else:
    print(min_cost)

Measured memory_bytes: 68720
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <algorithm>
using namespace std;
#define MP make_pair


class node{
public:
	long long d;int h,n;
	node(){

	}
	node(long long dd,int nn,int hh=0){
		d=dd;h=hh;n=nn;
	}
};

bool operator<(const node &n1,const node &n2){
	if(n1.d==n2.d) return n1.h<n2.h;
	else return n1.d<n2.d;
}

bool operator>(const node &n1,const node &n2){
	if(n1.d==n2.d) return n1.h>n2.h;
	else return n1.d>n2.d;
}

priority_queue<node,vector<node>,greater<node> > pq;
vector<pair<int,int> > pat[100010];
bool used[100010]={};

int hei[100010];

int main(){
	int N,M,X,a,b,d,pan,pad;
	long long res;
	node no,ino;
	vector<pair<int,int> >::iterator it;
	cin>>N>>M>>X;
	for(int i=1;i<=N;i++){
		cin>>hei[i];
	}
	for(int i=1;i<=M;i++){
		cin>>a>>b>>d;
		pat[a].push_back(MP(d,b));
		pat[b].push_back(MP(d,a));
	}

	res=-1;
	pq.push(node(0,1,X));
	while(!pq.empty()){
		no=pq.top();pq.pop();
		//if(!used[no.n])cout<<"d="<<no.d<<"h="<<no.h<<"n="<<no.n<<endl;//
		if(no.n==N){
			if(res!=-1){
				res=min(res,no.d+hei[N]-no.h);
			}
			else{
				res=no.d+hei[N]-no.h;
			}
			continue;
		}

		if(!used[no.n]){
			used[no.n]=true;
			for(it=pat[no.n].begin();it!=pat[no.n].end();it++){
				pad=it->first;
				pan=it->second;
				if(no.h-pad<=hei[pan]&&no.h-pad>=0){
					ino.d=no.d+pad;
					ino.h=no.h-pad;
					ino.n=pan;
					pq.push(ino);
				}
				else if(no.h-pad>hei[pan]){
					ino.d=no.d+no.h-hei[pan];
					ino.h=hei[pan];
					ino.n=pan;
					pq.push(ino);
				}
				else if(hei[no.n]-pad>=0){
					ino.d=no.d+2*pad-no.h;
					ino.h=0;
					ino.n=pan;
					pq.push(ino);
				}
			}
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 29120
#include<bits/stdc++.h>
using namespace std;
const int N=51;
int n,m,G[N][N],ans,edge[N*N][2],cnt,vis[N];
void dfs(int u,int fa){
	vis[u]=1;cnt++;
	for(int i=1;i<=n;++i){
		if(i==u||i==fa||G[u][i]==0||vis[i]==1) continue;
		dfs(i,u);
	}
}
int main(){
//	freopen("ex.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i){
		int x,y;
		scanf("%d%d",&x,&y);
		G[x][y]=G[y][x]=1;
		edge[i][0]=x;
		edge[i][1]=y;
	}
	for(int i=1;i<=m;++i){
		int x=edge[i][0],y=edge[i][1];
		G[x][y]=G[y][x]=0;
		cnt=0;
		memset(vis,0,sizeof(vis));
		dfs(1,0);
		if(cnt!=n) ans++;
		G[x][y]=G[y][x]=1;
	}
	printf("%d",ans);
	return 0;
}

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

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type,Name, n,m,d)vector<vector<Type>> vv(n, vector<Type>(m, d));

using namespace std;
using ll = long long;

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

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}


int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);

	ll n, m;	cin >> n >> m;
	vector<ll> a(n);

	rep(i, n) {
		ll ii; cin >> ii;
		if (ii % 2 == 1) {
			cout << 0 << endl;
			return 0;
		}
		a[i] = ii / 2;
	}


	//cnt 2;
	int cnt = -1;
	rep(i, n) {
		int c = 0;
		ll b = a[i];
		while (true) {
			if (b % 2 == 1) break;
			b /= 2;
			c++;
		}

		if (cnt == -1) cnt = c;
		else if (cnt != c) {
			cout << 0 << endl;
			return 0;
		}
	}

	ll lc = 1;
	rep(i, n) {
		lc = lcm(lc, a[i]);
		if (lc > m) {
			cout << 0 << endl;
			return 0;
		}
	}

	ll ans = 0;
	for (ll i = lc; i <= m; i += lc * 2) ans++;
	cout << ans << endl;





	return 0;
}


Measured memory_bytes: 3972
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 200010;
const double PI = 3.141592653589793238462643383279502884197169399375;
int p[N], t[N];
struct Node {
    int x, y;
} w[N];

inline bool cmp(Node a, Node b)
{
    if (a.x == b.x) return a.y > b.y;
    return a.x < b.x;
}

inline void add(int x, int k)
{
    for (; x < N; x += (x & (-x))) {
        t[x] = max(t[x], k);
    }
}

inline int query(int x)
{
    int ret = 0;
    for (; x; x -= (x & (-x))) {
        ret = max(ret, t[x]);
    }
    return ret;
}

int main()
{
    int a, b, c, d, n;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    scanf("%d", &n);
    int tot = 0;
    for (register int i = 1, x, y; i <= n; ++i) {
        scanf("%d %d", &x, &y);
        if (min(a, c) <= x && x <= max(a, c) && min(b, d) <= y && y <= max(b, d)) {
            w[++tot].x = x, w[tot].y = y;
            p[tot] = y;
        }
    }
    sort(p + 1, p + tot + 1);
    if (c < a) swap(a, c), swap(b, d);
    if (b > d) {
        for (register int i = 1; i <= tot; ++i) {
            w[i].x = -w[i].x;
        }
    }
    sort(w + 1, w + tot + 1, cmp);
    for (register int i = 1; i <= tot; ++i) {
        int pos = lower_bound(p + 1, p + tot + 1, w[i].y) - (p + 1) + 1;
        int pt = query(pos - 1);
        add(pos, pt + 1);
    }
    int num = query(tot);
    double ans = 100.0 * (abs(c - a) + abs(d - b)) - 20.0 * num + 5.0 * PI * num;
    if (num == min(abs(c - a), abs(d - b)) + 1) ans += 5.0 * PI;
    printf("%.13f\n", ans);
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
 
   /* Input vector size */
  int n;
  cin>>n;

  /* Input vector data */
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }

  /* Selection Sort */
  int cnt=0;
  for(int i=0;i<n;i++){
    int min_j=i;
    for(int j=i;j<n;j++){
      if(a.at(j)<a.at(min_j))
        min_j=j;
    }
    if(a.at(i)>a.at(min_j)){
      int wk=a.at(i);
      a.at(i)=a.at(min_j);
      a.at(min_j)=wk;
      cnt++;
    }
  }

  /* Output Sorted vector data */
  for(int i=0;i<n;i++){
    if(i<n-1)
      cout<<a.at(i)<<' ';
    else
      cout<<a.at(i)<<endl;
  }
  /* Output exchange count */
  cout<<cnt<<endl;

  return 0;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int> >
#define ll long long
const int INF = 1e8;
const int MAXN = 3e5 + 200;
const  long double eps = 1e-16;
const long double pi = acos(-1.0);
using namespace std;

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


void solve(){
    int a, b, c;
    int five = 0, sv = 0;
    cin >> a >> b >> c;
    if (a == 5) five++;
    if (b == 5) five++;
    if (c == 5) five++;

    if (a == 7) sv++;
    if (b == 7) sv++;
    if (c == 7) sv++;
    if (sv == 1 && five == 2){
        cout << "YES" << endl;
    } else cout << "NO";
}

int main(){
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(7);
    //freopen("inevit.in", "r", stdin);
    //freopen("inevit.out", "w", stdout);
    int step;
    step = 1;
    //cin >> step;
    for (int i = 1; i <= step; i++)
        solve();

}

Measured memory_bytes: 256
N, M = map(int, input().split())

lb, ub = 0, 10**18
K = 2 * N + M

while ub - lb > 1:
    md = (ub + lb) >> 1
    n, m = N, M
    n -= md
    if n < 0:
        m -= -n * 2
    if md * 2 <= m:
        lb = md
    else:
        ub = md

print(lb)

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

const int Maxn = 200005;

int K, N;
int a[Maxn];
int mx;

int main()
{
    scanf("%d %d", &K, &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &a[i]);
        if (i > 0) mx = max(mx, a[i] - a[i - 1]);
    }
    mx = max(mx, a[0] + K - a[N - 1]);
    cout << K - mx << endl;
    return 0;
}


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

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

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(int N, const vector<ll>& xs)
{
    return 0;
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    string s;
    cin >> s;

    if (s.size() <= N)
        cout << s << '\n';
    else
        cout << s.substr(0, N) << "..." << endl;

    return 0;
}


Measured memory_bytes: 3656
h, w=gets.split.map &:to_i
c=[]
10.times{ c<<gets.split.map(&:to_i) }
10.times{|k| 10.times{|i| 10.times{|j| c[i][j]=[c[i][j], c[i][k]+c[k][j]].min } } }

res=0
h.times{ gets.split.map(&:to_i).map{|x| res += x<0 ? 0 : c[x][1]} }
puts res


Measured memory_bytes: 2428
N,M=map(int,input().split())
AC=[0]*N; WA=[0]*N;

for i in range(M):
  p,S=map(str,input().split())
  p=int(p)
  if AC[p-1]==0:
    if S=="AC":
      AC[p-1]+=1
    else:
      WA[p-1]+=1
for i in range(N):
  if AC[i]==0:
    WA[i]=0
print(sum(AC),sum(WA))

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

using namespace std;
typedef long long ll;
int main()
{
          ll a,b,c=0;
          cin>>a;
          for(ll i=1;i<a+1;i++)
          {
                    ll s=0,d;
                    d=i;
                    while(d!=0)
                    {
                              d/=10;s++;
                    }
                    if(s&1)c++;
          }
          cout<<c<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    if((s[0]==s[1]&&s[0]==s[2])||(s[1]==s[2]&&s[1]==s[3])){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	n := readInt()
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = readInt()
	}

	// カエルが足場 i へと移動するのに必要な最小コスト
	dp := make([]int, n)
	for i := range dp {
		dp[i] = INF
	}
	dp[0] = 0
	for i := 1; i < n; i++ {
		chmin(&dp[i], dp[i-1]+abs(h[i]-h[i-1]))
		if i > 1 {
			chmin(&dp[i], dp[i-2]+abs(h[i]-h[i-2]))
		}
	}
	fmt.Println(dp[n-1])
}

/*-------------------utilities-------------------*/

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
)

var (
	readString func() string
)

func init() {
	readString = newReadString(os.Stdin)
}

/*-------------------inputs-------------------*/

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readf() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}


Measured memory_bytes: 2688