akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ln(a) cout << (a) << endl
#define debug(a, n) rep(hoge, n) printf("%d%c", a[hoge], hoge == (n) - 1? '\n' : ' ');
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 1e9
#define LINF 1e18

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

signed main() {
    int n;
    cin >> n;
    string* s = new string[n];
    int* t = new int[n];
    rep(i, n) cin >> s[i] >> t[i];

    string x;
    cin >> x;
    rep(i, n) {
        if(s[i] == x) {
            int ans = 0;
            for(int j = i + 1; j < n; j++) ans += t[j];
            ln(ans);
            return 0;
        }
    }
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
ans = 1
now = A[0]
flag = -1
for i in range(1, N):
    d = A[i] - now
    if d == 0:
        continue
    elif d > 0:
        if flag == 0:
            ans += 1
            flag = -1
        else:
            flag = 1
    else:
        if flag == 1:
            ans += 1
            flag = -1
        else:
            flag = 0
    now = A[i]
print(ans)

Measured memory_bytes: 14252
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> p;
typedef unsigned long long int ull;
const ll MOD=998244353;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;

int main(){
    int n,m;cin>>n>>m;
    vector<ii> c(n);
    for(int i=0;i<n;i++){
        int a,b;cin>>a>>b;
        c[i]=ii(a,b);
    } 
    sort(c.begin(),c.end());
    int i=0;
    int ans=0;
    priority_queue<int> que;
    for(int d=1;d<=m;d++){
        while(c[i].first<=d&&i<n){
            que.push(c[i].second);
            i++;
        }
        if(que.empty()) continue;
        int mx=que.top();que.pop();
        ans+=mx;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long
 
const int N = 2000001;
 
int n, k, fact[N], inv[N], mod = 1e9 + 7;
string s;
 
int powlog(int a, int b){
    if(b == 0) return 1;
    int ret = powlog(a, b / 2);
    if(b % 2) return 1LL * ret * ret % mod * a % mod;
    return 1LL * ret * ret % mod;
}
int C(int n, int r){
    if(r > n) return 0;
    return 1LL * fact[n] * inv[n - r] % mod * inv[r] % mod;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    fact[0] = 1;
    for(int i = 1 ; i < N ; i++){
        fact[i] = 1LL * i * fact[i - 1] % mod;
    }
    inv[N - 1] = powlog(fact[N - 1], mod - 2);
    for(int i = N - 2 ; i >= 0 ; i--){
        inv[i] = 1LL * (i + 1) * inv[i + 1] % mod;
    }
    cin >> k >> s;
    n = s.size();
    int ans = 0;
    for(int i = 0 ; i <= k ; i++){
        ans = (ans + 1LL * powlog(25, k - i) * powlog(26, i) % mod * C(n - 1 + k - i, n - 1)) % mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 19836
n = int(input())
h = list(map(int, input().split()))
ans = "Yes"
M = 0 #max
for i in range(n):
    if h[i]-1 >= M:
        M = h[i] - 1
    elif h[i] == M:
        continue
    else:
        ans = "No"
        break
print(ans)


Measured memory_bytes: 14396
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (a, b, c, d) = {
      let v: Vec<i64> = read_vec();
      (v[0], v[1], v[2], v[3])
    };

    if (a - c).abs() <= d || ((a - b).abs() <= d && (b - c).abs() <= d) {
      println!("Yes");
    } else {
      println!("No");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
using namespace std;

int main(){
  int n;
  string s;
  cin>>n>>s;
  string tmp="No";
  if(n%2==0 && s.substr(0,n/2)==s.substr(n/2,n)) tmp="Yes";
  cout<<tmp<<endl;
  return 0;
}

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<ll> mp(n + 1, 0), cta(n + 1, 0);
    vector<ll> a(m);
    vector<string> s(m);
    rep(i, 0, m)
    {
        cin >> a[i] >> s[i];
    }
    ll maru = 0;
    ll batu = 0;
    rep(i, 0, m)
    {
        if (mp[a[i]] == 0) //初採点の場合
        {
            if (s[i] == "AC")
                mp[a[i]] = 2;
            else if (s[i] == "WA")
                mp[a[i]] = 1, cta[a[i]]++;
        }
        else if (mp[a[i]] == 1) //2回目以降
        {
            if (s[i] == "AC")
                mp[a[i]] = 2;
            else
                cta[a[i]]++;
        }
    }
    rep(i, 0, n + 1) if (mp[i] == 2) maru++, batu += cta[i];
    cout << maru << " " << batu << endl;
}


Measured memory_bytes: 8556
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace touitsu {
    class Program {
        static void Main(string[] args) {

            var length = int.Parse(Console.ReadLine());

            var strA = Console.ReadLine().Trim().ToList();
            var strB = Console.ReadLine().Trim().ToList();
            var strC = Console.ReadLine().Trim().ToList();

            var count = 0;

            for (int i = 0; i < length; i++) {
                if (strA[i].CompareTo(strB[i]) == 0) {
                    if (strA[i].CompareTo(strC[i]) == 0) {
                        // 全一緒
                    }
                    else {
                        // A equal B not C
                        strC[i] = strA[i];
                        count++;
                    }
                }
                else {
                    // A not B
                    if (strA[i].CompareTo(strC[i]) == 0) {
                        // A = C / B
                        strB[i] = strA[i];
                        count++;
                    }
                    else {
                        // A / (B C)
                        if (strB[i].CompareTo(strC[i]) == 0) {
                            // A / B = C
                            strA[i] = strB[i];
                            count++;
                        }
                        else {
                            //　全部違う
                            strA[i] = strB[i] = strC[i];
                            count += 2;
                        }
                    }
                }
            }
            Console.WriteLine(count);
            // Console.ReadLine();
        }
    }
}


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

int main(){
  string s;
  cin >> s;

  int bi;
  rep(i,s.size()){
    if (s[i] == 'A'){
      bi = i;
      break;
    }
  }
  int ei;
  rep(i,s.size()){
    if (s[s.size() - 1 - i] == 'Z'){
      ei = s.size() - 1 - i;
      break;
    }
  }
  cout << ei - bi + 1 << endl;
  return 0;
}

Measured memory_bytes: 3732
import copy
H, W, K = map(int, input().split())
cs = [list(input()) for _ in range(H)]
# print(*cs)

def black_cnt(List):
  cnt = 0
  for c in List:
    cnt += c.count("#")
  return cnt

ans = 0

for i in range(2 ** (H+W)):
  cc = copy.deepcopy(cs)
  cnt = 0
  # print(bin(i))
  for j in range(H+W):
    if ((i >> j) & 1):
      if j < H:
        cc[j] = ["@"]*W
      else:
        for h in range(H):
          cc[h][j-H] = "@"
  # print(*cc)
  if black_cnt(cc) == K:
    # print("OK")
    ans += 1

print(ans)

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

int main() {
  long long a;
  double b;
  cin >>a>>b;
  long long ib=b*100+0.5;
  a*=ib;
  a/=100;
  printf("%lld\n",a);
  return 0;
}

    


Measured memory_bytes: 3772
H, W = map(int, input().split())

a = [input() for i in range(H)]

row = [False] * H
col = [False] * W

for i in range(H):
  for j in range(W):
    if a[i][j] == '#':
      row[i] = True
      col[j] = True

      
for i in range(H):
  if row[i]:
    for j in range(W):
      if col[j]:
        print(a[i][j], end='')
    print()
 

Measured memory_bytes: 4468
n = input().split()
X = int(n[0])
N = int(n[1])

try:
    n2 = input()
except:
    pass

if N == 0:
    print(X)

else:
    n2 = n2.split()
    p = [int(item) for item in n2]

    for i in range(101):
        if i == 0:
            if X not in p:
                print(X)
                break
        tmp = []

        if (X + i not in p ):
            tmp.append(X + i)

        if (X - i not in p ):
            tmp.append(X - i)
    
        if len(tmp)!=0:
            print(min(tmp))
            break


Measured memory_bytes: 9208
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        n:usize,x:usize,
        l:[usize;n],
    }
    let mut d = 0;
    let mut ans = 0;
    for i in 0..n {
        d = d + l[i];
        ans += 1;
        if d > x {
            break;
        }
        if i == n - 1 {
            ans = n + 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2172
/*	ex9_1
	suzuto	*/

#include <stdio.h>
#include <stdlib.h>
#define SIZE 10

typedef struct stack{ /*入力した文字をスタックとして重ねていくための構造体を作る*/
  int size;
  int count;
  char inp_str[SIZE];
  char *top;
}stack;

/*プロトタイプ宣言*/
void initialize_stack(stack *stack_ptr);
void push(stack *stack_ptr, char add_elem);
char pop(stack *stack_ptr);

int main(void){
  stack inp_stack, res_stack; /*変数の宣言*/
  char inp[SIZE + 1], ins;
  int i;

  initialize_stack(&inp_stack); /*inp_stackを初期化*/
  initialize_stack(&res_stack); /*res_stackを初期化*/

  scanf("%s", inp); /*入力内容を記憶*/

  for(i = 0; i < SIZE + 1; i++){
    ins = inp[i]; /*i + 1番目の入力取り出し*/
    if(ins == '\0'){ /*末尾の識別*/
      break;
    }
    if(ins == 'B'){ /*バックスペースの時、スタックから一番上=最後に入力した文字を取り出す*/
      pop(&inp_stack);
    }
    else{
      push(&inp_stack, ins); /*文字入力の時、スタックの一番上に追加*/
    }
  }

  while (inp_stack.count > 0){ /*inp_stackの中身を全て(逆順に)res_stackに移し替える*/
    push(&res_stack, pop(&inp_stack));
  }

  while (res_stack.count > 0){ /*res_stackの中身を上から順に取り出していって答えを出力*/
    putchar(pop(&res_stack));
  }
  printf("\n"); /*改行*/
  return 0;
}

void initialize_stack(stack *stack_ptr){ /*スタックを初期化する関数*/
  stack_ptr->count = 0; /*要素の数 = 0*/
  stack_ptr->size = SIZE;
  stack_ptr->top = &(stack_ptr->inp_str[SIZE]); /*スタックの底に頂点を合わせる*/
}

void push(stack *stack_ptr, char add_elem){ /*スタックに要素を追加する関数*/
  if(stack_ptr->count >= stack_ptr->size){ /*スタックをあふれた時のエラー出力*/
    fprintf(stderr, "Error: stack overflow.\n");
    exit(1);
  }else{ /*頂点の位置を1つ上げて、その位置に要素を積む*/
    stack_ptr->top--;
    *(stack_ptr->top) = add_elem;
    stack_ptr->count++;
  }
}

char pop(stack *stack_ptr){
  char output_elem;
  if(stack_ptr->count <= 0){ /*スタックの底が尽きている時には何も取り出さない*/
    return 'B'; /*意味のない仮の出力*/
  }else{ /*一番上の要素を取り出し、頂点を一個下げる*/
    output_elem = *(stack_ptr->top);
    stack_ptr->count--;
    stack_ptr->top++;
    return output_elem;
  }
}


Measured memory_bytes: 1632
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int inf=0x3f3f3f3f3f3f3f3f;
const int N=400;
int n;
int a[N+1];
int Sum[N+1];
int dp[N+1][N+1];
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i],Sum[i]=Sum[i-1]+a[i];
	for(int i=n;i;i--)for(int j=i+1;j<=n;j++){
		dp[i][j]=inf;
		for(int k=i;k<j;k++)
			dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+Sum[j]-Sum[i-1]);
	}
	cout<<dp[1][n];
	return 0;
}
/*1
4
10 20 30 40
*/
/*2
5
10 10 10 10 10
*/
/*3
3
1000000000 1000000000 1000000000
*/
/*4
6
7 6 8 6 1 1
*/

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
using namespace std;
 vector<int> v;
 
 void count(int b,int e,int k)
 {
     int res=0;
     for(int i=b;i<e;i++) 
     {
         if(v[i]==k) res++;
     }
     cout<<res<<endl;
 }
 
int main()
{
    int n;
   
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int z;
        cin>>z;
        v.push_back(z);
    }
    
    int q;
    cin>>q;
    for(int i=0;i<q;i++)
    {
        int b,e,k;
        cin>>b>>e>>k;
        count(b,e,k);
    }
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

ll cal(ll x){
    if(x%2==0){
        return (x/2)%2;
    }
    else {
        return cal(x-1)^(x-1);
    }
}

int main(){
    ll a,b;cin >>a>>b;
    ll ans=cal(b+1)^cal(a);
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter
import kotlin.math.max

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val H = nextIntList()
    var ans = 0L
    var tmp = 0L
    for (i in 0 until N - 1) {
        if (H[i] >= H[i + 1]) tmp++
        else {
            ans = max(ans, tmp)
            tmp = 0L
        }
    }
    ans = max(ans, tmp)
    println(ans)
}

Measured memory_bytes: 52064
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<vector<int> > a(n, vector<int>(n));
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                cin >> a[i][j];
            }
        }

        vector<vector<int> > b(m, vector<int>(m));
        for(int i=0; i<m; ++i){
            for(int j=0; j<m; ++j){
                cin >> b[i][j];
            }
        }

        int retY = -1;
        int retX = -1;

        for(int i=0; i<4; ++i){
            int dx = 0;
            while(b[0][dx] == -1)
                ++ dx;

            for(int y=0; y+m<=n; ++y){
                for(int x=0; x+m<=n; ++x){
                    bool ng = false;
                    for(int j=0; j<m; ++j){
                        for(int k=0; k<m; ++k){
                            if(b[j][k] != -1 && b[j][k] != a[y+j][x+k]){
                                ng = true;
                                break;
                            }
                        }
                        if(ng)
                            break;
                    }
                    if(!ng){
                        retY = y;
                        retX = x + dx;
                        break;
                    }
                    if(y == retY && x + dx == retX)
                        break;
                }
                if(y == retY)
                    break;
            }

            vector<vector<int> > c(m, vector<int>(m));
            for(int j=0; j<m; ++j){
                for(int k=0; k<m; ++k){
                    c[k][m-1-j] = b[j][k];
                }
            }
            b = c;
        }

        if(retY == -1)
            cout << "NA" << endl;
        else
            cout << (retX+1) << ' ' << (retY+1) << endl;
    }
}

Measured memory_bytes: 972
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
typedef long long ll;
int main(void){
  int i;
  int n;
  cin>>n;
  set<ll> a;
  ll ba;
  rep(i,n){cin>>ba;a.insert(ba);}
  if(a.size()==n)cout<<"YES";
  else cout<<"NO";
  return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int n;
long long f[400];
int main(){
    cin>>n;
    f[0]=2;
    for(int i=0;i<=n;i++)
    f[i]=f[i-1]*2+2;
    cout<<f[n]<<endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,vec) V vec(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a));reverse(all(a))
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define cont const auto
#define fi first
#define se second
#define V vector
#define P pair
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
#define PQ priority_queue
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<PL> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

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

  str s;
  cin>>s;
  int n=SZ(s)-1;
  int ans=0;
  for(int bit=0;bit<(1<<n);++bit){
    stack<char> stk;
    for(int show=0;show<n;++show){
      stk.push(s[n-show]);
      if((bit>>show)&1)stk.push('+');
    }
    stk.push(s[0]);
    ll res=0;
    while(!stk.empty()){
      if(stk.top()=='+'){
        ans+=res;
        res=0;
      }
      else{
        res*=10;
        res+=stk.top()-'0';
     }
      stk.pop();
    }
    ans+=res;
  }
  out(ans);
  
  
  
  
  return 0;
}



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

int main(){
  int N,K,X,Y; cin >> N >> K >> X >> Y;
  
  int ans = 0;
  for(int i = 1; i <= N; i++){
    if(i <= K) ans += X;
    if(K < i) ans += Y;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
a, b, c = [0] * N, [0] * N, [0] * N
for i in range(N):
	a[i], b[i], c[i] = map(int, input().split())
dp = [[0] * 3 for _ in range(N)]

dp[0] = [a[0], b[0], c[0]]
for i in range(N - 1):
	dp[i + 1][0] = max(dp[i][1] + a[i + 1], dp[i][2] + a[i + 1])
	dp[i + 1][1] = max(dp[i][0] + b[i + 1], dp[i][2] + b[i + 1])
	dp[i + 1][2] = max(dp[i][0] + c[i + 1], dp[i][1] + c[i + 1])
print(max(dp[N - 1]))

Measured memory_bytes: 61272
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int N; cin >> N;
    vi A(N); REP(i, N) cin >> A[i];

    map<int, int> mp;
    REP(i,N) {
        mp[A[i] - 1]++;
        mp[A[i]]++;
        mp[A[i] + 1]++;
    }

    int ans = 0;
    int x = 0;
    for(auto p : mp) {
        ans = max(ans, p.second);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5120
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)); //整数型のまま切り上げ演算する
#define PI 3.14159265359
#define MOD 1000000007
typedef long long LL;
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; }cout << endl; }
const LL LLINF = 1LL << 60;

int main(void) {
	LL N, M;
	cin >> N >> M;

	if (N == 1 and M == 1) {
		cout << 1 << endl;
	}
	else if (N == 1 and M != 1) {
		cout << abs(M - 2) << endl;
	}
	else {
		cout << abs(N - 2) * abs(M - 2) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
N = gets.to_i

f = []
N.times do |i|
  f << gets.split.map(&:to_i)
end

p = []
N.times do |i|
  p << gets.split.map(&:to_i)
end

ans = -(10**7)*N
# p ans

i = -1
[0, 1].repeated_permutation(10) do |a|
  i += 1
  next if i == 0
  # p a
  
  tmp = 0
  N.times do |j|
    
    cnt = 0
    10.times do |k|
      cnt += 1 if a[k] == 1 && f[j][k] == 1
    end
    
    # p cnt
    tmp += p[j][cnt]
    
  end
  # p a if ans < tmp
  ans = tmp if ans < tmp
end

puts ans

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

int main() {
  
  int k, a, b;
  cin >> k >> a >> b;
  
  int s = b / k;
  
  if (s * k >= a) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
  
}


Measured memory_bytes: 3628
//==========================================
// ABC139b
//
// 2019/09/01
//==========================================

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char* argv[])
{
  int a, b;
  cin >> a >> b;

  int k=1;
  int cnt=0;
  while(k < b)
  {
    k = k -1 + a;
    cnt++;
  }

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

ll gcd(const ll sx, const ll sy) {
    ll x = min(sx, sy);
    ll y = max(sx, sy);
    ll tmp;
    while (x > 0) {
        tmp = y;
        y = x;
        x = tmp % x;
    }
    return y;
}

ll lcm(const ll x, const ll y) {
    return x / gcd(x, y) * y;
}

int N;
vector<ll> as;

int main(void) {
    cin >> N;

    as.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> as[i];
    }

    // ll m = 1LL;
    // for (int i = 0; i < N; i++) {
    //     m = lcm(m, as[i]);
    // }
    // cout << m << endl;

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += as[i] - 1;
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
  int n, m, count;
  cin >> n >> m;
  vector<int> num(m * 2);
  
  for (int i = 0; i < m * 2; i++) {
    cin >> num.at(i);
  }
  
  for (int i = 0; i < n; i++) {
    count = 0;
    for (int j = 0; j < m * 2; j ++) {
      if (num.at(j) == i + 1) {
        count++;
      }
    }
    cout << count << endl;
  }
}



Measured memory_bytes: 256
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    x1, y1, x2, y2 = MI()
    x3 = x2 - y2 + y1
    y3 = y2 + x2 - x1
    x4 = x3 - x2 + x1
    y4 = y3 - y2 + y1
    print("{} {} {} {}".format(x3, y3, x4, y4))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9064
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
const ld eps = 1e-9;
struct point {ld x, y; };
struct line {point a, b; };
void ReadPointInt(point &a) {read(a.x), read(a.y); }
void ReadLineInt(line &a) {ReadPointInt(a.a), ReadPointInt(a.b); }
point operator + (point a, point b) {return (point) {a.x + b.x, a.y + b.y}; }
point operator - (point a, point b) {return (point) {a.x - b.x, a.y - b.y}; }
point operator * (point a, ld b) {return (point) {a.x * b, a.y * b}; }
ld dot(point a, point b) {return a.x * b.x + a.y * b.y; }
ld operator * (point a, point b) {return a.x * b.y - a.y * b.x; }
ld moo(point a) {return sqrtl(a.x * a.x + a.y * a.y); }
ld dist(point a, point b) {return moo(a - b); }
point unit(point a) {
	ld tmp = moo(a);
	assert(tmp > eps);
	return a * (1.0 / tmp);
}
point Projection(point x, line a) {
	ld d = dot(x - a.a, a.b - a.a) / dist(a.a, a.b);
	return a.a + unit(a.b - a.a) * d;
}
point Reflection(point x, line a) {
	return Projection(x, a) * 2 - x;
}
int main() {
	line a; ReadLineInt(a);
	int q; read(q);
	while (q--) {
		point x; ReadPointInt(x);
		x = Reflection(x, a);
		printf("%.10Lf %.10Lf\n", x.x, x.y);
	}
	return 0;
}


Measured memory_bytes: 3232
#include <stdio.h>

int main(void)
{
int   n, x;
int   i, j, k, ans;

while (scanf("%d %d", &n, &x), n || x)
{
ans = 0;
for (i = 1; i <= n; i++) 
{
for (j = i + 1; j <= n; j++)
{
for (k = j + 1; k <= n; k++)
{
if (i + j + k == x) ans++;
}
}
}

printf("%d\n", ans);
}


return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N, x;
	cin >> N >> x;
	if(x==1||x==2*N-1){
		cout << "No" << endl;
		return 0;
	}else if(N==2){
		if(x==2){
			cout << "Yes" << endl;
			REP(i, 3) cout << i+1 << endl;
		}else{
			cout << "No" << endl;
		}
	}else{
		ll res[2*N-1];
		set<ll> st;
		REP(i, 2*N+1) st.insert(i+1);
		if(x==2){
			cout << "Yes" << endl;
			res[N-3] = 4;st.erase(4);
			res[N-2] = 1;st.erase(1);
			res[N-1] = 2;st.erase(2);
			res[N] = 3;st.erase(3);
			REP(i, N-3){
				res[i] = *st.begin();
				st.erase(st.begin());
			}
			for(int i=N+1;i<2*N-1;i++){
				res[i] = *st.begin();
				st.erase(st.begin());
			}
		}else{
			cout << "Yes" << endl;
			res[N+1] = x-2;st.erase(x-2);
			res[N] = x+1;st.erase(x+1);
			res[N-1] = x;st.erase(x);
			res[N-2] = x-1;st.erase(x-1);
			REP(i, N-2){
				res[i] = *st.begin();
				st.erase(st.begin());
			}
			for(int i=N+2;i<2*N-1;i++){
				res[i] = *st.begin();
				st.erase(st.begin());
			}
		}
		REP(i, 2*N-1) cout << res[i] << endl;
	}
	
    return 0;
}

Measured memory_bytes: 12544
{-# OPTIONS_GHC -O #-}

import Control.Monad
import Data.List

main=do
    [n,y] <- map read.words<$>getLine ::IO[Int]
    putStrLn $ case  [(a,b) | a<-[0..n], b<-[0..n-a], 1000*a+5000*b+10000*(n-a-b) == y] of
        [] -> "-1 -1 -1"
        ((a,b):_) -> show (n-a-b) ++" "++show b++" "++show a

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;

int main(){
	ll n,s;cin>>n>>s;
	if(n==s){
		cout<<n+1<<endl;return 0;
	}
	for(ll i=2;i*i<=n;i++){
		ll b=i,tmp=n;
		int sum=0;
		while(tmp){
			sum+=tmp%b;
			tmp/=b;
		}
		if(sum==s){
			cout<<i<<endl;
			return 0;
		}
	}
	ll ns=n-s;
	vector<ll>cands;
	for(ll i=1;i*i<=ns;i++){
		if(ns%i==0){
			cands.push_back(i);
			if(ns/i!=i)cands.push_back(ns/i);
		}
	}
	sort(cands.begin(),cands.end());
	for(ll u:cands){
		ll b=u+1;
		ll sum=0,tmp=n;
		while(tmp){
			sum+=tmp%b;tmp/=b;
		}
		if(sum==s){
			cout<<b<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}

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

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 2 * 100 * 1000 + 17;

ll n, k, a[MAXN], sum;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n - k; i++)
		sum += a[i];
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 1792
n = int(input())
d = list(map(int,input().split()))
count = 0

d.sort()
m = int(n / 2)
i = d[m-2] + 1
if (d[m-1] != d[m]):
  print(d[m] - d[m-1])

elif (d[m-1] == d[m]):
  print(0)
  

Measured memory_bytes: 52684
#include<bits/stdc++.h>
#define M 100005
#define NO {printf("Second\n"); return 0;}
#define YES {printf("First\n"); return 0;}
using namespace std;

struct edge{int u,next;}e[M*2]={0}; int head[M]={0},use=0;
void add(int x,int y){use++;e[use].u=y;e[use].next=head[x];head[x]=use;}
int du[M]={0},ye[M]={0};
int ok=1;
int dfs(int x,int fa){
	int cnt=0; 
	for(int i=head[x];i;i=e[i].next) if(e[i].u!=fa){
		ye[x]=0;
		cnt+=dfs(e[i].u,x);
	}
	if(cnt>1){
		printf("First\n");
		exit(0);
	}
	return cnt^1;
}

int main(){
	int n;
	scanf("%d",&n);
	if(n&1) YES
	if(n==2) NO
	for(int i=1;i<n;i++){
		int x,y; scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
		du[x]++; du[y]++;
	}
	for(int i=1;i<=n;i++) 
	if(du[i]>1){
		dfs(i,0);
		NO
	}
}
	

Measured memory_bytes: 2944
from queue import Queue

def bfs(point):
    global visit, s
    while point.qsize() > 0:
        hh, ww = point.get()
        h_w_list = [[1, 0], [- 1, 0], [0, 1], [0, - 1]]
        for h_, w_ in h_w_list:
            h_ = h_ + hh
            w_ = w_ + ww
            if (h_ in range(h)) & (w_ in range(w)):
                if s[h_][w_] == ".":
                    if visit[h_][w_] == inf:                    
                        point.put([h_, w_])
                        visit[h_][w_] = visit[hh][ww] + 1
        
    
inf = 10 ** 9    
h, w = map(int, input().split())
s = []
point_num = 0
for _ in range(h):
    k = input()
    point_num += k.count(".")
    s.append(list(k))
visit = [[inf for _ in range(w)] for _ in range(h)]
point = Queue()
point.put([0, 0])
visit[0][0] = 0
bfs(point)
ans = point_num - visit[-1][-1] - 1
if ans < 0:
    ans = -1
print(ans)



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

void print_frame(int H, int W);
void print_bread(int W);
void print_meat(int W);

int main() {
	int H, W;
	while(cin >> H >> W){
		if (H == 0 && W == 0) break;
		print_frame(H, W);
	}
}

void print_frame(int H, int W){
	print_bread(W);
	for (int h=2; h != H; ++h){
		print_meat(W);
	}
	print_bread(W);
	cout << endl;
}

void print_bread(int W){
	for (int w=0; w != W; ++w){
			cout << '#';
	}
	cout << endl;
}

void print_meat(int W){
	cout << '#';
	for (int w=2; w != W; ++w){
		cout << '.';
	}
	cout << '#' << endl;
}

Measured memory_bytes: 1152
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << ' ' << y << ' ' << z << '\n';
}


Measured memory_bytes: 888
#include <iostream>
using namespace std;
int main() {
int n,m,l;
long a[100][100]={},b[100][100]={},c[100][100]={};
cin>>n>>m>>l;
for(int i=0;i<n;i++){
  for(int j=0;j<m;j++){
  cin>>a[i][j];
  }
}
for(int i=0;i<m;i++){
  for(int j=0;j<l;j++){
  cin>>b[i][j];
  }
}
for(int i=0;i<n;i++){
  for(int j=0;j<m;j++){
    for(int k=0;k<l;k++){
      c[i][k]+=a[i][m-1-j]*b[m-1-j][k];
    }
  }
}
for(int i=0;i<n;i++){
  for(int j=0;j<l;j++){
    if(j<l-1){cout<<c[i][j]<<" ";
    }else{cout<<c[i][j]<<endl;}
  }
}
  return 0;
}

Measured memory_bytes: 1404
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> dp(k + 1, 0);
    for (int gc = k; gc >= 1; --gc) {
        int total_multiples = k / gc;
        int temp = fast_pow(total_multiples, n, MOD);
        temp %= MOD;
        int extra = 0;
        for (int j = gc * 2; j <= k; j += gc) {
            extra = (extra + dp[j]) % MOD;
        }
        dp[gc] = (temp - extra + MOD) % MOD;
    }
    int ans = 0;
    for (int i = 1; i <= k; ++i) {
        int add = (dp[i] % MOD * i % MOD) % MOD;
        ans += add, ans %= MOD;
    }
    cout << ans << endl;

}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for (int i = 1; i <= test; i++) {
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

Measured memory_bytes: 3964
/**-------------------------
|--------From A.R.A--------|
-------------------------**/

#include <bits/stdc++.h>

#define ll            long long int
#define pb            push_back
#define ull           unsigned long long int
#define endl          "\n"
#define sz(c)         (c).size()
#define sall(c)       sort((c).begin(),(c).end())
#define rsall(c)      sort((c).rbegin(),(c).rend())
#define rev(c)        reverse((c).begin(),(c).end())
#define FOR(i,n)      for(ll i=0;i<n;i++)
#define max3(a,b,c)   max(max(a,b),c)
#define min3(a,b,c)   min(min(a,b),c)
#define input(a,i,n)  for(ll i=0;i<n;i++){      cin>>a[i];}
#define output(a,i,n) for(ll i=0;i<n;i++){cout<<a[i]<<" ";}

using namespace std;
int64_t R=1;
void solution(){
    int64_t n,sum=0;
    cin>>n;
    string s;
    map <string,int64_t> m1;
    for(int i=0;i<n;i++){
        cin>>s;sall(s);
        m1[s]++;
    }
    for(auto i:m1){
        int64_t x=i.second-1;
        sum+=((1+x)*x)/2;
    }
    cout<<sum<<endl;

}
int main()
{
    FOR(i,R){solution();}
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
template<class T, class T2> inline void chkmax(T &x, const T2 &y) { if(x < y) x = y; }
template<class T, class T2> inline void chkmin(T &x, const T2 &y) { if(x > y) x = y; }
const int MAXN = (55);

int n;
int a[MAXN], b[MAXN];

void read()
{
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) cin >> b[i];
}

int dp[MAXN][MAXN];
bool blocked[MAXN];

int can(int from, int to)
{
	if(from == to) return 1;
	if(from < to) return 0;

	if(dp[from][to] != -1) return dp[from][to];
	dp[from][to] = 0;

	vector<int> tmp;
	for(int d = 1; d <= from; d++)
		if(!blocked[d])
			dp[from][to] |= can(from % d, to);

	return dp[from][to];
}

void solve()
{
	memset(dp, -1, sizeof(dp));

	int bg = 1;
	for(int i = 0; i < n; i++)
		bg &= can(a[i], b[i]);

	if(!bg)
	{
		cout << -1 << endl;
		return;
	}

	vector<int> li;
	for(int i = 50; i >= 1; i--)
	{
		memset(dp, -1, sizeof(dp));

		blocked[i] = 1;
		int ok = 1;
		for(int p = 0; p < n; p++)
			ok &= can(a[p], b[p]);

		if(!ok)
		{
			li.push_back(i);
			blocked[i] = 0;
		}
	}

	int64_t answer = 0;
	for(int i: li)
		answer += ((1ll) << (i * 1ll));

	cout << answer << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	read();
	solve();
	return 0;
}



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

#define forn(e,n,s) for(int i = e; i < n;i += s)
#define forr(e,n,s) for(int i = e; i >= n; i -= s)
#define PI 3.14159265358979323846264338327950L

using namespace std;

const int MOD = 1e9+7;

void go(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout<<fixed;
  cout<<setprecision(20);

  #ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
  #endif
}

int main(){
    go(); 

    // code here
    int n,k;cin>>n>>k;
    int arr[n];
    forn(0, n, 1) cin>>arr[i];
    vector<bool> dp(k+1,0);
    for(int i = 1 ; i <= k; i++){
        bool include = true;
        for(int j = 0; j < n; j++ ){
            if((i - arr[j]) >= 0 and !dp[i - arr[j]]) include = false;
        }
        if(!include) dp[i] = true;
    }
    cout<<(dp[k]?"First":"Second")<<endl;
   
}





Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
using TCost = pair<long long, long long>;
using TDestination = pair<TCost, int>;

int main(void){
    int N, M, Bbuf, Cbuf, Dbuf, Ubuf, Vbuf;
    long long Abuf, S;
    long long maxExpense = 0LL;
    cin >> N >> M >> S;
    vector<vector<TDestination>> Graph(N);
    for(int i=0; i<M; i++){
        cin >> Ubuf >> Vbuf >> Abuf >> Bbuf;
        Ubuf--;
        Vbuf--;
        Graph[Ubuf].push_back(TDestination(TCost(Bbuf, Abuf), Vbuf));
        Graph[Vbuf].push_back(TDestination(TCost(Bbuf, Abuf), Ubuf));
        maxExpense = max(maxExpense, Abuf);
    }
    maxExpense *= N-1;
    for(int i=0; i<N; i++){
        cin >> Cbuf >> Dbuf;
        Graph[i].push_back(TDestination(TCost(Dbuf, -Cbuf), i));
    }
    priority_queue<TDestination, vector<TDestination>, greater<TDestination>> que;
    que.push(TDestination(TCost(0, min(S, maxExpense)), 0));
    vector<vector<bool>> Experienced(N, vector<bool>(maxExpense, false));
    vector<long long> timFirstVisit(N, -1LL);
    while(!que.empty()){
        TDestination curStatus = que.top();
        que.pop();
        long long curTime = curStatus.first.first;
        long long curMoney = curStatus.first.second;
        int curCity = curStatus.second;
        if(Experienced[curCity][curMoney])continue;
        if(timFirstVisit[curCity] == -1)timFirstVisit[curCity] = curTime;
        Experienced[curCity][curMoney] = true;
        bool breakable = true;
        for(int i=0; i<N; i++)breakable = breakable && (timFirstVisit[i] != -1);
        if(breakable)break;
        for(TDestination nxtMove: Graph[curCity]){
            long long nxtTime = curTime + nxtMove.first.first;
            long long nxtMoney = min(curMoney - nxtMove.first.second, maxExpense);
            int nxtCity = nxtMove.second;
            if(nxtMoney < 0)continue;
            que.push(TDestination(TCost(nxtTime, nxtMoney), nxtCity));
        }
    }
    for(int i=1; i<N; i++)cout << timFirstVisit[i] << endl;
    return 0;
}

Measured memory_bytes: 9576
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long long
using namespace std;

signed main() {
	int N;
	cin >> N;
	map<int,int> ma;
	for(int i = 0;i < N;i++) {
		int A;
		cin >> A;
		ma[A]++;
	}
	int answer = 0;
	for(auto x : ma) {
		auto key = x.first;
		auto value = x.second;
		if(key > value) {
			answer += value;
		}
		else {
			answer += value - key;
		}
	}
	cout << answer << endl;
}

Measured memory_bytes: 6272
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public long N;
        public long H;
        public long[] A, B, S;
        public void Run()
        {
            {
                var line = Input.ReadLongArray();
                N = line[0];
                H = line[1];
            }

            A = new long[N];
            B = new long[N];
            for (int i = 0; i < N; i++)
            {
                var line = Input.ReadLongArray();
                A[i] = line[0];
                B[i] = line[1];
            }

            Array.Sort(A);
            Array.Reverse(A);
            Array.Sort(B);
            Array.Reverse(B);

            S = new long[N + 1];
            for (int i = 0; i < N; i++)
            {
                S[i+1] = S[i] + B[i];
            }

            long ret = long.MaxValue;
            for (int b = 0; b <= N; b++)
            {
                long t = b;
                long h = H - S[b];
                if (h > 0)
                {
                    t += (h + A[0] - 1) / A[0];
                }

                ret = Math.Min(t, ret);
            }

            Console.WriteLine(ret);
           
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 19772
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }


int main(){ 
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll res = 0;
    if(a>0 and d<0){
        res = a * d;
    }else if(c>0 and b<0){
        res = b * c;
    }else{
        //正*正
        ll x1 = LINF;
        if(a>=0)x1 = a; if(b>=0 and b > a)x1 = b;
        ll y1 = LINF;
        if(c>=0)y1 = c; if(d>=0 and d > c)y1 = d;
        if(x1!=LINF and y1 !=LINF)res = x1 * y1;

        x1 = LINF;
        if(b<=0)x1 = b; if(a<=0 and a < b)x1 = a;
        y1 = LINF;
        if(d<=0)y1 = d; if(c<=0 and c < d)y1 = c;
        if(x1!=LINF and y1 !=LINF)chmax(res, x1 * y1);        
    }
    cout << res << ln;
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, Q;
  string S;
  cin >> N >> S >> Q;
  vvll a(26, vll(N, 0));
  for(int i = 0; i < N; i++){
    a.at(S.at(i) - 'a').at(i) = 1;
  }
  vvll sum(26, vll(N+1, 0));
  for(int i = 0; i < 26; i++){
    for(int j = 0; j < N; j++){
      sum.at(i).at(j+1) = sum.at(i).at(j) + a.at(i).at(j);
    }
  }
  vll ans(0);
  vvll del(26, vll(0));
  vvll app(26, vll(0));
  while(Q--){
    ll query;
    cin >> query;
    if(query == 1){
      ll ii;
      char cc;
      cin >> ii >> cc;
      ii--;
      if(S.at(ii) != cc){
        del.at(S.at(ii) - 'a').push_back(ii);
        sort(ALL(del.at(S.at(ii) - 'a')));
        app.at(cc - 'a').push_back(ii);
        sort(ALL(app.at(cc - 'a')));
        S.at(ii) = cc;
      }
    }
    else{
      ll left, right;
      cin >> left >> right;
      left--; right--;
      ll res = 0LL;
      for(int i = 0; i < 26; i++){
        ll counter = sum.at(i).at(right+1) - sum.at(i).at(left);
        auto d1 = lower_bound(ALL(del.at(i)), left);
        auto d2 = lower_bound(ALL(del.at(i)), right+1);
        auto a1 = lower_bound(ALL(app.at(i)), left);
        auto a2 = lower_bound(ALL(app.at(i)), right+1);
        counter -= distance(d1, d2);
        counter += distance(a1, a2);
        if(counter > 0) res++;
      }
      ans.push_back(res);
    }
  }
  for(auto x: ans) cout << x << endl;
}

Measured memory_bytes: 207960