akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define fix(n) cout<<fixed<<setprecision(n);
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int n,m; cin>>n>>m;
  int a[n][m],b[m];
  rep(i,0,n) rep(j,0,m) cin>>a[i][j];
  rep(i,0,m) cin>>b[i];
  rep(i,0,n){
    int c=0;
    rep(j,0,m) c+=a[i][j]*b[j];
    co(c);
  }
  return 0;
}


Measured memory_bytes: 3136
N = int(input())
X = list(map(int, input().split()))

ma = max(X)
mi = min(X)

ans = 10**9

for n in range(mi, ma+1):
  count = 0
  for x in X:
    count += abs(x-n)**2

  if ans > count:
    ans = count

print(ans)

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

using namespace std;

#define ll long long

int main() {
    vector<int> a;
    int x, y, z;
    cin >> x >> y >> z;
    a.push_back(x);
    a.push_back(y);
    a.push_back(z);
    sort(a.begin(), a.end());
    if (a[0] == 5 && a[1] == 5 && a[2] == 7) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 3596
from copy import deepcopy

n, m = [int(i) for i in input().split()]
es = [[int(j) for j in input().split()] for i in range(m)]

x = [float('-inf')] * (n+1)
x[1] = 0

for i in range(n):
    for a, b, c in es:
        x[b] = max(x[b], x[a]+c)

prevxn = x[n]
for a, b, c in es:
        x[b] = max(x[b], x[a]+c)

if prevxn != x[n]:
    print('inf')
else:
    print(x[n])

Measured memory_bytes: 3828
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   String S = sc.next();
   int SS = 0;
   if(S.equals("SUN")) SS = 7;
   else if(S.equals("MON")) SS = 6;
   else if(S.equals("TUE")) SS = 5;
   else if(S.equals("WED")) SS = 4;
   else if(S.equals("THU")) SS = 3;
   else if(S.equals("FRI")) SS = 2;
   else if(S.equals("SAT")) SS = 1;
     
   System.out.println(SS);
 }
}

Measured memory_bytes: 22740
// at_dp_h.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define FOR(i,a) for(int i=0;i<a;i++)
int MOD = 1e9 + 7;
int row, col;
int dp[1001][1001];
char arr[1001][1001];
int main()
{
	memset(dp, 0, sizeof(dp));
	cin >> row >> col;
	FOR(i, row) {
		FOR(a, col) {
			cin >> arr[i][a];
			
		}
	}
	dp[1][1] = 1;
	FOR(i, row) {
		FOR(a, col) {
			if (i == 0 && a == 0)continue;
			dp[i + 1][a + 1] = (dp[i][a + 1] + dp[i + 1][a]) % MOD;
	
			if (arr[i][a] == '#') {
				dp[i + 1][a + 1] = 0;
			}
		}
	}
	/*FOR(i, row+1) {
		FOR(a, col + 1) {
			cout << dp[i][a] << " ";
		}
		cout << "\n";
	}*/
	cout << dp[row][col] << "\n";
}



Measured memory_bytes: 5120
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn rotate(s: String) -> String {
    let mut s1 = s.chars().collect::<Vec<char>>();
    let c1 = s1.pop().unwrap();
    s1.insert(0, c1);
    s1.into_iter().collect::<String>()
}

fn main() {
    let s = read::<String>();
    let t = read::<String>();

    let mut ss = s.clone();
    loop {
        if ss == t {
            yn(true);
            break;
        }
        ss = rotate(ss);
        if ss == s {
            yn(false);
            break;
        }
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;



int main() {
	int n; cin >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		if (b[i] <= a[n / 2 - 1]) cout << a[n / 2] << endl;
		else cout << a[n / 2 - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3712
import java.util.*;
class Main {
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  int a = sc.nextInt();
  int b = sc.nextInt();
  int c = sc.nextInt();
  int cnt = 0;
  for( int i = a; i <= b; i++ ) {
   if( c % i == 0 ) {
    cnt++;
   }
  }
  System.out.println(cnt);
 }
}


Measured memory_bytes: 26344
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int n,m,l,r;
int main()
{
	cin>>n>>m;
	l=1,r=n;
	while(m--)
	{
		int tl,tr;
		cin>>tl>>tr;
		l=max(l,tl);
		r=min(r,tr);
	}
	if(l>r)
	{
		cout<<0;
		return 0;
	}
	else
	{
		cout<<r-l+1;
	}
}

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

using P = pair<int,int>;
int bfs(int h,int w, vector<string> &s, int x, int y, int gx, int gy);
int main(void) {
    int H,W;
    int before = 0;
    int distance;
    cin >> H >> W;

    vector<string> s(H);
    for(int i=0;i<H;i++) {
        cin >> s[i];
        for(int j=0;j<s[i].size();j++) {
            if(s[i][j] == '#') {
                before++;
            }
        }
    }

    // 普通にBFSして距離を取る
    // H*W - 距離 - 事前の黒の数 が 答え
    
    distance = bfs(H,W,s,0,0,H-1,W-1);
    if(distance == -1) {
        cout << "-1\n";
    } else {
        cout << H * W - distance - before - 1 << endl;
    }

    return 0;
}

int bfs(int h,int w, vector<string> &s, int x, int y, int gx, int gy) {
    vector<int> dx = {-1,0,0,1};
    vector<int> dy = {0,-1,1,0};
    int cnt = 0;
    vector<vector<int>> dist(h,vector<int>(w,INT_MAX));

    queue<P> q;
    q.push(make_pair(x,y));
    dist[x][y] = 0;    
    while(!q.empty()) {
        P p = q.front();q.pop();
        if(p.first == gx && p.second == gy) return dist[gx][gy];

        for(int i=0;i<dx.size();i++) {
            x = p.first + dx[i];
            y = p.second + dy[i];
            if(x < 0 || y < 0 || x >= h || y >= w) continue;
            if(s[x][y] == '#') continue;
            if(dist[x][y] != INT_MAX) continue;
            dist[x][y] = dist[p.first][p.second] + 1;
            q.push(make_pair(x,y));
        }
    }
    return -1;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define mp make_pair
#define f first
#define s second
#define mod 1000*1000*1000+7
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    cout<<n*n<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int main() {
  int ab, bc, ca;
  cin >> ab >> bc >> ca;
  int ans = ab + bc;
  ans = min(ans, ca + bc);
  ans = min(ans, ab + ca);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void doIt() { 
		int a[] = new int [5];
		for(int i = 0;i < 5;i++){
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		for(int i = 4;i >= 1;i--){
			System.out.print(a[i]+" ");
		}
		System.out.println(a[0]);
     }
    public static void main(String[] args) {
    	// TODO Auto-generated method stub
    	new Main().doIt();
    }
}

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

int main(){
	int n; cin >>n;
    int cnt=0, tmp;
    for(int i=1; i<n+1; i++){
        cin >> tmp;
        if(tmp!=i) cnt++;
    }
    if(cnt==0 || cnt==2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define f(i,s,n) for(int i=s;i<=n;++i)
const lli mx = 1e9+7;
int main(){
   lli n;
   cin>>n;
   vector<int> arr(n);

   f(i,0,n-1){
       cin>>arr[i];
   }
   vector<int> temp(n+1, 0);
    temp[n]=0;

    lli sum=0;
   for(int i=n-1;i>=0;--i){
       temp[i] = (temp[i+1]+arr[i])%mx;
   }
    sum=0;
   for(int i=1;i<=n; ++i){
       sum += ((temp[i]%mx)*(arr[i-1]%mx))%mx;
   }
   cout<<sum%mx<<endl;

}

Measured memory_bytes: 4840
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String[] splited = s.split("/");
        if(Integer.parseInt(splited[0]) < 2019) {
            System.out.println("Heisei");
            return;
        }
        if(Integer.parseInt(splited[0]) > 2019) {
            System.out.println("TBD");
            return;
        }
        if(Integer.parseInt(splited[1]) <= 4) {
            System.out.println("Heisei");
            return;
        }
        System.out.println("TBD");
    }
}


Measured memory_bytes: 22996
import math

class Point:
    def __init__(self,x,y):
        self.x = x
        self.y = y

    def __add__(self,a):
        return self.__class__(self.x+a.x,self.y+a.y)

    def __sub__(self,a):
        return self.__class__(self.x-a.x,self.y-a.y)

    def __mul__(self,d):
        return self.__class__(self.x*d,self.y*d)

    def __truediv__(self,d):
        return self.__class__(self.x/d,self.y/d)

    def __str__(self):
        return '%.10f %.10f'%(self.x,self.y)

    def abs(self):
        return self.norm()**(1.0/2.0)

    def norm(self):
        return (self.x*self.x+self.y*self.y)

    def rotate(self,d):
        r = math.pi*d/180.0
        return self.__class__( self.x*math.cos(r)-self.y*math.sin(r),
                               self.x*math.sin(r)+self.y*math.cos(r))

    def dot(self,p):
        return (self.x*p.x+self.y*p.y)

class Segment:
    def __init__(self,p1,p2):
        self.p1 = p1
        self.p2 = p2

def reflect(s,p):
    v = s.p2-s.p1
    r = v.dot(p-s.p1)/v.norm()
    return s.p1+v*r

def main():
    a,b,c,d = map(float,input().split())
    s = Segment(Point(a,b),Point(c,d))
    q = int(input())
    for _ in range(q):
        e,f = map(float,input().split())
        p = Point(e,f)
        print (reflect(s,p))


if __name__ == '__main__':
    main()




Measured memory_bytes: 5700
from collections import deque
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


LIST = deque()

num_command = int(input())

for loop in range(num_command):

    input_command = input()

    if input_command == 'deleteFirst':
        LIST.popleft()
    elif input_command == 'deleteLast':
        LIST.pop();
    else:
        com,num = input_command.split()

        if com == 'insert':
            LIST.appendleft(num)
        elif com == 'delete':
            try:
                LIST.remove(num)
            except:
                pass

print(' '.join(LIST))


Measured memory_bytes: 70168
#include<iostream>
using namespace std;
int n,sum,i;
main(){
  cin>>n;
  sum=n;
  for(i=2;i*i<=n;i++){
    if(n%i==0){
      sum=sum/i*(i-1);
      while(n%i==0){
        n/=i;
      }
    }
  }
  if (n!=1) {
    sum=sum/n*(n-1);
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 3104
def insertion_sort(A, n, g):
    global cnt
    for i in range(g, n):
        val = A[i]
        j = i - g
        while j >= 0 and A[j] > val:
            A[j + g] = A[j]
            j = j - g
            cnt += 1
        A[j + g] = val


def shell_sort(A, n):
    global cnt
    cnt = 0
    G = []
    h = 1
    while h <= len(A):
        G.append(h)
        h = 3 * h + 1
    G.reverse()
    print(len(G))
    print(' '.join(map(str, G)))
    for i in range(0, len(G)):
        insertion_sort(A, n, G[i])


if __name__ == '__main__':
    n = int(input())
    l = [int(input()) for _ in range(n)]
    shell_sort(l, n)
    print(cnt)
    for i in l:
        print(i)



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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

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

void Main() {
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  rep(i, n/2) {
    if (s[i] != s[n-1-i]) ans++;
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define pie 3.14159265358979323846264338327950288419716939937510
#define mod1 998244353
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
typedef unsigned long long int ull;
using namespace std;
bool sortbysec(const pair<li,li>&a,const pair<li,li>&b)
{
    return (a.second<b.second);
}
li mpow(li x,li y)
{
  li ans=1;
  while(y)
  {
    if(y%2!=0)
    ans=(ans%mod)*(x%mod)%mod;
    y/=2;
    x=((x%mod)*(x%mod))%mod;
  }
  return ans;
}
int main()
{
fast_io
li r;
cin>>r;
long double ans=2*pie*r;
cout<<fixed<<setprecision(20)<<ans;
  return 0;
}


Measured memory_bytes: 3800
n=int(input())
L={}
for i in range(n):
    l=''.join(sorted(list(input())))
    if l in L:
        L[l]+=1
    else:
        L[l]=1
c=0
for v in L.values():
    if v>=2:
        c+=v*(v-1)//2
print(c)

Measured memory_bytes: 17808
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


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

ll N;

vector<ll> A(N + 1);

ll ch(ll i) {
	ll s = 0;
	repn(j, i) s += A[j];

	for (ll j = i + 1; j <= N; j++) {
		if (s * 2 < A[j]) { return false; }
		s += A[j];
	}

	return true;
}



int main() {

	cin >> N;
	A.assign(N + 1, 0);
	repn(i, N) cin >> A[i];
	sort(++A.begin(), A.end());

	ll le = 0;
	ll ri = N + 1;

	while (ri - le > 1) {
		ll m = (le + ri) / 2;
		if (ch(m)) { ri = m; }
		else { le = m; }
	}

	cout << N - le;
	

	system("PAUSE");
}


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

using namespace std;


int main(){
string s;
cin>>s;
int q;
cin>>q;
int flag =0;
string a="",b="";
for(int i=0;i<q;i++){
    int temp; cin>>temp;
    if(temp==1){
        //reverse(s.begin(),s.end());
        flag= (flag+1)%2;
    }
    if(temp==2){
        int f;
        string c;
        cin>>f;
        cin>>c;
        if(f==1){
            if(flag==0){
                a=c+a;
            }
            else{
                b=b+c;
            }
        }
        if(f==2){
            if(flag==0){
                b=b+c;
            }
            else{
                a=c+a;
            }
        }
    }
}

if(flag%2==0){
    cout<<a+s+b;
}
else{
    reverse(s.begin(),s.end());
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    s= b+s+a;
    cout<<s;
}

  return 0;
}
 


Measured memory_bytes: 1512
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Array.Unboxed

main :: IO ()
main = do
  [n,m] <- getl $ wrds toInt
  solve n m <$> replicateM n (getl toInt) >>= mapM_ print

solve :: Int -> Int -> [Int] -> [Int]
solve n m xs = elems $ foldl f ia [1..m]
  where
    ia = listArray (1,n) xs :: UArray Int Int
    f a k = foldl g a [1..n-1]
      where
        g b i
          | b ! i `mod` k > b ! (i+1) `mod` k = b // [(i,b ! (i+1)),(i+1, b ! i)]
          | otherwise = b

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 10316
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
use std::io::prelude::*;

fn input<T>() -> T
    where T: std::str::FromStr {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

const MOD: i64 = 1e9 as i64 + 7;
fn trial_division(mut n :usize) -> HashMap<usize, usize>{
    let mut primes = HashMap::new();
    let mut i = 2;

    //  n を root n 以下の整数で割り切れるまで割っていく
    while i * i <= n {
        while n % i == 0 {
            n /= i;
            if primes.contains_key(&i) {
                let mut x = primes.get_mut(&i).unwrap();
                *x += 1;
            } else {
                primes.insert(i, 1);
            }
        }
        i+=1;
    }

    // 最後にnが素数になっている場合はそれ自身も素因数に含めて終了
    if n > 1 {
        if primes.contains_key(&n) {
            let mut x = primes.get_mut(&n).unwrap();
            *x += 1;
        } else {
            primes.insert(n, 1);
        }
    }
    primes
}



fn main() {
    let n: usize = input();
    let mut hm = HashMap::new();
    for i in 1..n+1 {
        for (k, v) in trial_division(i) {
            if !hm.contains_key(&k) {
                hm.insert(k, 1);
            } else {
                let x = hm.get_mut(&k).unwrap();
                *x += v;
            }
        }
    }
    let mut cnt = 1;
    for (k, v) in hm {
        cnt *= v + 1;
        cnt %= MOD as usize;
    }
    println!("{}", cnt as i64 % MOD);
}

Measured memory_bytes: 4352
N=input()
N = list(N)
LEN = len(N)
N = int(N[LEN-1])


if N == 2 or N == 4 or N == 5 or N == 7 or N == 9:
	print('hon')
elif N == 0 or N == 1 or N == 6 or N == 8:
	print('pon')
elif N == 3:
	print('bon')

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int d;
    string a,b,c;
    cin>>a>>b;
    d=a.size();
    c=b.substr(0,d);
    if(a.compare(c)==0)
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 3600
#coding: utf-8
import math
n, d = map(int,input().split())
points = [list(map(int,input().split())) for i in range(n)]

ans = 0

for i in range(n):
    for j in range(i+1,n):
        dis_sq = 0
        for k in range(d):
            dis_sq += (points[i][k]-points[j][k]) ** 2
        dis = math.sqrt(dis_sq)
        if dis.is_integer():
            ans += 1

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

// 1 - indexed
template <typename T>
struct BIT
{
   vector<T> bit;

   BIT(int sz) : bit(sz + 1, 0) {}

   // sum of [1, k]
   T sum(int k)
   {
      T res = 0;
      for (int x = k; x > 0; x -= x & -x)
         res += bit[x];
      return res;
   }

   void add(int k, T w)
   {
      for (int x = k; x < bit.size(); x += x & -x)
         bit[x] += w;
   }

   // sum of [x, y)
   T getSum(int x, int y)
   {
      return sum(y - 1) - sum(x - 1);
   }

   // find an index i s.t. a[1] + a[2] + ⋯ + a[x] ≧ w
   T lower_bound(T w)
   {
      if (w <= 0)
         return 0;

      T x = 0;
      int p = 1, N = bit.size();

      while (2 * p <= N)
         p *= 2;

      for (T k = p; k > 0; k /= 2)
      {
         if (x + k <= N && bit[x + k] < w)
         {
            w -= bit[x + k];
            x += k;
         }
      }

      return x + 1;
   }
};

int main()
{
   fast();

   int N, Q;
   cin >> N >> Q;
   vector<int> c(N + 1);
   for (int i = 0; i < N; i++)
      cin >> c[i + 1];

   vector<vector<pair<int, int>>> queries(N + 1, vector<pair<int, int>>());

   for (int i = 0, l, r; i < Q; i++)
   {
      cin >> l >> r;
      queries[l].emplace_back(r, i);
   }

   vector<priority_queue<int, vector<int>, greater<int>>> pos(N + 1);

   for (int i = 1; i <= N; i++)
      pos[c[i]].push(i);

   BIT<int> bit(N);

   for (int i = 1; i <= N; i++)
   {
      if (pos[i].empty())
         continue;
      bit.add(pos[i].top(), 1);
      pos[i].pop();
   }

   vector<int> ans(Q);

   for (int l = 1; l <= N; l++)
   {
      for (auto q : queries[l])
      { // 左端がlのクエリ
         int R = q.first + 1, ind = q.second;
         ans[ind] = bit.getSum(l, R);
      }

      bit.add(l, -1);
      if (pos[c[l]].empty())
         continue;

      int nxt = pos[c[l]].top();
      pos[c[l]].pop();
      bit.add(nxt, 1);
   }

   for (int i = 0; i < Q; i++)
   {
      cout << ans[i] << "\n";
   }
}

Measured memory_bytes: 62592
const main = (input) => {
  input = input.split('\n');
  const A = parseInt(input[0], 10);
  const B = parseInt(input[1], 10);
  const C = parseInt(input[2], 10);
  const D = parseInt(input[3], 10);
  
  console.log(Math.min(A, B)+Math.min(C, D));
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
char c[400][400];
int H,W;
int c1,c2;

void dfs(int x,int y,bool f){
    rep(i,4){
        int a=x+dx[i],b=y+dy[i];
        if(a>=H || a<0 || b>=W || b<0);
        else if(c[a][b]=='.' && f){
            c[a][b]='v'; 
            c1++;
            dfs(a,b,false);
        }
        else if(c[a][b]=='#' && !f){
            c[a][b]='v'; 
            c2++;
            dfs(a,b,true);
        }
    }
    return;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    cin >> H >> W;
    int ans=0;
    rep(i,H) rep(j,W) cin >> c[i][j];
    rep(i,H){
        rep(j,W){
            if(c[i][j]=='#'){
                c[i][j]='v';
                c1=0; c2=1;
                dfs(i,j,true);
                ans+=c1*c2;
            }
        }
    }
    cout << ans << endl;
}

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

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

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

ll n, x;
ll cnt[51], dp[51];

// p          0, 1
// b(p)p(p)b    2, 3
// b(bpppb)p(bpppb)b           6, 7
void init() {
    cnt[0] = 1;
    dp[0] = 1;
    for (int i = 1; i <= 50; ++i) {
        cnt[i] = cnt[i - 1] * 2 + 3;
        dp[i] = dp[i - 1] * 2 + 1;
    }
}
ll f(ll a, ll b) {
    if (b == 0) return 0;
    if (a == 0) return 1;
    if (b >= cnt[a]) return dp[a];
    ll res = 0;
    --b;
    if (b > cnt[a - 1]) {
        res += f(a - 1, b) + 1 + f(a - 1, b - cnt[a - 1] - 1);
    } else {
        res += f(a - 1, b);
    }
    return res;
}
int main() {
    init();
    cin >> n >> x;
    ll ans = f(n, x);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    cin >> ans;
    for(int i = 1; i < n; i++){
        int a; cin >> a;
        ans = __gcd(a,ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
vector<int>hako[100100];
priority_queue<int>que;
int main(){
  int n,m;
  cin >> n  >> m;
  rep(i,0,n){
    int a,b;
    cin >> a >> b;
    hako[a].push_back(b);
  }
  LL res = 0;
  for(int i=1;i<=m;i++){
    rep(j,0,hako[i].size()){
      que.push(hako[i][j]);
    }
    if(!que.empty()){
      res += que.top();que.pop();
    }
  }
  cout << res << endl;
	return 0;
}


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

int main(){
 int a;
  cin>>a;
  vector<double> n(a+2);
  n[a]=0;
  n[a+1]=0;
  for(int i=0;i<a;i++){
    cin>>n[i];
    n[a]=max(n[a],n[i]);
    }
  for(int i=0;i<a;i++){
 n[a+1]+=n[i];
  }
  n[a+1]-=n[a];
  if(n[a+1]>n[a]){
       cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

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

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

int main(void)
{
    ll a,b;
    cin >> a >> b;
    pr(lcm(a,b));
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
import java.lang.Math.*;
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);
        int n = in.nextInt();
        int k = in.nextInt();
        int [][] dp = new int[n+1][k+1];
        int []ai = new int[n+1];
        int mod = (int)1e9+7;
        dp[0][0]=1;
        for(int i=1;i<=n;i++)
            ai[i] = in.nextInt();
        for(int i=1;i<=n;i++){
            int []psum = new int[k+2];
            int cur =0;
            for(int idex=0;idex<=k;idex++){
                cur= (cur + dp[i-1][idex])%mod;
                psum[idex+1]=cur%mod;
            }
            for(int j=0;j<=k;j++){
                int mx = Math.min(ai[i],j);
                int a= psum[j+1];
                int b = psum[(j-mx)];
                if (a<b)
                    a+=mod;
                dp[i][j] = (a-b)%mod;
            }
        }
        System.out.println(dp[n][k]%mod);


    }
}


Measured memory_bytes: 105788
#include<iostream>
#include<vector>
#include<cstdlib>
#include<algorithm>


const long long MOD = 10e9 + 7;

typedef long long ll;

using namespace std;

ll arr[101][100001];

ll max(ll a, ll b){
	if(a>b)
		return a;
	return b;
}

ll maxVal(int W, vector<int> wt, vector<int> v, int n){
	int i,w;
	for(int i=0;i<=n;i++){
		for(w=0;w<=W;w++){
			if(i==0 || w==0)
				arr[i][w]=0;
			else if( wt[i-1] <=w){
				arr[i][w] = max(
					v[i-1] + arr[i-1][w-wt[i-1]],
					arr[i-1][w]				
				);
			}
			else
				arr[i][w] =arr[i-1][w]; 
	//		cout<<"i:"<<i<<"w:"<<w<<"ans:"<<arr[i][w]<<endl;		
		}	
	}
	return arr[n][W];
}

int main(){
	int N,W;
	cin>>N>>W;
	vector<int> w,v;
	int x,y;
	for(int i=0;i<N;i++){
		cin>>x>>y;
		w.push_back(x);
		v.push_back(y);	
	}
	cout<<maxVal(W,w,v,N)<<endl;
	
}

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

const double eps = 1e-9;

bool same(double a, double b) { return a == b; }

struct P {
    double x, y;
    P() : x(0), y(0) {}
    P(double x, double y) : x(x), y(y) {}
    P operator + (P b) { return P(x + b.x, y + b.y); }
    P operator - (P b) { return P(x - b.x, y - b.y); }
    P operator * (double b) { return P(x * b, y * b); }
    P operator / (double b) { return P(x / b, y / b); }
    double operator * (P b) { return x * b.x + y * b.y; }
    double operator ^ (P b) { return x * b.y - y * b.x; }
    double abs() { return hypot(x, y); }
    P unit() { return *this / abs(); }
};

struct L{
    // ax + by + c = 0
    double a, b ,c, o;
    P pa, pb;
    L() : a(0), b(0), c(0), o(0), pa(), pb() {}
    L(P pa, P pb) : a(pa.y - pb.y), b(pb.x - pa.x), c(pa ^ pb), o(atan2(-a, b)), pa(pa), pb(pb) {}
    P project(P p) { return pa + (pb - pa).unit() * ((pb - pa) * (p - pa) / (pb - pa).abs()); }
    P reflect(P p) { return p + (project(p) - p) * 2; }
    double get_ratio(P p) { return (p - pa) * (pb - pa) / ((pb - pa).abs() * (pb - pa).abs()); }
    bool inside(P p) {
        double z = get_ratio(p);
        return z >= 0 && z <= 1;
    }
};

bool parallel(L x, L y) { return same(x.a * y.b, x.b * y.a); }

P intersect(L x, L y) { return P(-x.b * y.c + x.c * y.b, x.a * y.c - x.c * y.a) / (-x.a * y.b + x.b * y.a); }

int main() {
    int q; cin >> q; while (q--) {
        P p[4]; 
        for (int i = 0; i < 4; ++i) cin >> p[i].x >> p[i].y;
        P z = intersect(L(p[0], p[1]), L(p[2], p[3]));
        cout << fixed << setprecision(12) << z.x << " " << z.y << endl;
    }
}



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

#define int long long int
#define mp make_pair
using namespace std;

int32_t main() {
    int n;
    scanf("%lld", &n);
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        scanf("%lld", &v[i]);
    }
    sort(v.begin(), v.end());
    int f = 0, b = n - 1;
    int x = 0;
    int index = (n + 1)/2;
    index--;
    vector<int> ans,ans1;
    ans.push_back(v[index]);
    ans1.push_back(v[index]);
    int n1 = n , n2 = n;
    n1--,n2--;
    while(n1){
        if(x%2 == 0) {
            ans.push_back(v[b]);
            b--;
        }
        else{
            ans.push_back(v[f]);
            f++;
        }
        x++;
        n1--;
    }
    x = 0;
    f = 0,b = n-1;
    while(n2){
        if(x%2 == 0) {
            ans1.push_back(v[f]);
            f++;
        }
        else{
            ans1.push_back(v[b]);
            b--;
        }
        x++;
        n2--;
    }
    int ans2 = 0;
    /*for (int i = 0; i < ans.size(); ++i) {
        cout << ans[i] << " ";
    }*/
    for (int i = 1; i < ans.size(); ++i) {
        ans2 += abs(ans[i] - ans[i-1]);
    }
    int ans3 = 0;
    for (int i = 1; i < ans1.size(); ++i) {
        ans3 += abs(ans1[i] - ans1[i-1]);
    }
    ans2 = max(ans2 , ans3);
    printf("%lld",ans2);
}

Measured memory_bytes: 3316
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> trp;
typedef vector<ll> vi;
typedef vector<pll> vp;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define pob         pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"YES"<<endl
#define prN         cout<<"NO"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define	mp3(a,b,c)  make_pair(a,make_pair(b,c))
#define se          second
#define fi          first 
#define sse         second.second
#define sfi         second.first
#define soA         sort(A+1,A+1+n)
#define so(A,n)     sort(A+1,A+1+n)
#define sov(v)      sort(all(v))
#define sovr(v)     sort(all(v),greater<ll>())
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5],X;
vp dske[MAXN+5];
void DFS(ll x,ll dad, ll cdad){
	ll c=0;
	fuv(i,dske[x]){
		ll y=dske[x][i].fi;
		if(y==dad)continue;
		c++;
		if(c==cdad)c++;
		A[dske[x][i].se]=c;
		DFS(y,x,c);
	}
}
ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	sc(n);
	f1(i,n-1){
		sc2(x,y);
		dske[x].pb(mp(y,i));
		dske[y].pb(mp(x,i));
	}	
	f1(i,n)mxz(X,sz(dske[i]));
	DFS(1,0,0);
	pr(X);
	f1(i,n-1)pr(A[i]);
	
	
	
	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	if(fopen("locin.txt", "r"))INPUT;
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	} 		
}

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

template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

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

    int n; cin >>n;
    vector<int> a(n); cin >> a;

    for (int i=n-1; i >= 0; i-=2) {
        // cout << a[i] << " ";
        printf("%d ", a[i]);
    }
    for (int i = n%2; i < n; i+=2) {
        // cout << a[i] << " ";
        printf("%d ", a[i]);
    }
    printf("\n");
    // cout << endl;
}


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

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

  vector<string> vec { istream_iterator<string>(cin), istream_iterator<string>() };
  sort(vec.begin(), vec.end());
  
  for(auto item: vec)
  {
    cout << item;
  }
}


Measured memory_bytes: 256
N = int(input())
SP = [list(input().split()) for i in range(N)]

for i in range(N):
  SP[i][1] = int(SP[i][1])
  SP[i].append(i+1)
  
SP.sort(key=lambda x:(x[0],-x[1]))

for i in range(N):
  print(SP[i][2])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll N;
ll A[52];
int main()
{
	scanf("%lld",&N);
	for(ll i=0;i<N;i++){
		scanf("%lld",&A[(int)i]);
	}
	ll l=-1,r=(ll)(1000000000000000000);
//	printf("%lld\n",r-l);
	while(r-l>1){
		ll c=(l+r)/2LL;
		ll cou=0LL;
		for(ll i=0LL;i<N;i++){
			cou+=max(0LL,(A[(int)i]+c+1)/(N+1LL));
		}
		//printf("c=%lld:cou=%lld\n",c,cou);
		if(cou<=c){
			r=c;
		}
		else{
			l=c;
		}
	}
	//printf("%lld\n",r);
	ll ans=max(0LL,r-N*N);
	while(true){
		ll c=ans;
		ll cou=0LL;
		for(ll i=0LL;i<N;i++){
			cou+=max(0LL,(A[(int)i]+c+1)/(N+1LL));
		}
		if(cou<=c){
			break;
		}
		else{
			ans++;
		}
		
	}
	printf("%lld\n",ans);
	return 0;
}


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;


int main() {
  string s;
  cin >> s;
  bool ans = false;
  if(s[0] == s[1] && s[1] == s[2]) ans = true;
  if(s[1] == s[2] && s[2] == s[3]) ans = true;
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A, B = map(int, input().split())
P = list(map(int, input().split()))

l = ["x" if i <= A else "y" if A < i <= B else "z" for i in P]
c = [l.count("x"), l.count("y"), l.count("z")]
c.sort()

print(c[0])

Measured memory_bytes: 3064
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split(/[ |\n]/).map(Number);
  const n = lines.shift();
  const arr = lines;
  buildMaxHeap(arr, n);
  console.log(arr.reduce((s, e) => s += ` ${e}`, ''));
})();

function buildMaxHeap(arr, n) {
  const maxHeapify = (i) => {
    let left, right, largest;
    left = 2 * i + 1;
    right = 2 * i + 2;
    largest = left < n && arr[left] > arr[i] ? left : i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(n / 2); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 147560
import java.util.Scanner;
class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    n %= 500;
    if(a>=n){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21972
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var R = ReadInt();
            var G = ReadInt();
            Println(2 * G - R);
        }


        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


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

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Point = Tuple!(double, "x", double, "y");

enum eps = 1e-11;

void main() {
    int N;
    scan(N);
    auto ps = new Point[](N);

    foreach (i ; 0 .. N) {
        double xi, yi;
        scan(xi, yi);
        ps[i] = Point(xi, yi);
    }

    double ng = 0, ok = 1000000;

    foreach (t ; 0 .. 100) {
        double mid = (ng + ok) / 2;
        Point[] cs;

        foreach (i ; 0 .. N) {
            foreach (j ; i + 1 .. N) {
                if (dist(ps[i], ps[j]) > 2*mid + eps) {
                    ng = mid;
                    continue;
                }
                cs ~= f(ps[i], ps[j], mid);
            }
        }

        debug {
            writeln(cs);
        }

        bool check;

        foreach (ci ; cs) {
            bool b = true;
            foreach (i ; 0 .. N) {
                if (dist(ci, ps[i]) > mid + eps) b = false;
            }
            if (b) check = true;
        }

        (check ? ok : ng) = mid;
    }

    writefln("%.12f", ok);
}


double dist(Point p, Point q) {
    return sqrt((p.x - q.x)^^2 + (p.y - q.y)^^2);
}

Point[] f(Point p, Point q, double R) {
    auto xm = (p.x + q.x) / 2;
    auto ym = (p.y + q.y) / 2;
    auto h = sqrt(R^^2 - (p.x - xm)^^2 - (p.y - ym)^^2);
    auto v = [q.x - p.x, q.y - p.y];
    auto vl = sqrt(v[0]^^2 + v[1]^^2);
    auto vn = [v[0] / vl, v[1] / vl];
    auto vu = [-vn[1], vn[0]];
    auto vd = [vn[1], -vn[0]];
    auto p1 = Point(xm + vu[0] * h, ym + vu[1] * h);
    auto p2 = Point(xm + vd[0] * h, ym + vd[1] * h);
    return [p1, p2];
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

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

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

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

int main(void) {
    int a;
    string s;

    cin>>a>>s;

    if(a>=3200){
        cout<<s<<endl;
    }else{
        cout<<"red"<<endl;
    }
}


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

using namespace std;

int main(){

    int N, M;
    cin >> N >> M;

    vector <bool> a(N + 1);

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

    for (int i = 0; i < M; i++){
        int A;
        cin >> A;
        a[A] = true;
    }

    vector <long long> ans(N + 1);

    ans[0] = 1;
    if (a[1] == false){
        ans[1] = 1;
    }else{
        ans[1] = 0;
    }
    
    for (int i = 2; i < N + 1; i++){
        if (a[i] == true){
            ans[i] = 0;
        }else{
            ans[i] = ans[i - 2] + ans[i - 1];
            ans[i] = ans[i] % 1000000007;
        }
    }
    
    cout << ans[N] << endl;
    
    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <map>
#include <set>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 100000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n, m, k, i, j;
    cin >> n;
    vector<int> a1(n), a2(n), ans(n);
    rep(i,n) cin >> a1[i];
    rep(i,n) cin >> a2[i];

    rep(i,n) {
        for (int j = 0; j <= i; j++) {
            ans[i] += a1[j];
        }
        for (int ii = i; ii < n; ii++) {
            ans[i] += a2[ii];
        }
    }

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

    cout << ans[n-1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main() {    
    string line;
     
    while (getline(cin,line)) {
        for (int i = 0; i != 26; i++) {
            for (int j = 0; j != line.size(); j++) {
                if (isalpha(line[j])) {
                    line[j] = (line[j] - 'a' + 1) % 26 + 'a';
                }            
            }
            if (line.find("the") != string::npos || line.find("this") != string::npos || line.find("that") != string::npos) {break;}                    
        }
        cout << line << endl;
    }    
    return 0;
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
using namespace std;
int main()
{int k,s,t=0;
 cin>>k>>s;
 for(int i=0;i<=k;i++)
   for(int j=0;j<=k&&i+j<=s;j++)
     if (s-i-j<=k)t++;
 cout<<t;
}

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;
const int mxn=1e5+5;
int h[mxn];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n,k;
	cin >> n >> k;
	int ans = 0;
	for(int i=0; i<n; i++){
		cin >> h[i];
		if(h[i]>=k)ans++;
	}
	cout << ans << '\n';
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 3972