akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define INF 10000000001
#define DIM 200001
#define mod 1000000007
#define PI 3.1415926535897932384626433
#define se second
#define fi first
#define pb push_back
#define T true
#define F false
#define endl "\n"
typedef char ch;
typedef bool boll;
typedef string st;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef set < string > sst;
typedef set < long long > sl;
typedef queue < long long > que;
typedef vector < long long > vec;
typedef map < long long, long long > mll;
typedef pair < long long, long long > pll;
typedef vector < pair < long long, long long > > vpl;
typedef pair < long long, unsigned long long > pul;


int main(){
    long long n,m,sum=0;
    cin >> n >> m;
    long long arr[m];
    for (int i=0;i<m;i++){
        cin >> arr[i];
        sum += arr[i];
    }
    if(sum>n) cout << "-1";
    else cout << n-sum;
}



Measured memory_bytes: 3620
#１　最終的にはRLとなっているところに集まる
#2  RRRRRRLLLLLLRRRRLLLRRLLLLLみたいになっている時RRRRRLLLLLで
#   ひとまとまりとして考えられる
#   つまり互いに干渉しあわないことがわかる
#3  実験により隣あう場所にいる人たちは必ず交わることのない
#4  最終的にRRLLのRにいるのはRと二つ飛ばしで同じになる人たちである
#5  10^100回も繰り返せば最終的な状態に必ず落ち着く
#6  まとめ＝RRRRLLLLの組みを見つけ単独で考えRLと偶奇が同じものの個数を考えればいい

#入力
s=list(input())+["R"]
n=len(s)

#連結成分を調べる
i=1
r_start=0
l_start=0
l_last=0
while i<n:
  if s[i-1]=="R" and s[i]=="L":
    l_start=i
    i=i+1
  elif s[i-1]=="L" and s[i]=="R":
    l_last=i-1
    for j in range(r_start,l_last+1):
      if j==l_start-1:
        if (l_last-r_start)%2==1:
          print((l_last-r_start)//2+1,end=" ")
        else:
          if (l_start-r_start)%2==0:
            print((l_last-r_start)//2,end=" ")
          else:
            print((l_last-r_start)//2+1,end=" ")
      elif j==l_start:
        if (l_last-r_start)%2==1:
          print((l_last-r_start)//2+1,end=" ")
        else:
          if (l_start-r_start)%2==0:
            print((l_last-r_start)//2+1,end=" ")
          else:
            print((l_last-r_start)//2,end=" ")          
      else:
        print(0,end=" ")
    r_start=i
    i=i+1
  else:
    i=i+1
    
    
    
    
    
    
    
    
    
    

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

using namespace std;

int main(){
    int n, q; cin >> n >> q;
    string s; cin >> s;
    vector<int> nums(n);
    nums[0]=0;
    for(int i=1; i<n; ++i){
        nums[i]=nums[i-1]+(s[i]=='C' && s[i-1]=='A' ? 1 : 0);
    }
    for(int i=0; i<q; ++i){
        int l, r; cin >> l >> r;
        --l; --r;
        cout << nums[r]-nums[l] << endl;
    }
    return 0;
}


Measured memory_bytes: 1408
n, y = map(int, input().split())

for i in range(n+1):
  for j in range(n-i+1):
    	if 10000*i+5000*j+1000*(n-i-j) == y:
          print("{} {} {}".format(i,j,n-i-j))
          exit()
print("-1 -1 -1")

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

int main() {
  int n, l, r;
  int sum = 0;
  
  cin >> n;
  rep(i, n) {
    cin >> l >> r;
    sum += r - l + 1;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
s=input()
t=input()
ans=0
for i in range(len(s)):
    if s[i]!=t[i]:
        ans+=1
print(ans)

Measured memory_bytes: 73656
while (True):
  r_count = 0
  r0, w0, c, r = map(int, input().split())
  if not(r0 and w0 and c and r):
    break
  
  while ((r0 + r * r_count) / w0 < c):
    r_count += 1

  print(r_count)
  

  
  


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n, u, v;
  cin >> n >> u >> v;
  vector<vector<int>> g(n+1);
  rep(i, n-1) {
    int a, b; cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<int> taka(n+1, INF), aoki(n+1, INF);

  queue<int> q;
  auto update = [&](int now, vector<int> &dist) {
    for(auto next : g[now]) {
      if(chmin(dist[next], dist[now]+1)) q.push(next);
    }
  };

  taka[u] = 0;
  q.push(u);
  while(!q.empty()) {
    int now = q.front(); q.pop();
    update(now, taka);
  }

  aoki[v] = 0;
  q.push(v);
  while(!q.empty()) {
    int now = q.front(); q.pop();
    update(now, aoki);
  }

  int ans = 0;
  for(int i = 1; i <= n; ++i) {
    if(g[i].size() != 1 || taka[i] >= aoki[i]) continue;

    int tmp = taka[i] + (aoki[i]-taka[i])-1;
    chmax(ans, tmp);
  }

  cout << ans << endl;
}

Measured memory_bytes: 9548
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007

using namespace std;
using ll = long long;
using ldb = long double;

typedef struct {
	int par = 0, hei = 1;
}node_t;
vector<node_t> node;

int root(int a) {
	if (node[a].par == 0) return a;
	node[a].par = root(node[a].par);
	return node[a].par;
}

void unite(int a, int b) {
	int art = root(a), brt = root(b);
	if (art == brt) return;
	int up, lo;
	if (node[art].hei >= node[brt].hei) up = art, lo = brt;
	else up = brt, lo = art;

	node[lo].par = up;
	node[up].hei = max(node[up].hei, node[lo].hei + 1);
}

int main() {
	int N, M; cin >> N >> M;
	vector<int> p(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> p[i];
	}
	node = vector<node_t>(N + 1);
	for (int i = 0; i < M; i++) {
		int x, y; cin >> x >> y;
		unite(x, y);
	}

	int ans = 0;
	for (int i = 1; i <= N; i++) {
		if (root(i) == root(p[i]))ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll N; cin >> N;
    vector<ll> A, B;
    rep(i,N) {
        int a, b; cin >> a >> b;
        if (b == 1) continue;
        A.push_back(a);
        B.push_back(b);
    }
    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());
    assert(A.size() == B.size());

    ll cnt = 0;
    N = A.size();
    rep(i,N) {
        ll a = A[i], b = B[i];
        a += cnt;
        if (a % b != 0) {
            cnt += b - (a % b);
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 5096
N=int(input())
A=[int(input()) for _ in range(N)]
AS=sorted(A)
# for i in range(N):
#     if AS[-1]==A[i]:
#         print(AS[-2])
#     else:
#         print(AS[-1])
for i in range(N):
    print(AS[-2] if AS[-1]==A[i] else AS[-1])

Measured memory_bytes: 70360
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		ABC057AASolve solve = new ABC057AASolve();
		solve.main();
	}
}

class ABC057AASolve {
	
	int A;
	int B;
	
	ABC057AASolve() {
		Scanner cin = new Scanner(System.in);
		this.A = cin.nextInt();
		this.B = cin.nextInt();
	}
	
	void main() {
		int time = A + B;
		System.out.println(time % 24);
	}
}

Measured memory_bytes: 22868
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int h, w; cin >> h >> w;
    vector<vector<bool>> field(h+2, vector<bool>(w+2));
    queue<pair<int, pair<int, int>>> que;
    for(int hi=1; hi<=h; ++hi){
        for(int wi=1; wi<=w; ++wi){
            char c; cin >> c;
            field[hi][wi]=c=='.';
            if(!field[hi][wi]) que.push(make_pair(0, make_pair(hi, wi)));
        }
    }
    int ans=0;
    int dw[]={1, 0, -1, 0 };
    int dh[]={0, 1, 0, -1 };
    while(!que.empty()){
        auto e=que.front();
        ans=max(ans, e.first);
        for(int i=0; i<4; ++i){
            int new_hi=e.second.first+dh[i];
            int new_wi=e.second.second+dw[i];
            if(field[new_hi][new_wi]){
                que.push(make_pair(e.first+1, make_pair(new_hi, new_wi)));
                field[new_hi][new_wi]=false;
            }
        }
        que.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12560
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
    return (a.second<b.second);
}
int main()
{
    ios;
    double a,b;
    cin>>a>>b;
    int ans=0,k=1;
    while(k<b)
    {
        --k;
        k+=a;
        ans++;
    }
    cout<<ans<<endl;



}
//Alhamdulillah











Measured memory_bytes: 3764
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    int A = scanner.nextInt();
		    int B = scanner.nextInt();
		    int C = scanner.nextInt();
		    int X = scanner.nextInt();
		    int counter = 0;
		    
		    for( int i = 0; i <= A; i++ ) 
		    {
		    	for( int j = 0; j <= B; j++ ) 
			    {
		    		for( int k = 0; k <= C; k++ ) 
				    {
				    	if( 500 * i + 100 * j + 50 * k == X ) 
				    	{
				    		counter++;
				    	}
				    }
			    }
		    }
		    System.out.println(counter);
		    
		    scanner.close(); }
		  }

Measured memory_bytes: 21716
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func Reverse(buf []byte) {
	i := 0
	j := len(buf) - 1
	for i < j {
		buf[i], buf[j] = buf[j], buf[i]
		i++
		j--
	}
}

func main() {
	var s string
	var n int
	fmt.Scan(&s, &n)

	var reverse bool
	head := []byte{}
	tail := []byte{}
	body := []byte(s)
	for i := 0; i < n; i++ {
		t := scanInt()
		if t == 1 {
			head, tail = tail, head
			reverse = !reverse
		} else {
			f, c := scanInt(), scanString()

			if f == 1 {
				head = append(head, c[0])
			} else {
				tail = append(tail, c[0])
			}
		}
	}

	Reverse(head)
	if reverse {
		Reverse(body)
	}

	ans := []byte{}
	ans = append(ans, head...)
	ans = append(ans, body...)
	ans = append(ans, tail...)
	fmt.Println(string(ans))
}


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

using namespace std;

int main() {
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;

  int total = a1 + a2 + a3;

  if (total >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <utility>
#include <algorithm>
#include <set>
#include <queue>
#include <climits>
#include <limits>
#include <map>

#define ll long long
#define max(A, B) ((A) > (B) ? (A) : (B))
#define min(A, B) ((A) < (B) ? (A) : (B))
#define mp(A, B) make_pair(A, B)
#define pb push_back
#define fu(A, B, C) for(ll (A) = (B); (A) < (C); (A)++)
#define fu0(A, B) fu((A), 0, (B))
#define fd(A, B, C) for(ll (A) = (B); (A) >= (C); (A)--)
#define mem(A, B) memset((A), (B), sizeof((A)))
#define v(A, B, C) vector<ll> (A)((B), (C));
#define v0(A, B) v((A), (B), 0);


using namespace std;

typedef pair<int, int> pi;

void perform() {
  int n; cin >> n;
  cout << (2 * M_PI * n) << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1; //cin >> t;
  fu0(i, t) {perform();}
}


Measured memory_bytes: 3284
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization ("Ofast")
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define siz(s) (int)s.size()

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;
}
template<class T> inline int getidx(vector<T> &v, T a) {
	return lower_bound(all(v), a) - v.begin();
}

constexpr int mod=1e9+7;
constexpr int inf=3e18;


int mod_pow(int x,int y){
	int res=1;
	while(y>0){
		if(y&1)(res*=x)%=mod;
		(x*=x)%=mod;y>>=1;
	}
	return res;
}
int N,dp[5005][5005];
string s;
signed main(){
	cin>>N>>s;
	dp[0][0]=1;
	rep(i,N){
		rep(j,i+1){
			dp[i][j]%=mod;
			dp[i+1][max(0ll,j-1)]+=dp[i][j];
			dp[i+1][j+1]+=dp[i][j]*2;
		}
	}
	cout<<dp[N][siz(s)]*mod_pow(mod_pow(2,siz(s)),mod-2)%mod<<endl;
}


Measured memory_bytes: 194048
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = pow(10, 9) + 7;

int main() {
    // source
    string s[8] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
    string temp;
    cin >> temp;

    rep(i, 7) {
        if (s[i] == temp) {
            cout << 7 - i << endl;
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 256
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::VecDeque;

fn main() {
    input!(n: usize, m: usize, s: chars, ab: [(usize1, usize1); m]);

    let mut graph = vec![vec![]; n];
    let mut a = vec![0; n];
    let mut b = vec![0; n];
    for &(a, b) in ab.iter() {
        graph[a].push(b);
        graph[b].push(a);
    }

    for i in 0..n {
        for &next in graph[i].iter() {
            if s[next] == 'A' {
                a[i] += 1;
            } else {
                b[i] += 1;
            }
        }
    }

    let mut visit = vec![false; n];
    let mut queue = VecDeque::new();
    for i in 0..n {
        if a[i] == 0 || b[i] == 0 {
            queue.push_back(i);
            visit[i] = true;
        }
    }

    while let Some(i) = queue.pop_front() {
        for &next in graph[i].iter() {
            if s[i] == 'A' {
                a[next] -= 1;
            } else {
                b[next] -= 1;
            }
            if (a[next] == 0 || b[next] == 0) && !visit[next] {
                queue.push_back(next);
                visit[next] = true;
            }
        }
    }

    for i in 0..n {
        if !visit[i] {
            println!("Yes");
            return;
        }
    }
    println!("No");
}


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

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

typedef long long ll;

int seg_n, n;
vector<ll> seg;

void init(int n) {
    seg_n = 1;
    while(seg_n < n) seg_n *= 2;
    seg.resize(seg_n * 2 - 1);
}

void update(int k, ll a) {
    k += seg_n - 1;
    seg[k] = a;
    while(k > 0) {
        k = (k - 1) / 2;
        seg[k] = max(seg[k*2+1], seg[k*2+2]);
    }
}

ll query(int a, int b, int k, int l, int r) {
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return seg[k];
    ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return max(vl, vr);
}

ll query(int x) { return query(0, x, 0, 0, seg_n); }

int main() {
    cin >> n;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    init(n + 1);
    rep(i, n) update(x[i], query(x[i]) + x[i]);
    cout << (ll)n * (n + 1) / 2 - query(n + 1) << endl;
}

Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

queue<pair<string,int> > Q;
int n;
int quantum;
int main(){
	int n;
	cin >> n >> quantum;
	REP(i,n){
		string tmpstr;
		int tmptime;
		cin >> tmpstr >> tmptime;
		Q.push(make_pair(tmpstr,tmptime));
	}
	ll int nowtime = 0;
	while(!Q.empty()){
		int tmp = Q.front().second;
		if(tmp<=quantum){
			nowtime+=tmp;
			cout << Q.front().first << " " << nowtime << endl;
			Q.pop();
		}else{
			nowtime+=quantum;
			Q.push(make_pair(Q.front().first,tmp-quantum));
			Q.pop();
		}
	}

}

Measured memory_bytes: 4400
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
ll n,a,b,c,ans=1e9,l[10];
void dfs(ll now,ll na,ll nb,ll nc,ll cn){
    if(now==n+1)return;
    if(na&&nb&&nc)ans=min(ans,abs(a-na)+abs(b-nb)+abs(c-nc)+10ll*(max(0ll,cn-3ll)));
    dfs(now+1,na+l[now],nb,nc,cn+1);
    dfs(now+1,na,nb+l[now],nc,cn+1);
    dfs(now+1,na,nb,nc+l[now],cn+1);
    dfs(now+1,na,nb,nc,cn);
}
int main(){
  cin>>n>>a>>b>>c;
  for(int i=0;i<n;i++)cin>>l[i];
  dfs(0,0,0,0,0);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

ll h, w, res;
vvll a(666, vll(666)), hs(666, vll(666)), vs(666, vll(666));
V<string> s(333);

int main() {
  cin >> h >> w;
  REP(i, h) {
    cin >> s.at(i);
    REP(j, w) if (s.at(i).at(j)=='#') a.at(i+j+1).at(i-j+300) = 1;
  }
  rep(i,1,600) rep(j,1,600) {
    hs.at(i).at(j) += a.at(i).at(j) + hs.at(i).at(j-1);
    vs.at(i).at(j) += a.at(i).at(j) + vs.at(i-1).at(j);
  }
  rep(i,1,600) rep(j,1,600) rep(k,j+1,600) {
    int d = k-j;
    if (a.at(i).at(j) && a.at(i).at(k)) {
      if (i-d>=0) {
        res += hs.at(i-d).at(k) - hs.at(i-d).at(j-1);
        res -= a.at(i-d).at(j) + a.at(i-d).at(k);
      }
      if (i+d<=600) {
        res += hs.at(i+d).at(k) - hs.at(i+d).at(j-1);
        res -= a.at(i+d).at(j) + a.at(i+d).at(k);
      }
    }
    if (a.at(j).at(i) && a.at(k).at(i)) {
      if (i-d>=0) res += vs.at(k).at(i-d) - vs.at(j-1).at(i-d);
      if (i+d<=600) res += vs.at(k).at(i+d) - vs.at(j-1).at(i+d);
    }
  }
	cout << res << endl;
}


Measured memory_bytes: 12928
N = input()
DP = [0,0]
kuriagari = 0
kuriagarazu = 0
for n in N:
    n = int(n)
    kuriagaru = 11 - n + kuriagari
    kuriagaranai = n + kuriagarazu
    DP.append([kuriagaru, kuriagaranai])
    kuriagari = DP[-1][0] - 2 if DP[-1][0] - 2 < DP[-1][1] else DP[-1][1]
    kuriagarazu = DP[-1][0] if DP[-1][0] < DP[-1][1] else DP[-1][1]

answer = min(DP[-1])
print(answer)

Measured memory_bytes: 138128
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

a,b=MI()
if a>=13:
    price=b
elif 6<=a<=12:
    price=int(b/2)
else:
    price=0
print(price)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    ll N; cin >> N;
    string ans = "";
    while (N) {
        N--;
        ans += (char)('a' + N % 26);
        N /= 26;
    }
    reverse(ALL(ans));
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
const ll mod=1000000009;
const ll INF=(ll)1000000007*1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long double ld;
int main(){
  int N; cin >> N; 
  ld T,A; cin >> T >> A;
  ld mi=1000000; int ans=0;
  rep(i,N){
    ld h; cin >> h;
    ld dif; dif=abs(A-(T-0.006*h));
    if(dif<mi){
      mi=dif;
      ans=i+1;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <queue>
#include <limits>

using namespace std;

static const int MAX=10000;
static const int INF=numeric_limits<int>::max();

int n,d[MAX];
vector<pair<int,int> > list[MAX];

void dijkstra(){
  //initialize as min-Heap
  priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > PQ;
  bool visited[n];
  for(int i=0;i<n;i++){
    visited[i]=false;
    d[i]=INF;
  }
  d[0]=0;
  PQ.push(make_pair(0,0));
  while(!PQ.empty()){
    pair<int,int> f=PQ.top(); PQ.pop();
    int u=f.second;
    visited[u]=true;

    //if(d[u]>f.first) continue;

    for(int i=0;i<list[u].size();i++){
      int v=list[u][i].first;
      if(visited[v]==false && d[v]>d[u]+list[u][i].second){
        d[v]=d[u]+list[u][i].second;
        PQ.push(make_pair(d[v],v));
      }
    }
  }
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    int u,k; cin >> u >> k;
    for(int j=0;j<k;j++){
      int v,c; cin >> v >> c;
      list[u].push_back(make_pair(v,c));
    }
  }
  dijkstra();
  for(int i=0;i<n;i++)
    cout << i << " " << d[i] << endl;
}

Measured memory_bytes: 7972
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);
	int n,m,x;
	cin >> n >> m >> x;
	vi c(n);
	vector<vector<int>> a(n, vi(m));
	REP(i, n) {
		cin >> c[i];
		REP(j, m) {
			cin >> a[i][j];
		}
	}
	int best = -1;
	REP(i, (1 << n)) {
		vi lvls(m);
		int cost = 0;
		REP(j, n) {
			if (i & (1 << j)) {
				cost += c[j];
				REP(k, m) {
					lvls[k] += a[j][k];
				}
			}
		}
		bool isOk = true;
		REP(k, m) if (lvls[k] < x) {
			isOk = false;
		}
		if (isOk) {
			if (best == -1 || cost < best) {
				best = cost;
			}
		}
	}
	cout << best << endl;
}

Measured memory_bytes: 3656
#include<iostream>
using namespace std;
int main(){
  int n, d, x,total=0;
  cin >> n;
  cin >> d;
  cin >> x;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    int j=0;
    int day = a[i]*j + 1;
    while(day<=d){
      total += 1;
      j++;
      day = a[i]*j + 1;
    }
  }
  cout << total+x << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int a,b,n,sum,i;
    while (scanf("%d %d %d\n",&a,&b,&n)!=EOF) {
        sum=0;
        a=(a%b)*10;
        for (i=0; i<n; i++) {
            sum+=a/b;
            a=(a%b)*10;
        }
        printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 600
import math
pi=math.pi
a,b,si=map(float,input().split())
S=(1/2)*a*b*math.sin(math.radians(si))
c2=a*a+b*b-2*a*b*math.cos(math.radians(si))
L=a+b+math.sqrt(c2)
h=(2*S)/a
print(S)
print(L)
print(h)


Measured memory_bytes: 5692
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//------------------------]---------------------------
signed main() {
	int a, b, p, q, r;
	cin >> a >> b >> p >> q >> r;
	ld t = q * (b - a);
	ld k = p * b;
	printf("%.20LF\n", (ld)b + (ld)(k - t) / (ld)(q + r));
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const ll INF = 2000000000;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int S = (1 << n);
  ll dp[S][m + 1] = {};
  REP(i, S) {
    REP(j, m + 1) { dp[i][j] = INF; }
  }

  vector<ll> a(m + 1);
  vector<int> mask(m + 1);
  FOR(i, 1, m + 1) {
    int b;
    cin >> a[i] >> b;
    REP(j, b) {
      int c;
      cin >> c;
      c--;
      mask[i] = (mask[i] | (1 << c));
    }
  }

  REP(i, m) { dp[0][i] = 0; }

  FOR(i, 1, m + 1) {
    REP(s, S) {
      dp[s][i] = min(dp[s][i - 1], dp[(s & (~mask[i]))][i - 1] + a[i]);
    }
  }

  ll ans = INF;
  REP(i, m + 1) { ans = min(ans, dp[S - 1][i]); }
  if (ans == INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 32256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    int N;
    cin >> N;
    map<int, int> mp;
    for (int i = 0; i < N; ++i) {
        int D;
        cin >> D;
        mp[D]++;
    }
    int M;
    cin >> M;
    for (int i = 0; i < M; ++i) {
        int T;
        cin >> T;
        if (!mp[T]) {
            cout << "NO" << endl;
            exit(0);
        }
        mp[T]--;
    }

    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 9600
import Foundation
func toTuple<T>(_ args: [T]) -> (T, T) { (args[0], args[1]) }
func toTuple<T>(_ args: [T]) -> (T, T, T) { (args[0], args[1], args[2]) }
func toTuple<T>(_ args: [T]) -> (T, T, T, T) { (args[0], args[1], args[2], args[3]) }
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }
func readDoubles() -> [Double] { readLine()!.split(separator: " ").map { Double($0)! } }
func readStrings() -> [String] { readLine()!.split(separator: " ").map { String($0) } }

let (x, n) = toTuple(readInts())
guard n != 0 else { print(x); exit(0)}
let pi = readInts()

var dec = x, inc = x
if !pi.contains(x) { print(x); exit(0) }
while true {
  inc += 1
  dec -= 1
  if (!pi.contains(inc) && !pi.contains(dec)) {
    print(dec)
    break
  } else if (!pi.contains(inc) && pi.contains(dec)) {
    print(inc)
    break
  } else if (pi.contains(inc) && !pi.contains(dec)) {
    print(dec)
    break
  }
}

Measured memory_bytes: 13656
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <time.h>
using namespace std;

int main() {
    int N,K;

    cin >> N>>K;
    if (!(1<=N&&N<=10^5)){
      //cout <<"dame";
      //return 1;
      return 1;
    }

    int h[N]={0};
    int i=0;
    int cnt=0;
    for(i;i<N;i++){
      cin >> h[i];
      if(K<=h[i]){
        cnt+=1;
      }
    }

    cout << cnt;






    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>
#define last last2

using namespace std;

struct Edge {
  int t,next;
  Edge() {}
  Edge(int a,int b):t(a),next(b) {}
};

Edge e[200005];
int head[200005];

int now[200005];
bool cir[200005],vis[200005];

int f[200005],id[200005];

void dfs(int x,int fa) {
  for(int i=head[x];i;i=e[i].next)
    if (e[i].t!=fa) dfs(e[i].t,x);
  for(int i=head[x];i;i=e[i].next) id[f[e[i].t]]=x;
  while (id[f[x]]==x) f[x]++;
}

int a[200005],b[200005];

bool calc(int rt,int x) {
  int last=x,t=rt;
  do {
  	t=now[t];
    last=(a[t]==last)?b[t]:a[t];
  } while (t!=rt);
  return last==x;
}

int main() {
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++) {
  	int x;
  	scanf("%d",&x);
  	now[i]=x;
  	e[i]=Edge(i,head[x]);
  	head[x]=i;
  }
  int rt=1;
  do {
  	vis[rt]=1;
  	rt=now[rt];
  } while (!vis[rt]);
  cir[rt]=1;
  for(int i=now[rt];i!=rt;i=now[i]) cir[i]=1;
  for(int i=1;i<=n;i++)
    if (cir[i]) {
    	for(int j=head[i];j;j=e[j].next)
    	  if (!cir[e[j].t]) dfs(e[j].t,i);
		for(int j=head[i];j;j=e[j].next)
		  if (!cir[e[j].t]) id[f[e[j].t]]=i;
		while (id[a[i]]==i) a[i]++;
		b[i]=a[i]+1;
		while (id[b[i]]==i) b[i]++;
	}
  puts((calc(rt,a[rt])|calc(rt,b[rt]))?"POSSIBLE":"IMPOSSIBLE");
  return 0;
}

Measured memory_bytes: 6272
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc066_a.cpp
 * time   : Tue Apr 28 22:57:18 2020
 * quest  : A - ringring
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(a + b, min(b + c, a + c)) << "\n";
  return 0;
}


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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{   
    gearup;
    int n,m; cin >> n >> m;
    vl a(n),b(n+1);
    rep(i,n)cin>>a[i];
    rep(i,n)b[i+1] = (b[i] + a[i]) % m;
    map<ll,ll> mp;
    rep(i,n+1)mp[b[i]]++;
    ll res = 0;
    for(auto m:mp){
        res += m.second * (m.second -1 ) / 2;
    }
    out(res);
}

Measured memory_bytes: 8572
#include<iostream>
using namespace std;
typedef long long ll;
int main() {
    int n,m;
    cin >> n >> m;
    int a;
    for (int i = 0; i < m; i++) {
        cin >> a;
        n -=a;
    }
    if (n < 0) cout << -1;
    else cout << n;
    return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define WRAP(y,x,h,w) (0<=y && y<h && 0<=x && x<w)

typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int n;
	cin >> n;
	vi num(n);
	int sum = 0;
	REP(i, n) {
		cin >> num[i];
		sum += num[i];
	}
	if (sum % 10 != 0) {
		cout << sum << endl;
	}
	else {
		bool b = true;
		SORT(num);
		REP(i, n) {
			if (num[i] % 10 != 0) {
				sum -= num[i];
				b = false;
				break;
			}
		}
		if (b)
			cout << 0 << endl;
		else
		cout << sum<< endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
    int N, i, cache1 = 0, cache2 = 100000, input, count = 0; 

    cin >> N;

    for(i = 0; i < N; i++) {
        cin >> input; 
        if(cache1 == cache2) cache2 = 100000; 
        else if(input == cache1) {
            count++;
            cache2 = cache1;
        }
        cache1 = input;
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;

vector<ll> a;

const ll INF = (ll)(1e18) + 1;
// const ll INF = 100;

int cnt_bs(int idx, ll x){
  int kl=idx-1, kr=a.size();
  while(kr-kl > 1){
    int kn = (kr + kl) / 2;
    ll v = a[idx] * a[kn];
    if (v >= x) kr = kn;
    else kl = kn;
  }
  int cnt = max(kr - idx - 1, 0);
  // printf("cnt: %d, idx: %d, kl: %d, kr: %d\n", cnt, idx, kl, kr);
  return cnt;
}

int cnt_bs_reverse(int idx, ll x){
  int kl=idx-1, kr=a.size();
  while(kr-kl > 1){
    int kn = (kr + kl) / 2;
    ll v = a[idx] * a[kn];
    if (v < x) kr = kn;
    else kl = kn;
  }
  int cnt = min((int) a.size() - kr, (int)a.size() - idx - 1);
  // printf("cnt r: %d, idx: %d, kl: %d, kr: %d\n", cnt, idx, kl, kr);
  return cnt;
}

int main() {
  ll n, k;
  cin >> n >> k;
  a.resize(n);
  rep(i, n) cin >> a[i];

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

  ll xr = INF, xl= -INF;
  while (xr-xl>1){
    ll x = (xr + xl) / 2;
    ll xk = 0;
    // printf("xl:%lld, xr:%lld, x: %lld\n", xl, xr, x);
    rep(i, n){
      int k_cnt = (a[i] >= 0) ? cnt_bs(i, x): cnt_bs_reverse(i, x);
      xk += k_cnt;
    }
    // printf("xl:%lld, xr:%lld, x: %lld, xk: %lld\n", xl, xr, x, xk);
    // cout << xk << endl << endl;
    if (xk >= k) xr = x;
    else xl = x;
  }

  cout << xl << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

const int INF = (1<<25);
const int MAX = (1<<16);
vector<int>T[16];
int dp[MAX],n;

void init(){
  fill(dp,dp+MAX,INF);
  for(int i = 0; i < 16; i++) T[i].clear();

}

int input(){
  cin >> n;

  for(int i = 0; i < n; i++)
    for(int j = 0; j < n+1; j++){
      int in;
      cin >> in;
      T[i].push_back(in);
    }
  return n;
}

int getTime(int now, int to){

  int t = T[to][0];

  for(int i = 1; i < T[to].size(); i++)
    if(now&(1<<(i-1))) t = min(t,T[to][i]);

  //cout << "to " << to << "t " << t << endl;
  return t;
}

void print(){
  for(int i = 0; i < (1<<n); i++)
    cout << dp[i] << endl;
  cout << endl;
}

void solve(){
  dp[0] = 0;

  for(int i = 0; i < (1<<n); i++)
    for(int j = 0; j < n; j++)
      if(!(i&(1<<j))) dp[i+(1<<j)]=min(dp[i+(1<<j)],dp[i]+getTime(i,j));

  cout << dp[(1<<n)-1] << endl;
}

int main(){
  while(1){
    init();
    if(!input()) break;;
    solve();
    // print();
  }
  return 0;
}

Measured memory_bytes: 1476
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int mem[1111][1<<13], a[1111], b[1111], c[1111][22], n, m;
int dp(int x, int rem){
    if(x==m){
        if(rem==((1<<n)-1))
            return 0;
        else
            return 1e9;
    }
    if(mem[x][rem]!=-1){
        return mem[x][rem];
    }
    ll res, tmp=rem;
    for(int i=0; i<b[x]; ++i){
        tmp|=(1<<c[x][i]);
    }
    res=min(dp(x+1, rem), a[x]+dp(x+1, tmp));
    mem[x][rem]=res;
    return res;
}

int main(){
    while(cin>>n>>m){
        ll ans=0;
        for(int i=0; i<m; ++i){
            scanf("%d%d",a+i, b+i);
            for(int j=0; j<b[i]; ++j){
                scanf("%d",&c[i][j]);
                --c[i][j];
            }
        }
        memset(mem, -1, sizeof mem);
        ans=dp(0, 0);
        if(ans>100000000){
            cout<<-1<<endl;
        }
        else{
            cout<<ans<<endl;
        }
    }
  return 0;
}




Measured memory_bytes: 35968
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <stack>
#include <set>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;

bool check(vector<int> v, double cur, int k) {
	int curk = 0;
	for (auto u : v) {
		curk += ceil(u / cur) - 1;
	}
	return k >= curk;
}

void solve() {
	int n, k; cin >> n >> k;
	vector<int> v(n);
	for (int i = 0; i < n; i++)cin >> v[i];
	int l = 0, r = 1e9 + 100;
	while (l < r - 1) {
		double mid = l + (r - l) / 2;
		if (!check(v, mid, k))l = mid;
		else r = mid ;
	}
	cout << r;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// int t; cin >> t;
	// while (t--)
	solve();

}

Measured memory_bytes: 4700
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n;
  vector<int> d(n);
  for(int i=0;i<n;i++){
    cin>>d[i];
  }
  cin>>m;
  vector<int> t(m);
  for(int i=0;i<m;i++){
    cin>>t[i];
  }
  if(n<m){
    cout<<"NO"<<endl;
    return 0;
  }
  sort(t.begin(),t.end());
  sort(d.begin(),d.end());
  int di=0;
  bool flag=true;
  for(int i=0;i<m;i++){
    while(1){
      if(d[di]==t[i]){
        di++;
        break;
      }
      di++;
      if(di>=n){
        flag=false;
        break;
      }
    }
    if(!flag){
      break;
    }
  }
  cout<<(flag?"YES":"NO")<<endl;
  return 0;
}

Measured memory_bytes: 4704
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int len(char w[1000]){
	int count=0;
	for(int i=0;i<1000;i++){
		if(((w[i]>=65) && (w[i]<=90)) || ((w[i]>=97) && (w[i]<=122))){
			count++;
		}else{
			break;
		}
	}
	return count;
}

int calc(char a,char b){
	if((a>=65) && (a<=90)){
		if(a==b){
			return 1;
		}else if(a==(b-32)){
			return 1;
		}else{
			return -1;
		}
	}else if((a>=97) && (a<=122)){
		if(a==b){
			return 1;
		}else if(a==(b+32)){
			return 1;
		}else{
			return -1;
		}
	}else{
		return -1;
	}
}

int main(void){
	char w[10],t[1000];
	int w_len;
	int flag=0,count=0;
	int w_count=0;

	scanf("%s",w);
	w_len = len(w);
	
	while(scanf("%s",t)!=EOF){
	//	printf("t:%s:::%d\n",t,len(t));
		if(w_len == len(t)){
			if(calc(w[0],t[0])==1){
				count=1;
				for(int i=1;i<w_len;i++){
					if(calc(w[i],t[i])==1){
						count++;
					}else{
						break;
					}
				}
				if(count==w_len){
					w_count++;
				//	printf("--------------------------------------%d\n",w_count);
				}
			}
		}
	}

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

}


Measured memory_bytes: 2052
#include <stdio.h>

int main()
{
    int a,b,c,n;
    
    scanf("%d%d%d",&a,&b,&c);
    
    if(b < a){
            n = a;
            a = b;
            b = n;
        }
    if(c < b){
            n = b;
            b = c;
            c = n;
            
        if(b < a){
            n = a;
            a = b;
            b = n;
        }
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}


Measured memory_bytes: 2056
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = []
b = []
for i in range(n):
    u, v = na()
    a.append(u)
    b.append(v)

if n % 2 == 1:
    a.sort()
    b.sort()
    print(b[n//2]-a[n//2]+1)
else:
    a.sort()
    b.sort()
    print((b[n//2]+b[n//2-1])-(a[n//2]+a[n//2-1])+1)


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

int main() {
	int h, w;

	while (1) {
		cin >> h >> w;
		if (h == 0 && w == 0) break;

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (i > 0 && i < h - 1 && j > 0 && j < w - 1) {
					cout << ".";
				}
				else {
					cout << "#";
				}
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3072
// Problem : A - ∴ (Therefore)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define ll long long
#define F first
#define S second
#define mod 1000000007
#define maxn 200005
#define INF 1000000000
#define ld long double
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;


int main() {
	FAST
	ll n;
	cin >> n;
	ll x = n%10;
	if(x == 2 || x == 4 || x == 5 || x == 7 || x == 9){
		cout << "hon" << endl;
	}
	else if(x == 3){
		cout << "bon" << endl;
	}
	else {
		cout << "pon" << endl;
	}
	return 0;
}

Measured memory_bytes: 3612
<?php
fscanf(STDIN, "%d %d", $n, $k);
$sunuke = [];

for ($i = 1; $i <= $k; $i++) {
    fscanf(STDIN, "%d", $d);
    $treat = explode(' ', trim(fgets(STDIN)));

    foreach ($treat as $s) {
        $sunuke[$s][] = $i;
    }
}

$count = 0;

for ($i = 1; $i <= $n; $i++) {
    if (!isset($sunuke[$i])) {
        $count++;
    }
}

echo "{$count}\n";


Measured memory_bytes: 17040
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
ll n,k;
ll arr[1001];
ll dp[1001][1001];
ll func(ll i,ll n,ll k)
{
	if(i==n+1)
	{
		if(k==0)
			return 0;
		else
			return INT_MAX;
	}
	if(k==0)
		return 0;
	else if(dp[i][k]!=-1)
		return dp[i][k];
	ll ans=0;
	ans=min(arr[i]+func(i+1,n,k-1),func(i+1,n,k));
	return dp[i][k]=ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
    	cin>>n>>k;
    	for(ll i=1;i<=n;i++)
    		cin>>arr[i];
    	memset(dp,-1,sizeof dp);
    	cout<<func(1,n,k);

    }
    return 0;
}

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

signed main() {
  int K,N;
  cin >> K >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++) cin >> A[i];
  int d = 0;
  for(int i=1; i<N; i++) {
    d = max(d, A[i] - A[i-1]);
  }
  d = max(d, K - A[N-1] + A[0]);
  cout << K-d<< endl;
}


Measured memory_bytes: 1792