akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n, m; cin >> n >> m;
	vector<vi> e(n);
	rep(i, m){
		int a, b; cin>> a >> b; a--; b--;
		e[a].pb(b);
		e[b].pb(a);
	}
	vi vis(n);
	queue<pi> q;
	q.emplace(0, 0);
	while(!q.empty()){
		int c = q.front().first, co = q.front().second; q.pop();
		if(vis[c]) continue;
		vis[c] = 1;
		if(c == n - 1){
			if(co == 2){
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}
		for(int i: e[c]) if(!vis[i]) q.emplace(i, co + 1);
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 13680
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll n,m;
string s,t;
int main()
{
    cin>>n>>m;
    cin>>s;
    cin>>t;
    if(s[0]!=t[0])
    {
        printf("-1\n");
        return 0;
    }
    ll gcd=__gcd(n,m);
    for(ll x=1;x<n;x++)
    {
        if(x*m%n!=0) continue;
        ll y=x*m/n;
        if(s[x]!=t[y])
        {
            printf("-1\n");
            return 0;
        }
    }
    cout<<n/gcd*m<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
namespace rmq {
	const int MAXN = 2e5 + 5;
	const int MAXLOG = 20;
	int Max[MAXN][MAXLOG], Min[MAXN][MAXLOG], Log[MAXN];
	int queryMax(int l, int r) {
		int len = r - l + 1, tmp = Log[len];
		return max(Max[l][tmp], Max[r - (1 << tmp) + 1][tmp]);
	}
	int queryMin(int l, int r) {
		int len = r - l + 1, tmp = Log[len];
		return min(Min[l][tmp], Min[r - (1 << tmp) + 1][tmp]);
	}
	void init(int *a, int n) {
		for (int i = 1; i <= n; i++) {
			Min[i][0] = a[i];
			Max[i][0] = a[i];
			Log[i] = Log[i - 1];
			if ((1 << (Log[i] + 1)) <= i) Log[i]++;
		}
		for (int t = 1; t < MAXLOG; t++)
		for (int i = 1, j = (1 << (t - 1)) + 1; j <= n; i++, j++) {
			Max[i][t] = max(Max[i][t - 1], Max[j][t - 1]);
			Min[i][t] = min(Min[i][t - 1], Min[j][t - 1]);
		}
	}
}
int n, k, a[MAXN];
bool flg[MAXN];
int main() {
	read(n), read(k);
	for (int i = 1; i <= n; i++)
		read(a[i]);
	rmq :: init(a, n);
	int ans = 0, now = 0;
	for (int i = 1; i <= k - 1; i++)
		now += a[i] < a[i + 1];
	for (int i = 1, j = k; j <= n; i++, j++) {
		if (now == k - 1) {
			ans = 1;
			flg[i] = true;
		}
		now -= a[i] < a[i + 1];
		now += a[j] < a[j + 1];
	}
	for (int i = 1, j = k; j <= n; i++, j++) {
		if (flg[i]) continue;
		if (i != 1 && a[i - 1] < rmq :: queryMin(i, j - 1) && a[j] > rmq :: queryMax(i, j - 1)) continue;
		else ans++;
	}
	writeln(ans);
	return 0;
}

Measured memory_bytes: 33280
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

     static Scanner scanner;

     public static void main(String[] args) {
         scanner = new Scanner(System.in);

         int N=gi();
         int[] a=new int[N];

         for (int i=0; i<N;i++) {
        	 a[i]=gi();
         }

         //Arrays.parallelSort(a);

         Map<Integer,Long> map=new HashMap<Integer, Long>();
         for (int i=0; i<N;i++) {
             if(map.containsKey(a[i])) {
            	 map.put(a[i], map.get(a[i])+1);
             } else {
            	 map.put(a[i], 1l);
             }
         }

         long max=0;
         for(Long v :map.values()) {
             long t=v*(v-1)/2;
             max+=t;
         }

         StringBuilder sb=new StringBuilder();
         for (int i=0; i<N;i++) {
             long v=map.get(a[i]);
             if(v>1) {
            	 long t1=v*(v-1)/2;
            	 long t2=(v-1)*(v-2)/2;
            	 sb.append(max-t1+t2);
            	 sb.append(System.lineSeparator());
             } else {
            	 sb.append(max);
            	 sb.append(System.lineSeparator());
             }
         }

         System.out.println(sb);
     }

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 63092
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner scan = new Scanner(System.in);

		while(true){

			//?????°?????????
			int n = scan.nextInt();
			//????????¢???????´?????????????
			double[] score = new double[n];
			//????¨????????????????????????°
			double total = 0.0;
			//?????????????????????????????°
			double average = 0.0;
			//?????£????????????????????°
			double var = 0.0;
			//?¨?????????????????????????????????°
			double result = 0.0;

			//???????????¶
			if(n==0){
				scan.close();
				break;
			}else{

				for(int i = 0; i < n; i++){
					score[i] = scan.nextDouble();
					total += score[i];
				}
				//?????????
				average = total / n;
				//?????£????¨????
				double temp = 0.0;
				for(int j = 0; j < n; j++){
					temp += Math.pow(score[j] - average ,2);
				}
				var = temp/n;
			}

			//?¨?????????????????±?????????¬???
			//?????£????????????????±???????
			result = Math.sqrt(var);
			System.out.println(result);
		}
	}

}

Measured memory_bytes: 27908
while True :
    x, y, s = map(int, input().split())
    if x == 0 :
        break
    
    else :
        S = s // 2 + 1
        # a < b と考える
        c = 0
        # 新税率の最大価格
        
        for i in range(1, s - 1) :
            a = i * (100 + x) // 100
            # 旧税率
            
            if(a <= S) :
                for j in range(1, s - 1) :
                    b = j * (100 + x) // 100
                    
                    if(s == a + b) :
                        A = i * (100 + y) // 100
                        # 新税率
                        B = j * (100 + y) // 100
                        
                        if(A + B > c) :
                            c = A + B
            
            else :
                break
            
        print(c)




Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  ll N, A, B;
  cin >> N >> A >> B;

  ll amari = N % (A + B);  //周期からはみ出た個数
  ll s = min(amari, A);
  ll ans = N / (A + B) * A + s;
  cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  int l, r;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n;
	while(cin >> n,n){
		int v[1000000];
		for(int i=0;i<1000000;i++) v[i]=1;
		v[0]=v[1]=0;
		for(int i=2;i*i<1000000;i++){
			if(v[i]){
				for(int j=i*2;j<1000000;j+=i){
					v[j]=0;
				}
			}
		}
		long s=0,i=0;
		while(n--){
			while(!v[i])i++;
			s+=i++;
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 6956
from itertools import accumulate

def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True


def main():
    N = [0] * (10 ** 5 + 1)
    for i in range(3, 10 ** 5 + 1, 2):
        if is_prime(i) and is_prime((i + 1) // 2):
            N[i] += 1

    A = list(accumulate(N))
    Q = int(input())
    for _ in range(Q):
        l, r = map(int, input().split())
        l -= 1
        print(A[r] - A[l])




if __name__ == "__main__":
    main()

Measured memory_bytes: 52444
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String res = "Good";
        for (int i = 0; i < 3; i++) {
            if (s.charAt(i) == s.charAt(i + 1)) {
                res = "Bad";
                break;
            }
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;

vector<ll> v(303030);
ll n,k,m,x,y;
string s,t;
bool dp[101010];

int main() {
  cin >> x;
  dp[0]=true;
  rep(i,x)if(dp[i])rep(j,6) dp[i+100+j]=true;
  cout << (dp[x] ? 1 : 0) << endl;
}

Measured memory_bytes: 2688
import sys

def f(n):
  X6 = []
  X9 = []
  for i in range(0, 10):
    if n >= 6**i:
      X6.append(6**i)
    if n >= 9**i:
      X9.append(9**i)
  return max(X6), max(X9)


def main():
  input = sys.stdin.readline
  N = int(input())
  dp = [0 for _ in range(N+1)]
  for i in range(1, N+1):
    can = []
    max6, max9 = f(i)
    X = [1, max6, max9]
    for x in X:
      can.append(dp[i-x] + 1)
    dp[i] = min(can)
  print(dp[N])

if __name__ == '__main__':
  main()

Measured memory_bytes: 3864
N = int(input())
A = list(map(int, input().strip().split()))
min_n = max_n = A[0]
for i in range(1, N):
	num = A[i]
	if min_n > num:
		min_n = num
	if max_n < num:
		max_n = num
result = max_n - min_n
print(result)
		

Measured memory_bytes: 2940
import math
a,b,x=map(lambda x: int(x), input().split())
ans=0
if a*b/2 > x/a:
    ans=math.atan(a*(b**2)/(2*x))*180/math.pi
else:
    ans=math.atan((2*b/a)-(2*x/(a**3)))*180/math.pi
print(ans)

Measured memory_bytes: 3060
# coding: utf-8
# Your code here!

N = int(input())

W = list(map(int, input().split()))

s1 = 0
s2 = 0

total = 0

for i in range(N):
    total += W[i]

# print(total)
# s2 = total

cnts1 = 0
cnts2 = N - 1
for i in range(N):
    if s1 <= s2:
        s1 += W[cnts1]
        cnts1 += 1
        # print("s1,", s1)
    else:
        s2 += W[cnts2]
        cnts2 -= 1
        # print("s2,", s2)
    

print(int(abs(s1 - s2)))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define li long long int
#define ld long double
#define eb push_back
#define pb pop_back
#define INF 1e18+10
#define MINF -1e18-10
#define rep(i,a,b) for(li i=a;i<b;i++)
#define size(a) a.size()
#define rev(a) reverse(a.begin(),a.end())
#define len(a) a.length()
#define f first
#define s second
#define sort(a) sort(a.begin(),a.end())
#define vli vector<li>
#define vvli vector<vli >
#define pli pair<li,li>
#define vpli vector<pli>
#define inp(t) li t;cin>>t; while(t--)
using namespace std;
const li mod = 1e9+7;
#define MAXN 1000005 
#define pi 3.14159265

li power(li a, li b) { a%=mod; li ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
li add(li a,li b) { return (((a%mod)+(b%mod))%mod);}
li sub(li a,li b) { return (((a%mod)-(b%mod))%mod);}
li mul(li a,li b) { return (((a%mod)*(b%mod))%mod);}

bool isprime(li n)
{
  if (n == 1)
    return false;
  int i = 2;
  while (i*i <= n){
      if (n % i == 0)return false;
      i += 1;
  }
  return true;
}

li dp[105][1000005];

void solve()
{
  li n,W;
  cin>>n>>W;

  vli weights(n),v(n);

  rep(i,0,n)
  cin>>weights[i]>>v[i];

  for(li i=1;i<=n;i++)
  {
    for(li w=1;w<=W;w++)
    {
      if(weights[i-1]<=w)
      {
        dp[i][w] = max(v[i-1] + dp[i-1][w - weights[i-1]] , dp[i-1][w]);
      }
      else
      {
        dp[i][w] = dp[i-1][w];
      }
    }
  }

  cout<<dp[n][W]<<endl;
}

int main()
{
    IOS;
    
    for(li i=0;i<1000005;i++)
    {
      dp[0][i] = 0;
    }
    for(li i=0;i<105;i++)
    {
      dp[i][0] = 0;
    }

    solve();
    return 0;
}

Measured memory_bytes: 301312
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
vector<int> G[MAX_N];
int dp[MAX_N];

int rec(int v)
{
	if (dp[v] != -1) return dp[v];

	int res = 0;
	rep(i,G[v].size())
	{
		res = max(res,rec(G[v][i]) + 1);
	}
	return dp[v] = res;
}

int main()
{
	int N,M;
	cin >> N >> M;
	rep(i,M)
	{
		int x,y;
		cin >> x >> y;
		x--; y--;
		G[x].push_back(y);
	}

	rep(i,N)
	{
		dp[i] = -1;
	}
	int ans = 0;
	rep(i,N)
	{
		ans = max(ans,rec(i));
	}
	cout << ans << endl;
	return 0;
}

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

int main(void){
  int n;
  cin >> n;
  int N[4];
  N[0] = n/1000;
  N[1] = n/100%10;
  N[2] = n/10%10;
  N[3] = n%10;
  if(N[0] == N[1]){
    if(N[1] == N[2]){
      cout << "Yes" << '\n';
    }
    else{
      cout << "No" << '\n';
    }
  }
  else{
    if(N[1] == N[2]){
      if(N[2] == N[3]){
        cout << "Yes" << '\n';
      }
      else{
        cout << "No" << '\n';
      }
    }
    else{
      cout << "No" << '\n';
    }
  }
}


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

using namespace std;
const int maxn=6e2+45;
#define INF 0x3f3f3f3f;
#define ll long long int
#define charmax(x,y) x=max(x,y)
#define charmin(x,y) x=min(x,y)
#define clr(x,p) memset(x,p,sizeof x)
int n,d1,d2;int w;
int a[maxn][maxn];
int vis[maxn][maxn];
void work(int d){
    int pos=0;
    while(d%4==0){
        d/=4;
        pos++;
    }
    if(d%2==1){
        for(int i=0;i<w;i++){
            for(int j=0;j<w;j++){
                if(((i>>pos)+(j>>pos))&1){
                    a[i][j]=1;
                }
            }
        }
    }
    else{
        for(int i=0;i<w;i++){
            for(int j=0;j<w;j++){
                if((i>>pos)&1) a[i][j]=1;
            }
        }
    }
}
int main()
{
    clr(a,0);clr(vis,0);
    scanf("%d %d %d",&n,&d1,&d2);
    w=2*n;
    work(d1);work(d2);
    int cs=0;
    for(int i=0;i<w;i++){
        for(int j=0;j<w;j++){
            if(cs==n*n) break;
            if(a[i][j]==0){
                printf("%d %d\n",i,j);
                cs++;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4224
#![allow(unused_imports)]
use std::cmp::*;
use proconio::*;

#[fastout]
fn main() {
   input! {
      n: usize,
      A: [i64; n],
   }
   let mut prev = A.iter().zip(0..n).collect::<Vec<_>>();
   prev.sort();
   let mut dp: Vec<i64> = (0..n+1).map(|_| 0).collect();
   for i in 0..n {
       let (a, pos) = prev[i];
       for l in 0..n-i {
           let r = l + i;
           dp[l] = max(dp[l] + a*(r as i64-pos as i64).abs(), dp[l+1] + a * (l as i64-pos as i64).abs());
       }
   }
   println!("{}", dp[0]);
}


Measured memory_bytes: 2280
#include <stdio.h>
#include <stdlib.h>

#define MAX_LEN (100000)
#define MAX_NUM (100000)

int main(int argc, char *argv[]) {
  int n, a[MAX_LEN];
  int cnt_even[MAX_NUM + 1] = {}, cnt_odd[MAX_NUM + 1] = {};
  int max1_cnt_even, max1_cnt_odd, max2_cnt_even, max2_cnt_odd;
  int max1_num_even, max1_num_odd, max2_num_even, max2_num_odd;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (int i = 0; i < n; i += 2)
    cnt_even[a[i]]++;
  for (int i = 1; i < n; i += 2)
    cnt_odd[a[i]]++;
  max1_cnt_even = -1; max1_num_even = -1;
  max2_cnt_even = -1; max2_num_even = -1;
  for (int i = 0; i <= MAX_NUM; i++) {
    // printf("i = %d\n", i);
    if (cnt_even[i] > 0) {
      if (max1_cnt_even <= cnt_even[i]) {
        max2_cnt_even = max1_cnt_even;
        max2_num_even = max1_num_even;
        max1_cnt_even = cnt_even[i];
        max1_num_even = i;
      } else if (max2_cnt_even <= cnt_even[i]) {
        max2_cnt_even = cnt_even[i];
        max2_num_even = i;
      }
    }
    // printf("1cnte = %d, 1nume = %d, 2cnte = %d, 2nume = %d\n",
    //        max1_cnt_even, max1_num_even, max2_cnt_even, max2_num_even);
  }
  // printf("1cnte = %d, 1nume = %d, 2cnte = %d, 2nume = %d\n",
  //        max1_cnt_even, max1_num_even, max2_cnt_even, max2_num_even);
  max1_cnt_odd = 0; max1_num_odd = -1;
  max2_cnt_odd = 0; max2_num_odd = -1;
  for (int i = 0; i <= MAX_NUM; i++) {
    if (cnt_odd[i] > 0) {
      if (max1_cnt_odd <= cnt_odd[i]) {
        max2_cnt_odd = max1_cnt_odd;
        max2_num_odd = max1_num_odd;
        max1_cnt_odd = cnt_odd[i];
        max1_num_odd = i;
      } else if (max2_cnt_odd <= cnt_odd[i]) {
        max2_cnt_odd = cnt_odd[i];
        max2_num_odd = i;
      }
    }
  }
  // printf("1cnto = %d, 1numo = %d, 2cnto = %d, 2numo = %d\n",
  //        max1_cnt_odd, max1_num_odd, max2_cnt_odd, max2_num_odd);
  if (max1_num_even != max1_num_odd) {
    printf("%d\n", n - max1_cnt_odd - max1_cnt_even);
  } else if (max1_cnt_odd + max2_cnt_even >= max2_cnt_odd + max1_cnt_even) {
    printf("%d\n", n - max1_cnt_odd - max2_cnt_even);
  } else {
    printf("%d\n", n - max2_cnt_odd - max1_cnt_even);
  }
  
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define fout(x) cout << fixed << setprecision(10) << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

auto print = [](auto &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
};

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k, n;
  cin >> k >> n;
  VI a(n), s(n);
  rep(i, n) cin >> a[i];
  rep(i, n-1) s[i] = a[i + 1] - a[i];
  s[n-1] = k - a[n - 1] + a[0];
  out(k - *max_element(all(s)));
  return 0;
}


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

#define ll long long 
#define sz(x) (int)x.size()

using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	for(int&i:a)cin>>i;
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	ll ans=0;
	for(int i=0;i<k;i++)ans+=a[i];
	cout<<ans;
	
}

Measured memory_bytes: 3620
#include<iostream>
#include <cmath>
using namespace std;
int ksm(int cifang,int shu)
{
    long long int sum=1;
    for (int i=1;i<=cifang;i++)
        sum*=shu;
    return sum;
}
int ws(int k)
{
    int num=0;
    while (k)
    {
        num++;
        k/=10;
    }
    return num;
}
int main()
{
    int a,b;
    cin>>a>>b;
    long long int x;
    x=a*ksm(ws(b),10)+b;
    int i=sqrt(x);
    if (i*i==x)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
} 

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int h,w;
	cin>>h>>w;
	vector<vector<int>> b=vector<vector<int>>(h+2,vector<int>(w+2,0));
	vector<vector<int>> b1=vector<vector<int>>(h+2,vector<int>(w+2,0));
	vector<vector<int>> b2=vector<vector<int>>(h+2,vector<int>(w+2,0));
	FORQ(i,1,h){
		string s;
		cin>>s;
		FORQ(j,1,w){
			if(s[j-1]=='.'){
				b[i][j]=1;
				b1[i][j]=1;
				b2[i][j]=1;
			}
		}
	}
	FORQ(i,1,h){
		FORQ(j,1,w){
			if(b[i][j]==0)continue;
			b1[i][j]+=b1[i][j-1];
		}
	}
	FORQ(i,1,w){
		FORQ(j,1,h){
			if(b[j][i]==0)continue;
			b2[j][i]+=b2[j-1][i];
		}
	}
	FORD(i,h+1,1){
		FORD(j,w+1,1){
			if(b[i][j]==0)continue;
			b1[i][j]=max(b1[i][j+1],b1[i][j]);
		}
	}
	FORD(i,w+1,1){
		FORD(j,h+1,1){
			if(b[j][i]==0)continue;
			b2[j][i]=max(b2[j+1][i],b2[j][i]);
		}
	}
	int ans=0;
	FORQ(i,1,h){
		FORQ(j,1,w){
			ans=max(ans,b1[i][j]+b2[i][j]-1);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 47360
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    REP(i, N) { cin >> L[i]; }
    long long d = 0;
    for(int cnt = 0; cnt < N + 1; cnt++) {
        d = d + L[cnt];
        if(d > X) {
            cout << cnt + 1 << endl;
            return 0;
        }
    }
    cout << N + 1 << endl;
    return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
    int n;
    string s;
    cin >> n >> s;
    int r = count(s.begin(), s.end(), 'R');
    cout << r - count(s.begin(), s.begin() + r, 'R') << endl;
}

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

int main(){
  int a,b,k;
  cin >> a >> b >> k;
  if(b-a+1>2*k){
    for(int i=0; i<k; i++){
      cout << a+i << endl;
    }
    for(int i=0; i<k; i++){
      cout << b-k+1+i << endl;
    }
  }
  else{
    for(int i=a; i<b+1; i++){
      cout << i << endl;
    }
  }
}

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

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;

signed main(){
	llin(a);
	llin(b);
	llin(c);
	sal((b/a>c?c:b/a));
}


Measured memory_bytes: 256
#!python3

# input
n = int(input())
A = list(map(int, input().split()))


def main():
    W = sorted(A)
    a = W[-1]
    h = a / 2
    b = W[0]
    for x in W[1:-1]:
        if max(b - h, h - b) > max(x - h, h - x):
            b = x
    print(a, b)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14052
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define pb                  push_back
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define mk(arr,n,type)      type *arr=new type[n];
#define dbg(x) cerr << #x << " is " << x << endl;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
clock_t beg = clock();
const int inf=1e18;const int mod=1e9+7;const int N=2e5+9;
const double pi = 3.1415926535897932384626433;
void FILE_IO(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}

void JH(){
    int d=0,e=0,f=0,g=0,p=0,w=0,flag=0,ans=INT_MAX,res=0,cnt=0,sum=0;double f1=0.0,f2=0.0,f3=0.0;
    int x,n;cin>>x>>n;
    int a[n];
    set<int> s;
    fo0(i,n){
        cin>>a[i];
        s.insert(a[i]);
    }
    if(n==0){
        cout<<x;
        return;
    }
    for(int i=-5;i<=105;i++){
        if(s.find(i)==s.end()){
            int diff=abs(x-i);
            if(diff<ans){
                ans=diff;
                res=i;
            }
        }
    }
    cout<<res;

}

int32_t main()
{
    FAST_IO;int t=1;
    // cin>>t;
    while(t--){JH();}cerr<<fixed<<setprecision(3)<<(double)(clock()-beg)/1000<<"s ";
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >>n;
  vector<double> vec(n);
  for(int i=0;i<n;i++){
    cin >>vec[i];
  }
  vector<double> vec2(n);
  for(int i=0;i<n;i++){
    vec2[i]=1/vec[i];
  }
  double b=0;
  for(int i=0;i<n;i++){
    b=b+vec2[i];
  }
 cout <<1/b<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    md = 10 ** 9 + 7
    n = int(input())
    aa = LI()
    cnt = [0] * 100005
    check = [0] * 100005
    zero = 0
    ans = 1
    for a in aa:
        if a == 0:
            zero += 1
        else:
            if cnt[a - 1] == 0:
                print(0)
                exit()
            ans *= cnt[a - 1]
            ans %= md
            cnt[a - 1] -= 1
        cnt[a] += 1
        check[a] += 1
        if check[a] > 3:
            print(0)
            exit()
    if zero == 1:
        ans *= 3
    else:
        ans *= 6
    if sum(cnt) == zero:
        print(ans % md)
    else:
        print(0)

main()


Measured memory_bytes: 13980
N=int(input())
A = [int(input()) for i in range(N)]
A_next=A[0]
A_list=[1,A_next]
for _ in A:
    A_list.append(A[A_next-1])
    A_next=A[A_next-1]
if not 2 in A_list:
    print(-1)
else:
    print(A_list.index(2))

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

int main(void){
  while(true){
    long n;
    cin >> n;
    if(n == 0){
      break;
    }
    vector<long> S;
    for(int i = 0; i < n;++i){
      long s;
      cin >> s;
      S.push_back(s);
    }
      long mx = *max_element(S.begin(), S.end());
      long mn = *min_element(S.begin(), S.end());
      long sum = accumulate(S.begin(), S.end(), 0);
      cout << (sum - mx - mn) / (n - 2)  << endl;
  }
 return 0;
}



Measured memory_bytes: 3004
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;cin>>n;
	vector<int> h(n,0);
	vector<int> dp(n+1,0);
	for(int i=0;i<n;i++)	cin>>h[i];
	dp[1]=abs(h[1]-h[0]);
	dp[2]=min(dp[1]+abs(h[2]-h[1]),abs(h[2]-h[0]));
	for(int i=3;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]) , dp[i-2]+abs(h[i]-h[i-2]));
	}
	
	
	//~ for(int i=0;i<n;i++)	cout<<dp[i]<<" ";
	cout<<endl;
	cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
double p[2999];
double dp[3000][3000];	//dp[回数][表] = 確率

signed main() {
	int i, j;
	
	cin >> n;
	rep(i, n) cin >> p[i];
	
	dp[0][0] = 1;
	rep(i, n) {
		rep(j, n) {
			dp[i + 1][j + 1] += dp[i][j] * p[i];
			dp[i + 1][j] += dp[i][j] * (1 - p[i]);
		}
	}
	
	double ans = 0;
	rep(i, n + 1) {
		if (i > n - i) {
			ans += dp[n][i];
		}
	}
	printf("%.14f\n", ans);
	return 0;
}

Measured memory_bytes: 70528
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

import org.omg.Messaging.SyncScopeHelper;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new Test_100().doIt();
	}
	class Test_100{
		void doIt() {
			int N = sc.nextInt();
			int A = sc.nextInt();
			int ans = N % 500;
			if(ans <= A)System.out.println("Yes");
			else System.out.println("No");
		}
	}
}


Measured memory_bytes: 23124
def get_power(number):
    number = int(number)
    count = 0
    while True:
        if number % (2**(count+1)) == 0:
            count += 1
        else:
            return count

n = int(input())
an = list(map(get_power, input().split()))

an.sort()
print(an[0])


Measured memory_bytes: 2940
N,Q = map(int, input().split())
S = input()
AC_cum = [0]
for i in range(N-1):
  if S[i:i+2] == 'AC':
    AC_cum.append(AC_cum[-1]+1)
  else:
    AC_cum.append(AC_cum[-1])
for q in range(Q):
  l,r = map(int, input().split())
  print(AC_cum[r-1]-AC_cum[l-1])

Measured memory_bytes: 6100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,int> Pi;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

template <class T>struct PairingHeap{
    struct node{
        T key;
        node *head,*next;
        explicit node(T key):key(key),head(nullptr),next(nullptr){}
    };
    node *r;
    PairingHeap():r(nullptr){}
    PairingHeap(node* r):r(r){}
    node* merge(node *a,node *b){
        if(!a||!b) return a?a:b;
        if(a->key<b->key){
            b->next=a->head,a->head=b;
            return a;
        }
        else{
            a->next=b->head,b->head=a;
            return b;
        }
    }
    node* mergelist(node *s){
        if(!s) return nullptr;
        node h((T()));
        while(s){
            node *a=s,*b=nullptr;
            s=s->next;a->next=nullptr;
            if(s) b=s,s=s->next,b->next=nullptr;
            a=merge(a,b);a->next=h.next;
            h.next=a;
        }
        node *t=h.next;
        s=t;
        t=t->next;
        while(t){
            node *u=t;
            t=t->next;
            s=merge(s,u);
        }
        return s;
    }
    T top(){
        if(!r) return numeric_limits<T>::min();
        return r->key;
    }
    void pop(){
        if(!r) return;
        r=mergelist(r->head);
    }
    void push(T k){r=merge(r,new node(k));}
    bool empty(){return !r;}
};

int main(){
    int n,m,p,q,c;
    cin>>n>>m;
    map<P,vector<Pi>> v;
    fr(i,m){
        cin>>p>>q>>c;
        v[mp(p,c)].pb(mp(mp(q,c),0));
        v[mp(q,c)].pb(mp(mp(p,c),0));
        v[mp(p,0)].pb(mp(mp(p,c),1));
        v[mp(p,c)].pb(mp(mp(p,0),0));
        v[mp(q,0)].pb(mp(mp(q,c),1));
        v[mp(q,c)].pb(mp(mp(q,0),0));
    }
    PairingHeap<iP> pq;
    map<P,bool> vis;
    pq.push(mp(0,mp(1,0)));
    while(!pq.empty()){
        iP ip=pq.top();
        pq.pop();
        int cst=ip.ft;
        P p=ip.sd;
        if(p==mp(n,0)){cout<<cst<<endl;return 0;}
        if(vis[p]) continue;
        vis[p]=1;
        fr(i,v[p].size()){
            if(vis[v[p][i].ft]) continue;
            pq.push(mp(cst+v[p][i].sd,v[p][i].ft));
        }
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 112512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)

int main(){
    int n, t, a;
    cin >> n >> t >> a;
    int ans = 0;
    double dist = 9999999.0;
    for(int i = 0; i < n; i++){
        int h;
        cin >> h;
        double temp = (double)t - (double)h*0.006;
        if(abs((double)a-temp)<dist){
            dist = abs((double)a-temp);
            ans = i+1;
        }
    }
    cout << ans << endl;

    return 0;
}


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


int main() {
	int n;
	cin >> n;
	string str = to_string(n);
	vector<string> check(10);
	for(int i=0; i<10; i++){
		string tmp = "";
		for(int j=0; j<3; j++){
			tmp += to_string(i);
		}
		check.at(i) = tmp;
	}
	bool ans = false;
	for(int i=0; i<10; i++){
		if(str.find(check.at(i)) >= 0 && str.find(check.at(i)) < str.size()) ans = true;
	}
	if(ans){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

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

int main(){    
    int N, M, K;
    cin >> N >> M >> K;

    vector<int long long> A(200010);
    vector<int long long> B(200010);
    
    A[0] = 0;
    for (int i = 1; i < N+1; i++)
    {
        int a; cin >> a;
        A[i] = A[i-1] + a;
    }

    B[0] = 0;
    for (int i = 1; i < M+1; i++)
    {
        int a; cin >> a;
        B[i] = B[i-1] + a;
    }

    int ans = 0;
    for (int i = 0; i < N+1; i++)
    {
        for (int j = M; j >= 0; j--)
        {
            if (A[i] + B[j] <= K)
            {
                ans = max(ans, i+j);
                M = j;
                // cout << "sum " << A[i]+B[j] << " ans " << ans << endl;
                break;
            }
        }
        
    }
        
    cout << ans << endl;

}

Measured memory_bytes: 6428
def main():
    N = int(input())
    up_lines = []
    down_lines = []
    for i in range(N):
        s = input()
        height = 0
        bottom = 0
        for c in s:
            if c == "(":
                height += 1
            else:
                height -= 1
                bottom = min(bottom, height)
        if height > 0:
            up_lines.append((bottom, height))
        else:
            down_lines.append((bottom-height, -height))
    up_lines.sort(reverse=True, key=lambda line: line[0])
    down_lines.sort(reverse=True, key=lambda line: line[0])
    left = 0
    for bottom, height in up_lines:
        if left + bottom < 0:
            print("No")
            return
        left += height
    right = 0
    for bottom, height in down_lines:
        if right + bottom < 0:
            print("No")
            return
        right += height
    if left == right:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 84196
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum,t;



int main()
{
	fast;
	cin>>n>>m;
	if(m<0)
	{
		t=(m-n+1);
		if(t%2==0)
			cout<<"Positive";
		else
			cout<<"Negative";
		return 0;
	}
	if(n<=0 && m>=0)
		return cout<<"Zero",0;
	if(n>0 && m>0)
		return cout<<"Positive",0;




}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

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

using namespace std;

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

#define X first
#define Y second

const int N=3e2+10;
const ll inf=1e16;
const int MOD=1e9+7;

priority_queue <int> pq;


int n,m,f[2][N][N];
vector <ii> v[N];
bool check(int p1,int p2,int p3){
    ///p1<=p2<=p3
    for(auto i:v[p3]){
        if (i.Y==1&&p2>=i.X) return 0;
        if (i.Y==2) {
            if (p2<i.X) return 0;
            if (p1>=i.X) return 0;
        }
        if (i.Y==3&&p1<i.X) return 0;
    }
    return 1;
}

int solve(){
    f[1][0][0]=3;
    for(int R=1;R<n;R++){
        int cur=R&1,next=cur^1;
        memset(f[next],0,sizeof(f[next]));
        for(int p1=0;p1<=R;p1++)
            for(int p2=p1;p2<=R;p2++) if (f[cur][p1][p2]){
                if (check(p1,p2,R+1))
                    f[next][p1][p2]=(f[next][p1][p2]+f[cur][p1][p2])%MOD;
                if (check(p2,R,R+1))
                    f[next][p2][R]=(f[next][p2][R]+f[cur][p1][p2])%MOD;
                if (check(p1,R,R+1))
                    f[next][p1][R]=(f[next][p1][R]+f[cur][p1][p2])%MOD;
            }
    }
    int ans=0;
    for(int p1=0;p1<=n;p1++)
        for(int p2=0;p2<=n;p2++) ans=(ans+f[n&1][p1][p2])%MOD;
    return ans;
}
int main(){
    scanf("%d%d",&n,&m);
    while (m--){
        int x,y,wei;
        scanf("%d%d%d",&x,&y,&wei);
        v[y].push_back(ii(x,wei));
        if (x==y&&wei!=1){
            printf("0");
            return 0;
        }
    }
    cout<<solve();
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>

typedef long long ll;
using namespace std;
 
 
ll GreatestCommonDivisor(ll p, ll q)
{
  if ( p < q ) swap( p, q);
  while ( true )
  {
    long long yo = p % q;
    if ( yo == 0 ) return q;
    p = q;
    q = yo;
  }
  return 1;
}
 
//最小公倍数
long long LeastCommonMultiple(ll a, ll b)
{
  return a / GreatestCommonDivisor(a,b) * b;
}
 
 
ll f(ll a)
{
  ll c = 0;
  while ( a % 2 == 0 && a > 0 )
  {
    ++c;
    a = a / 2;
  }
  return c;
}
 
int main()
{
  ll n, m;
  cin >> n >> m;
  
  vector<ll> a(n);
  for ( auto& ai : a) {
    cin >> ai;
    ai /= 2;
  }
 
 
  //ai に 含まれる2の数を計算（同じでないと半公倍数は存在せず）
  ll c = f( a[0] );
  for ( int i = 1; i < n; ++i )
  {
    if ( c != f(a[i])) { 
      cout << 0;
      return 0;
    }
  }
 
  //a の最小公倍数を計算
  ll lcm = a[0];
  for ( ll i = 1; i < n; ++i )
    lcm = LeastCommonMultiple(lcm, a[i]);
 
  // lcm * (2 p - 1) <= M を満たす最大のp
  cout << (m / lcm + 1) / 2;
  
  return 0;
}
 

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

class Node
{
    internal int parent;
    internal int depth;
    internal string type;
    internal List<int> children;
    public Node() {
        parent = -1;
        depth = 0;
        type = "";
        children = new List<int>();
    }
}

class A
{
    public static void Main() {
        int n = int.Parse(Console.ReadLine());
        Node[] nodes = new Node[n];
        for(int i = 0; i < n; i++) {
            nodes[i] = new Node();
        }
        for(int i = 0; i < n; i++) {
            int[] data = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            if (data[1] > 0) {
                for (int j = 0; j < data[1]; j++) {
                    nodes[data[0]].children.Add(data[j + 2]);
                    nodes[data[j + 2]].parent = data[0];
                }
            }    
        }
        for(int i = 0; i < n; i++) {
            nodes[i].depth = depthSet(nodes, i);
            if (nodes[i].parent != -1) {
                nodes[i].type = nodes[i].children.Count > 0 ? "internal node" : "leaf";
            } else {
                nodes[i].type = "root";
            }
        }
        StringBuilder output = new StringBuilder();
        for(int i=0;i<n;i++) {
            output.AppendLine("node " + i + ": parent = " + nodes[i].parent +
                    ", depth = " + nodes[i].depth + ", " + nodes[i].type +
                    ", [" + string.Join(", ", Array.ConvertAll(nodes[i].children.ToArray(), a => a.ToString())) + "]");
        }
        Console.Write(output);
    }
    static int depthSet(Node[] nodes, int id) {
        int d = 0;
        if (nodes[id].parent != -1) {
            d=1+depthSet(nodes, nodes[id].parent);
            return d;
        } else {
            return 0;
        }
    }
}


Measured memory_bytes: 62216
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String ans = "No";
        String sr = "";
        for(int i = 0;i<s.length();i++){
            sr += s.substring(s.length()-i-1,s.length()-i);
        }
        if(s.equals(sr)){
            String s1 = "";
            String s1r = "";
            s1 = s.substring(0, (s.length()-1)/2);
            for(int i = 0 ;i<s1.length();i++){
                s1r += s1.substring(s1.length()-i-1, s1.length()-i);
            }
            if(s1.equals(s1r)){
                String s2 = "";
                String s2r = "";
                s2 = s.substring((s.length()+3)/2-1,s.length());
                for(int i = 0 ; i<s2.length();i++){
                    s2r += s2.substring(s2.length()-i-1,s2.length()-i);
                }
                if(s2.equals(s2r)){
                    ans = "Yes";
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
from sys import stdin


class ModComb():
    def __init__(self, n_max, mod):
        self.fac = None
        self.mod = mod
        self.make_fac_table(n_max)

    def make_fac_table(self, n_max):
        self.fac = [1] + [0] * n_max
        for i in range(1, n_max + 1):
            self.fac[i] = self.fac[i - 1] * i % self.mod

    def mod_comb(self, n, k):
        if n == 0 and k == 0:
            return 1
        elif n < k or k < 0:
            return 0
        else:
            return self.fac[n] * pow(self.fac[n - k], self.mod - 2, self.mod) * \
                pow(self.fac[k], self.mod - 2, self.mod) % self.mod

    def mod_comb_with_rep(self, n, k):
        return self.mod_comb(n + k - 1, k)


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    S = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    ans = 0
    MOD = 10**9 + 7
    modcomb = ModComb(S + 1, MOD)
    min_ = 1
    max_ = S // 3
    for i in range(min_, max_ + 1):
        res = S - i * 3
        ans += modcomb.mod_comb_with_rep(res + 1, i - 1)
        ans %= MOD
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()

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

int main()
{
	int n;
	string s,t,ans={};
	cin>>n;
	cin>>s>>t;
	for(int i=0;i<n;i++)
	{
		ans+=s[i];
		ans+=t[i];
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

N = int(input())
a = [int(i) for i in input().split()]

a.sort()
print(a[-1]-a[0])


Measured memory_bytes: 5460
#include<stdio.h>

int A[20],n;

int solve(int i,int m)
{
	if (m == 0)
		return 1;
	else if (i >= n)
		return 0;

	return solve(i + 1, m) || solve(i+1,m-A[i]);
}
int main()
{
	int p, key;

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &A[0] + i);
	}
	scanf("%d", &p);
	for (int i = 0; i < p; i++)
	{
		scanf("%d", &key);
		if (solve(0, key))
			printf("yes\n");
		else
			printf("no\n");
	}

	return 0;
}


Measured memory_bytes: 2628
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
    ll a,b,i,j,cc=0,k;
    cin>>a>>b>>k;i=1;
    if(a>b)swap(a,b);
    i=a;
    while(i>0){
        if(a%i==0 && b%i==0){
            cc++;
        }
        if(cc==k){
            cout<<i<<endl;
            return 0;
        }
        i--;
    }
return 0;
}


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

typedef int64_t i64;

constexpr i64 llinf=4611686018427387903LL;

template <class T_>
class rupdq{
public:
    i64 n;
    i64 h;
    T_ *lz;
    void make(i64 N){
        n=1;
        h=0;
        while(n<N){
            n*=2;
            h++;
        }
		lz=new i64[n*2]{};
        for(i64 i=0;i<n*2;i++) lz[i]=(T_)llinf;
    }
    void update(i64 A,i64 B,T_ X){
        thrust(A+=n);
        thrust(B+=n-1);
        for(i64 l=A,r=B+1;l<r;l/=2,r/=2){
            if(l%2==1){
                lz[l]=X;
                l++;
            }
            if(r%2==1){
                r--;
                lz[r]=X;
            }
        }
    }
    T_ query(i64 K){
        thrust(K+=n);
        return lz[K];
    }
    void thrust(i64 K){
        for(i64 i=h;i>0;i--){
            i64 k=K>>i;
            if(lz[k]==(T_)llinf) continue;
            lz[k*2]=lz[k];
            lz[k*2+1]=lz[k];
            lz[k]=(T_)llinf;
        }
    }
};

int main(void){
    i64 n,q;
    scanf("%lli%lli",&n,&q);
    rupdq<i64> r;
    r.make(n);
    for(i64 i=0;i<q;i++){
        i64 c;
        scanf("%lli",&c);
        if(c==0){
            i64 s,t,x;
            scanf("%lli%lli%lli",&s,&t,&x);
            r.update(s,t+1,x);
        }
        if(c==1){
            i64 j;
            scanf("%lli",&j);
            j=r.query(j);
            if(j==llinf) printf("2147483647\n");
            else printf("%lli\n",j);
        }
    }
    return 0;
}



Measured memory_bytes: 5264