akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

constexpr int64_t mod = INT64_C(1000000007);

using acgt_t = std::array<std::array<std::array<int64_t, 4>, 4>, 4>;

int64_t solve(int n) {
  acgt_t acgt{};
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < 4; ++j) {
      for (int k = 0; k < 4; ++k) {
        if (i == 0 && j == 1 && k == 2) {
          continue;
        }
        if (i == 0 && j == 2 && k == 1) {
          continue;
        }
        if (i == 2 && j == 0 && k == 1) {
          continue;
        }
        acgt[i][j][k] = 1;
      }
    }
  }

  //

  for (int nn = 4; nn <= n; ++nn) {
    acgt_t next{};
    for (int i = 0; i < 4; ++i) {
      for (int j = 0; j < 4; ++j) {
        for (int k = 0; k < 4; ++k) {
          int64_t const value = acgt[i][j][k];
          if ((i == 0 & j == 0 & k == 2) || (i == 0 & j == 2 & k == 0) ||
              (i == 0 & j == 2 & k == 2) || (i == 0 & j == 2 & k == 3) ||
              (i == 0 & j == 3 & k == 2) || (i == 1 & j == 0 & k == 2) ||
              (i == 1 & j == 2 & k == 0) || (i == 2 & j == 0 & k == 2) ||
              (i == 2 & j == 2 & k == 0) || (i == 3 & j == 0 & k == 2) ||
              (i == 3 & j == 2 & k == 0)) {
            //  0021
            //  0201
            //  0221
            //  0231
            //  0321
            //  1021
            //  1201
            //  2021
            //  2201
            //  3021
            //  3201
            next[j][k][0] += value;
            next[j][k][2] += value;
            next[j][k][3] += value;
            next[j][k][0] %= mod;
            next[j][k][2] %= mod;
            next[j][k][3] %= mod;
          } else if ((i == 0 & j == 0 & k == 1) || (i == 1 & j == 0 & k == 1) ||
                     (i == 3 & j == 0 & k == 1)) {
            //  0012
            //  1012
            //  3012
            next[j][k][0] += value;
            next[j][k][1] += value;
            next[j][k][3] += value;
            next[j][k][0] %= mod;
            next[j][k][1] %= mod;
            next[j][k][3] %= mod;
          } else {
            next[j][k][0] += value;
            next[j][k][1] += value;
            next[j][k][2] += value;
            next[j][k][3] += value;
            next[j][k][0] %= mod;
            next[j][k][1] %= mod;
            next[j][k][2] %= mod;
            next[j][k][3] %= mod;
          }
        }
      }
    }
    acgt = next;
  }

  int64_t ret = 0;
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < 4; ++j) {
      for (int k = 0; k < 4; ++k) {
        ret += acgt[i][j][k];
        ret %= mod;
      }
    }
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n;
  std::cin >> n;
  std::cout << solve(n) << std::endl;
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
H = list(map(int, input().split()))
dp = [1 << 62] * N
dp[0] = 0
for i in range(1, N):
    for j in range(K):
        if i + j < N:
            cost = abs(H[i - 1] - H[i + j])
            dp[i + j] = min(dp[i + j], dp[i - 1] + cost)
print(dp[-1])


Measured memory_bytes: 52592
#include<bits/stdc++.h>
using namespace std;
int main(void){

	int N, M;		cin >> N >> M;
	long long Nans = 1;
	for(int i = 1 ; i <= N ; i++){
		Nans *= i;
      	Nans %= 1000000007;
    }

	long long Mans = 1;
	for(int i = 1 ; i <= M ; i++){
		Mans *= i;
      	Mans %= 1000000007;
    }
  
    long long ans = 1;
  	if(abs(M - N) < 2){
      
    	if(M == N){
      		ans *= Nans;
          	ans *= Mans;
          	ans *= 2;
   		 }else{
      		ans *= Nans;
          	ans *= Mans;
        }
    }else
      	ans = 0;

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


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n, s;
string a;

void f(ll p, ll q) {
	ll i, k=0;
	if(p==n) s += q;
	for(i=p; i<n; i++) {
		k = k*10 + a[i]-'0';
		f(i+1, q+k);
	}
}

int main() {
	cin>>a;
	n = a.size();
	f(0, 0);
	cout<<s;
	return 0;
}

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


int main(){
	double a, b, c;
	int i;
	while (cin >> a >> b){
		c = a + b;
		i = 1;
		while (c >= 10){
			c = c / 10;
			i++;
		}
		cout << i << endl;
	}

	return 0;
}

Measured memory_bytes: 1220
W,H,x,y,r = input().split()
W = int(W)
H = int(H)
x = int(x)
y = int(y)
r = int(r)
 
if x < 0 or y < 0:
    print("No")
 
else:
    if W - x >= r and H - y >= r:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 7672
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val X = sc.nextInt
    val Y = sc.nextInt
    val Z = sc.nextInt
    val K = sc.nextInt
    val A = Array.fill(X)(sc.nextLong).sorted.reverse
    val B = Array.fill(X)(sc.nextLong).sorted.reverse
    val C = Array.fill(X)(sc.nextLong).sorted.reverse

    val ar = new ArrayBuffer[Long]()
    var ai = 0
    while (ai < A.length) {
      var bi = 0
      while (bi < B.length && (ai + 1) * (bi * 1) <= K) {
        var ci = 0
        while (ci < C.length && (ai + 1) * (bi + 1) * (ci + 1) <= K) {
          ar.append(A(ai) + B(bi) + C(ci))
          ci += 1
        }
        bi += 1
      }
      ai += 1
    }
    ar.sorted.reverse.take(K).mkString("\n")
  }
}


Measured memory_bytes: 40984
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	Scanner sc = new Scanner(System.in);

	int INF = 1 << 28;
	double EPS = 1e-9;

	int n;
	int start, goal, ttl;
	LinkedList<Integer>[] graph;

	@SuppressWarnings("unchecked")
	void run() {
		n = sc.nextInt();
		graph = new LinkedList[n];
		for (int j = 0; j < n; j++) {
			int u = sc.nextInt() - 1;// [^Ô
			int m = sc.nextInt();
			graph[u] = new LinkedList<Integer>();
			for (int i = 0; i < m; i++) {
				int v = sc.nextInt() - 1;
				graph[u].add(v);
			}
		}
		int p = sc.nextInt();
		for (int i = 0; i < p; i++) {
			start = sc.nextInt() - 1;
			goal = sc.nextInt() - 1;
			ttl = sc.nextInt();
			solve();
		}
	}

	void solve() {
		LinkedList<Integer> que = new LinkedList<Integer>();
		boolean[] visited = new boolean[n];
		int[] d = new int[n];
		Arrays.fill(d, INF);
		que.offer(start);
		d[start] = 1;
		visited[start] = true;
		for (; !que.isEmpty();) {
			int u = que.poll();
			for (int v : graph[u]) {
				if (!visited[v]) {
					que.offer(v);
					d[v] = d[u] + 1;
					visited[v] = true;
				}
			}
		}
		if (d[goal] <= ttl) {
			println("" + d[goal]);
		} else {
			println("NA");
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s) {
		System.out.print(s);
	}

	void println(String s) {
		System.out.println(s);
	}

	public static void main(String[] args) {
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
typedef pair <int, int> P;

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

    int n;
    cin >> n;

    int x[n], y[n];
    vector <P> pq;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];

        for (int j = 0; j < i; j++) {
            int p = x[i] - x[j];
            int q = y[i] - y[j];
            pq.push_back(P(p, q));
            pq.push_back(P(-p, -q));
        }
    }

    if (n == 1) {
        cout << 1 << "\n";
        return 0;
    }

    int ans = 1 << 30;
    for (P tmp : pq) {
        int p = tmp.first;
        int q = tmp.second;

        int c = n;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (x[j] == x[i] - p && y[j] == y[i] - q) {
                    c--;
                }
            }
        }

        ans = min(ans, c);
    }

    cout << ans << '\n';
    return 0;
}

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

l_target=[]
for _ in range(m):
    a,b=map(int,input().split())
    l_target.append((a,b))

l_target.sort(key=lambda x:x[1])

count=0
pre_pos=0
for target in l_target:
    if (target[0]<pre_pos<target[1]):
        continue
    
    count+=1
    pre_pos=target[1]-0.5

print(count)

Measured memory_bytes: 18208
import java.util.*;

public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		String S = sc.next();
		int count =0;
		String T=sc.next();
		for(int i=0; i<3;i++) {
			if(S.charAt(i)==T.charAt(i)) count++;
		}
		System.out.println(count);
		
	}
}



Measured memory_bytes: 21844
N = int(input())
A = list(map(int, input().split()))

cnt=0
for i in range(N):
    if A[i]%2==0:
        if A[i]%6!=0 and A[i]%10!=0:
            cnt=1
            print('DENIED')
            break
    else:
        pass
if cnt==0:
    print('APPROVED')

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



int main()
{
    string s,s2;
    cin>>s;
    sort(s.begin(),s.end());
    char a;a='a';
    for(int i=0;i<s.size();i++){
        if(s[i]==a)a+=1;
    }
    if(a!='{')cout<<a;
    else cout<<"None";

    return 0;
}


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

#define int long long

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

    pair<int, int> p[200010];

    for(int i = 0;i < n;i++){
        cin >> p[i].second >> p[i].first;
    }

    sort(p, p+n);

    int t = 0;
    for(int i = 0;i < n;i++){
        t += p[i].second;
        if(t > p[i].first){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

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



typedef int stack_data;
#define success 1
#define failure 0

typedef struct{
  int data_num;
  int stack_size;
  stack_data *data;
}stack;


stack *make_stack(int stack_size){
  stack *p;
  p=malloc(sizeof(stack));
  p->data=malloc(stack_size*sizeof(stack_data));
  p->stack_size=stack_size;
  p->data_num=0;
  return p;
}


int push(stack *S,stack_data a){
  if(S->data_num < S->stack_size){
    S->data[S->data_num]=a;
    S->data_num++;
    return success;
  }
  else return failure;
}

int pop(stack *S,stack_data *p){
   if(S->data_num>0){
     *p=S->data[S->data_num -1];
      S->data_num--;
      return success;
   }
   else return failure;
}


int main(){
  char c[8];
  int *x,*y,z;
  x=malloc(sizeof(int));
  y=malloc(sizeof(int));
  stack *S;
  S=make_stack(101);
  while(scanf("%8s",c)!=EOF){
    if('+'==c[0]){
      pop(S,x);
      pop(S,y);
      z=x[0]+y[0];
      push(S,z);
    }
    else if('-'==c[0]){
      pop(S,x);
      pop(S,y);
      z=-x[0]+y[0];
      push(S,z);
    }
    else if('*'==c[0]){
      pop(S,x);
      pop(S,y);
      z=x[0]*y[0];
      push(S,z);
    }
    else{
      z=atoi(c);
      push(S,z);
    }
  }
  printf("%d\n",S->data[0]);
  return 0;
}

Measured memory_bytes: 576
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let X: i64 = sc.get();
    let Y: i64 = sc.get();
    if ((4 * X - Y) % 2 != 0 || 4 * X - Y < 0) || ((Y - 2 * X) % 2 != 0 || Y - 2 * X < 0) {
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll d[1<<21];

ll calc(ll a[],ll d) {
  ll ans=0;
  for(ll i=0;i<4;i++) {
    ll x=a[i],y=a[(i+1)%4];
    ans+=max(0LL,d+1-max(x,d)+x-max(y,d)+y-(d<=x)-(d<=y))+(d<=x);
  }
  return d?ans:1;
}

int main() {
  ll x,y,z,a,b,c,n;
  cin>>x>>y>>z>>a>>b>>c>>n;
  ll r[4]={a,b,x-a-1,y-b-1};
  for(ll i=0;i<(1<<21);i++)d[i%n]+=calc(r,i);
  for(ll i=0;i<n;i++) {
    if(i)cout<<' ';
    ll ans=(c/n+(z-c)/n)*x*y;
    for(ll j=1;j<=c%n;j++)ans+=d[(i+n-j)%n];
    for(ll j=0;j<(z-c)%n;j++)ans+=d[(i+n-j)%n];
    cout<<ans;
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 1168
// Mon Aug 24 16:24:09 IST 2020        
#include <bits/stdc++.h>        
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(ii,a,b)       for(int ii = (int)a ; ii < (int)b  ; ii++ )
#define scan(any)          for(auto &i:any) cin>>i;
#define debug(x)           cerr << #x << " " << x << " -- \n"
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int64              long long   
#define all(x)             (x).begin(),(x).end() 
#define ff                 first
#define ss                 second
#define pppp               pair <int,int> 
#define flushOff           fflush(stdout) 
#define precise(x)         cout << fixed << setprecision(12) << x << '\n'; 
using namespace std ;    
// policy based   
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
 
const int MOD1 = 1e9+7;
const int MOD2 = 1e9+9;
const double pi = 3.141592653589793238;
const int INF = 2e9+7; 

struct compare{
    bool operator()(pair <int,int> A, pair <int,int> B){
        if(A.first == B.first)
            return A.second > B.second;
        return A.first > B.first;
    }
}; 
int tests(){ 
    int n;
    cin >> n;
    vector <int64> a(n),suff(n);
    forn(i,0,n)
        cin >> a[i];
    suff[n-1] = a[n-1];
    for(int i = n-2 ; i > -1 ; i--)
        suff[i] =  (suff[i+1]+a[i])%MOD1;
    int64 ans = 0;
    forn(i,0,n-1){
        ans += (a[i]*suff[i+1])%MOD1;
        ans %= MOD1;
    }
    cout << ans << '\n';
    return 0;
}
int main(){
    I__O ;      
    int cases = 1 ;  
    // cin >> cases ;
    while(cases--)
        tests(); 
    return 0 ; 
}
 

Measured memory_bytes: 6360
#![allow(non_snake_case,unused_imports)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();

    let N = buf_it.next().unwrap().parse::<usize>().unwrap();

    let A = (0..N).map(|_| 
                (0..N-1).map(|_|
                    buf_it.next().unwrap().parse::<usize>().unwrap()
                ).collect::<Vec<_>>()
    ).collect::<Vec<_>>();

    let M = N*N;
    let mut Ef = (0..M).map(|_| HashSet::new()).collect::<Vec<_>>();
    let mut Eb = (0..M).map(|_| HashSet::new()).collect::<Vec<_>>();

    for i in 0..N{
        for j in 0..N-2{
            let f = index(i,A[i][j]-1,N);
            let t = index(i,A[i][j+1]-1,N);
            Ef[f].insert(t);
            Eb[t].insert(f);
        }
    }

    let mut ans = topological_sort(M,&Ef,&mut Eb).len() as isize;
    if ans == 0 { ans = -1}

    println!("{}",ans);
}

fn index(i:usize,j:usize,N:usize)->usize{
    if i>j {
        i*N+j
    } else {
        j*N+i
    }
}

fn topological_sort(M:usize,Ef:&Vec<HashSet<usize>>,Eb:&mut Vec<HashSet<usize>>) -> Vec<Vec<usize>>{
    let mut q = (0..M).filter(|&i| Eb[i].len()==0).collect::<Vec<_>>();
    let mut ret = Vec::new();
    while q.len()>0{
        ret.push(q.clone());
        let mut qq = vec![];
        while let Some(i) = q.pop(){
            for &j in &Ef[i]{
                Eb[j].remove(&i);
                if Eb[j].len()==0{
                    qq.push(j);
                }
            }
        }
        q = qq;
    }
    if Eb.iter().map(|r| r.len()).sum::<usize>()!=0{
        ret = Vec::new();
    }
    ret
}

Measured memory_bytes: 639224
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> ct(26,0);
  vector<int> cs(26,0);
  string s,t;
  cin>>s>>t;
  int n=s.length();
  for(int i=0;i<n;i++){
    cs[(int)(s.at(i)-'a')]++;
    ct[(int)(t.at(i)-'a')]++;
  }
  sort(ct.begin(),ct.end());
  sort(cs.begin(),cs.end());
  for(int i=0;i<26;i++){
    if(ct[i]!=cs[i]){cout<<"No"<<endl;return 0;}
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define print(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
ll MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}

ll modpow(ll x, ll y, ll m) {
    if (y == 0) return 1;
    ll res = modpow(x, y / 2, m);
    return res * res % m * (y & 1 ? x : 1) % m;
}
ll modinv(ll x) { return modpow(x, MOD - 2, MOD); }
 
map<ll,ll> LCM;

void lcm_calc(ll N){
    map<ll,ll> PF;
    for(ll i = 2; i * i <= N; i++) while(!(N%i)) PF[i]++, N /= i;
    if(N != 1) PF[N] = 1;
    
    for(auto itr = PF.begin(); itr != PF.end(); ++itr) {
        LCM[itr->first] = max(LCM[itr->first], itr->second);
    }
    return;
}
 
int main(){
    ll N; cin >> N;
    vector<ll> A(N); rep(i,N) cin >> A[i];
    
    rep(i,N) lcm_calc(A[i]);

    ll modlcm = 1;
    for(auto itr = LCM.begin(); itr != LCM.end(); ++itr) {
        modlcm *= modpow(itr->first, itr->second, MOD);
        modlcm %= MOD;
    }
    
    ll ans = 0;
    rep(i,N){
        ans += modlcm * modinv(A[i]);
        ans %= MOD;
    }
    print(ans);
}


Measured memory_bytes: 1024
import sys
from bisect import bisect_right

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, *A = map(int, read().split())

    dp = [A[-1]]
    for a in reversed(A[:-1]):
        if a >= dp[-1]:
            dp.append(a)
        else:
            dp[bisect_right(dp, a)] = a

    print(len(dp))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 14092
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>
#include<boost/multiprecision/cpp_int.hpp>



using namespace std;
using namespace boost::multiprecision;

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldb = long double;

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", v)
#define PRIY PRI("Yes")
#define PRIN PRI("No")
template<typename A, typename B>
void mins(A& a, const B& b) { a = min(a, (A)b); };
template<typename A, typename B>
void maxs(A& a, const B& b) { a = max(a, (A)b); };



//コンビネーション
class com_table {
public:

	//拡張ユークリッドの互除法。戻り値は最大公約数、x,yはax+by=gcd(a,b)を満たす組の一つ
	long long gcdext(long long a, long long b, long long& x, long long& y) {
		if (b == 0) {
			x = 1;
			y = 0;
			return a;
		}
		long long g = gcdext(b, a % b, y, x);
		y -= a / b * x;
		return g;
	}

	//モジュラ逆数
	long long modinv(long long a, long long mod) {
		long long x, y;
		gcdext(a, mod, x, y);
		x = ((x % mod) + mod) % mod;
		return x;
	}


	vector<long long> frac;
	vector<long long> finv;
	long long mod;
	com_table() = default;
	void init(long long size, long long mod) {
		this->mod = mod;
		frac.resize(size + 1);
		finv.resize(size + 1);
		frac[0] = 1;
		finv[0] = 1;
		for (int i = 1; i <= size; ++i) frac[i] = frac[i - 1] * i % mod;
		finv[size] = modinv(frac[size], mod);
		for (int i = size; i >= 2; --i) finv[i - 1] = finv[i] * i % mod;
	}
	long long operator()(int a, int b) {
		if (a < b)return 0;
		return ((frac[a] * finv[b] % mod) * finv[a - b]) % mod;
	}
};



int main() {
	ll mod = 1e9 + 7;
	com_table com;
	com.init(2000001, mod);
	ll H, W, A, B; cin >> H >> W >> A >> B;
	ll ans = 0;
	REP(k, 1, H - A+1) ans = (ans + com(B + k-2, B-1) * com(H - k + W - B - 1, H-k)) % mod;
	PRI(ans);
	return 0;
}


Measured memory_bytes: 34236
N,Y=map(int,input().split())

for x in range(N+1):
  for y in range(N+1-x):
    if 10000*x+5000*y+1000*(N-x-y)==Y:
      print("%d %d %d"%(x,y,N-x-y))
      exit()
print("-1 -1 -1")

Measured memory_bytes: 65248
#include <stdio.h>
#define N 100
void Tr(int m[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", m[i]);
  }
  printf("\n");
}
int main(void)
{
  int m[N+1],i,j,key,n,count=0;
  scanf("%d",&n);
  for(i=1 ; i<n+1 ; i++){
      scanf("%d",&m[i]);
    }
  for(i=1 ; i<n+1 ; i++){
      for(j=n ; j >= i+1 ; j--)
    {
      if(m[j] < m[j-1]){
          key = m[j];
          m[j] = m[j-1];
          m[j-1] = key;
          count++;
        }
    }
  }
  Tr(m, n);
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 604
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 210000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
int p[310];
int h[310];
long long dp[310][310][310];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	// for(int i=0;i<a;i++)h[i]=p[i];
	std::sort(h,h+a);
	for(int i=0;i<310;i++)for(int j=0;j<310;j++)for(int k=0;k<310;k++){
		dp[i][j][k]=inf;
	}
	dp[0][0][0]=0;
	for(int i=0;i<a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=i;k++){
				if(dp[i][j][k]==mod)continue;
				if(j<b){
					dp[i+1][j+1][k]=min(dp[i+1][j+1][k],dp[i][j][k]);
				}
				int cost=mod;
				if(k==0)cost=p[i];
				else cost=max(0,p[i]-p[k-1]);
				dp[i+1][j][i+1]=min(dp[i+1][j][i+1],dp[i][j][k]+cost);
			}
		}
	}
	long long ret=inf;
	for(int i=0;i<=b;i++){
		for(int j=0;j<=a;j++){
			ret=min(ret,dp[a][i][j]);
		}
	}
	printf("%lld\n",ret);
}

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

int main() {
    long n;
    cin >> n;
    set<char> st;
    char c;
    rep(i, n) {
        cin >> c;
        st.insert(c);
    } 
    if(st.size() == 3) cout << "Three" << endl;
    else cout << "Four" << endl;
}

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

int main() {
  ll X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  vector<ll> R(A), G(B), W(C);
  for (int i = 0; i < A; i++) {
    ll p;
    cin >> p;
    R.at(i) = p;
  }
  for (int i = 0; i < B; i++) {
    ll q;
    cin >> q;
    G.at(i) = q;
  }
  for (int i = 0; i < C; i++) {
    ll r;
    cin >> r;
    W.at(i) = r;
  }
  sort(R.begin(), R.end());
  reverse(R.begin(), R.end());
  sort(G.begin(), G.end());
  reverse(G.begin(), G.end());
  sort(W.begin(), W.end());
  reverse(W.begin(), W.end());
  vector<ll> apples(X + Y + C);
  for (int i = 0; i < X; i++) {
    apples.at(i) = R.at(i);
  }
  for (int i = X; i < X + Y; i++) {
    apples.at(i) = G.at(i - X);
  }
  for (int i = X + Y; i < X + Y + C; i++) {
    apples.at(i) = W.at(i - X - Y);
  }
  sort(apples.begin(), apples.end());
  reverse(apples.begin(), apples.end());
  ll sum = 0;
  for (int i = 0; i < X + Y; i++) {
    sum += apples.at(i);
  }
  cout << sum << endl;
}


Measured memory_bytes: 4736
char buf[5],out[2<<17];
sz,outsz;
i,j;
N;
char fs[1001]="01213121412131215121312141213121612131214121312151213121412131217121312141213121512131214121312161213121412131215121312141213121812131214121312151213121412131216121312141213121512131214121312171213121412131215121312141213121612131214121312151213121412131219121312141213121512131214121312161213121412131215121312141213121712131214121312151213121412131216121312141213121512131214121312181213121412131215121312141213121612131214121312151213121412131217121312141213121512131214121312161213121412131215121312141213121:1213121412131215121312141213121612131214121312151213121412131217121312141213121512131214121312161213121412131215121312141213121812131214121312151213121412131216121312141213121512131214121312171213121412131215121312141213121612131214121312151213121412131219121312141213121512131214121312161213121412131215121312141213121712131214121312151213121412131216121312141213121512131214121312181213121412131215121312141213121612131214121312151213121412131217121312141213121512131214121312161213121";
main(){
	read(0,buf,5);
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	for(;i++<N;)for(j=i;j++<N;)
	{
		out[outsz++]=fs[i^j];
		out[outsz++]='\n';
	}
	write(1,out,outsz);
}

Measured memory_bytes: 640
var perm=[];
var flag=[];
for(var i=0;i<4;i++)flag[i]=false;
var cnt=0;
for(var i=0;i<4;i++){flag[i]=true;
for(var ii=0;ii<4;ii++){if(flag[ii])continue;flag[ii]=true;
for(var iii=0;iii<4;iii++){if(flag[iii])continue;flag[iii]=true;
for(var iiii=0;iiii<4;iiii++){if(flag[iiii])continue;
perm[cnt]=[i,ii,iii,iiii];
cnt++;
}flag[iii]=false;
}flag[ii]=false;
}flag[i]=false;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
 
var Arr=(input.trim()).split("\n");
while(true){
var abcd=Arr.shift();
if(abcd=="0 0 0 0")break;
var ary=abcd.split(" ").map(Number);
var ans=0;
var s=["+","-","*"];
for(var i=0;i<3;i++){
for(var j=0;j<3;j++){
for(var k=0;k<3;k++){
perm.forEach(function(v){
var a=ary[v[0]];
var b=ary[v[1]];
var c=ary[v[2]];
var d=ary[v[3]];
if(ans==0 && eval(a+s[i]+b+s[j]+c+s[k]+d)==10)ans=a+s[i]+b+s[j]+c+s[k]+d;
if(ans==0 && eval("("+a+s[i]+b+s[j]+c+")"+s[k]+d)==10)ans="("+a+s[i]+b+s[j]+c+")"+s[k]+d;
if(ans==0 && eval("("+a+s[i]+b+")"+s[j]+"("+c+s[k]+d+")")==10)ans="("+a+s[i]+b+")"+s[j]+"("+c+s[k]+d+")";
if(ans==0 && eval("("+"("+a+s[i]+b+")"+s[j]+c+")"+s[k]+d)==10)ans="("+"("+a+s[i]+b+")"+s[j]+c+")"+s[k]+d;
});
}
}
}
 
console.log(ans);
}

Measured memory_bytes: 26812
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e9+1;

int main(){
    ll a,b;
    cin >> a >> b;
    if(a*b%2==0){
        cout << "Even" << endl;
    }
    else{
        cout << "Odd" << endl;
    }
    return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

string n;
ll k;

ll dp[105][4][2];

void solve(){
 cin >> n >> k;
 ll l=n.size();

  
  dp[0][0][0]=1;
  
  rep(i,0,l){
   rep(j,0,4){
    rep(m,0,2){
      ll nd=n[i]-'0';
      rep(d,0,10){
       ll nj=j,nm=m;
       if(d!=0) nj++;
       if(nj>k) continue; 
       if(m==0){ 
        if(d>nd) continue;
        if(d<nd) nm=1; 
       }
       dp[i+1][nj][nm]+=dp[i][j][m]; 
      }
    }
   }
  }
 cout << dp[l][k][0]+dp[l][k][1] << endl;
}

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

Measured memory_bytes: 256
#include "iostream"
#include "string"


int main()
{
	int n;
	std::cin >> n;
	int i = 1;

	for (; i <= n; i++) {
		if (i % 3 == 0)
				std::cout << " " << i;
		else {
			int temp = i;
			for (; temp >= 3;) {
				if (temp % 10 == 3) {
					std::cout << " " << i;
					break;
				}
				else
					temp /= 10;
			}
		}
	}

	std::cout << std::endl;
	return 0;
}

Measured memory_bytes: 3080
#include<stdio.h>
int a(int n){
  if(n<=111) return 111;
  if(n<=222) return 222;
  if(n<=333) return 333;
  if(n<=444) return 444;
  if(n<=555) return 555;
  if(n<=666) return 666;
  if(n<=777) return 777;
  if(n<=888) return 888;
  if(n<=999) return 999;
}
int main(){
  int N;
  scanf("%d",&N);
  printf("%d",a(N));
}


Measured memory_bytes: 128
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
vector<long long> tea;
int main() {
	iostream::sync_with_stdio(false);
	long long n;
	cin >> n;
	REP(i, n) {
		long long a;
		cin >> a;
		tea.push_back(a);
	}
	long long ans = 0;
	for (long long C = 1; C <= n - 1; C++) {
		long long tmp = 0;
		long long l = 0, r = n - 1;
		if ((n - 1) % C == 0) {
			while (l < r) {
				tmp += tea[l] + tea[r];
				ans = max(ans, tmp);
				l += C;
				r -= C;
			}
		}
		else {
			while (l + C < n - 1) {
				tmp += tea[l] + tea[r];
				ans = max(ans, tmp);
				l += C;
				r -= C;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

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

int w, h;
int c[55][55];

void dfs(int i, int j) {
    if(c[i][j] == 0) return;
    
    c[i][j] = 0;
    dfs(i-1, j-1);
    dfs(i-1, j);
    dfs(i-1, j+1);
    dfs(i  , j-1);
    dfs(i  , j+1);
    dfs(i+1, j-1);
    dfs(i+1, j);
    dfs(i+1, j+1);
}

int main() {
	while(1) {
	    cin >> w >> h;
	    if(w == 0 && h == 0) break;
	    
	    rep(i, h) rep(j, w) cin >> c[i+1][j+1];
	    
	    int ans = 0;
	    rep(i, h) {
	        rep(j, w) {
	            if(c[i+1][j+1] == 0) continue;
	            dfs(i+1, j+1);
	            ans++;
	        }
	    }
	    cout << ans << endl;
	}
}



Measured memory_bytes: 3108
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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)*}
    };
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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")
    };
}

macro_rules! chmax {
    ($x:expr, $e:expr) => {
        if $x < $e {
            $x = $e;
        }
    };
}
macro_rules! chmin {
    ($x:expr, $e:expr) => {
        if $x > $e {
            $x = $e;
        }
    };
}

const INF: i64 = 1 << 60;

fn main() {
    input!{
        N: usize,
        K: usize,
        R: usize,
        S: usize,
        P: usize,
        T: chars,
    }
    let mut ts = vec![Vec::new(); K];
    for i in 0..N {
        ts[i%K].push(T[i]);
    }
    let mut ans = 0;
    for i in 0..K {
        let t = &ts[i];
        let l = t.len();
        let mut dp = vec![vec![0; 3]; l+1];
        for i in 0..l {
            for h in 0..3 {
                if h == 0 {
                    chmax!(dp[i+1][h], dp[i][1]);
                    chmax!(dp[i+1][h], dp[i][2]);
                    if t[i] == 's' {
                        dp[i+1][h] += R;
                    }
                } else if h == 1 {
                    chmax!(dp[i+1][h], dp[i][0]);
                    chmax!(dp[i+1][h], dp[i][2]);
                    if t[i] == 'p' {
                        dp[i+1][h] += S;
                    }
                } else if h == 2 {
                    chmax!(dp[i+1][h], dp[i][0]);
                    chmax!(dp[i+1][h], dp[i][1]);
                    if t[i] == 'r' {
                        dp[i+1][h] += P;
                    }
                }
            }
        }
        ans += dp[l].iter().map(|&i| i).max().unwrap();
    }
    println!("{}", ans);
}


Measured memory_bytes: 12540
#[allow(unused_imports)]
use std::cmp::*;

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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


fn main() {
    // n
    // v_1 v_2 ... v_n
    input!{
        n: usize,
        m: usize,
        a: [usize; n],
    }

    let sum = a.iter().sum::<usize>();
    let cnt = a.iter().filter(|&e| e * 4 * m >= sum).count();
    let ans =
        if cnt >= m {"Yes"}
    else {"No"};
    println!("{}", ans);
}


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

int main(){
    int n;
    cin >> n;
    int arr[n];
    for(int i = 0;i< n;i++)
    {
        cin >> arr[i];
    }
    int ans = 0;
    for(int i = 0; i< n; i++)
    {
        if(arr[i] % 2 == 1 && i%2 == 0)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, x;
	int minv = INF;
	cin >> n >> x;
	int ans = n;
	while (n--)
	{
		int y;
		cin >> y;
		x -= y;
		minv = min(minv, y);
	}
	cout << ans + x / minv << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m,f[1010][1010];
char s[1010][1010];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	scanf("%s",s[i]+1);
	memset(f,0x3f,sizeof(f));
	f[1][1]=s[1][1]=='#';
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(i!=1) f[i][j]=min(f[i-1][j]+(s[i-1][j]=='.'&&s[i][j]=='#'),f[i][j]);
			if(j!=1) f[i][j]=min(f[i][j-1]+(s[i][j-1]=='.'&&s[i][j]=='#'),f[i][j]);
		}
	printf("%d\n",f[n][m]);
	return 0;
}

Measured memory_bytes: 4352
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

ll bit[200000*2], n;

ll sum(ll i){
  ll s = 0;
  while(i>0){
    s += bit[i];
    i-=i&-i;
  }
  return s;
}

void add(ll i, ll x){
  while(i<=n){
    bit[i] += x;
    i += i&-i;
  }
}

int main(){
  cin >> n;
  ll a[n];
  vector<ll> a_vec;
  REP(i,n){
    cin >> a[i];
    a_vec.push_back(a[i]);
  }
  ll b[n];
  sort(a_vec.begin(),a_vec.end());
  REP(i,n){
    b[i] = lower_bound(a_vec.begin(),a_vec.end(),a[i])-a_vec.begin() + 1;
  }
  ll ans = 0;
  REP(j,n){
    ans += j-sum(b[j]);
    add(b[j],1);
  }
  cout << ans << endl;
  return 0;
}



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

int main() {

  int N, X;
  cin >> N;
  string S;
  X = 0;
  for (int i = 0;i < N;i++){
   cin >> S;
    if(S == "Y"){
    X++;
    }
  }
  if(X == 0){
  cout << "Three" << endl;
  }else{
  cout << "Four" << endl;
  }
    
}

Measured memory_bytes: 3584
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

sumA = sum(As)
for i in range(N):
    num = min(As[i], Bs[i])
    As[i] -= num
    Bs[i] -= num
    num = min(As[i+1], Bs[i])
    As[i+1] -= num
    Bs[i] -= num

ans = sumA - sum(As)
print(ans)


Measured memory_bytes: 18624
h,n=map(int, input().split()) 
ab=[list(map(int, input().split())) for _ in range(n)] 

INF = 10**18
dp = [INF]*(h+1)
#dp[i]: hpがiの相手に消費する魔力の最小値
dp[0]=0

for i in range(h):#i:累積ダメージi
    for j in range(n):#
        if i+ab[j][0]<=h: #
            dp[i+ab[j][0]]=min(dp[i+ab[j][0]],dp[i]+ab[j][1])
        else:
            dp[-1]=min(dp[-1],dp[i]+ab[j][1])
print(dp[-1])

Measured memory_bytes: 42220
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n<0)break;
    char s[10][10]={"0111111","0000110",
                    "1011011","1001111",
                    "1100110","1101101",
                    "1111101","0100111",
                    "1111111","1101111"};
    int d;
    cin>>d;
    cout<<s[d]<<endl;
    int b=d;
    rep(i,n-1){
      cin>>d;
      rep(j,7)
        if(s[b][j]==s[d][j])
          cout<<"0";
        else
          cout<<"1";
      cout<<endl;
      b=d;
    }
  }
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
struct edge {int to,costa,costb;};


signed main() {
int n;
cin>>n;
int a,k[60]={};
for(int i=0;i<n;i++){
    cin>>a;
    for(int j=0;j<60;j++)if(a&(1ll<<j))k[j]++;
}
int ans=0;
for(int i=0;i<60;i++){
    ans=(ans+ ((((1ll<<i)%MOD)*k[i])%MOD)*(n-k[i]))%MOD;
}
cout<<ans;


return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, ll> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

struct Edge {
    int to, cost;
};
typedef vector<vector<Edge>> Graph;

int main()
{
    ios::sync_with_stdio(false);

    int K; cin >> K;

    deque<PII> Q;
    set<int> vis;
    Q.emplace_front(1, 1);
    while (Q.size()) {
        PII p = Q.front(); Q.pop_front();
        int v = p.first, c = p.second;

        if (vis.count(v)) continue;
        vis.insert(v);

        if (v == 0) {
            cout << p.second << endl;
            break;
        }

        Q.emplace_back((v+1) % K, c + 1);
        Q.emplace_front((v*10) % K, c);
    }
}

Measured memory_bytes: 6656