akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input!{
        n: usize,
        p: [usize; n],
    }
    let mut cnt = 0;
    for i in 0..n {
        if i+1 != p[i] {
            cnt += 1;
        }
    }
    if cnt <= 2 {
        println!{"YES"};
    } else {
        println!("NO");
    }
}


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

using namespace std;
using ll = long long;

const int INF = 100000005;

int main() {
  int n;
  cin >> n;
  vector<int> as(n, INF);
  vector<int> bs(n - 1);
  rep(i, n - 1) { cin >> bs[i]; }
  for (int i = n - 2; 0 <= i; i--) {
    as[i + 1] = min(bs[i], as[i + 1]);
    as[i] = min(bs[i], as[i]);
  }
  int sum = 0;
  rep(i, n) { sum += as[i]; }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;
template <typename T>
void vecin(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
}
template <typename T>
void vecout(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n - 1; ++i)
    {
        cout << v[i] << " ";
    }
    cout << v[n - 1] << endl;
}

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    vector<vint> dist(h, vint(w, INF));
    REP(i, h)
    {
        cin >> s[i];
    }
    queue<pint> que;
    que.emplace(pint(0, 0));
    int dx[4]{1, 0, -1, 0}, dy[4]{0, 1, 0, -1};
    dist[0][0] = 0;
    while (que.size())
    {
        pint now = que.front();
        que.pop();
        if (now == pint(h-1,w-1))
            break;
        REP(i, 4)
        {
            pint nxy = make_pair(now.FI + dy[i], now.SE + dx[i]);
            if (nxy.FI < 0 || nxy.FI > h-1 || nxy.SE <0 || nxy.SE > w-1){
                continue;
            }
            if (s[nxy.FI][nxy.SE] == '.' && dist[nxy.FI][nxy.SE] == INF){
                dist[nxy.FI][nxy.SE] = dist[now.FI][now.SE] + 1;
                que.emplace(nxy);
            }
        }
    }
    int tot = 0;
    REP(i, h)
    {
        REP(j,w){
            if (s[i][j] == '.')
                ++tot;
        }
    }
    if (dist[h-1][w-1] == INF){
        cout << -1 << endl;
    }else{
        cout << tot - dist[h - 1][w - 1] - 1 << endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;

class Program
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int[] a = new int[N];
        int[] b = new int[N];
        int[] c = new int[N];

        for (int i = 0; i < N; i++)
        {
            string[] Input = Console.ReadLine().Split(' ');
            a[i] = int.Parse(Input[0]);
            b[i] = int.Parse(Input[1]);
            c[i] = int.Parse(Input[2]);

        }

        //DPテーブル
        int[,] dp = new int[N, 3];

        //入力完了

        //        dp[0] = 0;
        //        dp[1] = Math.Abs(h[1] - h[0]);

        dp[0, 0] = a[0];
        dp[0, 1] = b[0];
        dp[0, 2] = c[0];

        for (int i = 1; i < N; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (j == 0)
                {
                    dp[i, j] = a[i] + max(dp[i - 1, 1], dp[i - 1, 2]);
                }
                else if (j == 1)
                {
                    dp[i, j] = b[i] + max(dp[i - 1, 0], dp[i - 1, 2]);
                }
                else if (j == 2)
                {
                    dp[i, j] = c[i] + max(dp[i - 1, 0], dp[i - 1, 1]);
                }
            }
        }

        int Answer = 0;
        for (int i = 0; i < 3; i++)
        {
            Answer = max(Answer, dp[N - 1, i]);
        }
        Console.WriteLine(Answer);
    }

    static int max(int a, int b)
    {
        return a > b ? a : b;
    }
}

Measured memory_bytes: 17344
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

int main()
{
	int a[3];
	for(int i = 0; i < 3; i++)
	{
		cin >> a[i];
	}
	sort(a,a+3);
	if (a[0]==5&&a[1]==5&&a[2]==7)
	{
		cout << "YES" << endl;
	}else
	{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;

        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next(){
            while(st==null || !st.hasMoreElements()){
                try{
                    st=new StringTokenizer(br.readLine());
                }
                catch(IOException e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt(){
            return Integer.parseInt(next());
        }

        Long nextLong(){
            return Long.parseLong(next());
        }

        double nextDouble(){
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str="";
            try{
                str=br.readLine();
            }
            catch(IOException e){
                e.printStackTrace();
            }
            return str;
        }
    }
    public static void main(String[] args) throws IOException {
       FastReader in = new FastReader();
       int n = in.nextInt();
       int m=in.nextInt();
       long sum=0;
       for(int i=0;i<m;i++){
           sum+=in.nextInt();
       }
       if(sum>n){
           System.out.println(-1);
       }else{
           System.out.println(n-sum);
       }
    }
}


Measured memory_bytes: 33936
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}
template<class T>istream&operator>(istream&i,T&t){return i>>t;}
#ifndef LOCAL
struct ostdmy{
template<class T>ostdmy&operator<<(const T&t){return*this;}
template<class T>ostdmy&operator<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n,k;
    cin>n>k;
    string s;
    cin>s;
    s[k-1]=tolower(s[k-1]);
    cout<s;
    return 0;
}


Measured memory_bytes: 256
N,M=gets.split.map(&:to_i)
a=gets.split.map(&:to_i).sort
BC=M.times.map{gets.split.map(&:to_i)}.sort_by{|a|-a[1]}

ans = 0
BC.each do |b,c|
    #t = a.bsearch_index{|x| x>c} || N
    #t = b if t > b
    t = a[0, b].index {|x| x >= c } || [b, a.size].min

    break if t == 0
    ans += c*t
    a.shift(t)
end

puts ans + (a.inject(:+) || 0)


Measured memory_bytes: 21024
import sys
input = sys.stdin.readline
from pprint import pprint
N, M = map(int, input().split())
A = [-1]*M
B = [-1]*M
C = [-1]*M

for i in range(M):
    A[i], B[i] = map(int, input().split())
    ls = list(map(int, input().split()))
    c = 0
    for j in range(len(ls)):
        c += 2 ** (ls[j]-1)
    C[i] = c


dp = [[float('inf')]*(2**N) for _ in range(M)]

j = 0
for i, di in enumerate(C):
    if i == 0:
        dp[i][di] = A[i]
        dp[i][0] = 0
        continue
    for j in range(2**N):
        stay = dp[i - 1][j | di]
        buy = dp[i - 1][j] + A[i]
        now = dp[i][j | di]
        dp[i][j | di] = min(stay, buy, now)
    for j in range(2**N):
        dp[i][j] = min(dp[i][j], dp[i-1][j])

ans = dp[-1][2**N-1]
if ans > sum(A):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 133128
def maxProf2(n, a):
    init = True
    for i in range(1, n):
        if init:
            vmin = min(a[:i])
            vmax = a[i]
            diffmax = vmax - vmin
            init = False
            continue
        vmin = min(vmin, a[i-1])
        diffmax = max(diffmax, a[i]-vmin)
    print(diffmax)
    return

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
maxProf2(n, a)



Measured memory_bytes: 13592
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl;


int main(){
  long long n,m;
  cin >> n>>m;
  m=m*2+1;
  if(n%m==0)
    cout << n/m;
  else{
    cout << n/m+1;
  }
}

Measured memory_bytes: 256
// vim: ts=2 sw=2 sts=2
#include <bits/stdc++.h>
using namespace std;

int main() {
  int x = 0, fx = 0;
  int n;

  cin >> n;
  x = n;

  while (n > 0) {
    fx += n % 10;
    n /= 10;
  }

  if (x % fx == 0)
    cout << "Yes" << endl;
  else
    cout << "No"  << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e5 + 50;
const int INF = 1e9;

int w[MAXN], val[MAXN];
int dp[150][MAXN];
int cap, n;

int solve(int id, int restou)
{
	if(id == n or restou < 0) return 0;
	if(dp[id][restou] != -1) return dp[id][restou];
	int ans = -1;
	int n_esc = solve(id+1, restou);
	if(restou - w[id] >= 0)
	{
		int esc = solve(id+1, restou - w[id]);
		return dp[id][restou] = max(n_esc, esc+val[id]);
	}
	
	return dp[id][restou] = max(ans, n_esc);
}



int32_t main()
{
	cin >> n >> cap;
	for(int i = 0; i < n; i++)
		cin >> w[i] >> val[i];
	memset(dp, -1, sizeof dp);
	cout << solve(0, cap) << '\n';
}

Measured memory_bytes: 119040
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <limits>
using namespace std;

double inf = numeric_limits<double>::infinity();

int main() {
    long a = 0, b = 0, c = 0, d = 0;
    long MOD = 1e9 + 7;
    
    long n, m;
    cin >> n >> m;
    
    long x, y;
    for (long i = 0; i < n; i++) {
        cin >> x;
        a += i * x;
        a %= MOD;
        b += (n - 1 - i) * x;
        b %= MOD;
    }
    a = a - b;
    
    for (long i = 0; i < m; i++) {
        cin >> y;
        c += i * y;
        c %= MOD;
        d += (m - 1 - i) * y;
        d %= MOD;
    }
    c = c - d;
    
    cout << (a * c % MOD + MOD) % MOD << endl;
}


Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) REV(SORT(V)) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) for(int i = 0; i < (V).size(); i++) {cout << (V).at(i) << endl;}

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,x,y,z;
double d,e,f;
string s,t;
//

signed main() {
  RAPID;
  IN2(n,x);
  FOR(i,(x-n+1),(x+n)) {
    cout << i << " ";
  }
  cout << endl;
}

Measured memory_bytes: 256
K = int(input())
A, B = map(int, input().split())

count = 0
for i in range(1, 1001):
    a = i * K
    if A <= a:
        if a <= B:
            count += 1
    else:
        pass
if count >= 1:
    print("OK")
else:
    print("NG")

Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main (void) {
    vector<string> words;
    vector<int> count;
    int N = 0;
    while (1) {
        string w;
        cin >> w;
        if (cin.eof()) break;
        int index = 0;
        while (index < N && words[index] != w) index++;
        if (index == N) {
            words.push_back(w);
            count.push_back(1);
            N++;
        } else {
            count[index]++;
        }
    }
    string frequent;
    string longest;
    int freq = 0, size = 0, s;
    for (int i = 0; i < N; i++) {
        if (count[i] > freq) {
            freq = count[i];
            frequent = words[i];
        }
        s = words[i].size();
        if (s > size) {
            size = s;
            longest = words[i];
        }
    }
    cout << frequent << ' ' << longest << endl;
    return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <cstdio>
using namespace std;
int a[1000];
int main()
{
    int n,m,x;
    scanf("%d%d%d",&n,&m,&x);
    for(int i = 0; i < m; i++)
    {
        int tem;
        scanf("%d",&tem);
        a[tem] = 1;
    }
    int zuo = 0,you = 0;
    for(int i = x; i >= 0; i--)
        zuo += a[i];
    for(int i = x; i <= n; i++)
        you += a[i];
        printf("%d\n",zuo < you ? zuo : you);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int e;
int x,y,z;
int main(){
  while(true){
    cin>>e;
    int ans=1000000;
    if(e==0) break;
    for(int z=0;z*z*z<=e;z++){
      for(int y=0;y*y+z*z*z<=e;y++){
        x=e-y*y-z*z*z;
        ans=min(ans,x+y+z);
          }
    }
    cout<<ans<<endl;
  }
}

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

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

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

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());


signed main()
{
    gearup;
    ll n; cin >> n;
    //ABを作る
    //末尾A、先頭Bを集める
    //AかつBをCと定義
    ll A,B,C;
    A = B = C =0;
    ll res = 0;
    rep(i,n){
        string s;
        cin >> s;
        ll m = s.size();
        rep(j,m-1){
            if(s[j] == 'A' && s[j+1] == 'B')res++;
        }
        if(s[0] == 'B' && s[m-1] == 'A')C++;
        else if(s[0] == 'B')B++;
        else if(s[m-1] == 'A')A++;
    }
    if(A+B == 0)res += max(0LL,C-1);
    else res += C + min(A,B);
    out(res);
}

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

int main() {
  int n, k;

  cin >> n >> k;

  long long ans = 1;
  ans *= k;
  for (int i = 0; i < n - 1; i++) {
    ans *= k - 1;
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

struct COM {
    vector<ll> inv, fac, finv;
    COM(int N) : inv(N), fac(N), finv(N) {
        inv[1] = 1;
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        for (int i = 2; i < N; ++i) {
            inv[i] = MOD - (MOD / i) * inv[MOD % i] % MOD;
            fac[i] = fac[i - 1] * i % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    ll calc(int a, int b) {
        return (fac[a] * finv[b] % MOD) * finv[a - b] % MOD;
    }
};

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

    int N, M;
    cin >> N >> M;
    COM com(M + 1);

    ll ans = (com.fac[M] * com.finv[M - N]) % MOD;
    ll tmp = 0;
    for (int i = 0; i <= N; ++i) {
        if (i & 1)
            tmp -= (com.fac[M - i] * com.calc(N, i)) % MOD;
        else
            tmp += (com.fac[M - i] * com.calc(N, i)) % MOD;
        tmp %= MOD;
    }
    (tmp *= com.finv[M - N]) %= MOD;

    (ans *= tmp) %= MOD;
    if (ans < 0)
        ans += MOD;
    cout << ans << endl;

    return 0;
}


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

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

using namespace std;

int dfs(int n)
{
  if (n < 6)
  {
    return n;
  }
  int a = 1;
  while (a <= n)
  {
    a *= 6;
  }
  a /= 6;
  int b = 1;
  while (b <= n)
  {
    b *= 9;
  }
  b /= 9;
  return 1 + min(dfs(n - a), dfs(n - b));
}

int main()
{
  int n;
  cin >> n;
  cout << dfs(n) << endl;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<vector>
using namespace std;
vector<int> adj_list[100005];
bool biper=true;
int check[100005]={0};
void DFS(int v){
	if(!biper){
		return;
	}
	for(int i=0; i<adj_list[v].size(); i++){
		if(check[adj_list[v][i]]==check[v]){
			biper=false;
			return;
		}else if(check[adj_list[v][i]]!=0){
			continue;
		}
		if(check[v]==1){
			check[adj_list[v][i]]=2;
			DFS(adj_list[v][i]);
		}else{
			check[adj_list[v][i]]=1;
			DFS(adj_list[v][i]);
		}
	}
	
}
int main(){
	long long int N, M;
	scanf("%lld %lld", &N, &M);
	for(int i=0; i<M; i++){
		int temp1, temp2;
		scanf("%d %d", &temp1, &temp2);
		temp1--;
		temp2--;
		adj_list[temp1].push_back(temp2);
		adj_list[temp2].push_back(temp1);
	}
	check[0]=1;
	DFS(0);
	if(!biper){
		printf("%lld", N*(N-1)/2-M);
	}else{
		long long int A=0;
		for(int i=0; i<N; i++){
			if(check[i]==1){
				A++;
			}
		}
		printf("%lld", A*(N-A)-M);
	}
}

Measured memory_bytes: 6528
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>
#include<iomanip>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
const llong MOD = 1000000007;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
int main() {
	int n;
	cin >> n;
	map<llong, llong> mp;
	VE vec(n);
	//int old_num = mp.size();
	REP(i, n) {
		cin >>vec[i];
		mp[vec[i]]++;
	}
	llong all_ans = 0;
	for (auto m : mp) {
		all_ans += (m.second * (m.second - 1)) / 2;
	}
	REP(i, n) {
		llong ans = all_ans - (mp[vec[i]] - 1);
		cout << ans << endl;
	}
	return 0;
}


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

#define N 100000
#define nil -1
#define WHITE 0
#define BLACK 1
#define INF 1<<21

typedef struct 
{
	int prev,next,cost;
}Edge;

int n,d[N];
Edge e[500000];

void dijkstra(int);

int main(){
	int i,j,u,k,c,ed=0,v,w=INF,r;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&u,&k);
		for(j=0;j<k;j++){
			e[ed].prev = u;
			scanf("%d%d",&e[ed].next,&e[ed].cost);
			ed++;
		}
	}

	dijkstra(ed);

	for(i=0;i<n;i++)printf("%d %d\n",i,d[i] );

		return 0;

}

void dijkstra(int edges){
	int i,flag;

	for(i=0;i<n;i++)d[i] = INF;
		d[0] = 0;

	flag = 1;
	while(flag!=0){
		flag = 0;
		for(i=0;i<edges;i++){
			if(e[i].cost+d[e[i].prev]<d[e[i].next]){
				d[e[i].next] = e[i].cost+d[e[i].prev];
				flag = 1;
			}
		}
	}
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 100005;
int N;
int H[MAX_N];

signed main()
{
  cin >> N;
  REP(n,N) {
    cin >> H[n];
  }

  int ans = 0;
  int tmp = 0;
  int preH = INF_LL;
  REP(n,N) {
    if(preH >= H[n]) {
      tmp++;
      preH = H[n];
    } else {
      ans = max(tmp, ans);
      preH = H[n];
      tmp = 1;
    }
  }
  
  cout << max(ans, tmp) - 1 << endl;

  return 0;
}


Measured memory_bytes: 1024
n = int(input())
ans = 0

for i in range(1, n+1):
  m = len(str(i))
  top = int(str(i)[0])
  bottom = i % 10
  counter = 0
  if bottom*top == 0:
    continue
  if top == bottom:
    counter += 1
  for j in range(1, 7):
    left = bottom*(10**j) + top
    right = bottom*(10**j) + top + 10**j - 10
 
    if n < left:
      break
    elif left <= n and n <= right:
      counter += (n - left) // 10 + 1
      break
    elif right < n:
      counter += 10**(j-1)
  ans += counter
  
print(ans)
    

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1e18;

int main(){
    int m;
    cin>>m;
    ll sum=0;
    ll dsum=0;
    for(int i=0;i<m;i++){
        ll d,c;
        cin>>d>>c;
        sum+=d*c;
        dsum+=c;
    }
    ll ans=dsum-1;
    while(sum>=10){
        ll t=sum/10;
        ans+=t;
        sum=t+sum%10;
    }
    cout<<ans<<endl;
}

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

using namespace std;
using ll = long long;

const string MIN = "-";

ll match[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
vector<string> dp(10010);

void chmax(string &a, string b) {
  if (a == MIN)
    a = b;
  else if (a.size() < b.size())
    a = b;
  else if (a.size() == b.size()) {
    if (a < b) a = b;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  for (int i = 0; i < M; i++)
    cin >> A[i];
  for (int i = 0; i < 10010; i++)
    dp[i] = MIN;
  dp[0] = "";
  for (int i = 0; i <= N; i++) {
    if (dp[i] == MIN) continue;
    for (auto a : A)
      chmax(dp[i + match[a]], dp[i] + (char)('0' + a));
  }
  cout << dp[N] << '\n';
  return 0;
}


Measured memory_bytes: 43648
import sys
sys.setrecursionlimit(10**8)
N=int(input())
G=[[] for i in range(N)]
F=[0 for i in range(N)]
A=[]
for i in range(N-1):
  a,b=map(int,input().split())
  a-=1;b-=1
  G[a].append(b)
  G[b].append(a)
  A.append([a,b])
  
def dfs(s,R):
  F[s]=1
  
  if s==N-1:
    return [s]
  else:
    for n in G[s]:
      if F[n]==0:
        k=dfs(n,R)
        if len(k)!=0:
          k.append(s)
          return k
     
  return []
  
root=dfs(0,[])
#print(root[::-1])
p=root[::-1][len(root)//2+len(root)%2-1]
q=root[::-1][len(root)//2+len(root)%2]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf = UnionFind(N) 
for i in range(N-1):
  a,b=map(int,A[i])
  if a==p and b==q:
    continue
  if a==q and b==p:
    continue
  uf.union(a, b)

scoreA=uf.size(0)
scoreB=N-scoreA
#print(scoreA,scoreB)

if scoreA>scoreB:
  print("Fennec")
else:
  print("Snuke")

Measured memory_bytes: 149864
N, D = map(int, input().split())

ans = 0
for i in range(N):
    x, y = map(int, input().split())
    # dist = pow((x * x + y * y), 0.5)
    dist = (x * x + y * y)
    
    # print(dist)
    if dist <= D*D:
        ans += 1

print(ans)


Measured memory_bytes: 9184
N, *AS = $stdin.read.split.map(&:to_i)

min_i = max_i = nil
min = Float::INFINITY
max = -Float::INFINITY
AS.each.with_index do |a, i|
  if a < min
    min, min_i = a, i
  end
  if a > max
    max, max_i = a, i
  end
end

if min.abs < max.abs
  puts( N + N-1 )
  N.times do |i|
    puts "#{max_i+1} #{i+1}"
  end
  (N-1).times do |i|
    puts "#{i+1} #{i+2}"
  end
else
  puts( N + N-1 )
  N.times do |i|
    puts "#{min_i+1} #{i+1}"
  end
  N.downto(2) do |i|
    puts "#{i} #{i-1}"
  end
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
const long double PI = acos(-1.0);
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define SORT(v) sort(ALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;

#define HOGE COUT("HOGE")

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
int main() {
    IN(int, n);
    int ma = INF;
    int ans = 0;
    REP(i, n){
        IN(int, k);
        if (chmin(ma, k)) {
            ans++;
        }
    }
    COUT(ans);
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)

//関数定義
//最大公約数
ll gcd(ll a, ll b);

//最小公倍数
ll lcm(ll a, ll b);

int main() {
  // ========================================================
  char c;
  cin >> c;
  cout << (char)(c + 1) << endl;
}

//最大公約数
ll gcd(ll a, ll b) {
  if (!b) return a;
  return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <cstdio>
using namespace std;

#define _USE_MATH_DEFINES

int main(void){
    double a, b, c;
    cin >> a >> b >> c;
    double h = b * sin(c * M_PI / 180.0);
    double s = a * h / 2;
    double l = a + b + sqrt(h*h + pow((a - b*cos(c * M_PI / 180.0)), 2));
    printf("%.8lf\n%.8lf\n%.8lf\n", s, l, h);
    
    return 0;
}

Measured memory_bytes: 3616
import sys

def calc(listA, listB):
    hit = 0
    for i, j in zip(listA, listB):
        if i == j:
            hit += 1
    brow = len(set(listA) & set(listB))
    return (hit, brow-hit)

listA = list()
listB = list()

for i, line in enumerate(sys.stdin.readlines()):
    line = line.strip()
    if i % 2 == 0:
        listA = map(int, line.split())
    else:
        listB = map(int, line.split())
        print "{0:d} {1:d}".format(*calc(listA, listB))

Measured memory_bytes: 5396
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

struct UnionFind {
	vector<int>d;

	UnionFind(int N) :d(N, -1){}

	int find(int x) {
		if (d[x] < 0)return x;
		return d[x] = find(d[x]);
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return false;
		if (d[x] > d[y])swap(x, y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return -d[find(x)];
	}
};

int main() {
	init();

	string s; cin >> s;
	vector<int>ans(s.size(), 0);
	int cnt = 0;
	rep(i, 0, s.size()) {
		if (s[i] == 'R')++cnt;
		else {
			ans[i-1] += (cnt + 1) / 2;
			ans[i] += cnt / 2;
			cnt = 0;
		}
	}
	cnt = 0;
	rREP(i, 0, s.size()) {
		if (s[i] == 'L')++cnt;
		else {
			ans[i] += cnt / 2;
			ans[i+1] += (cnt + 1) / 2;
			cnt = 0;
		}
	}
	rep(i, 0, s.size()) {
		cout << ans[i] << (i == s.size() - 1 ? "\n" : " ");
	}

	return 0;
}

Measured memory_bytes: 1104
from queue import deque
from math import ceil

h, w, k = map(int, input().split())

rooms = [None] * h
for i in range(h):
    row = input().strip()
    rooms[i] = row
    if 'S' in row:
        s = (i, row.index('S'))


def generate_neighbors(i, j):
    for ni, nj in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]:
        if rooms[ni][nj] == '.':
            yield ni, nj


def get_dist_to_exit(i, j):
    return min(i, h - i - 1, j, w - j - 1)


def first_bws():
    visited = {s}
    queue = deque((1, ij) for ij in generate_neighbors(*s))
    min_exit = get_dist_to_exit(*s)
    while queue:
        dist, ij = queue.popleft()
        if dist > k:
            break
        if ij in visited:
            continue
        i, j = ij
        tmp_min_exit = get_dist_to_exit(i, j)
        if tmp_min_exit == 0:
            return 0
        min_exit = min(min_exit, tmp_min_exit)
        visited.add(ij)
        queue.extend((dist + 1, nij) for nij in generate_neighbors(i, j) if nij not in visited)
    return min_exit


dist_to_exit = first_bws()
print(ceil(dist_to_exit / k) + 1)


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

int main() {
  long n, a, b, t;
  cin>>n>>a>>b;
  if ((b-a) % 2 != 0) {
    t = min(b-1, n-a);
    if ((b-1) < (n-a)) {
      t = min(t, (a+b-1)/2);
    }
    else {
      t = min(t, ((2*n-a-b+1)/2));
    }
  }
  else {
    t = (b-a)/2;
  }
  cout<<t<<endl;
}

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

int main() {
  int A,B;
  scanf("%d %d",&A,&B);
  
  int add,sub,mul,ans;
  add = A+B;
  sub = A-B;
  mul = A*B;
  if(add > sub){
    if(add > mul){
      ans = add;
    }
    else{
      ans = mul;
    }
  }
  else{
    if(sub > mul){
      ans = sub;
    }
    else{
      ans = mul;
    }
  }
  
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int x,y,s;
  int i,j;
  int maximum=0;

  while(1){
    maximum=0;
    scanf("%d %d %d",&x,&y,&s);
  if(x==0||y==0||s==0)
    break;
  for(i=1;i<s;i++){
    for(j=i;j<s;j++){
      if(tax(x,i)+tax(x,j) == s)
	maximum= max(maximum,tax(y,i)+tax(y,j));
	  }
  }printf("%d\n",maximum);
  }
  return 0;
}

int tax(int a,int b){
  int c;
  c=(a+100)*b/100;
  return c;
}

int max(int e,int f){
  int g;
  if(e<f){
    return f;
  }else
    return e;
}

Measured memory_bytes: 600
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long A, long B, long K) {
    return iota(max(A, B), 0, -1).filter!(i => A % i == 0 && B % i == 0).drop(K - 1).front;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long A;
    A = input.front.to!long;
    input.popFront;

    long B;
    B = input.front.to!long;
    input.popFront;

    long K;
    K = input.front.to!long;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(A, B, K);
    else
        solve(A, B, K).writeln;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <set>
using namespace std;
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

using ll = long long int;

struct Ele {
  ll sum;
  int ai, bi, ci;
  Ele(ll sum_, int ai_, int bi_, int ci_) {
    this->sum = sum_;
    this->ai = ai_;
    this->bi = bi_;
    this->ci = ci_;
  }
};

bool operator<(const Ele &x, const Ele &y) { return x.sum < y.sum; };

int main(void) {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x);
  vector<ll> b(y);
  vector<ll> c(z);
  vector<ll> sum;
  for (int i = 0; i < x; i++)
    cin >> a[i];
  for (int i = 0; i < y; i++)
    cin >> b[i];
  for (int i = 0; i < z; i++)
    cin >> c[i];

  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());
  sort(c.begin(), c.end(), greater<ll>());

  Ele xx = Ele(a[0]+b[0]+c[0], 0, 0, 0);
  priority_queue<Ele> pq;
  set<pair<pair<ll, ll>, ll>> s;
  
  pq.push(xx);
  int cnt = 0;
  while(cnt < k) {
    Ele e = pq.top();
    pq.pop();
    pair<pair<ll, ll>, ll> p = make_pair(make_pair(e.ai, e.bi), e.ci);
    if(s.find(p)!=s.end())
      continue;
    s.insert(p);
    cnt++;
    std::cout << e.sum << std::endl;
    if(e.ai+1 < x) {
      Ele e1 = Ele(e.sum-a[e.ai]+a[e.ai+1], e.ai+1, e.bi, e.ci);
      pq.push(e1);
    }
    if(e.bi+1 < y) {
      Ele e2 = Ele(e.sum-b[e.bi]+b[e.bi+1], e.ai, e.bi+1, e.ci);
      pq.push(e2);
    }
    if(e.ci+1 < z) {
      Ele e3 = Ele(e.sum-c[e.ci]+c[e.ci+1], e.ai, e.bi, e.ci+1);
      pq.push(e3);
    }
  }

  return 0;
}
/*
 * a1, a2, ..., ax
 * b1, b2, ..., by
 * c1, c2, ..., cz
 *
 * 6 4
 * 5 1
 * 8 3
 *
 * 6+5+8
 * 4+5+8
 *
 */


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define debug(x) cerr<<#x<<": "<<x<<endl;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)



int main() {
	int X;
  	cin>>X;
  
  	if(X>=30) cout<<"Yes"<<endl;
  	else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>

#define rep(i,p) for(long long int i=0;i<p;i++)
#define reep(i,p) for(long long int i=1;i<=p;i++)
#define ll long long

using namespace std;

int main(){

ll int N;
ll int ans=0;

cin >> N;
vector<ll int > A(N),B(N),C(N);
rep(i,N){
	cin >> A[i];
}
rep(i,N){
	cin >> B[i];
}
rep(i,N-1){
	cin >> C[i];
}


rep(i,N){
	ans += B[A[i]-1];


	if(i!=0){
		if(A[i-1]+1 == A[i]){
			ans += C[A[i-1]-1];
		}
		else{}
	}
	else{}
//cout << B[A[i]-1] << endl;
}
cout << ans << endl;






	return 0;

}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main()
{
    ll n{},k{},q{};
    cin>>n>>k>>q;
    ll temp = k-q;
    ll A[n]{};
    for(ll i=0;i<n;i++){
        A[i] = temp;
    }
    while(q--){
        ll p{};
        cin>>p;
        A[p-1]++;
    }
    for(ll i=0;i<n;i++){
        if(A[i]<=0){
            cout<<"No"<<endl;
        }
        else{
            cout<<"Yes"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int n,d;
int main(){
    cin>>n>>d;int x[n][d];for(int i=0;i<n;i++){for(int j=0;j<d;j++)cin>>x[i][j];}
    int cnt=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
          int ans=0;
          for(int k=0;k<d;k++){
            ans+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
          }
          double d=sqrt(ans);
                if(floor(d)==d)cnt++;
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
/*
   Created by Rahul Goel.
*/

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1e9;
const ll LINF = 1e18;

#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(c) (c).begin(), (c).end()
#define pii pair < ll, ll >
#define vi vector < ll >
#define vb vector < bool >
#define vvi vector < vector < ll > >
#define vvb vector < vector < bool > >
#define vpii vector < pair < ll, ll > >
#define vvpii vector < vector < pair < ll, ll > > >
#define present(c,x) ((c).find(x) != (c).end())//for sets,maps,multimaps
#define cpresent(c,x) (find(all(c),x) != (c).end())//for vectors
#define min_pq(t) priority_queue < t, vector < t >, greater < t > >
#define max_pq(t) priority_queue < t >
#define pb push_back
#define ff first
#define ss second

ll mod_sum() { return 0ll; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

ll mod_prod() { return 1ll; }
template<typename T, typename... Args>
T mod_product(T a, Args... args) { return (a*mod_product(args...))%mod; }

// --------------------------------------------------------------

ll solve(){
    string s, t;
    cin >> s >> t;
    string k = t.substr(0, s.size());
    if(k == s)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

int main(){
    fastio;

    ll t = 1;
    while(t--)
        solve();

    return 0;
}



Measured memory_bytes: 3644
import sys

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


H, W, K = MI()
S = [None] * H
empty = set()
padding = [(0, 0)] * H
pad = 0
for i in range(H):
    S[i] = list(input())
    if all(c == '.' for c in S[i]):
        empty.add(i)
        pad += 1
    else:
        padding[i] = (pad, 0)
        pad = 0
if pad > 0:
    up, _ = padding[-pad - 1]
    padding[-pad - 1] = (up, pad)

color = 1
ans = [[0] * W for _ in range(H)]
for i in range(H):
    if i in empty:
        continue
    up, lp = padding[i]
    last = 0
    for j in range(W):
        if S[i][j] == '#':
            for x in range(last, j + 1):
                for y in range(-up, lp + 1):
                    ans[i + y][x] = color
            color += 1
            last = j + 1
    if S[i][-1] == '.':
        for x in range(last, W):
            for y in range(-up, lp + 1):
                ans[i + y][x] = color - 1

for l in ans:
    print(' '.join(str(c) for c in l))



Measured memory_bytes: 49884
{-# LANGUAGE ViewPatterns #-}
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLn >>= main'
    where
        main' n = replicateM 2 readLine >>= print . solve n

solve :: Int -> [[Int]] -> Int
solve n [as, bs] = check . foldl' ff (empty, 0, 0) $ zip as bs
    where
        check (pop -> Just (x, h), r, c)
            | r <= 0 = c
            | otherwise = check (h, r + x, c + 1) 
        check (_, r, c)
            | r > 0 = -1
            | otherwise = c

        ff (h, r, c) (a, b)
            | x < 0 = (push x h, r, c)
            | x > 0 = (h, r + x, c + 1)
            | otherwise = (h, r, c)
            where
                x = b - a

readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

data Heap a = E | T Int a (Heap a) (Heap a)
    deriving (Show)
    
empty :: Heap a 
empty = E

null :: Heap a -> Bool 
null E = True
null _ = False

merge :: (Ord a) => Heap a -> Heap a -> Heap a
merge lh@(T _ lv la lb) rh@(T _ rv ra rb)
    | lv <= rv = makeT lv la $ merge lb rh
    | otherwise = makeT rv ra $ merge lh rb
    where
        makeT v a b
            | rank a >= rank b = T (rank b + 1) v a b
            | otherwise = T (rank a + 1) v b a
        rank (T r _ _ _) = r
        rank _ = 0
        
merge lh E = lh
merge _ rh = rh

push :: (Ord a) => a -> Heap a -> Heap a
push x = merge (T 1 x E E)

pop :: (Ord a) => Heap a -> Maybe (a, Heap a) 
pop (T _ x a b) = Just (x, merge a b)
pop _ = Nothing

fromList :: (Ord a) => [a] -> Heap a
fromList = br . fmap (\x -> T 1 x E E)
    where
        build (x : y : zs) = merge x y : build zs
        build xs = xs
        br [x] = x
        br xs = br $ build xs

Measured memory_bytes: 12668
def main():
    n,a,b,c,d = map(int,input().split()) 
    s=list(input())
    for i in range(max(c,d)-a-1):
        if s[a+i-1]=="#" and s[a+i]=="#":
            print("No")
            return
    if c<d:
        print("Yes")
        return
    else:
        for i in range(d-b+1):
            if s[b+i-2]==s[b+i-1] and s[b+i-1] == s[b+i] and s[b+i]==".":
                print("Yes")
                return
        print("No")
main()

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

using namespace std;

typedef long long ll;

int const N = 8192;

int main() {
  ll n;
  cin >> n;
  ll l = 1;
  ll r = n;
  ll ans = n;

  while(l <= r) {
    ll m = l+r >> 1;
    ll x = m/2*11 + 6*(m&1);  
    if(x < n)
      l = m + 1;
    else
      r = m - 1, ans = m;
  }

  cout << ans;
}

Measured memory_bytes: 384