akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline ll input() {
    ll n;
    cin >> n;
    return n;
}

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 2e5 + 10;
const ll INF = 8e18;
const ll MOD1 = 998244353;
const ll MOD2 = 1e9 + 7;
const ll MOD3 = 1e9 + 9;

ll n , p[MAXN][3] , dp[MAXN][3];

int main() {
    fast_io;

    cin >> n;
    for(ll i = 1 ; i <= n ; i++)    cin >> p[i][0] >> p[i][1] >> p[i][2];

    for(ll i = 1 ; i <= n ; i++)
    {
        for(ll j = 0 ; j < 3 ; j++)
        {
            for(ll k = 0 ; k < 3 ; k++)
            {
                if(k != j)
                {
                    dp[i][j] = max(dp[i][j] , dp[i - 1][k] + p[i][j]);
                }
            }
        }
    }
    cout << max({dp[n][0] , dp[n][1] , dp[n][2]});

    return 0;
}
/*
todo :
    1- set constants
    2- check TimeLimit and MemoryLimit
    3- check special test cases
    4- don't forget BS can help you that is good idea(use for loop for floats)
    5- don't forget printf and scanf can help you in your code speed
*/


Measured memory_bytes: 8448
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int c = scanner.nextInt();
            
            if (a > b && a > c && a*a == b*b + c*c) {
                System.out.println("YES");
            } else if (b > a && b > c && b*b == a*a + c*c) {
                System.out.println("YES");
            } else if (c > a && c > b && c*c == a*a + b*b) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
}

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

int main(){
  int n,m,k;
  cin >>n >>m >>k;
  for(int i=0;i<=n;i++){
    for(int r=0;r<=m;r++){
      int sum=n*r+m*i-2*i*r;
      if(k==sum){cout << "Yes" << endl;
                return 0;}
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
object Main extends App {
  val Array(n, a, b) = io.StdIn.readLine().split(" ").map(_.toInt)
  def convert(i: Int): Int = {
    val x = i.toString.toSeq.map(s => s.toString.toInt).sum
    if (x >= a && x <= b) i else 0
  }
  val res = Seq.range(1, n + 1).map(convert).sum
  println(res)
}

Measured memory_bytes: 40296
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<int> T(N);
  for(auto& t : T){
    cin >> t;
  }

  int sum_T = 0;
  for(auto& t : T){
    sum_T += t;
  }
  
  int M;
  cin >> M;
  for(int ii=0; ii<M; ii++){
    int p, x;
    cin >> p >> x;
    cout << sum_T - T[p-1] + x << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K,X;
    cin >> K >> X;
    rep(i,X-K+1, X+K){
        cout << i << " \n"[i == X+K-1];
    }
    
    
}

Measured memory_bytes: 256
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
//using
using namespace std;
/*using vi = vector <int>;
using vs = vector <string>;
using vc = vector <char>;*/
//vector<vector<char> > hyou(N, vector<char>(N));
//define
#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
//グローバル変数宣言
int a=0,b=0,c=0,d=0,e=0,f=0,g=0;

signed main(){
    cin>>a>>b>>c;
    if (a%2==1||b%2==1||c%2==1){d=0;}
    else if(a==b&&b==c){d=-1;}
    else{
    rep(i,1000000000)
    {
        e=a/2;f=b/2;g=c/2;d++;a=f+g;b=e+g;c=e+f;
        if(a%2==1||b%2==1||c%2==1)break;
    }}
    print(d);
}


Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

int main(){
	IO_STREAM;
	int H,W,K;	cin>>H>>W>>K;
	int c[H][W]={0};
	rep(i,0,H){
		rep(j,0,W){
			char p;	cin>>p;
			if(p=='#'){
				c[i][j]=1;
			}
			else{
				c[i][j]=0;
			}
		}
	}
	int ans=0;
	rep(bitH,0,(1<<H)){
		rep(bitW,0,(1<<W)){
			int sum = 0;
			rep(i,0,H){
				if (bitH & (1<<i)) continue;
				rep(j,0,W){
					if (bitW & (1<<j)) continue;
					sum+=c[i][j];
				}
			}
			if(sum==K) ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main() {
	int ti = clock();
	int R, G, B, N; cin >> R >> G >> B >> N;
	long long res = 0;
	for (int r = 0; r * R <= N; r++)
	{
		for (int g = 0; r * R + g * G <= N; g++)
		{
			if((N - r * R - g * G) % B == 0) res++;
		}
	}
	cout << res << endl;
//	cout << (double)(clock() - ti) / CLOCKS_PER_SEC << endl;;
	return 0;
}


Measured memory_bytes: 3600
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<String> s = Arrays.asList(sc.next().split(""));
        Collections.sort(s);
        Set<String> set = new HashSet<>(s);
        char alphabet = 'a';
        for (int i = 0; i < 26; i++) {
            if (!set.contains(String.valueOf(alphabet))) {
                System.out.println(alphabet);
                return;
            }
            alphabet++;
        }
        System.out.println("None");
    }

}


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

#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
const ll INF = 1e9, MOD = INF + 7;

/////////////////////////////////////////////////////////////////////

const int N = 3e5 + 5;

int main(){
	
	sync;

	double sum = 0;
	int n; cin >> n;
	for(int i = 0; i < n; i++) {
		int x; cin >> x;
		sum += (1.0 / (1.0 * x));
	}
	cout << fixed << setprecision(5) << (1.0 / sum) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <queue>
#include <string>

using namespace std;

const double PI = 3.14159265358979;

int G[101][101];
bool visited[101];
int timex[101][2];
int now_time = 1;
int n;

void dfs(int node) {

	if (!visited[node]) {
		visited[node] = 1;
		timex[node][0] = now_time++;
		for (int i = 0; i < n; i++)	{
			if (G[node][i] && visited[i] == 0) {
				dfs(i);
			}
		}
		timex[node][1] = now_time++;
	}
}

void dfs_stack(int node) {

	stack<int> st;
	st.push(node);
	visited[node] = 1;
	timex[node][0] = now_time++;
	while (!st.empty()) {
		int ver = st.top();

		bool flag = false;
		for (int i = 0; i < n; i++)	{
			if (G[ver][i] && visited[i] == 0) {
				visited[i] = 1;
				timex[i][0] = now_time++;
				st.push(i);
				flag = true;
				break;
			}
		}
		if (!flag) {
			timex[ver][1] = now_time++;
			st.pop();
		}
	}

}


int main() {
	
	cin >> n;

	for (int i = 0; i < n; i++)	{
		int id, degree;
		cin >> id >> degree;
		for (int j = 0; j < degree; j++) {
			int idx; cin >> idx;
			G[id - 1][idx - 1] = 1;
		}
	}

	for (int i = 0; i < n; i++) {
		if (!visited[i])
			dfs_stack(i);
	}
	

	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << timex[i][0] << " " << timex[i][1] << endl;
	}


	return 0;
}



Measured memory_bytes: 3136
A, B = map(int, input().split())

Amin= A*100/8
AMAX= (A+1)*100/8
Bmin= B*100/10
BMAX= (B+1)*100/10

Alist=[0]*1257
Blist=[0]*1257
ANSlist=[10000]*1257

for i in range(1257):
    if Amin <=i <AMAX:
        Alist[i]=i

for i in range(1257):
    if Bmin <=i <BMAX:
        Blist[i]=i

for i in range(1257):
    if Alist[i]!=0 and Blist[i]!=0:
        ANSlist[i]=i

if min(ANSlist)==10000:
    print(-1)
else:
    print(min(ANSlist))


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

int main()
{
    int a,b,c;
    cin>>a>>b>>c;

    if(a<b && b<c){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3104
def resolve():
    x = int(input())
    aa = [i**5 for i in range(1000)]

    for i in range(len(aa)):
        a = aa[i]
        for j in range(len(aa)):
            b = aa[j]
            if a - b == x:
                print(i,j)
                break
            elif a + b == x:
                print(i,-j)
                break
            elif -a - b == x:
                print(-i, j)
                break
            elif -a + b == x:
                print(-i, -j)
                break
        else:
            continue
        break

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9208
package main

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

var sc = bufio.NewScanner(os.Stdin)

func swap(a int64, b int64) (int64, int64) {
	return b, a
}

func GCD(a int64, b int64) int64 {
	if b > a {
		a, b = swap(a, b)
	}
	if b == 0 {
		return a
	} else {
		return GCD(a%b, b)
	}
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(),10,64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func CheckniconiLevel(s []rune) int {
	n := len(s)
	mx := 0
	tmp := 0
	fmt.Printf("%d\n", n)
	for i := 0; i < n-1; i++ {
		if s[i] == '2' && s[i+1] == '5' {
			tmp += 2
			i += 1
			mx = int(math.Max(float64(tmp), float64(mx)))
		} else {
			tmp = 0
		}
	}
	return int(mx)
}

func main() {
	sc.Split(bufio.ScanWords)
	ans := 1
	N := nextLong()
	P := nextLong()
	var times int64
	times=1
	if N==1{
		fmt.Printf("%d\n", P)
		return
	}
	for i:=2; i<=int(math.Sqrt(float64(P)));i++{
		var tmp int64
		tmp=1
		times=0
		for{
			times++
			tmp*=int64(i)
			if tmp*int64(i)>=P || times==N-1{
				break
			}
		}
		if(times==N-1 && P%tmp==0){
		ans = int(math.Max(float64(ans),math.Min(float64(i), float64(GCD(P/tmp,int64(i))))))
		}
	}
	fmt.Printf("%d\n", ans)
}


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

using namespace std;

int main() {
	int a, b, c, k;
	scanf("%d%d%d", &a, &b, &c);
	scanf("%d", &k);

	int val = max(a, max(b, c));
	int ans = a + b + c - val;
	for (int i = 0; i < k; ++i)
		val *= 2;
	ans += val;
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize "03"
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int N = 1e5 + 5;
const int mod = 1e9 + 7;

int dp[N], h[N];

signed main() {
	#ifdef LOCAL
		freopen("input.txt","r",stdin);
	#endif
	IOS;
	int n, k;	cin >> n >> k;
	for(int i = 1; i <= n; i++){
		cin >> h[i];	
		dp[i] = mod;
		if(i == 1)
			dp[i] = 0;
		for(int j = 1; j <= k; j++){
			if(i > j)
				dp[i] = min(dp[i], dp[i-j] + abs(h[i-j] - h[i]));
		}
	}
	cout << dp[n];
	return 0;
}

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

s = [0] * m

for i in range(m):
    k, *li = map(int, input().split())
    for j in range(k):
        s[i] += 2**(li[j]-1)

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


ans = 0

for i in range(2**n):
    tmp = True
    for j in range(m):
        if bin(i & s[j]).count("1") % 2 != p[j]:
            tmp = False
            break

    if tmp:
        ans += 1

print(ans)


Measured memory_bytes: 3064
s=input()
l=len(s)

suuti=[]
for _ in s:
    suuti.append(int(_))

rei=[]
for _ in range(l):
    rei.append(_%2)

c=0
for _ in range(l):
    if rei[_]==suuti[_]:
        c+=1

print(min(c,l-c))

Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
 
/* constant */
 
const double PI = acos(-1.0);
 
/* typedef */
 
template <typename T>
struct Pt {
  T x, y;
 
  Pt() {}
  Pt(T _x, T _y) : x(_x), y(_y) {}
  Pt(const Pt& pt) : x(pt.x), y(pt.y) {}
 
  bool operator==(const Pt pt) const { return x == pt.x && y == pt.y; }
  Pt<T> operator+(const Pt pt) const { return Pt<T>(x + pt.x, y + pt.y); }
  Pt<T> operator-() const { return Pt<T>(-x, -y); }
  Pt<T> operator-(const Pt pt) const { return Pt<T>(x - pt.x, y - pt.y); }
  Pt<T> operator*(T t) const { return Pt<T>(x * t, y * t); }
  Pt<T> operator/(T t) const { return Pt<T>(x / t, y / t); }
  T dot(Pt v) const { return x * v.x + y * v.y; }
  T cross(Pt v) const { return x * v.y - y * v.x; }
  Pt<T> mid(const Pt pt) { return Pt<T>((x + pt.x) / 2, (y + pt.y) / 2); }
  T d2() { return x * x + y * y; }
  double d() { return sqrt(d2()); }
 
  Pt<T> rot(double th) {
    double c = cos(th), s = sin(th);
    return Pt<T>(c * x - s * y, s * x + c * y);
  }
 
  Pt<T> rot90() { return Pt<T>(-y, x); }
 
  bool operator<(const Pt& pt) const {
    return x < pt.x || (x == pt.x && y < pt.y);
  }
 
  void print(string format) {
    printf(("(" + format + ", " + format + ")\n").c_str(), x, y);
  }
  void print() { print("%.6lf"); }
};
 
typedef Pt<double> pt;
typedef vector<pt> vpt;
 
/* global variables */
 
/* subroutines */
 
void rec(int n, vpt &ps, pt p4) {
  if (n <= 0) {
    ps.push_back(p4);
    return;
  }
 
  pt &p0 = ps.back();
 
  pt p1 = (p0 * 2 + p4) / 3;
  pt p2 = p1 + (p1 - p0).rot(PI / 3);
  pt p3 = (p0 + p4 * 2) / 3;
 
  rec(n - 1, ps, p1);
  rec(n - 1, ps, p2);
  rec(n - 1, ps, p3);
  rec(n - 1, ps, p4);
}
 
/* main */
 
int main() {
  int n;
  cin >> n;
 
  vpt ps;
  ps.push_back(pt(0.0, 0.0));
 
  rec(n, ps, pt(100.0, 0.0));
 
  for (int i = 0; i < ps.size(); i++)
    printf("%.8lf %.8lf\n", ps[i].x, ps[i].y);
  return 0;
}


Measured memory_bytes: 3260
#include <vector>
#include <cstdio>
using namespace std;
typedef unsigned long long ull;

ull pow_binary_mod(ull x,ull y,ull m){
	ull z = 1;
	for(;y;y>>=1){
		if(y&1)z = z * x % m;
		x = x * x % m;
	}
	return z;
}

int main(){
	ull n,m,k;
	scanf("%llu%llu%llu",&n,&m,&k);
	n%=10;
	if(n==0)puts("0");
	else{
		int mul=pow_binary_mod(n,m,10);
		vector<int>v;
		int z=n,s=0;
		do{
			v.push_back(z);
			s+=z;
			z=z*mul%10;
		}while(z!=n);
		ull d=k/v.size()*s,r=k%v.size();
		for(k=0;k<r;k++)d+=v[k];
		printf("%llu\n",d);
	}
}


Measured memory_bytes: 1060
n,k = map(int, input().split())
word = [0 for i in range(26)]
ans = 0
for i in range(n):
    q = input()
    word[ord(q[0]) - ord('A')] += 1
word.sort(reverse=True)
for i in range(n//k):
    for j in range(k):
        word[j] -= 1
        if word[j] < 0:
            print(ans)
            exit()
    ans += 1
    word.sort(reverse=True)
print(ans)

Measured memory_bytes: 43736
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
        puts("Yes");
    }else {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 384
//A Figure on Surface

#include<iostream>
#include<string>
using namespace std;

int main(void)
{
	const int N = 8;
	while(1)
	{
		string a[N];
		int i, j;
		for(i = 0; i < N; i++)
		{
			cin >> a[i];
		}
		if(!cin)
			break;

		//¶ã©çÌÀWð²×é
		for(i = 0; i < N; i++)
		{
			for(j = 0; j < N; j++)
			{
				if(a[i][j] == '1')
					goto DISCOVER;
			}
		}
		DISCOVER:
		//ÔÈñÄÇ¤ÅàÇ¢©çÀSÉs«Üµå¤
		if( (i < N-1) && (j < N-1) && 
			(a[i][j] == a[i+1][j]) &&
			(a[i][j] == a[i][j+1]) &&
			(a[i][j] == a[i+1][j+1]) )
			cout << 'A' << endl;
		else if((i < N-3) && 
			(a[i][j] == a[i+3][j]) )
			cout << 'B' << endl;
		else if((j < N-3) &&
			(a[i][j] == a[i][j+3]) )
			cout << 'C' << endl;
		else if((i < N-2) && (j > 0 ) &&
			(a[i][j] == a[i+2][j-1]) )
			cout << 'D' << endl;
		else if((j < N-2) &&
			(a[i][j] == a[i+1][j+2]) )
			cout << 'E' << endl;
		else if((i < N-2) &&
			(a[i][j] == a[i+2][j+1]) )
			cout << 'F' << endl;
		else
			cout << 'G' << endl;
	}
	return 0;
}

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

const int INF = INT_MAX;
const int MAXN = 5000;
const int B = 250;
const int BNUM = MAXN / B;

int n, m;
pair<int, int> ps[MAXN];
int x[MAXN], y[MAXN];
vector<int> bucket[BNUM];

int main() {
  while(scanf("%d%d", &n, &m) != EOF) {
    for(int i = 0; i < n; ++i) {
      scanf("%d%d", &ps[i].first, &ps[i].second);
    }
    sort(ps, ps+n);
    fill(bucket, bucket + BNUM, vector<int>());
    for(int i = 0; i < n; ++i) {
      x[i] = ps[i].first;
      y[i] = ps[i].second;
      bucket[i/B].push_back(y[i]);
    }
    for(int b = 0; b < BNUM; ++b) {
      sort(bucket[b].begin(), bucket[b].end());
    }
    while(m--) {
      int s, t, u, v; 
      scanf("%d%d%d%d", &s, &t, &u, &v);
      int l = lower_bound(x, x+n, s) - x;
      int r = upper_bound(x, x+n, u) - x;
      int res = 0;
      while(l < r && l % B != 0) {
        res += (t <= y[l] && y[l] <= v);
        ++l;
      }
      while(l < r && r % B != 0) {
        --r;
        res += (t <= y[r] && y[r] <= v);
      }
      while(l < r) {
        int b = l / B;
        res += upper_bound(bucket[b].begin(), bucket[b].end(), v)
          - lower_bound(bucket[b].begin(), bucket[b].end(), t);
        l += B;
      }
      printf("%d\n", res);
    }
  }
  return 0;
}

Measured memory_bytes: 1308
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(){
    ll x;
    cin >> x;
    ll ans = 0;
    ans = (x/11)*2;
    x %= 11;
    if(x>6)
        ans+=2;
    else if(x>0)
        ans+=1;

    cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

bool erat[50100];

int main()
{
    for (int i = 2; i*2 <= 50100; i++) {
        erat[0] = true;
        erat[1] = true;
        if (!erat[i]) {
            for (int j = 2; i*j <= 50100; j++) {
                erat[i*j] = true;
            }
        }
    }

    int n;
    while (cin >> n) {
        for (int i = n-1; i >= 0; i--) {
            if (!erat[i]) {
                cout << i << " ";
                break;
            }
        }
        for (int i = n+1; i < 50100; i++) {
            if (!erat[i]) {
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}

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

int main(){
    int num;
    cin >> num;
    int ans=0;
    vector<int> vec(num);
    rep(i,num){
        cin >> vec.at(i);
    }
    while (true){
        bool flag=false;
        rep(j,num){
            if(vec[j]%2==1) flag=true;
        }
        if (flag){
            break;
        }
        else{
            rep(k,num){
                vec[k]/=2;
            }
            ++ans;
        }
    }
    cout << ans << endl;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, l;
  while (cin >> n >> l) {
    vector<string> v(n);
    cin >> v;
    sort(v.begin(), v.end());
    each (s, v) cout << s << flush;
    cout << endl;
  }
  
  return 0;
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

int ctoi(char c) {
    if (c == 'r') { return 0; }
    if (c == 's') { return 1; }
    return 2;
}

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

    int n, k;
    vi points(3);
    cin >> n >> k >> points[0] >> points[1] >> points[2];
    string T;
    cin >> T;

    int ans = 0;
    rep(i, 0, k) {
        int num_games = (n - i + k - 1) / k;
        vvi dp(num_games, vi(3, 0));

        rep(j, 0, num_games) {
            int hand = ctoi(T[i + j * k]);
            if (j == 0) {
                dp[j][hand] = 0;
                dp[j][(hand + 1) % 3] = 0;
                dp[j][(hand + 2) % 3] = points[(hand + 2) % 3];
            } else {
                int prev_best_without_hand = max(dp[j - 1][hand], dp[j - 1][(hand + 1) % 3]);
                int prev_best = max(prev_best_without_hand, dp[j - 1][(hand + 2) % 3]);
                dp[j][hand] = prev_best;
                dp[j][(hand + 1) % 3] = prev_best;
                dp[j][(hand + 2) % 3] = prev_best_without_hand + points[(hand + 2) % 3];
            }
        }
        ans += max(dp.back()[0], max(dp.back()[1], dp.back()[2]));
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5840
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        abc161_b solver = new abc161_b();
        solver.solve(1, in, out);
        out.close();
    }

    static class abc161_b {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            Integer A[] = new Integer[N];
            long ttl = 0;
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
                ttl += A[i];
            }
/*
        Arrays.sort(A, Comparator.reverseOrder());
        if (A[M - 1]>= (double)ttl / (4.0*(double)M)) {
            out.println("Yes");
        } else {
            out.println("No");
        }
        */
            int count = 0;
            double quort = (double) ttl / (4.0 * (double) M);
            for (double val : A
            ) {
                if (val >= quort) {
                    count++;
                }
                if (count >= M) {
                    out.println("Yes");
                    return;
                }
            }
            out.println("No");
        }

    }
}



Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
int main() 
{
    long long int a,b,c,d;
    cin>>a>>b>>c>>d;
    long long int t1=a*c;
    long long int t2=a*d;
    long long int t3=b*c;
    long long int t4=b*d;
    long long int ans=max(t1,max(t2,max(t3,t4)));
    //cout<<ans;
    cout<<ans;    
}


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

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

  int A;
  for (int i = 0; i < M; i++) {
    cin >> A;
    N -= A;
  }

  cout << (N < 0 ? -1 : N) << endl;

  return 0;
}


Measured memory_bytes: 3612
import bisect
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
m=b[-1]
tmp=m/2

t=bisect.bisect_left(b,tmp)
ans=0
if(b[t]==tmp):
    ans=b[t]
elif(t==0):
    ans=b[0]
elif(t==len(b)-1):
    ans=b[-2]
else:
    c=abs(tmp-b[t-1])
    d=abs(tmp-b[t])
    if(c<=d):
        ans=b[t-1]
    else:
        ans=b[t]
print(m,ans)

Measured memory_bytes: 14052
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;

int main(){
  int n,d;
  scanf("%d%d",&n,&d);
  d = 2*d+1;
  if(n%d == 0) cout << n/d << endl;
  else cout << n/d + 1 << endl;
 
}

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

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
	return x * f;
}

const int N = 2e5 + 5;
int a[N], n, k;

bool check(int x)
{
	int res = 0;
	for (int i = 1; i <= n; ++i) res += (a[i] - 1) / x;
	return res <= k;
}

int main()
{
	n = read(); k = read();
	for (int i = 1; i <= n; ++i) a[i] = read();
	int mx = 0;
	for (int i = 1; i <= n; ++i) mx = max(mx, a[i]);
	
	int l = 1, r = mx;
	while (l < r)
	{
		int mid = l + r >> 1;
		if (check(mid)) r = mid;
			else l = mid + 1;
	}
	printf("%d\n", l);
	return 0;
}


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

int main(){
	int K, N;
	cin >> K >> N;
	int A[N];
	int dA, dAw;
	int dAmax = 0;
	for(int i=0; i<N; i++){
		cin >> A[i];
	}
	for(int i=0; i<N; i++){
		dA = 0;
		dAw = 0;
		//cout << "A[i] ->" << A[i] << endl;
		if(i == 0){
			dAw = A[i] + K - A[N-1];
			dA = A[i+1] - A[i];
		}
		else if(i == N-1){
			dAw = A[i] - A[i-1];
			dA = K- A[i] + A[0];
		}
		else{
			dAw = A[i] - A[i-1];
			dA = A[i+1] - A[i];
		}
		//cout << "dAw->" << dAw << " ||dA->" << dA << endl;
		if(dA > dAmax){
			dAmax = dA;
		}
		if(dAw > dAmax){
			dAmax = dAw;
		}
	}

	cout << K - dAmax << endl;
}


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

using namespace std;

const int M = 1000001;
int n,m,k,a[M],d[M];
char c[M];
int main()
{
	scanf("\n%s",c+1);
	n=strlen(c+1);
	for(int i=1;i<=n;i++) a[i]=c[i]-'0';
	if(!a[1] || a[n]) 
	{
		printf("-1");
		return 0;
	}
	int m=n/2;
	for(int i=1;i<=m;i++) if(a[i]!=a[n-i]) 
	{
		printf("-1");
		return 0;
	}
	k=2;
	printf("1 2\n");
	for(int i=2;i<=m;i++)
	{
		printf("%d %d\n",i+1,k);
		if(a[i]) k=i+1;
	}
	for(int i=m+2;i<=n;i++) printf("%d %d\n",i,k);
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
int m_mul(int x, int y) {
    return 1LL * x * y % MOD;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, pos = 0, neg = 0, zero = 0;
    cin >> n >> k;
    vector<int> a(n);
    for (int& it : a) {
        cin >> it;
        if (it > 0)
            pos++;
        else if (it < 0)
            neg++;
        else
            zero++;
    }
    int ans = 1;
    if (pos + neg < k) {
        ans = 0;
    } else if (n == k) {
        for (int it : a)
            ans = m_mul(ans, it);
        if (ans < 0)
            ans += MOD;
    } else if (pos == 0) {
        if (k % 2 == 1) {
            if (zero)
                ans = 0;
            else {
                sort(a.rbegin(), a.rend());
                for (int i = 0; i < k; i++)
                    ans = m_mul(ans, a[i]);
                if (ans < 0)
                    ans += MOD;
            }
        } else {
            sort(a.begin(), a.end());
            for (int i = 0; i < k; i++)
                ans = m_mul(ans, -a[i]);
        }
    } else {
        int i = 0;
        vector<int> P, N;
        sort(a.begin(), a.end(), [](int x, int y) { return abs(x) > abs(y); });
        for (i = 0; i < k; i++) {
            if (a[i] > 0)
                P.push_back(a[i]);
            else
                N.push_back(a[i]);
        }
        if ((int)N.size() % 2 == 1) {
            int nxp = 0, nxn = 0;
            for (; i < n; i++) {
                if (a[i] < 0 && !nxn)
                    nxn = a[i];
                else if (a[i] > 0 && !nxp)
                    nxp = a[i];
                if ((nxn && nxp) || a[i] == 0)
                    break;
            }
            if (P.empty() || (ll)nxp * P.back() >= (ll)nxn * N.back()) {
                N.pop_back();
                P.push_back(nxp);
            } else {
                P.pop_back();
                N.push_back(nxn);
            }
        }
        for (int it : P)
            ans = m_mul(ans, it);
        for (int it : N)
            ans = m_mul(ans, it);
    }
    cout << ans << endl;
    return 0;
}

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

#define PI 4*atan(1)
#define INF 1e8

typedef long long ll;

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

int main(){
  ll Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;
  ll min_025 = Q, min_05 = min(Q * 2, H), min_1 = min(min_05 * 2, S), min_2 = min(min_1 * 2, D);
  ll ans = 0;

  ll n = N / 2 * min_2;
  N -= N / 2 * 2;
  ans += n;

  n = N * min_1;
  ans += n;

  cout << ans << endl;
  // for(auto m : mins)cout << m << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i =0 ; i<(N); i++)
using namespace std;
//using ll = long long;
#define ll long long 
int main(){
	ll N;
	cin>>N;
	//scanf("%ll", &N);
	ll ans = 0;
	for(int i = 1; i<=N; i++){
		for(int j = i; j<=N; j += i){
			//if( i % j == 0) 
			ans += j;
			}
		}
		//printf("%ll", ans);
		cout<<ans<<endl;
	return 0;
	}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

#define ll long long
#define rep(cnt,a,n) for(ll cnt=a;cnt<n+a;cnt++) //aから始めてn回ループ
#define vector2(type,name,a,b) vector<vector<type>> name(a, vector<type>(b))

int main()
{
    ll n;
    ll m;
    cin >> n;
    cin >> m;
    vector<ll> h(n);
    vector<ll> t(n);
    rep(cnt, 0, n) {
        cin >> h[cnt];
        t[cnt] = 0;
    }
    rep(cnt, 0, m) {
        ll a;
        ll b;
        cin >> a;
        cin >> b;
        a -= 1;
        b -= 1;
        if (h[a] <= h[b]) {
            t[a] = 1;
        }
        if (h[a] >= h[b]) {
            t[b] = 1;
        }
    }
    ll ans=0;
    rep(cnt, 0, n) {
        if (t[cnt] == 0) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4848
import java.util.*;

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

        int N = sc.nextInt();
        int M = sc.nextInt();

        int[] bits = new int[M];
        for (int i = 0; i < M; i++) {
            int n = sc.nextInt();
            for (int j = 0; j < n; j++) {
                bits[i] += Math.pow(2, sc.nextInt() - 1);
            }
        }

        int[] p = new int[M];
        for (int i = 0; i < M; i++) {
            p[i] = sc.nextInt();
        }

        int c = (int) Math.pow(2, N);
        int res = 0;
        for (int num = 0; num < c; num++) {
            boolean isOk = true;
            for (int i =0; i < M; i++) {
                int amp = num & bits[i];
                if (Integer.bitCount(amp) % 2 != p[i]) {
                     isOk = false;
                }
            }

            if (isOk) {
                res++;
            }
        }

        System.out.println(res);
    }
}

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

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

    int h, w;
    cin >> h >> w;

    char a[h][w];
    int black_h[h] = {0};
    int black_w[w] = {0};
    rep(i, h) rep(j, w) {
        cin >> a[i][j];
        if(a[i][j] == '#'){
            black_h[i] = 1;
            black_w[j] = 1;
        }
    }

    rep(i, h){
        rep(j, w){
            if(black_h[i] + black_w[j] != 2) continue;
            else cout << a[i][j];
        }
        if(black_h[i] == 1) cout << endl;
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;
 
int main(){
  using namespace std;
  int n, m;
  cin>>n>>m;
  bool used[n] = {};
  int val[n] = {};
  int s[m], c[m];
  REP(i, m){
    cin>>s[i]>>c[i];
    s[i]--;
    if(used[s[i]]){
      if(val[s[i]] != c[i]){
        cout<<-1<<endl;
        return 0;
      }
    }else{
      used[s[i]] = true;
      val[s[i]] = c[i];
    }
  }
  if(n > 1 && used[0] && val[0] == 0){
    cout<<-1<<endl;
    return 0;
  }
  if(n > 1 && val[0] == 0){
    val[0] = 1;
  }
  REP(i, n){
    cout<<val[i];
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int W,H,N;cin>>W>>H>>N;
  int p=0,q=W,r=0,s=H;
  int x,y,a;
  for(int i=0;i<N;i++){
    cin>>x>>y>>a;
    if(a==1)p=max(x,p);
    else if(a==2)q=min(x,q);
    else if(a==3)r=max(y,r);
    else s=min(y,s);
  }
  int ans=0;
  if(p<q && r<s)ans=(q-p)*(s-r);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env/ ruby

alice_num, bob_num = gets.split.map(&:to_i)

if alice_num == bob_num
    puts "Draw"
elsif alice_num == 1
    puts "Alice"
elsif bob_num == 1
    puts "Bob"
elsif alice_num > bob_num
    puts "Alice"
elsif bob_num > alice_num
    puts "Bob"
end

Measured memory_bytes: 1788
#include<stdio.h>//1からnまでの数の中から重複無しで３つの数を選びそれらの合計がxとなる組み合わせの数を求めるプログラム

int main (void){

	int n,x,i,j,k;
	int count=0;

	scanf("%d %d",&n,&x);
	
	while(1){
		for(i=1;i<=n;i++){
			for(j=i+1;j<=n;j++)
				for(k=j+1;k<=n;k++)
					if(i+j+k==x){
						count++;
					}
			}
		printf("%d\n",count);
		scanf("%d %d",&n,&x);
		if(x==0&&n==0)
			break;
		count=0;
	}

	return 0;
}

Measured memory_bytes: 600
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define slice(l, r) substr(l, r-l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
    #include "lib/dump.hpp"
#else
    #define dump(...) 42
    #define dump_1d(...) 42
    #define dump_2d(...) 42
    #define cerrendl 42
#endif
//}}}

signed main() {
    int n,k;cin>>n>>k;
    vi x(n);
    int ans = 0;
    rep(i, n){
        cin>>x[i];
        ans += 2 * min(x[i], abs(k-x[i]));
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

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

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

/**
 * D - Semi Common Multiple
 * https://atcoder.jp/contests/abc150/tasks/abc150_d
 */
void Main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll x = 1;
    ll ans = 0;
    rep(i, N) {
        ll a = A[i];
        a /= 2;
        x = lcm(x, a);
    }
    ll ok2 = true;
    rep(i, N) {
        ll a = A[i];
        a /= 2;
        if ((x / a) % 2 == 0) {
            ok2 = false;
        }
    }
    if (x <= M && ok2) {
        M -= x;
        ans++;
        ans += M / (2 * x);
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
A = list(map(int, input().split()))

MOD = 10 ** 9 + 7

sqsum = 0
asum = 0
for a in A:
  sqsum += a**2
#  sqsum %= MOD
  asum += a
#  asum %= MOD

ans = ((asum ** 2) - sqsum) // 2
ans %= MOD

print(ans)

Measured memory_bytes: 31436
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){ 
  int w,h,n;
  cin >>w>>h >> n;
  vector<int> x(n),y(n),a(n);
  rep(i,n){
    cin >>x.at(i)>>y.at(i)>>a.at(i);
  }
  int rx=w,lx=0,uy=h,sy=0;
  rep(i,n){
    if(a.at(i)==1){
      lx=max(lx,x.at(i));
    }else if(a.at(i)==2){
      rx=min(rx,x.at(i));
    }else if(a.at(i)==4){
      uy=min(uy,y.at(i));
    }else{
      sy=max(sy,y.at(i));
    }
  }
  if(rx-lx<=0 || uy-sy<=0){
    cout << 0;
    return 0;
  }
  cout << (rx-lx)*(uy-sy);
}

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

int main() {
  int N,X,d=0;
  cin >> N >> X;
  vector<int> m(N);
  for(int i=0; i<N; i++){
    cin >> m.at(i);
    X-=m.at(i);
    d++;
  }
  sort(m.begin(),m.end());
  while(X>=m.at(0)){
    X-=m.at(0);
    d++;
  }
  cout << d << endl;
}

Measured memory_bytes: 256
//ABC 132 C Divide the Problems

#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    int d[n];
    for(int i=0; i<n; i++) cin >> d[i];
    sort(d, d+n);
    cout << d[n/2] - d[n/2-1] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <math.h>

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

	int count = 0;
	int cost;
	int max = floor(X/100);
	for (int i = 0; i <= max; i++)
	{
		for (int j = 0; j <= max; j++)
		{
			for (int k = 0; k <= max; k++)
			{
				for (int l = 0; l <= max; l++)
				{
					for (int m = 0; m <= max; m++)
					{
						for (int n = 0; n <= max; n++)
						{
							cost = 100 * i + 101 * j + 102 * k + 103 * l + 104 * m + 105 * n;
							if (cost == X)
							{
								count++;
								goto loopend;
							}
						}
					}
				}
			}
		}
	}

	loopend:
		if (count >= 1)
		{
			std::cout << 1;
		}
		else
		{
			std::cout << 0;
		}
		
	return 0;
}

Measured memory_bytes: 256
program answer
  implicit none
  integer :: i, A, B, C, D, E, aa, bb, cc, dd, ee, ans
  read(*,*) A
  read(*,*) B
  read(*,*) C
  read(*,*) D
  read(*,*) E
  aa=A-(A/10)*10
  bb=B-(B/10)*10
  cc=C-(C/10)*10
  dd=D-(D/10)*10
  ee=E-(E/10)*10

  ans=(A/10+B/10+C/10+D/10+E/10+5)*10
  if(aa==0) then
     ans=ans-10
  end if
  if(bb==0) then
     ans=ans-10
  end if
  if(cc==0) then
     ans=ans-10
  end if

  if(dd==0) then
     ans=ans-10
  end if
  if(ee==0) then
     ans=ans-10
  end if

  if(min(aa,bb,cc,dd,ee)==aa) then
     ans=ans-(A/10+1)*10+A
  else if(min(aa,bb,cc,dd,ee)==bb) then
     ans=ans-(B/10+1)*10+B
  else if(min(aa,bb,cc,dd,ee)==cc) then
     ans=ans-(C/10+1)*10+C
   else if(min(aa,bb,cc,dd,ee)==dd) then
     ans=ans-(D/10+1)*10+D
  else if(min(aa,bb,cc,dd,ee)==ee) then
     ans=ans-(E/10+1)*10+E
  end if

  if(aa==0.or.bb==0.or.cc==0.or.dd==0.or.ee==0) then
     if(aa==0) then
        aa=10
     end if
     if(bb==0) then
        bb=10
     end if
     if(cc==0) then
        cc=10
     end if
     if(dd==0) then
        dd=10
     end if
     if(ee==0) then
        ee=10
     end if
     ans=ans+min(aa,bb,cc,dd,ee)
  end if

  write(*,*) ans
  stop
 end program answer
     

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 201
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

struct M {
    int r, h;
};

bool comp_r (const M& l, const M& r) {
    return l.r < r.r;
}

bool comp_h (const M& l, const M& r) {
    return l.h < r.h;
}

int main() {


    int n, m, dp[MAXN];
    M a[MAXN];


    while (cin >> n, n) {
        vector<pair <int, int> >A;
        int h, r;
        rep(i, n) {
            cin >> a[i].h >> a[i].r;
        }
        cin >> m;

        rep(i, m) {
            cin >> a[n+i].h >> a[n+i].r;
        }

        sort(a, a+n+m, comp_r);

        dp[0] = 1;

        for(int i=1; i<n+m; ++i) {
            dp[i] = 1;
            for(int j=0; j<i; ++j) {
                if ( a[j].r < a[i].r and a[j].h < a[i].h ) {
                    dp[i] = max(dp[i], dp[j]+1);
                }
            }
        }

        int res_r = dp[n+m-1];

        sort(a, a+n+m, comp_h);

        dp[0] = 1;
        for(int i=1; i<n+m; ++i) {
            dp[i] = 1;
            for(int j=0; j<i; ++j) {
                if ( a[j].r < a[i].r and a[j].h < a[i].h) {
                    dp[i] = max(dp[i], dp[j]+1);
                }
            }
        }
        int res_h = dp[n+m-1];
        cout << max(res_r, res_h) << endl;
    }
}




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

int main(){
    int n;
    double total=0;
    cin>>n;
    double x[n],y[n];
    for (int i=0;i<n;i++){
        cin>>x[i]>>y[i];
    }
    for (int i=0;i<n;i++) {
        for (int j = 0; j < n; j++) {
            total += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
        }
    }
    printf("%.8f", total/n);
}

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

maxNum= 0
maxIndex= -1
secondNum= 0



for i in range(N):
    tmp= int(input())
    if tmp> maxNum :
        secondNum= maxNum
        maxNum= tmp
        maxIndex= i
    elif tmp> secondNum:
        secondNum= tmp



for j in range(N):
    if(j == maxIndex):
        print(secondNum)
    else :
        print(maxNum)




Measured memory_bytes: 4540
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
typedef long long ll;
using namespace std;

int main(void)
{
	int n, k, x, y; cin >> n >> k >> x >> y;
	int ans = 0;

	for (int i = 1; i <= n; i++)
	{
		if (i <= k) ans += x;
		else ans += y;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[1000005],n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",a+i);
	}
	sort(a+1,a+n+1);int ans=0;
	for(int i=1;i<=n;){
		int j=i;
		while(a[i]==a[j])++i;
		if(i-j<a[j])ans+=i-j;
		else ans+=i-j-a[j];
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 640