akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int n;
int c[5][4];
int dp[1 << 20];

int dfs(int cnum, int rem) {
	int val[5][4];
	int id[5][4];
	
	if (dp[rem] != -1) return dp[rem];
	
	int cor = 0;
	for (int i = 0; i < 20; i++) {
		if ((rem >> i) % 2) {
			val[cor/4][cor%4] = c[i/4][i%4];
			id[cor/4][cor%4] = i;
			cor++;
		}
	}
	
	int ret = 0;
	for (int y = 0; y < 5; y++) {
		for (int x = 0; x < 4; x++) {
			if (y * 4 + x >= cnum) continue;
			for (int sy = y - 1; sy <= y + 1; sy++) {
				for (int sx = x - 1; sx <= x + 1; sx++) {
					if (sy * 4 + sx >= cnum) continue;
					if (!(0 <= sy && sy < 5 && 0 <= sx && sx < 4)) continue;
					if (sy == y && sx == x) continue;
					if (val[y][x] != val[sy][sx]) continue;
					ret = max( ret, 2 + dfs(cnum - 2, rem - (1 << id[y][x]) - (1 << id[sy][sx])) );
				}
			}
		}
	}
	return (dp[rem] = ret);
}

int main() {
	cin >> n;
	while (n--) {
		for (int i = 0; i < 20; i++) cin >> c[i/4][i%4];
		for (int i = 0; i < (1 << 20); i++) dp[i] = -1;
		cout << 20 - dfs(20, (1 << 20) - 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 5256
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=np.int64)

neg = np.count_nonzero(A[A < 0])
ans = np.abs(A).sum()
if neg % 2 == 1:
    v = np.abs(A).min()
    ans -= 2 * v

print(ans)


Measured memory_bytes: 24804
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];

  std::sort(A.begin(), A.end(), std::greater<int>());

  long long sum = 0;
  N--;

  sum += A[0];
  N--;
  int i = 1;
  while (N > 0)
  {
    sum += A[i];
    N--;
    if (N <= 0)
      break;

    sum += A[i];
    N--;

    i++;
  }

  cout << sum << endl;

  return 0;
}


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

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

    }
    sort(v.begin(),v.end());

    int answer=v[v.size()/2]-v[v.size()/2-1];
    cout<<answer<<endl;
    return 0;

}

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

int main()
{
    long long n,m,total=0,cnt=0;
    cin>>n>>m;
    long long arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        total+=arr[i];
    }
    //cout<<total<<endl;
    long long x=4*m;
    long long z=ceil((total*1.0)/x);
    //cout<<z<<endl;
    for(int i=0;i<n;i++)
    {
        if(arr[i]>=z)
            cnt++;
    }
    if(cnt>=m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main(){
	string s;
	cin >> s;
    int a = 0, b = 0, c = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'a') a++;
        else if(s[i] == 'b') b++;
        else c++;
    }
    int mi = min({a, b, c});
    int ma = max({a, b, c});
    cout << ((ma - mi <= 1)? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys
import itertools
import collections
from queue import Queue
import functools
import math
import numpy as np

INF = 10**9


def main():
    H, W = [int(x) for x in input().split()]
    a = [input() for _ in range(H)]

    # print(a)
    ans = []
    for item in a:
        flag = False
        for v in item:
            if v == "#":
                flag = True
        if flag == True:
            ans.append(item)
    a = ans
    H = len(a)

    # 列
    ans = [[] for x in range(H)]
    for i in range(W):
        flag = False
        for item in a:
            if item[i] == "#":
                flag = True
        if flag == True:
            for j in range(H):
                ans[j].append(a[j][i])
    for item in ans:
        print(*item, sep="")
    pass


if __name__ == '__main__':
    main()


Measured memory_bytes: 19928
#include <iostream>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vll vector <pll>
#pragma 03
using namespace std;
ll weight[100005], val[100005];
ll dp[105][100005];
int main(){
	ll n, w;
	cin >> n >> w;
	for (ll i = 0; i<n; i++) cin >> weight[i] >> val[i];
	for (ll i = 0; i<100005; i++) dp[0][i] = 0;
	for (ll i = 1; i<=n; i++){
		for (ll j = 0; j<100005; j++){
			if (j + weight[i-1] <= w) dp[i][j + weight[i-1]] = max(dp[i][j + weight[i-1]], dp[i-1][j] + val[i-1]);
			dp[i][j] = max(dp[i][j], dp[i-1][j]);
		}
	}
	ll mx = 0;
	for (ll i = 0; i<=w; i++) mx = max(mx, dp[n][i]);
	cout << mx << endl;
	return 0;
}
 


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

using namespace std;
typedef long long ll;

// #define DEBUG

const int inf = 1e9;
vector<tuple<int, int, int>> node_list;
vector<int> dist_list;


void bellman_ford(int r, int v)
{
    int x, y, z;
    bool negative_cycle_flag = false;
    vector<int> new_dist_list;
    vector<int> dist1, dist2;

    dist_list[r] = 0;

    for (int i = 0; i < v; i++)
    {
        new_dist_list = dist_list;
        for (auto w : node_list)
        {
            x = get<0>(w), y = get<1>(w), z = get<2>(w);
            if (new_dist_list[x] != inf)
                new_dist_list[y] = min(new_dist_list[y], dist_list[x] + z);
        }
        dist_list = new_dist_list;

        if (v > 1 && i == v - 2)
            dist1 = dist_list;
        if (v > 1 && i == v - 1)
            dist2 = dist_list;
    }
    if (v > 1)
        for (int i = 0; i < v; i++)
            if (dist1[i] != dist2[i])
                negative_cycle_flag = true;

    if (negative_cycle_flag)
        cout << "NEGATIVE CYCLE" << endl;
    else
        for (auto i : dist_list){
            if (i != inf)
                cout << i << endl;
            else
                cout << "INF" << endl;    
        }
    return;
};

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int v, e, r, s, t, d;
    cin >> v >> e >> r;
    dist_list.resize(v);
    fill(dist_list.begin(), dist_list.end(), inf);
    for (int i = 0; i < e; i++)
    {
        cin >> s >> t >> d;
        node_list.push_back(make_tuple(s, t, d));
    }
    bellman_ford(r, v);

    return 0;
}



Measured memory_bytes: 3208
N,C = map(int,input().split())

pre_mx = [(0,0)]
suf_mx = [(0,0)]
run_psum = 0
run_ssum = 0
data = []
for i in range(N):
    x,v = map(int,input().split())
    if run_psum + v - x > pre_mx[i][1]:
        pre_mx.append((x,run_psum + v - x))
    else:
        pre_mx.append((pre_mx[i][0],pre_mx[i][1]))
    run_psum += v
    data.append((x,v))

for i in range(N-1,-1,-1):
    if run_ssum + data[i][1] - C + data[i][0] > suf_mx[N-1-i][1]:
        suf_mx.append((C - data[i][0],run_ssum + data[i][1] - C + data[i][0]))
    else:
        suf_mx.append((suf_mx[N-1-i][0],suf_mx[N-1-i][1]))
    run_ssum += data[i][1]

ansp = anss = 0
for i in range(N+1):
    if ansp < pre_mx[i][1] + suf_mx[-i-1][1] - pre_mx[i][0]:
        ansp = pre_mx[i][1] + suf_mx[-i-1][1]
        if suf_mx[-i-1][0] != 0:
            ansp -= pre_mx[i][0]

for i in range(N+1):
    if anss < suf_mx[i][1] + pre_mx[-i-1][1] - suf_mx[i][0]:
        anss = suf_mx[i][1] + pre_mx[-i-1][1]
        if pre_mx[-i-1][0] != 0:
            anss -= suf_mx[i][0]

print(max(ansp,anss))


Measured memory_bytes: 40352
n=int(input())
a=list(map(int,input().split()))
red=0
kind=0
b=[]
for i in range(8):
    b.append([i,0])
for i in range(n):
    if a[i]<3200:
        b[a[i]//400][1]+=1
    else:
        red+=1
for i in range(8):
    if b[i][1]!=0:
        kind+=1
minc=1 if kind==0 else kind
maxc=kind+red 
print(str(minc)+" "+str(maxc))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define endl              "\n"
#define pb              push_back
#define fir               first
#define sec               second
#define all(arr,n)          ((arr , arr+n))
#define allv(v)            ((v).begin()), ((v).end())
#define sz(v)            ((int)((v).size()))
#define ll              long long
#define ld              long double
#define lp(i, n)        for(int i = 0 ; (int)i<n ; i++)
#define loop(i, x, n)       for(int i=x ; (int)i<=n ; i++)
#define isPowerOfTwo(s) (!(s & (s-1)))
#define vll vector<ll>
typedef vector<int> vi;
typedef deque<int> de;
void origi() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}
float sq(int x, int y, int a, int b, int c, int d)
{
    return .5 * abs(((x * b) + (a * d) + (c * y)) - ((y * a) + (b * c) + (d * x)));
}
bool inside(int x, int y, int a, int b, int c, int d, int e, int f, int o, int p)
{
    float area = sq(a, b, c, d, e, f) + sq(a, b, c, d, o, p);
    float a1 = sq(a, b, e, f, x, y);
    float a2 = sq(a, b, o, p, x, y);
    float a3 = sq(c, d, e, f, x, y);
    float a4 = sq(c, d, o, p, x, y);
    if (area == a1 + a2 + a3 + a4)
    {
        return true;
    }
    return false;
}
int arr[132675][8];
void tiranga() {
    ll n;
    cin >> n;
    ll x , sum=0 , c=0;
    ll Min = 100000000000;
    lp(i, n) {
        cin >> x;
        sum += abs(x);
        Min = min(Min, abs(x));
        c += x < 0;
    }
    if (c % 2)sum -= Min*2;
    cout << sum;
}
int main() {
#ifndef ONLINE_JUDGE.
    //freopen("input.txt", "r", stdin);
#else
#endif
    //cout << 43 % 2;
    origi();
    tiranga();
    //cout << sumOfDig(123654);
   // genLarge(10, 10);
   // genSmall(10);

}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
long long i,n,max=-1000000,min=1000000,total=0;
scanf("%d",&n);
int inp[n];
for(i=0;i<n;i++){
scanf("%d ",&inp[i]);
total+=inp[i];
if(max<inp[i])max=inp[i];
if(min>inp[i])min=inp[i];
}
printf("%ld %ld %ld\n",min,max,total);
return 0;
}

Measured memory_bytes: 644
WHITE = 0
GRAY = 1
BLACK = 2
tt = -1

def next(u, m, n, nt):
    start = nt[u]
    for v in range(start, n):
        nt[u] = v + 1
        if m[u][v]:
            return v
    return -1


def dfs_visit(r, m, n, color, d, f):
    nt = [0] * n
    stack = [r]
    color[r] = GRAY
    global tt
    tt += 1
    d[r] = tt

    while len(stack) != 0:
        u = stack[-1]
        v = next(u, m, n, nt)
        if v != -1:
            if color[v] == WHITE:
                color[v] = GRAY
                tt += 1
                d[v] = tt
                stack.append(v)
        else:
            stack.pop()
            color[u] = BLACK
            tt += 1
            f[u] = tt


def dfs(n, m):
    color = [WHITE] * n
    d = [-1] * n
    f = [-1] * n
    global tt
    tt = 0
    for u in range(n):
        if color[u] == WHITE:
            dfs_visit(u, m, n, color, d, f)
    for i in range(n):
        print('{0} {1} {2}'.format(i+1, d[i], f[i]))



n = int(input())
m = [[False] * n for i in range(n)]
for i in range(n):
    line = [int(v) for v in input().split()]
    u = line[0] - 1
    for v in line[2:]:
        v -= 1
        m[u][v] = True

dfs(n, m)


Measured memory_bytes: 5696
#include<stdio.h>
#define N 50

int fibonacci(int n){
  int i,F[N],val;
  F[0] = 1;
  F[1] = 1;
  val = 0;

  if(n < 2){
    return 1;
  }

  for(i = 2;i <= n;i++){
    F[i] = F[i - 1] + F[i - 2];
    val = F[i];
  }

  return val;
}

int main()
{
  int n;
  scanf("%d",&n);
  printf("%d\n",fibonacci(n));
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k,a,b,c,d,max=0,ar[100005];
    cin>>n;
    for(i=0;i<n;i++)
        cin>>ar[i];
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            d=abs(ar[j]-ar[i]);
            if(d>max)
                max=d;
        }

    }
    cout<< max << endl;
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <vector>
#include <deque>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

map< pair< int , deque<int> > , int > memo;
int scheduled[100];
int n , m;

int f(int pos,deque<int> prev){
	deque<int> current = prev;
	if( memo.count(make_pair(pos,prev)) ) return memo[make_pair(pos,prev)];
	
	if(prev.size() == 3 && count(prev.begin(),prev.end(),prev[0]) == 3 ) return 0;
	
	if(pos == n) return 1;
	
	if(prev.size() == 3) prev.pop_front();
	
	int ans = 0;
	if(scheduled[pos] == -1){
		for(int i = 1 ; i <= 3 ; i++){
			prev.push_back(i);
			ans = ( ans + f(pos+1,prev) ) % 10000;
			prev.pop_back();
		}
	}else{
		prev.push_back(scheduled[pos]);
		ans = ( ans + f(pos+1,prev) ) % 10000;
	}
	return memo[make_pair(pos,current)] = ans;
}

int main(){
	memset(scheduled,-1,sizeof(scheduled));
	
	cin >> n >> m;
	for(int i = 0 ; i < m ; i++){
		int a,b;
		cin >> a >> b;
		a--;
		scheduled[a] = b;
	}
	cout << f(0,deque<int>()) << endl;
}

Measured memory_bytes: 0
n,m,X,Y = [int(x) for x in input().split()]
x = [int(x) for x in input().split()]
y = [int(x) for x in input().split()]

x_max = max(x)
y_min = min(y)

ans = False
for i in range(X+1, Y+1):
    if i > x_max and i <= y_min:
        ans = True
        break

if ans:
    print("No War")
else:
    print("War")


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin>>n;
  int flag=0;
  
  for(int i=0;i<=25;i++){
    for(int j=0;j<=15;j++){
      if(i*4+j*7==n) flag=1;
    }
  }
  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define pi 3.141592653589
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)
#define pii pair<int,int>
using namespace std;

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



int main() {

	int k, s, cnt = 0;

	cin >> k >> s;
	for (int i = 0; i <= k; i++) {
		for (int j = i; j <= k; j++) {
			for (int l = j; l <= k; l++) {
				if (i + j + l == s) {
					if (i == j&&j == l)cnt += 1;
					else if ((i == j&&j != l) || (j == l&&i != j) || (i == l&&i != j))cnt += 3;
					else cnt += 6;
				}
			}
		}
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#define max 246913 
using namespace std;

int main(){
	int n,ans;
	int N[max]={};
	int i,j;
	
	for(i = 2 ; i < max ; i++){
		if(N[i]==0){
			for(j = 2*i ; j < max ; j+=i){
				N[j]=1;
			}
		}
	}
	
	while(1){
		ans = 0;
		cin >> n;
		if(n==0){
			break;
		}
		for(i = n+1 ; i <= 2*n ; i++){
			if(N[i]==0){
				ans++;
			}
		}
		
		if(n==1){
			cout << 1 << endl;
		}else{
			cout << ans << endl;
		}
	}
	return 0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    double t,x;cin>>t>>x;
    cout<<setprecision(10)<<t/x<<endl;
}



Measured memory_bytes: 256
using System;

namespace ITP1_2_C
{
    class Program
    {
        static void Main(string[] args)
        {
            //??\???
            var inputs = new Inputs();
            inputs.Read();
            int a = inputs.GetInteger(0);
            int b = inputs.GetInteger(1);
            int c = inputs.GetInteger(2);

            compare(ref a,ref b,ref c);

            //??????
            Console.WriteLine(a + " " + b + " " + c);
        }

        private static void compare(ref int a, ref int b,ref int c)
        {
            int[] array = { a, b, c };
            for(int i = 0; i < array.Length - 1; i++)
            {
                for (int j = array.Length - 1;j > i; j--) {
                    if (array[j] < array[j - 1])
                    {
                        int buf = array[j];
                        array[j] = array[j - 1];
                        array[j - 1] = buf;
                    }
                }
            }
            a = array[0];
            b = array[1];
            c = array[2];
        }
    }
}

namespace ITP1_2_C
{
    class Inputs
    {
        // ?????????????????\??????????????????????????????
            private string[] inputs;

            public void Read()
            {
                string line = Console.ReadLine();
                this.inputs = line.Split(' ');
            }

            public int GetInteger(int number)
            {
                int data = int.Parse(inputs[number]);
                return data;
            }
    }
}

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

char prime_list_beta[200000];
int prime_list[200000];
int prime_num;

void make_prime_list(void) {
	int i,j;
	for(i=2;i<200000;i++)prime_list_beta[i]=1;
	for(i=2;i*i<200000;i++) {
		if(prime_list_beta[i]) {
			for(j=i+i;j<=200000;j+=i)prime_list_beta[j]=0;
		}
	}
	prime_num=0;
	for(i=2;i<200000;i++) {
		if(prime_list_beta[i])prime_list[prime_num++]=i;
	}
}

int find_min_prime(int n) {
	int left,right,mid;
	left=0;right=prime_num-1;
	while(left<=right) {
		mid=(left+right)/2;
		if(n<prime_list[mid])right=mid-1; else left=mid+1;
	}
	return right+1;
}

int qsort_comp(const void* x,const void* y) {
	const int* a=(const int*)x;
	const int* b=(const int*)y;
	if(*a>*b)return 1;
	if(*a<*b)return -1;
	return 0;
}

int thelist[10000];

int main(void) {
	int N,P;
	make_prime_list();
	while(scanf("%d%d",&N,&P)==2 && (N!=-1 || P!=-1)) {
		int start=find_min_prime(N);
		int i,j,pos;
		if(prime_num-start<100)return 1;
		pos=0;
		for(i=0;i<P;i++) {
			for(j=i;j<P;j++)thelist[pos++]=prime_list[start+i]+prime_list[start+j];
		}
		qsort(thelist,pos,sizeof(int),qsort_comp);
		printf("%d\n",thelist[P-1]);
	}
	return 0;
}

Measured memory_bytes: 944
#include <bits/stdc++.h>
using namespace std;
 
typedef vector<int> vi;
typedef vector<double> vd;
 
double mypow(double b ,int e){
      if(e == 0) return 1;
      if(e%2==0)
            return mypow( b*b, e/2 );
      else
            return mypow( b*b, e/2 ) * b;
}
 
int main(){
 
 
      int N,M,L; cin >> N >> M >> L ;
      if(N==1){
            cout << 1.0 << endl;
            return 0;
      }
      vector<vd> prob(N,vd(M+1,0.0));
      vector<vd> dist(N,vd(M+1,0.0));
 
      vd p(N),t(N),v(N);
      for(int i=0; i<N; i++) cin >> p[i] >> t[i] >> v[i];
 
      // PRE PROCESS
      for(int i=0; i<N; i++){
            dist[i][0] = (double)L / v[i];
            for(int j=1; j<=M; j++){
                  dist[i][j] = dist[i][j-1] + t[i];
            }
      }
      for(int i=0; i<N; i++)
            prob[i][0] = mypow((100-p[i])/100,M);
      for(int i=0; i<N; i++){
            for(int j=1; j<=M; j++){
                  if(p[i] != 100)
                        prob[i][j] = (prob[i][j-1] * (p[i]/100)) / ((100-p[i])/100);
                  else
                        prob[i][j] = 1.0;
            }
      }
      double comb = 1;
      for(int j=1; j<=M; j++){
            comb = comb * (M - j + 1) / j; 
            for(int i=0; i<N; i++){
                  prob[i][j] *= comb;
            }
      }
       
      vector<vd> sum = prob;
      for(int i=0; i<N; i++){
            for(int j=M-1; j>=0; j--){
                  sum[i][j] += sum[i][j+1];
                  if(sum[i][j] > 1) sum[i][j] = 1;
            }
      }
 
      vector<vd> ans = prob;
      for(int i=0; i<N; i++){
            for(int j=0; j<=M; j++){
                  for(int k=0; k<N; k++){
                        if(i==k) continue;
                        int id = upper_bound(dist[k].begin(),dist[k].end(), dist[i][j]) - dist[k].begin();
                        if(id > M) ans[i][j] = 0.0;
                        else       ans[i][j] *= sum[k][id];
 
                  }
            }
      }
 
      for(int i=0; i<N; i++){
            double tmp = 0.0;
            if(p[i] == 100) tmp = ans[i][M];
            else
                  for(int j=0; j<=M; j++)
                        tmp += ans[i][j];
            if(tmp > 1) tmp = 0;
            printf("%.10f\n",tmp);
      }
                         
}

Measured memory_bytes: 3344
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 1000003
#define Q 80

int n, q, ks[Q], m;
string s;

ll data[N];

void add(ll k, ll x) {
  while(k <= m) {
    data[k] += x;
    k += k & -k;
  }
}

ll get(ll k) {
  ll s = 0;
  while(k > 0) {
    s += data[k];
    k -= k & -k;
  }
  return s;
}

ll solve(int k) {
  rep(i, m+1) data[i] = 0;
  queue<int> que;
  ll res = 0, cur = 0;
  int l = 1, r = 1;
  rep(i, n) {
    char c = s[i];
    while(!que.empty() && i-que.front() >= k) {
      que.pop();
      cur -= get(l);
      l += 1;
    }
    if(c == 'D') {
      r += 1;
      que.push(i);
    } else if(c == 'M') {
      cur += r-l;
      add(l, 1);
      add(r, -1);
    } else if(c == 'C') {
      res += cur;
    }
  }
  return res;
}

int main() {
  cin >> n >> s >> q;
  rep(i, q) cin >> ks[i];
  m = 0;
  rep(i, n) {
    if(s[i] == 'D') ++m;
  }

  rep(i, q) {
    cout << solve(ks[i]) << endl;
  }

  return 0;
}

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

using namespace std;

int main(void) {
  int n;
  cin >> n;
  map <long long, int> mp;
  long long sum = 0;
  mp[0]++;

  long long ret = 0;
  for(int i = 0; i < n; i++) {
    //    cout << "i: " << i << endl;
    //    cout << "sum: " << sum << endl;
    //    cout << "ret: " << ret << endl;
    int x;
    cin >> x;
    //    cout << "a[" << i << "]: " << x << endl;
    //    cout << "-------------------------" << endl;
    sum += x;
    ret += mp[sum];
    mp[sum]++;
  }

  cout << ret << endl;
}

Measured memory_bytes: 12800
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def main():
    N, K = map(int, input().split())
    x_lsit = list(map(int, input().split()))
    INF = pow(10, 9)

    min_time = INF
    for i in range(N-K+1):
        x_l = x_lsit[i]
        x_r = x_lsit[i+K-1]
        this_time = int()
        if x_l <= -1:
            if x_r <= 0:
                this_time = -x_l
            else:
                this_time = min(-x_l, x_r)*2 + max(-x_l, x_r)
        else:
            this_time = x_r
        min_time = min(min_time, this_time)
    print(min_time)
    return

if __name__ == "__main__":
    main()



Measured memory_bytes: 20120
#include<bits/stdc++.h>
#pragma warning(disable:4996)
#ifdef _MSC_VER
#  define __builtin_popcount __popcnt
#endif
#define int long long
using namespace std;
using ll = long long;
using ld = long double;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
inline void my_io() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cout << fixed << setprecision(10);
}
int x, y, e;
vector<vector<int>>G;//グラフの隣接リスト表現
vector<int>match;//マッチングのペア
vector<bool>used;//ループチェック用
//uとvを結ぶ辺をグラフに追加する
void add_edge(int u, int v) {
	G[u].push_back(v);
	G[v].push_back(u);
}

//増加パスをDFSで探す
bool dfs(int v) {
	used[v] = true;
	for (int i = 0; i<G[v].size(); i++) {
		int u = G[v][i], w = match[u];
		if (w<0 || !used[w] && dfs(w)) {
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}
//二部グラフの最大マッチングを求める
int bipartitea_matching() {
	int res = 0;
	fill(match.begin(), match.end(), -1);
	for (int v = 0; v<x+y; v++) {
		if (match[v]<0) {//頂点vのマッチングのペアがない場合
			fill(used.begin(), used.end(), false);
			if (dfs(v)) {
				res++;
			}
		}
	}
	return res;
}

signed main() {
	cin >> x >> y >> e;
	G.resize(x + y);
	match.resize(x + y);
	used.resize(x + y);
	for (int i = 0; i < e; i++) {
		int u, v;
		cin >> u >> v;
		v += x;
		add_edge(u, v);
	}
	cout << bipartitea_matching() << endl;
	return 0;
}




Measured memory_bytes: 3292
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
	string l;
	cin >> l;
	if (l[0] == '7'|| l[1] == '7' || l[2] == '7')  cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> grid(H, vector<char>(W));
  rep(i, 0, H) rep(j, 0, W) cin >> grid[i][j];
  
  vector<vector<int>> dp(H, vector<int>(W, 0));
  rep(i, 0, H) {
    if (grid[i][0] == '.') dp[i][0] = 1;
    else break;
  }
  rep(i, 0, W) {
    if (grid[0][i] == '.') dp[0][i] = 1;
    else break;
  }
  rep(i, 1, H) {
    rep(j, 1, W) {
      if (grid[i][j] == '.') {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % 1000000007;
      }
    }
  }
  
  cout << dp[H - 1][W - 1] << endl;
  return 0;
}

Measured memory_bytes: 5248
N,K= [int(s) for s in input().split()]
h = [int(s) for s in input().split()]
dp = [10**10]*(N+K)
h = h + [0]*K
dp[0] = 0
for i in range(N):
    for j in range(1,K+1):
        dp[i+j] = min(dp[i+j], dp[i]+abs(h[i]-h[i+j]))
print(dp[N-1])


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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	string s;
	int k;
	cin >> s >> k;

	set<string> se;
	for (int i = 0; i < s.size(); i++) {
		for (int j = 0; j <= k; j++) {
			string v = s.substr(i, j);
			if (v.size() != 0) {
				se.emplace(s.substr(i, j));
			}
		}
	}

	int cnt = 1;
	for (auto v : se) {
		if (cnt == k) {
			cout << v << endl;
			break;
		}
		cnt++;
	}
	return 0;
}


Measured memory_bytes: 1664
package main

import (
	"fmt"
	"sort"
)
func main() {
	var n,x int
	var a []int
	fmt.Scan(&n,&x)
	nn := n
	for nn >0{
		var i int
		fmt.Scan(&i)
		a = append(a,i)
		nn --
	}
	//fmt.Scan(&a)
	//n = 3
	//x = 70
	//a = []int64{20,30,10}
	//n = n

	//sort.Slice(a, func(i, j int) bool {
	//	return a[i] < a[j]
	//})

	sort.Ints(a)

	var count int64
	for i,v := range a{
		//log.Println(x,v)
		if x < v{
			break
		}
		if i == len(a)-1 && x != v{
			break
		}
		x = x - v
		count++
	}
	fmt.Println(count)

}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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

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

signed main(){
    int n; cin >> n;
    vector<int> p( n );
    REP( i, n ){
        cin >> p[i];
    }


    int t = -1;
    REP( i, n - 1 ){
        if( t != -1 && p[i] > p[i + 1] ){
            swap( p[i + 1], p[t] );
            break;
        }
        if( p[i] > p[i + 1] ) t = i;
    }

    REP( i, n - 1 ){
        if( p[i] > p[i + 1 ] ){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
	int main(void) {
		int n, k, i, r, t, result, max;
		scanf("%d %d", &n, &k);
		if(k<1 || n<k ||n>50){
			return 1;
		}
		int l[n];
		for(i=0; i<n; i++){
			scanf("%d",&l[i]);
			if(l[i]<1 || l[i]>50){
				return 1;
			}
		}
		max = 0;
		result = 0;
		for(r=0; r<k; r++){
			for(i=0; i<n; i++){
				if(l[i]>max){
					max = l[i];
					t = i;
				}
			}
			l[t] = 0;
			t = 0;
			result = result + max;
			max = 0;
		}
		printf("%d",result);
		return 0;
	}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
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;}
const int inf = 1001001001;

int main() {
    int n,m;
    cin >> n >> m;
    vector<P> dr(n);
    rep(i,n) cin >> dr[i].first >> dr[i].second;
    sort(all(dr));
    ll ans = 0;
    ll now = 0;
    ll cnt = 0;
    while(cnt < m)  {
        ll nf = dr[now].first;
        ll ns = dr[now].second;
        if(ns + cnt <= m) {
            cnt += ns;
            ans += nf*ns;
        } else {
            ans += nf*(m-cnt);
            break;
        }
        now++;
    }
    cout << ans << endl;
}

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

#define int long long
#define REP(i, l, r) for (int i = (l); i != (r); (l)<(r)?++i:--i)
#define popcount __builtin_popcountll

const int INF = 1LL<<60;
const int MOD = 1000000007;

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")";
}

template <typename A>
string to_string(vector<A> v) {
    bool first = true;
    string result = "[";
    for (A i : v) {
        if (!first) result += ", ";
        first = false;
        result += to_string(i); 
    }
    return result + "]";
}

template <typename A>
string to_string(A x[], int n) {
    string result = "{";
    REP(i, 0, n) {
        if (i!=0) result += ", ";
        result += to_string(x[i]); 
    }
    return result + "}";
}

string bin_string(int x) {
    const int d = 64;
    string result(d, ' ');
    REP(i, d-1, -1) result[d-1-i] = '0'+((x&1LL<<i)!=0);
    return result;
}

vector<int> getZ(string s) {
    int n = s.size();
    vector<int> z(n);
    int x = 0, y = 0;
    REP(i, 1, n) {
        z[i] = max(0LL, min(z[i-x], y-i+1));
        while (i+z[i] < n && s[z[i]] == s[i+z[i]]) {
            x = i;
            y = i+z[i];
            ++z[i];
        }
    }
    return z;
}


int powa(int base, int exp) {
    if (exp<=0) return 1;
    if (base<=0) return 0;
    int val = powa(base, exp>>1);
    val = val*val % MOD;
    if (exp&1) {
        val = val*base % MOD;
    }
    return val;
}

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

    srand(time(NULL)); rand();

    int n;
    cin >> n;
    int m = 1<<n;
    multiset<int, greater<int>> hp;
    int best = -1;
    REP(i, 0, m) {
        int x;
        cin >> x;
        hp.insert(x);
        best = max(best, x);
    }
    vector<int> slimes = {best};
    hp.erase(hp.find(best));
    if (hp.count(best) != 0) {
        cout << "No";
        return 0;
    }
    
    REP(round, 0, n) {
        vector<int> slimecopy = slimes;
        for (int s : slimecopy) {
            auto it = hp.upper_bound(s);
            if (it == hp.end()) {
                cout << "No";
                return 0;
            }
            int x = *it;
            slimes.push_back(x);
            hp.erase(hp.find(x));
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 15724
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    h,w = LI()
    a = ['#'*(w+2)] + ['#' + S() + '#' for _ in range(h)] + ['#'*(w+2)]

    return '\n'.join(a)



print(main())


Measured memory_bytes: 7112
#include <stdio.h>		// standard input output
#include <iostream>		// input output stream, cin cout( console in console out)
#include <cmath>		// circle math ( sin, con, sinh
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>		// input output manipulation

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep3(i, a, n) for(int i = (int)(a); i < (int)(n); i++)
#define ll long long

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






int main() {
  string s,t; // 変数の宣言
  int ans=1000000;
  cin >>s>>t; // 標準入力

 
  rep(i,s.length()-t.length()+1){
    int ans2 =0;
    rep(j,t.length()){
      if(s.at(i+j) !=t.at(j)){
	ans2++;
      }
    }
    ans=min(ans,ans2);
  }
  cout << setprecision(12) << ans << endl; // 標準出力
}
 

Measured memory_bytes: 3560
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	char a,b,c;
	int d=0;
	cin>>a>>b>>c;
	if(a=='1'){
		d++;
	}
	if(c=='1'){
		d++;
	}
	if(b=='1'){
		d++;
	}
	cout<<d<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] d = new int[n];
        for(int i = 0 ; i < n ; i++ ){
            d[i] = sc.nextInt();
        }
        int s = 0;
        for(int i = 0 ; i < n ; i++ ){
            for(int j = 0 ; j < i ; j++ ){
                s += d[i] * d[j];
            }
        }
        System.out.println(s);
        sc.close();
    }
}

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

typedef long long ll;

int main()
{
	ll n, w;
	cin >> n >> w;
	vector<vector<ll>> arr(n,vector<ll>(2,0));
	for(ll i = 0; i < n; i++)
	{
		for(ll j = 0; j < 2; j++)
		{
			cin >> arr[i][j];
		}
	}
	vector<ll> dp_arr(n*1000+1,INT_MAX);
	ll max_ = 0;
	dp_arr[0] = 0;
	for(ll i = 1; i <= n; i++)
	{
		for(ll j = n*1000; j >= arr[i-1][1]; j--)
		{
			dp_arr[j] = min(dp_arr[j], arr[i-1][0] + dp_arr[j-arr[i-1][1]]);
			if(dp_arr[j] <= w)
				max_ = max(max_,j);
		}
		// cout << "i: " << i << " dp: " << max_ << endl;
	}
	cout << max_ << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;
const double PI = 3.14159265358979323846;
int main() {
    double a;
    cin >> a;
    cout << 2.0 * a * PI << endl;
}


Measured memory_bytes: 3784
n,m,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
temp=False
if Y-X>0:
    for i in range(X+1,Y):
        if max(x)<i and i<=min(y):
            temp=True
            break
if temp==False:
    print("War")
else:
    print("No War")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




int main(){

	int X,Y;
	scanf("%d %d",&X,&Y);

	for(int a = 0; a <= X; a++){
		if(a*2+4*(X-a) == Y){

			printf("Yes\n");
			return 0;
		}
	}

	printf("No\n");

	return 0;
}


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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int N;
  cin >> N;

  string S;
  cin >> S;

  int right = 0;
  int left = 0;
  string left_ans = "";
  for(int i = 0; i < S.size(); i++){
    if(S[i] == '('){
      left++;
    } else { 
      if(left > 0){
        left--;
      } else { 
        left_ans += "(";
      }
    }
  }

  right = 0;
  left = 0;
  string right_ans = "";
  for(int i = S.size()-1; i >= 0; i--){
    if(S[i] == ')'){
      right++;
    } else { 
      if(right > 0){
        right--;
      } else { 
        right_ans += ")";
      }
    }
  }

  cout << left_ans + S + right_ans << endl;

}


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

int main() {
    int n, k, ans = 0;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; ++i) {
        cin >> k;
        a[k-1] = i+1;
    }
    for(int i = 0; i < n; ++i) {
        cout << a[i] << " ";
    }
    cout << endl;
}

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

int main()
{
    int n, k;
    cin >> n >> k;

    vector<int> hpList;
    for (int i = 0; i < n; ++i)
    {
        int input;
        cin >> input;
        hpList.push_back(input);
    }

    sort(hpList.begin(), hpList.end());

    long long remainSum = 0;
    for (int i = 0; i < n - k; ++i)
    {
        remainSum += hpList.at(i);
    }

    cout << remainSum << endl;
}

Measured memory_bytes: 1400
#include <algorithm>
#include <array>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define vint vector<int>

template <class T> class SegmentTree {
    int n;
    vector<T> seg_tree;
    T unit;
    function<T(T, T)> operation;
    function<T(T, T)> update;
    T _query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l)
            return unit;
        if (a <= l && r <= b) {
            return seg_tree[k];
        } else {
            T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2);
            T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r);
            return operation(c1, c2);
        }
    }

  public:
    SegmentTree(size_t _n, T _unit, function<T(T, T)> _operation,
                function<T(T, T)> _update)
        : unit(_unit), operation(_operation), update(_update) {
        n = 1;
        while (n < _n) {
            n *= 2;
        }
        seg_tree = vector<T>(2 * n - 1, unit);
    }

    void change(int index, T changed) {
        index += n - 1;
        seg_tree[index] = update(seg_tree[index], changed);
        while (index > 0) {
            index = (index - 1) / 2;
            seg_tree[index] =
                operation(seg_tree[index * 2 + 1], seg_tree[index * 2 + 2]);
        }
    }
    T query(int a, int b) { return _query(a, b, 0, 0, n); }
    T operator[](int index) { return seg_tree[index + n - 1]; }
};

int main() {
    int n, q;
    cin >> n >> q;
    SegmentTree<ll> st(n, 0, [](ll a, ll b) { return a + b; },
                       [](ll a, ll b) { return b; });
    rep(query, q) {
        int c, x, y;
        cin >> c >> x >> y;
        // cout << st.operator[](x) << endl;
        if (c == 0){
            st.change(x - 1, st.operator[](x - 1) + y);
        }else{
            cout << st.query(x - 1, y) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4848
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;

int main(){
    double x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    double a=x2-x1;
    double b=y2-y1;
    double c=pow(a,2);
    double d=pow(b,2);
    double e=c+d;
    double ans =sqrt(e);
    
    printf("%8lf\n",ans);
}


Measured memory_bytes: 3188
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(d)]

ans = float("inf")
for b in range(1<<d):
    m = set(range(1, d+1))
    c = 0
    s = 0
    for i in range(d):
        if b & (1<<i):
            c += pc[i][0]
            s += 100*(i+1)*pc[i][0] + pc[i][1]
            m.discard(i+1)
    if s >= g:
        ans = min(ans, c)
        continue
    while s < g and m:
        p = pc[max(m)-1][0]
        for _ in range(p):
            c += 1
            s += 100*max(m)
            if s >= g:
                break
        m.discard(max(m))
    ans = min(ans, c)
print(ans)


Measured memory_bytes: 42780
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll a[1000000 + 10];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	rep(i, 1, n + 1){
		cin >> a[i];
	}
	sort(a + 1, a+ 1 + n);
	ll sum = 1;
	ll maxn = 1e18;
	rep(i, 1, n + 1){
		if(sum == 0 || a[i] == 0){
			cout << "0" << endl;
			return 0;
		}
		if(maxn / a[i] < sum ){
			cout << "-1" << endl;
			return 0;
		}
		sum *= a[i];
	}
	if(sum <= maxn)cout << sum << endl;
	else cout << "-1" << endl;
	return 0;
}

Measured memory_bytes: 4400
#include<bits/stdc++.h>
#define ll long long int
#define F first
#define S second
#define pb push_back
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y);
#define sdl(x) scanf("%lld",&x)
#define sd2l(x,y) scanf("%lld%lld",&x,&y);
#define sz(x) (int)(x.size())
#define nax 101010
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define mp make_pair
#define pi pair<int ,int>
#define pii pair <int,pi>
using namespace std;
int main(int argc, char const *argv[])
{
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  int a,b;
  cin >> a >> b;
  ll fans =  0;
  ll f1,f2;
  f1 = f2= 1;
  if(abs(a-b) > 1)
  {
    puts("0");
    return 0;
  }
  else
  {
    f1 = 1;
    f2 = 1;
    for(int i = 1;i<=a;i++)
    {
      f1 = (f1*i) %MOD;
    }
    for(int i = 1;i<=b;i++)
    {
      f2 = (f2*i) %MOD;
    }
    if(a>=b)
    {
      fans+=(f1*f2)%MOD;
    }
    if(b>=a)
    {
      fans+=(f1*f2)%MOD;
    }
    printf("%lld\n",fans%MOD);
  }
  return 0;
}
 

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

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

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}

const int MAXN=50,MAXM=20;
int N,M;
vpint G[MAXN];
int U[MAXM],V[MAXM];

int par[MAXN],parEdgeID[MAXN];
void dfs(int v,int p,int pe){
    par[v]=p;
    parEdgeID[v]=pe;
    for(auto &e:G[v]){
        if(e.fi==p)continue;
        dfs(e.fi,v,e.se);
    }
}

int lis[MAXM];
int dp[1<<MAXM];
signed main(){

    cin>>N;
    rep(i,N-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].eb(b,i);
        G[b].eb(a,i);
    }

    cin>>M;
    rep(i,M)cin>>U[i]>>V[i],U[i]--,V[i]--;
    rep(i,M){
        dfs(U[i],-1,-1);
        int v=V[i];
        while(v!=U[i]){
            lis[i]|=1ll<<parEdgeID[v];
            v=par[v];
        }
    }

    for(int i=1;i<1<<M;i++){
        int k=topbit(i);
        dp[i]=dp[i^(1<<k)]|lis[k];
    }

    int ans=0;
    rep(i,1<<M){
        int num=N-1-popcount(dp[i]);
        int tmp=1ll<<num;
        if(parity(i))ans-=tmp;
        else ans+=tmp;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N;
  cin >>N;
  int r, l;
  int S=0;
  for(int i=0;i<N;i++)
  {
    cin>>l>>r;
    S+=r-l+1;
  }
  cout<<S<<endl;
}

Measured memory_bytes: 256
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
h = i()
n = 0
while h > 0:
    h = h//2
    n += 1
print(2**n-1)

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

#define pb push_back
#define ff first
#define ss second

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

const int MAXN = 5 * 100 * 1000 + 17;

int n, k, a[MAXN], seg[MAXN << 2], p[MAXN];
set<int> s;

void upd(int pos, int v = 1, int l = 1, int r = n + 1) {
	if (pos < l || r <= pos) return;
	if (l + 1 == r) {
		seg[v] = pos;
		return;
	}
	upd(pos, v << 1, l, l + r >> 1);
	upd(pos, v << 1 | 1, l + r >> 1, r);
	if (a[seg[v << 1]] > a[seg[v << 1 | 1]]) seg[v] = seg[v << 1];
	else seg[v] = seg[v << 1 | 1];
}
int get(int lp, int rp, int v = 1, int l = 1, int r = n + 1) {
	if (rp <= l || r <= lp) return 0;
	if (lp <= l && r <= rp) return seg[v];
	int lg = get(lp, rp, v << 1, l, l + r >> 1), rg = get(lp, rp, v << 1 | 1, l + r >> 1, r);
	if (a[lg] > a[rg]) return lg;
	else return rg;
}
int getST(int x) { return x * (k - 1) + 1; }
int getEN(int x) { return min((x + 1) * (k - 1) + 1, n + 1); }
void addMAX(int x) {
	int pos = get(getST(x), getEN(x));
	if (get(pos - k + 1, pos + k) == pos && a[pos] > 0)
		s.insert(pos);
}
int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> a[i], upd(i);
	if (k == 1) {
		for (int i = 1; i <= n; i++)
			cout << i << '\n';
		return 0;
	}
	for (int i = 0; i < (n + k - 2) / (k - 1); i++) addMAX(i);
	int label = n;
	while (s.size()) {
		int u = *s.rbegin();
		s.erase(u);
		a[u] = -1;
		upd(u);
		p[u] = label--;
		int bl = (u - 1) / (k - 1);
		addMAX(bl);
		if (bl == 0) addMAX(bl + 1);
		else if (bl + 1 == (n + k - 2) / (k - 1)) addMAX(bl - 1);
		else addMAX(bl - 1), addMAX(bl + 1);
	}
	for (int i = 1; i <= n; i++)
		cout << p[i] << '\n';
	return 0;
}


Measured memory_bytes: 21120