akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let k: usize = sc.cin();
    let mut ans = 0;
    for _ in 0..n {
        let h: usize = sc.cin();
        if h>=k { ans += 1 }}
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


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

int main(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int n = max(x,y);
    unsigned int min = -1;
    for(int i = 0; i <= n; i++){
        int cost = i*2*c + max(0,x-i) * a + max(0,y-i) * b;
        if(min > cost)
            min = cost;
    }
    cout << min;
}

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

int main() {
  string s;
  int n = 0;
  cin >> s;
  for (int i = 0;4 > i;i++) {
    for (int j = i + 1;4 > j;j++) {
      if (s.at(i) == s.at(j))
        n++;
    }
  }
  
  if (n == 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

using namespace std;

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

    vector <int> p(a);
    vector <int> q(b);
    vector <int> r(c);
    vector <int> s(x + y);

    for(int i = 0; i < a; i++){
        cin >> p.at(i);    
    }
    for(int i = 0; i < b; i++){
        cin >> q.at(i);    
    }
    for(int i = 0; i < c; i++){
        cin >> r.at(i);    
    }
    // rを大きい順にソート
    sort(r.begin(), r.end());
    reverse(r.begin(), r.end());

    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());
    for(int i = 0; i < x; i++){
        s.at(i) = p.at(i);
    }
    
    sort(q.begin(), q.end());
    reverse(q.begin(), q.end());
    for(int i = x; i < y + x; i++){
        s.at(i) = q.at(i - x);
    }

    sort(s.begin(), s.end());
    long long Oishisa = 0;
    for (int i = 0; i < min(s.size(), r.size()); i++){
        if(s.at(i) < r.at(i)){
            s.at(i) = r.at(i);
        }
    }
    
    for(int i = 0; i < x + y; i++){
        Oishisa += s.at(i);
    }

    cout << Oishisa << endl;
    return 0;
}

Measured memory_bytes: 2176
var
  n,i,j,k,t,s:longint;
  a:array[0..55] of longint;
begin
  readln(n,k);
  for i:=1 to n do read(a[i]);
  for i:=1 to n-1 do
   for j:=i+1 to n do 
    if a[i]<a[j] then begin t:=a[i];a[i]:=a[j];a[j]:=t; end;
  for i:=1 to k do s:=s+a[i];
  writeln(s);
end.

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

typedef int i32;
typedef long long i64;
typedef unsigned int u32;
typedef unsigned long long u64;


template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};


#define debug(x)  cerr<<x<<"\n";
#define loop(i,n) for(i32 i = 0; i < n; ++i)
#define pi  pair<i32,i32>
#define ti  triple<i32,i32,i32>
#define mk  make_pair
#define vi  vector<i32>
#define vll vector<i64>
#define fastInOut ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pr(a) for(auto x:a) cout<<x<<" ";
#define prmap(m) for(auto x:m) cout<<x.first<<" "<<x.second<<"\n";
using namespace std;

bool isPrime(i64 x){
	
	for(i64 i=2;i*i<=x;i++)
		if(x%i==0)
			return false;
	return true;
}

vi V;
const i32 N=7e7+9;
bool prime[N]; 
void SieveOfEratosthenes(){ 
    for (int  p=2; p*p<=N; p++){ 
        if (prime[p] == false){ 
            for (int  i=p*p; i<=N; i += p) 
                prime[i] = true; 
        } 
    } 
    int u=0,mx=0;
    for (int p=2; p<=N; p++){ 
      if (!prime[p]) {
          V.push_back(p);
      }
    }
   
}

i64 n,d,c;
int main(){
    fastInOut
     cin>>n>>d;
      i64 sum=0;
     for(int i=0;i<d;i++) {
         cin>>c;
         sum+=c;}
     if(sum>=n)
         cout<<"Yes\n";
    else 
      cout<<"No\n";
    return 0;
}








Measured memory_bytes: 256
from time import perf_counter
t0 = perf_counter()


import sys
sys.setrecursionlimit(300000)
from collections import defaultdict
from random import randint

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


D = I()
C = LMI()
S = [LMI() for _ in range(D)]


# 貪欲解の生成
last = defaultdict(int)
ans0 = []
for d in range(D):
    m = -INF
    ans = -1
    for i in range(26):
        lans = S[d][i]
        for j in range(26):
            if i == j:
                lans -= C[j] * (d + 1 - d - 1)
            else:
                lans -= C[j] * (d + 1 - last[j])
        if lans > m:
            m = lans
            ans = i
    ans0.append(ans)



T = ans0
last = [[i + 1] * 26 for i in range(D)]
for d in range(D):
    i = T[d]
    j = 0
    for dd in range(d, D):
        last[dd][i] = j
        j += 1

def eval(d, q):
    i = T[d]
    val = S[d][q] - S[d][i]

    contrib = 0
    if d == 0:
        j = 1
    else:
        j = last[d - 1][i] + 1
    for dd in range(d, D):
        if dd > d and last[dd][i] == 0:
            break
        contrib += j - last[dd][i]
        # last[dd][i] = j
        j += 1
    val -= contrib * C[i]

    contrib = 0
    j = 0
    for dd in range(d, D):
        if last[dd][q] == 0:
            break
        contrib += last[dd][q] - j
        # last[dd][q] = j
        j += 1
    val += contrib * C[q]

    # T[d] = q

    return val

def apply(d, q):
    i = T[d]

    if d == 0:
        j = 1
    else:
        j = last[d - 1][i] + 1
    for dd in range(d, D):
        if dd > d and last[dd][i] == 0:
            break
        last[dd][i] = j
        j += 1

    j = 0
    for dd in range(d, D):
        if last[dd][q] == 0:
            break
        last[dd][q] = j
        j += 1

    T[d] = q

i = 0
while perf_counter() - t0 < 1.8:
    d = randint(0, D - 1)
    q = randint(0, 25)
    if eval(d, q) > 0:
        apply(d, q)
    else:
        if randint(0, (i + 1) ** 2) == 0:
            apply(d, q)
    i += 1
for t in T:
    print(t + 1)

Measured memory_bytes: 83408
#include <iostream>
using namespace std;
int main(void)
{
    int H,W;
    while (true) {
        cin >> H >> W;
        if (H == 0 && W == 0){break;}
        for(int j = 0; j < W; j++){cout << '#';}
        cout << endl;    
        for(int i = 1; i < H-1; i++){cout << '#';
        for(int j = 1; j < W-1; j++){cout << '.';}
        cout << '#' << endl;
    }
        for(int j = 0; j <W; j++){cout << '#';}
        cout << endl << endl;
    }
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, s, t) for(int i = (s); i < (t); i++)
#define MAXN 5

int N;
int match[25][25];
ll DP[22][1<<22];
ll sum[405];
// 0 - Taro's turn
// 1 - Jiro's turn

ll rek(int a, int maskb)
{
    if(a == N && (maskb == (1<<N)-1))
    {
        return 1LL;
    }
    if(DP[a][maskb] != -1)
        return DP[a][maskb];
    DP[a][maskb] = 0;
    for(int j = 0; j < N; j++)
    {
        if((maskb&(1<<j)) == 0)
        {
            if(match[a][j])
            {
                int maskb2 = maskb | (1<<j);
                ll x = rek(a+1, maskb2);
                x %= 1000000007;
                DP[a][maskb] += x;
                DP[a][maskb] %= 1000000007;
            }
        }
    }
    return DP[a][maskb];
}

int main()
{
    scanf("%d", &N);
    REP(i, 0, N)
    {
        REP(j, 0, N)
        {
            scanf("%d", &match[i][j]);
        }
    }

    memset(DP, -1, sizeof(DP));
    ll x = rek(0, 0);
    printf("%lld", x);

    return 0;
}


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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a+b>c+d) cout << "Left ";
    else if(a+b==c+d) cout << "Balanced ";
    else cout << "Right ";
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <utility>
using namespace std;

int grid[100][100];

int main() {
    int h, w;
    scanf("%d %d", &h, &w);

    int n;
    scanf("%d", &n);

    vector<int> a;
    for (int i = 0; i < n; i++) {
        int num_a;
        scanf("%d", &num_a);
        a.push_back(num_a);
    }

    // initialize grid / wall: -1
    int grid[h+2][w];
    for (int hi = 0; hi < h + 2; hi++) {
        for (int wi = 0; wi < w; wi++) {
            if (hi == 0 || hi == h + 1) {
                grid[hi][wi] = -1;
            } else {
                grid[hi][wi] = 0;
            }
        }
    }

    int hi = 1, wi = 0;
    int dir_h = 1;

    for (int ai = 0; ai < n; ai++) {
        for (int j = 0; j < a[ai]; j++) {
            grid[hi][wi] = ai + 1;
            if (grid[hi+dir_h][wi] == -1) {
                dir_h *= -1;
                wi++;
            } else {
                hi += dir_h;
            }
        }
    }

    for (int hi = 1; hi < h + 1; hi++) {
        for (int wi = 0; wi < w; wi++) {
            if (wi) { printf(" "); }
            printf("%d", grid[hi][wi]);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 384
#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>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}

void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main(){
  ll N,H; cin>>N>>H;
  vector<ll> A;
  vector<ll> B;
  rep(i,N){
    int a,b; cin>>a>>b;
    A.push_back(a);
    B.push_back(b);
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  
  ll amax=A[0];
  ll count=0;
  rep(i,N){
    if(B[i]>amax){
      H-=B[i];
      count++;
      if(H>0) continue;
      else break;
    }
    else break;
  }
  if(H>0) {
    count+=(H+(amax-1))/amax;
    cout<<count<<endl;
  }
  else cout<<count<<endl;
}
  

Measured memory_bytes: 2036
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N;
	static int K;

	public static void main(String[] args) {
		N = sc.nextInt();
		K = sc.nextInt();

		char[] S = sc.next().toCharArray();
		if (S[K - 1] == 'A') {
			S[K - 1] = 'a';
		} else if (S[K - 1] == 'B') {
			S[K - 1] = 'b';
		} else if (S[K - 1] == 'C') {
			S[K - 1] = 'c';
		}

		System.out.println(S);
	}

}

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

int  check(char c, int i,char s[]){
  
  int k;
  //char c1 = ')', c2 = ']';
  
  for(k = i-1 ; k >=  0; k--){
    if(c == ')' && s[k] == '['){
      return -1;
    }
    if(c == ']' && s[k] == '('){
      return -1;
    }
     if(c == ')' && s[k] == '('){
       s[k] = '_';
      return 1;
    }
    if(c == ']' && s[k] == '['){
      s[k] = '_';
      return 1;
    }
  }
  return -1;
}
 

int main(){
  
  char text[200];
  int s;
  int i;
  
  while(1){
  fgets(text, sizeof(text),stdin);
    
  if(text[0] == '.' && (text[1] == '\0' || text[2] == '\0'))
      break;
    
    
    s = 0;
   
    for(i = 0; text[i] != '\0'; i++){
      if(text[i] == ')' || text[i] == ']'){
	s = check(text[i],i,text);

	if(s == -1){
	  break;
	}
	if(s == 1){
	  text[i] = '_';
	}
      }
     
    }


    for(i = 0; text[i] != '\0'; i++){
      if(text[i] == '(' || text[i] == '[')
	s = -1;
    }
    if(s == 1 || s == 0){
      printf("yes\n");
    }
    if(s == -1){
      printf("no\n");
    }
}

  return 0;
}

  



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

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

    int n2;
    if(n % 2 == 0){
        n2 = n / 2 - 1;
    }
    else{
        n2 = n / 2;
    }
    cout << n2 << endl;
}

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

const int MAX_N = 2500;
const int MAX_M = 5000;

struct edge {
    int from, to, cost;
};

edge es[MAX_M];
bool jb[MAX_N], jf[MAX_N];
int ben[MAX_N];
int n, m, p;

int main() {
    scanf("%d %d %d", &n, &m, &p);
    for (int i = 0; i < m; i++) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        es[i].from = a - 1;
        es[i].to = b - 1;
        es[i].cost = c - p;
    }
    
    jb[n - 1] = true;
    jf[0] = true;
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < m; j++) {
            if (jb[es[j].to]) jb[es[j].from] = true;
            if (jf[es[j].from]) jf[es[j].to] = true;
        }
    }
    
    bool update;
    for (int i = 1; i < n; i++) ben[i] = -1e9;
    for (int i = 0; i < n; i++) {
        update = false;
        for (int j = 0; j < m; j++) {
            if (ben[es[j].to] < ben[es[j].from] + es[j].cost && jb[es[j].to] && jf[es[j].from]) {
                ben[es[j].to] = ben[es[j].from] + es[j].cost;
                update = true;
            }
        }
    }
    
    if (update) {
        printf("-1\n");
        return 0;
    }

    printf("%d\n", std::max(ben[n - 1], 0));
    return 0;
}


Measured memory_bytes: 384
import itertools


def calc(num):
    abs_result = abs(num) ** (1/5)
    if num < 0:
        return int(-abs_result)
    else:
        return int(abs_result)


X = int(input())

s = set()
for i in range(0, 150):
    s.add(i**5)
    s.add(-i**5)

for comb in itertools.combinations(s, 2):
    if comb[0] - comb[1] == X:
        A = calc(comb[0])
        B = calc(comb[1])
        print(A, B)
        break
    if comb[1] - comb[0] == X:
        A = calc(comb[1])
        B = calc(comb[0])
        print(A, B)
        break


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

using namespace std;

int main(){
	long long n,k;
	cin>>n>>k;
	long long a[n+1][3];
	for(int i=1;i<=n;i++){
		for(int j=1;j<=2;j++){
			a[i][j]=0;
		}
	}
	for(int i=1;i<=n;i++){
		cin>>a[i][1];
	}
	if(n>=k){
		long long o=1LL;
		for(int i=1;i<=k;i++){
			o=a[o][1];
		}
		cout<<o;
		return 0;
	}
	long long l=1LL,i=1LL,size=0LL,bsize=0LL;
	while(1){
		if(a[a[l][1]][2]==0){
			a[a[l][1]][2]=i;
			l=a[l][1];
		}
		else {
			size=fabs(i-a[a[l][1]][2]);
			bsize=a[a[l][1]][2]-1;
			break;
		}
		i++;
	}
	long long yu=(k-bsize)%size;
	if(yu==0)yu=size;
	for(long long q=1;q<yu;q++){
		a[l][1]=a[a[l][1]][1];
	}
	cout<<a[l][1];
	return 0;
}

Measured memory_bytes: 8324
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int               long long
#define ff                first
#define ss                second
#define md                1000000007
#define md1               998244353
#define inf               1000000000000000
#define minf              -1000000000000000
#define pb                push_back
#define in                insert
#define mkp               make_pair
#define mpll              map<ll,ll>
#define len(p)            (ll)p.size()
#define pll               pair<ll,ll>
#define all(v)            v.begin(),v.end()
#define mem(a,t)          memset(a,t,sizeof(a))
#define endl              "\n"
#define ar                array
#define vl                vector<ll>
#define vpll              vector<pair<ll,ll>>
#define f(i,yha,wha)      for(ll i=yha;i<wha;i++)
#define rf(i,wha,yha)     for(ll i=wha;i>=yha;i--)
#define f0(n)             for(ll i=0;i<n;i++)
#define f1(n)             for(ll i=1;i<=n;i++)
#define fg(i,yha,wha,gap) for(ll i=yha;i<wha;i+=gap)


void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll pw(ll x, ll y)
{
    if (y == 0)
        return 1;
    if (y == 1)
        return x;
    ll ans = pw(x, y / 2);
    ans = ans * ans;
    if (y % 2 == 1)
        ans = ans * x;
    return ans;
}






void solve()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    if (k > a) {
        ans += a;
        k -= a;
    } else {
        cout << k << endl;
        return;
    }
    if (k > b) {
        k -= b;
    } else {
        cout << ans << endl;
        return;
    }
    cout << ans - k << endl;

}

int32_t main()
{
    flash();
    int t;
    t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>

using int64 = long long;

struct Edge {
    using Weight = int;

    int end1_, end2_, from_, to_;
    Weight weight_;

    Edge() = default;
    Edge(int end1, int end2, Weight w):
        end1_{end1}, end2_{end2}, from_{end1}, to_{end2}, weight_{w} {}
    
    bool operator<(const Edge& e) const {
        return weight_ < e.weight_;
    }
};

struct UndirectedGraph {
    int num_nodes_;
    std::vector<std::vector<Edge>> adjacent_list_;
    std::vector<Edge> edges_;

    UndirectedGraph() = default;
    UndirectedGraph(int num_node): num_nodes_{num_node}, adjacent_list_(num_node) {}

    const std::vector<Edge>& operator[](int u) const { return adjacent_list_[u]; }
    std::vector<Edge>& operator[](int u) { return adjacent_list_[u]; }

    void addEdge(int end1, int end2, Edge::Weight weight) {
        adjacent_list_[end1].emplace_back(end1, end2, weight);
        adjacent_list_[end2].emplace_back(end2, end1, weight);
        edges_.emplace_back(end1, end2, weight);
    }
};

using Tree = UndirectedGraph;

int64 dfs(const Tree& tree, std::vector<int64>& A, int u, int par) {
    if (tree[u].size() == 1) {
        return A[u];
    }

    std::vector<int64> sub_results;

    for (const Edge& e : tree[u]) {
        if (e.to_ == par) continue;

        int64 sub_res = dfs(tree, A, e.to_, u);

        if (sub_res > 0) {
            sub_results.push_back(sub_res);
        }
    }

    std::sort(sub_results.begin(), sub_results.end());

    int64 sum = 0,
          x = 0;
    for (int i = 0; i < sub_results.size(); i++) {
        if (i == sub_results.size() - 1) {
            x = (sum <= sub_results[i]) ? sum : ((sum + sub_results[i]) / 2);
        }
        sum += sub_results[i];
    }
    A[u] -= sum;
    x = std::max(0LL, std::min(-A[u], x));
    A[u] += x;
    sum -= 2 * x;

    if (A[u] != 0) {
        std::cout << "NO" << std::endl;
        std::exit(0);
    }
    return sum;
}

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

    int N;
    std::cin >> N;

    std::vector<int64> A(N);
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
    }

    Tree tree(N);

    for (int i = 0; i < N - 1; i++) {
        int a, b;
        std::cin >> a >> b;
        a--;
        b--;

        tree.addEdge(a, b, 0);
    }

    if (N == 2) {
        std::cout << ((A[0] == A[1]) ? "YES" : "NO") << std::endl;
        return 0;
    }

    int root = -1;
    for (int u = 0; u < N; u++) {
        if (tree[u].size() > 1) {
            root = u;
        }
    }

    std::cout << ((dfs(tree, A, root, -1) == 0) ? "YES" : "NO") << std::endl;

    return 0;
}


Measured memory_bytes: 21392
n,k=map(int,input().split())
r,s,p=map(int,input().split())
point={'s':r,'p':s,'r':p}
string=input()
ans=[0]*(n+1)
for i in range(k):
  ans[i]=point[string[i]]
  double=string[i]
  for j in range(1,n//k+1):
    if j*k+i>n-1:
      break
    else:
      now=string[j*k+i]
      if now==double:
        double=''
      else:
        ans[j*k+i]=point[now]
        double=now
print(sum(ans))

Measured memory_bytes: 4084
N,K = map(int,input().split())
H = list(map(int,input().split()))

dp = [0]*N
for i in range(1,N):
    dp[i] = min(abs(H[i]-H[i-n]) + dp[i-n] for n in range(1,min(K+1,i+1)))

print(dp[-1])

Measured memory_bytes: 53600
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int N;
cin>>N;
if(N>0 && N<=999){
int k=N%10;
if(k==2 ||k==4 || k==5 ||  k==7 || k==9){
cout<<"hon";
} 
else if(k==0 || k==1 || k==6 || k==8){
cout<<"pon";
}
else{
cout<<"bon";
}

}  
 
 
return 0;
}

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define inn(x, y) int x,y;cin>>x>>y
#define innn(x, y, z) int x,y,z;cin>>x>>y>>z
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define outt(x,y) cout<<(x)<<" "<<(y)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;
#define errrr(x,y,z) cerr<<(x)<<" "<<(y)<<" "<<(z)<<endl;

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 200010
#define lim9 1000000010

#define deg(rad) (((rad)/2/M_PI)*360)
#define mid(min, max) ((min + max) / 2)

int main() {
	inn(n, k);
	bool sunuke[110] = {};
	repp(i, k) {
		in(d);
		repp(j, d) {
			in(sunuke_id);
			sunuke[sunuke_id] = true;
		}
	}
	int ans = n;
	repp(i, n) {
		if (sunuke[i]) --ans;
	}
	out(ans);
    return 0;
}


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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])

int main() {
    long long X;
    cin >> X;
    int gh = X / 500;
    int go = (X - gh*500) / 5;
    cout << gh*1000 + go*5;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
list_AB = [ list(map(int,input().split(" "))) for i in range(m)]
list_MAP = [0]*(n+1)

for l in list_AB:
    l.sort()
    if l[0] == 1:
        list_MAP[l[1]] += 1
    if l[1] == n:
        list_MAP[l[0]] += 1

ans = "IMPOSSIBLE"

for num in list_MAP:
    if num > 1:
        ans = "POSSIBLE"

print(ans)

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

int main() {
	// your code goes here
	int n,k[10000];
	while(cin >> n){
		if (n==0)
		break;
		int maxim=0,sum=0;
		for(int i=0;i<n;i++){
			cin >> k[i];
			sum+=(int)(bool)(k[i]);
			maxim=max(maxim,k[i]);
		}
		if(maxim<=1)
		cout <<"NA" << endl;
		else
		cout << sum+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
n, k = map(int, input().split())
a = list(map(int, input().split()))
d ={}
for key in a:
    if key in d:
        d[key] += 1
    else:
        d[key] = 1

d = sorted(d.items(), key=lambda  x:x[1])
ans = 0
if len(d) <= k:
    print(ans)
else:
    for i in range(len(d)-k):
        ans += d[i][1]
    print(ans)

Measured memory_bytes: 98376
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);


int main() {
	string s;
	cin >> s;
	int ans = INF;
	int a = 0,b = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i]-'0' == 1) a++;
		else b++;
		swap(a,b);
	}
	cout << min(a,b) << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
#define f(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
int y[100010];
signed main(){
	string s;
	cin>>s;
	int x=0,z=0;
	f(i,s.size()){
		if(s[i]=='R'){
			x=i;
			z++;
		}
		else{
			y[x]+=(z+1)/2;
			y[x+1]+=z/2;
			z=0;
			if((i-x)%2){
				y[x+1]++;
			}
			else y[x]++;
		}
	}
	f(i,s.size()){
		if(i)cout<<" ";
		cout<<y[i];
	}
	return 0;
}


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

int main() {
  int h, n;
  scanf("%d %d", &h, &n);
  
  int s = 0;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    s += a;
  }

  if (s < h)
    printf("No\n");
  else
    printf("Yes\n");

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
 
int n,a[200000],rb = 0;
cin >> n;
for (int i = 0; i < n ;i++){
    cin >> a[i];
}

for (int i = 1; i <= n; i++){
    if (a[rb] == 2){
        cout << i << endl;
        goto end;
    }
    rb = a[rb] - 1;
    
}

cout << "-1" << endl;
 
 end:
 
 return 0; 
}


Measured memory_bytes: 640
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    int a;
    cin >> a;

    cout << a + a * a + a * a * a;

    return 0;
}

Measured memory_bytes: 3648
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll sm[200005];


int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    ll ans=0;
    ll tol=0;
    rep(i,n){
        cin >> a[i];
        tol+=a[i];
        if(i!=0){
            sm[i]=sm[i-1]+a[i];
            sm[i]%=mod;
        }else{
            sm[i]=a[0];
        }
    }
    rep2(i,n-1){
        ll temp=a[i]*(sm[i-1])%mod;
        ans+=temp;
        ans%=mod;
    }
    ans%=mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6416
#include <bitset>
#include <cmath>
#include <cstdio>
#include <map>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <set>
#include <iterator>
#include <climits>
#include <stack>
#include <cstring>
#include <cmath>
#include <utility>
#include <list>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
using namespace std;


#define ll long long
#define vi vector<int>
#define mod 1000000007
ll _sieve_size;
bitset<10000010> bs;
vi primes;

void sieve(ll upperbound) {
    _sieve_size = upperbound + 1;
    bs.set();
    bs[0] = bs[1] = 0;
    for (ll i = 2; i <= _sieve_size; i++) if (bs[i]) {
            for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0;
            primes.push_back((int) i);
        }
}

bool isPrime(ll N) {
    if (N <= _sieve_size) return bs[N];
    for (int i = 0; i < (int) primes.size(); i++)
        if (N % primes[i] == 0) return false;
    return true;
}

int binarysearch(int n, int arr[], int value) {
    int upper = n;
    int lower = 0;
    int mid = n / 2;
    while (lower <= upper) {
        mid = (lower + upper) / 2;
        if (arr[mid] == value)
            return mid;
        else if (arr[mid] < value)
            lower = mid + 1;
        else
            upper = mid - 1;
    }
    return -1;
}

ll binaryPower(ll a,ll b){
    if(b == 0)
        return 1;
    ll res = binaryPower(a,b/2)%mod;
    if(b%2)
        return (((res * res)%mod) * a)%mod;
    else
        return (res*res)%mod;        
    return (((res * res)%mod) * a)%mod;

}
int main(void){
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    string s;
    int num;
    map<string,vector<pair<int,int>>> raa;
    for(int i = 0;i < n;++i){
        cin >> s >> num;
        raa[s].push_back(make_pair(num,i+1));
    }
     map<string,vector<pair<int,int>>> :: iterator it,jt;
     for(it = raa.begin();it != raa.end();++it){
         sort(raa[it->first].begin(),raa[it->first].end());
 
         for(int j = raa[it->first].size()-1; j >= 0;--j){
             cout << raa[it->first][j].second << endl;
         }
     }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX 10000
#define NIL -1
using namespace std;
struct Node
{
    int parent,left,right;
};
Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d)
{
    if(u==NIL)return;
    D[u]=d;
    setDepth(T[u].left,d+1);
    setDepth(T[u].right,d+1);
}

int setHeight(int u)
{
    int h1=0,h2=0;
    if(T[u].left!=NIL)
        h1=setHeight(T[u].left)+1;
    if(T[u].right!=NIL)
        h2=setHeight(T[u].right)+1;
    return H[u]=(h1>h2?h1:h2);
}

int getSibling(int u)
{
    if(T[u].parent==NIL)return NIL;
    if(T[T[u].parent].left!=u&&T[T[u].parent].left!=NIL)
        return T[T[u].parent].left;
    if(T[T[u].parent].right!=u&&T[T[u].parent].right!=NIL)
        return T[T[u].parent].right;
    return NIL;
}

void print(int u)
{
    printf("node %d: ",u);
    printf("parent = %d, ",T[u].parent);
    printf("sibling = %d, ",getSibling(u));
    int deg=0;
    if(T[u].left!=NIL)deg++;
    if(T[u].right!=NIL)deg++;
    printf("degree = %d, ",deg);
    printf("depth = %d, ",D[u]);
    printf("height = %d, ",H[u]);

    if(T[u].parent==NIL)
    {
        printf("root\n");
    }else if(T[u].left==NIL&&T[u].right==NIL)
    {
        printf("leaf\n");
    }else
    {
        printf("internal node\n");
    }
}

int main()
{
	int v,l,r,root=0;
	scanf("%d",&n);

	for(int i=0;i<n;i++)T[i].parent=NIL;

	for(int i=0;i<n;i++)
    {
        scanf("%d %d %d",&v,&l,&r);
        T[v].left=l;
        T[v].right=r;
        if(l!=NIL)T[l].parent=v;
        if(r!=NIL)T[r].parent=v;
    }

    for(int i=0;i<n;i++)if(T[i].parent==NIL) root=i;

    setDepth(root,0);
    setHeight(root);

    for(int i=0;i<n;i++)
    {
        print(i);
    }
 	return 0;
}



Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
// const ll MOD=998244353;

int main(){
  int M,K; cin>>M>>K;
  if(K>=(1<<M)){
    cout<<-1<<endl;
    return 0;
  }
  
  if(M==1){
    if(K==0){
      cout<<"0 0 1 1\n";
    }else{
      cout<<-1<<endl;
    }
    return 0;
  }
  for(int i=(1<<M)-1;i>=0;i--) if(i!=K) cout<<i<<" ";
  cout<<K<<" ";
  for(int i=0;i<(1<<M);i++) if(i!=K) cout<<i<<" ";
  cout<<K<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
 
using namespace std;
 
int main(){
    double a,b,c,degree,S;
    scanf("%lf %lf %lf",&a,&b,&degree);
    S = (0.5)*a*b*sin(M_PI*degree/180);
    c = sqrt(a*a+b*b-2*a*b*cos(M_PI*degree/180));
    printf("%.8lf\n",S);
    printf("%.8lf\n",a+b+c);
    printf("%.8lf\n",2*S/a);
}


Measured memory_bytes: 3076
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
struct H {
	int x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad＝座標上の2点間の距離
int ari(int a, int b, int c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	string s, t;
	vector<string>ans;
	cin >> s >> t;
	if (t.size() > s.size()) {
		cout << "UNRESTORABLE\n";
		return 0;
	}
	for (int i = 0; i <= s.size() - t.size(); i++) {
		string h = s;
		bool l = 1;
		for (int j = 0; j < t.size(); j++)
			l = l && (s[i + j] == t[j] || s[i + j] == '?');
		if (l) {
			for (int j = 0; j < t.size(); j++)
				h[i + j] = t[j];
			for (int j = 0; j < s.size(); j++) if (h[j] == '?') h[j] = 'a';
			ans.push_back(h);
		}
	}
	sort(ans.begin(), ans.end());
	if (ans.size() == 0)
		cout << "UNRESTORABLE\n";
	else
		cout << ans[0] << endl;
	getchar(); getchar();
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();

        int n = 0;

        if(a>=b){
            n += a;
            a--;
        }else{
            n += b;
            b--;
        }

        if(a>=b){
            n += a;
            a--;
        }else{
            n += b;
            b--;
        }

        System.out.println(n);
        
    }
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define req(i, j, n) for(int i = j; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


const ll MAX=100007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
ll COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main() {
  COMinit();
ll n,k;
  cin>>n>>k;
  ll a[n+1];
  for(int i=1;i<=n;i++){
    cin>>a[i];}
  sort(a+1, a+n+1);
  
  ll minw=0;
  ll maxw=0;
  for(int i=1;i<=n-k+1;i++){
    minw+=a[i]*COM(n-i, k-1);
    minw%=MOD;}
  for(int i=k;i<=n;i++){
    maxw+=a[i]*COM(i-1, k-1);
    maxw%=MOD;}
  
  ll ans=maxw+MOD-minw;
  ans%=MOD;
  cout<<ans<<endl;
  
  

}

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

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

    int n,m;
    cin >> n >> m;

    int a[m],b[m];
    rep(i,m) cin >> a[i] >> b[i];

    vector<vector<int>> G(n+1);
    rep(i,m){
        int v = a[i], u = b[i];
        G[v].push_back(u);
        G[u].push_back(v);
    }

    vector<int> ans(n+1);
    vector<int> used(n+1);
    queue<int> q;
    q.push(1);
    while(!q.empty()){
        int now = q.front(); q.pop();
        rep(i,G[now].size()){
            int p = G[now][i];
            if(used[p] == 0){
                ans[p] = now;
                q.push(p);
                used[p] = 1;
            }
        }
    }

    cout << "Yes" << endl;
    for(int i=2;i<=n;i++){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 12180
import sys
 
sys.setrecursionlimit(1000000)
n, m, *a = map(int, open(0).read().split())
dp = [1] + [-1] * n
dp[1] = 1
for i in a:
    dp[i] = 0
 
def count(n):
    if dp[n] != -1:
        return dp[n]
    dp[n] = (count(n - 1) + count(n - 2)) % (10**9 + 7)
    return dp[n]
 
 
print(count(n))

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

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
//#define gcd __gcd
//#define lcm(a, b) ((a) * (b) / gcd((a), b))
#define all(x) x.begin(), x.end()
#define rep(i, x, n) for (ll i = x; i < n; i++)
#define fastio() ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0)
#define endl '\n'

typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;

template <class T> inline T RD(T &a) {T x; cin >> x; return a = x;}

//OJ freopen Template

const float pi = acos(-1);

signed main()
{
	fastio();

	float r; cin >> r;
    cout << pi * 2 * r;
}


Measured memory_bytes: 3796
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<int, int> pii;
#define X first
#define Y second

int main(){
    int n,k;
    cin >> n >> k;
    k--;
    vector<pii> p(n);
    for(int i=0; i<n; i++){
        cin >> p[i].X >> p[i].Y;
    }
    for(int i=0; i<n-k; i++){
        map<pii, int> dirs;
        for(int j=i+1; j<n; j++){
            pii dir(p[i].X-p[j].X, p[i].Y-p[j].Y);
            if(dir.X < 0 or (dir.X == 0 and dir.Y < 0)){
                dir = pii(-dir.X, -dir.Y);
            }
            int d = __gcd(abs(dir.X), abs(dir.Y));
            dir = pii(dir.X/d, dir.Y/d);
            if(++dirs[dir] >= k){
                cout << 1 << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3304
inp = list(input())
a = inp[0]
b = inp[1]
c = inp[2]
d = inp[3]
for i in range(8):
    temp = format(i, '03b')
    templist = list(temp)
    if templist[0] == "0":
        op1 = "+"
    else:
        op1 = "-"
    if templist[1] == "0":
        op2 = "+"
    else:
        op2 = "-"
    if templist[2] == "0":
        op3 = "+"
    else:
        op3 = "-"
    ans = eval(a+op1+b+op2+c+op3+d)
    if ans == 7:
        print(a+op1+b+op2+c+op3+d+"=7")
        exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
const ll M = pow(10,9)+7;
/*template*/


int main()
{
  ll K,N;cin>>K>>N;
  ll a[N];
  for(ll i=0;i<N;i++){
    cin>>a[i];
  }
  ll ans=0;
  for(ll i=0;i<N;i++){
    if(i==0){
      chmax(ans,a[0]-a[N-1]+K);
    }else{
      chmax(ans,a[i]-a[i-1]);
    }
  }
  cout<<K-ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int c[3][3];
    for(int i=0;i<3;++i){
        for(int j=0;j<3;++j) {
            cin >> c[i][j];
        }
    }

    int a[3] = {0, 0, 0};
    for(a[0]=0;a[0]<=100;++a[0]) {
        int b[3];
        for(int j=0;j<3;++j) b[j] = c[0][j] - a[0];
        for(a[1]=0;a[1]<=100;++a[1]) {
            for(a[2]=0;a[2]<=100;++a[2]) {
                bool ok = true;
                for(int i=0;i<3;++i) {
                    for(int j=0;j<3;++j) {
                        if(a[i] + b[j] != c[i][j]) {
                            ok = false;
                        }
                    }
                }
                if(ok) {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
    return 0;

}


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

N = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(N):
    min = i
    for j in range(i, N):
        if A[min] > A[j]:
            min = j
    A[i], A[min] = A[min], A[i]
    if min != i:
        count += 1


print(' '.join(list(map(str, A))))
print(count)



Measured memory_bytes: 5608
import java.util.Scanner;

public class Main {

	static int heisei=1988, showa=1925, taisho=1911, meiji=1867;
	static int year,month,day;
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()){
			year = cin.nextInt();
			month = cin.nextInt();
			day = cin.nextInt();
			if(year<1868){
				System.out.println("pre-meiji");
			}
			else if(year==1868){
				if(month<9){
					System.out.println("pre-meiji");
				}
				else if(month>9){
					print("meiji");
				}
				else{
					if(day<8){
						System.out.println("pre-meiji");
					}
					else{
						print("meiji");
					}
				}
			}
			else if(year<1912){
				System.out.println("meiji "+(year-meiji)+" "+month+" "+day);
			}
			else if(year==1912){
				if(month<7){
					print("meiji");
				}
				else if(month>7){
					print("taisho");
				}
				else{
					if(day<30){
						print("meiji");
					}
					else{
						print("taisho");
					}
				}
			}
			else if(year<1926){
				System.out.println("taisho "+(year-taisho)+" "+month+" "+day);
			}
			else if(year==1926){
				if(month<12){
					
					print("taisho");
				}
				else if(month>12){
					print("showa");
				}
				else{
					if(day<25){
						
						print("taisho");
					}
					else{
						print("showa");	
					}
				}
			}
			else if(year<1989){
				System.out.println("showa "+(year-showa)+" "+month+" "+day);
			}
			else if(year==1989){
				if(month<1){
					print("showa");
				}
				else if(month>1){
					print("heisei");
				}
				else{
					if(day<8){
						print("showa");	
					}
					else{
						print("heisei");	
					}
				}
			}
			else{
				System.out.println("heisei "+(year-heisei)+" "+month+" "+day);
			}
		}
	}
	static void print(String str){
		if(str.equals("heisei")){
			year-=heisei;
		}
		else if(str.equals("showa")){
			year-=showa;
		}
		else if(str.equals("taisho")){
			year-=taisho;
		}
		else if(str.equals("meiji")){
			year-=meiji;
		}
		System.out.println(str + " " +year+" " + month+" " + day);
			
		
	}
}

Measured memory_bytes: 12000
#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;
 
int main()
{
    int n;
    cin >> n;
    map<int,int> mp;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        mp[a]++;
    }

    int ans = 0;
    for(auto x: mp){
        if(x.first < x.second) ans += x.second - x.first;
        if(x.first > x.second) ans += x.second;
    }

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

Measured memory_bytes: 4736
from itertools import combinations
N = int(input())
town = []
for n in range(N):
    x, y = map(int,input().split())
    town.append((x,y))

ans = 0
for i,j in combinations(town,2):
    ans += ((i[0]-j[0])**2 + (i[1]-j[1])**2)**0.5
print (2*ans/N)

Measured memory_bytes: 3188
#include <stdio.h>
int main() {
  int A,B,C;
  /* A:not delicious medicine B:delicious mesicine C:delicious poison */
  scanf("%d %d %d",&A,&B,&C);
  int ans;
  if (A + B >= C) {
    ans	= B + C;
  } else {
    ans	= (A + B) + B + 1;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
N = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(N):
  if  a[a[i] - 1] < 0: continue
  if a[a[i] - 1] == i + 1:
    ans += 1
    a[a[i] - 1] = 0
print(ans)

Measured memory_bytes: 13880
fun main(args: Array<String>) {
    val l = mutableListOf<Int>()
    var d = 0
    var n = readLine()!!.toInt()
    for(i in 1..200){
        d = 0
        for(j in 1..100){
            if (i % (2 * j + - 1) == 0) d += 1
        }
        if (d == 8) l.add(i)
    }
    println(l.filter{ it <= n }.count())
}

Measured memory_bytes: 33680
c11, c12, c13 = map(int, input().split())
c21, c22, c23 = map(int, input().split())
c31, c32, c33 = map(int, input().split())
ans = 'No'
if c11 - c21 == c12 - c22 & c12 - c22 == c13 - c23:
    if c21 - c31 == c22 - c32 & c22 - c32 == c23 - c33:
        if c11 - c12 == c21 - c22 & c21 -c22 == c31 - c32:
            if c12 - c13 == c22 - c23 & c22 - c23 == c32 - c33:
                ans = 'Yes'
print(ans)

Measured memory_bytes: 9124