akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int N,i;scanf("%d",&N);
  int a[N];
  map<int,int> ml,mr;
  for(i=0;i<N;i++) scanf("%d",&a[i]);
  int ng = 0;vector<int> ans;
  for(i=0;i<N;i++){
    ml[a[i]]++;
    if(ml[a[i]] == mr[a[i]]) ng--;
    else if(ml[a[i]]-1 == mr[a[i]]) ng++;
    mr[a[N-i-1]]++;
    if(ml[a[N-i-1]] == mr[a[N-i-1]]) ng--;
    else if(ml[a[N-i-1]] == mr[a[N-i-1]]-1) ng++;
    if(ng == 0) ans.push_back(i+1);
  }
  for(i=0;i<ans.size()-1;i++) printf("%d ",ans[i]);
  printf("%d\n",ans.back());
}


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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    ll a=0,b=0,c=0,ans=0;
    a=n/500;
    b=n%500;
    c=b/5;
    ans=a*1000+c*5;
    cout<<ans;
}

Measured memory_bytes: 256
#include<cstdio>
typedef long long ll;
ll max(ll x,ll y){return (x>y)?x:y;}
ll dp[100001];
int main(){
  int n,w;
  scanf("%d%d",&n,&w);
  for(int i=1;i<=w;i++)dp[i]=-1;
  dp[0]=0;
  for(int i=0;i<n;i++){
    int wi;
    ll vi;
    scanf("%d%lld",&wi,&vi);
    for(int i=w-wi;i>=0;i--)dp[i+wi]=max(dp[i+wi],dp[i]+vi);
  }
  for(int i=0;i<w;i++)dp[w]=max(dp[w],dp[i]);
  printf("%lld",dp[w]);
  return 0;
}

Measured memory_bytes: 896
from bisect import bisect_right

N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

P = [0]
Q = [0]
for i in range(N):
    P.append(P[-1] + A[i])

for i in range(M):
    Q.append(Q[-1] + B[i])

ans = 0
for i in range(N+1):
    if K - P[i] >= 0:
        ans = max(ans, i + bisect_right(Q, K - P[i]) - 1)

print(ans)

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

int main() {
  string s;
  cin >> s;
  int counter = 0;
  if (s[0] == '1') counter++;
  if (s[1] == '1') counter++;
  if (s[2] == '1') counter++;
  cout << counter << endl;
  return 0;
}

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

int main()
{
	int n, x;
	cin.tie(0);
	while (true) {
		cin >> n >> x;
		if (n == 0) break;
		int cnt = 0;
		for (int a = 1; a <= n; a++) {
			for (int b = a + 1; b <= n; b++) {
				for (int c = b + 1; c <= n; c++) {
					if (x == a + b + c)  cnt++;
				}
			}
		}
		cout << cnt << "\n";
	}
}



Measured memory_bytes: 3060
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
        int w = sc.nextInt();
    
		// 出力
		System.out.println(H * W - (H * w + W * h ) + h * w);
	}
}

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

int main() {
  int sss;
  cin >> sss;
  int s1 = sss / 100 %2;
  int s2 = sss /10 % 2;
  int s3 = sss % 2;
  cout << s1+s2+s3 << endl;
}
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




int main()
{
    ll H;
    cin >> H;

    ll count = 0;
    while(H > 1){
        count++;
        H /= 2;
    }

    ll ans = 0;
    rep(i,count + 1){
        ans += pow(2,i);
    }

    cout << ans << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

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

int main(void) {
  long long N,W;
  cin >> N >> W;
  vector<int64_t> w(N),v(N);
  for (int64_t i = 0; i < N;++i)
    cin >> w[i] >> v[i];
  
  vector<int64_t> dp(W+1,0);
  for (int64_t i = 0; i < N;++i)
    for (int64_t j = W;j >= 0;--j) {
        if (j + w[i] <= W) {
          dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
        }
    }
  cout << dp[W] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <bitset>

using std::ios_base;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using std::fixed;

using std::vector;
using std::string;
using std::stack;
using std::queue;
using std::deque;
using std::map;
using std::set;
using std::unordered_map;
using std::unordered_set;
using std::bitset;

using std::tuple;
using std::make_tuple;
using std::pair;
using std::make_pair;

using std::sort;
using std::reverse;
using std::nth_element;

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

const int MAXN = 100005;
const int INF = 1e9;
const int MOD = 1e9+7;
const int64_t L_INF = 4e18;

int n;
pair<int, int> c[MAXN];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> c[i].first >> c[i].second;
    }
    sort(c, c + n, [](auto& a, auto& b) {
        if (a.first + a.second == b.first + b.second) {
            return a.first > b.first;
        }
        return a.first + a.second > b.first + b.second;
    });

    int64_t res = 0;
    for (int i = 0; i < n; i++) {
        if (i & 1) {
            res -= c[i].second;
        } else {
            res += c[i].first;
        }
    }
    cout << res << '\n';

    #ifdef LOCAL
        cerr << "\n== " << 1.0 * clock() / CLOCKS_PER_SEC << " sec.\n";
    #endif
    return 0;
}


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






int main(){
  


  int n;
  cin>>n;
  
  vector<int> data(n+2);
  
  data.at(0)=0;
  data.at(n+1)=0;
  
  for (int i=1;i<=n;i++){
    int tmp;
    cin>>tmp;
    data.at(i)=tmp;
  }
  
  long long sum=0;
  
  for (int i=0;i<n+1;i++){
    sum+=abs(data.at(i+1)-data.at(i));
  }
  
  for (int i=1;i<=n;i++){
    cout<<sum-abs(data.at(i)-data.at(i-1))-abs(data.at(i+1)-data.at(i))+abs(data.at(i+1)-data.at(i-1))<<endl;
  }
  
    
      
    
    
  


    
  
  
  
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 998244353;


int main() {
    int k; 
    cin >> k;
    string s;
    cin >> s;
    if (k < s.size()) {
        string ns = s.substr(0, k);
        ns += "...";
        cout << s.substr(0, k) << "..." << endl;
    } else {
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 3600
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

fn main() {
    input! {
        k: usize,
        s: String,
    }
    if s.len() <= k {
        println!("{}", s);
    } else {
        for c in s.chars().take(k) {
            print!("{}", c);
        }
        println!("...");
    }
}


Measured memory_bytes: 2188
//Author - Sanket Mundra
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define IIITA ios::sync_with_stdio(0)
#define sanket cin.tie(0)
#define mundra cout.tie(0)
ll M = 1000000007;

ll lcm(ll a, ll b)
{
	return a*(b/__gcd(a,b));
}

int main()
{
	IIITA; sanket; mundra;
	ll t,i,j,n,m,l,k,r,sum,ans,mx,mn,x,y,z; cin>>i>>j;
	cout<<lcm(i,j)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <sstream>
#include <algorithm>
#include <fstream>
#include <list>
#include <unordered_map>
#include <map>
#include <istream>
#include <sstream>
#include <stack>
#include <set>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <queue>
#include <string>

#define int long long
#define ull unsigned long long
#define endl "\n"
#define all(x) x.begin(),x.end()
#define rr return 0
#define xx first
#define yy second
#define pii pair<int,int>

using namespace std;

typedef long double ld;

const int MOD = 1e9 + 7;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int h,w;
    cin >> h >> w;
    vector<vector<int>> a(h,vector<int>(w));
    string s;
    for(int i = 0;i < h;i++){
        cin >> s;
        for(int j = 0;j < w;j++){
            if(s[j] == '.')
                a[i][j] = 0;
            else
                a[i][j] = 1;
        }
    }
    vector<vector<int>> dp(h, vector<int>(w));
    dp[0][0] = 1;
    for(int i = 1;i < h;i++){
        if(a[i][0] == 1){
            break;
        }
        dp[i][0] = 1;
    }
    for(int i = 1;i < w;i++){
        if(a[0][i] == 1){
            break;
        }
        dp[0][i] = 1;
    }
    for(int i = 1;i < h;i++){
        for(int j = 1;j < w;j++){
            if(a[i][j] == 0)
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
            else
                dp[i][j] = 0;
        }
    }
    
    
    cout << dp[h-1][w-1];
}


Measured memory_bytes: 16000
#include <stdio.h>

int main(void) {
    int n, d, count = 0;
    scanf("%d%d", &n, &d);
    while(1) {
        if(n > 0) {
            count++;
            n -= 2*d+1;
            if(n <= 0) {
                break;
            }
        }
    }
    printf("%d\n", count);
    return 0;
}


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

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    for (int i=A; i<=B; i++){
        if (i%K==0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
 
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
gp_hash_table<int, int> mp;*/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = -1e6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 200001;
ll n;
vector<int> adj[mxN];
vector<int> all[mxN];
ll val[mxN];
ll sz[mxN];
ll col[mxN];
ttgl inout[mxN];
int cnt = 0;
ll ans[mxN];
bool cmp(int a, int b) {
    return inout[a].first<inout[b].first;
}
bool isanc(int a, int b) {
    return ((inout[a].first<=inout[b].first)&&(inout[a].second>=inout[b].second));
}
void dfs(int u, int p) {
    sz[u] = 1;
    ll bad = 0;
    ll save = col[val[u]];
    inout[u].first = cnt++;
    for(int v: adj[u]) {
        if(v^p) {
            col[val[u]] = 0;
            dfs(v, u);
            sz[u]+=sz[v];
            bad=col[val[u]];
            ans[val[u]]+=(sz[v]-bad)*(sz[v]-bad+1)/2;
        }
    }
    inout[u].second = cnt++;
    //ans[val[u]]+=(sz[u]-bad)*(sz[u]-bad+1)/2;
    col[val[u]] = save+sz[u];
}
int main()
{   
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n;
    owo(i, 0, n) {
        cin>>val[i];
        val[i]--;
        all[val[i]].senpai(i);
    }
    int a,b;
    owo(i, 0, n-1){
        cin>>a>>b;
        a--; b--;
        adj[a].senpai(b);
        adj[b].senpai(a);
    }
    dfs(0, 0);
    owo(i, 0, n) {
        sort(all[i].begin(), all[i].end(), cmp);
        ll bad = 0;
        int curr = -1;
        for(int k: all[i]) {
            if((curr==-1)||(!isanc(curr, k))) {
                curr = k;
                bad+=sz[k];
            }
        }
        //cout<<i<<" "<<ans[i]<<" "<<bad<<"\n";
        bad = sz[0]-bad;
        ans[i]+=(bad*(bad+1))/2;
        //cout<<i<<" "<<ans[i]<<"\n";
    }
    owo(i, 0, n) {
        ans[i] = (n*(n+1))/2-ans[i];
        cout<<ans[i]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 49748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define UP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define UU(a,b,c) for(ll (a)=(b);(a)<=(c);(a)++)
#define DN(a,b,c) for(ll (a)=(b);(a)>(c);(a)--)
#define DU(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
int main()
{
	ll n,m;
	cin>>n>>m;
	cout<<((n*(n-1))+(m*(m-1)))/2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) 
{
    os << "{ ";
    for(auto& y : x) 
    {
        os << y << " ";
    }
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) 
{
    return os << "[" << p.ff << ", " << p.ss << "]";
}

ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }

    return gcd(b, a%b);
}

ll modexp(ll a, ll b, ll c)
{   
    a%=c;

    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%c;
        }

        a = (a*a)%c;
        b >>= 1;
    }

    return ans;
}

const ll L = 1e5+5;

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

    ll A, B, K;
    cin >> A >> B >> K;

    if(K > A)
    {
        cout << 0 << " " << max(0LL, B-(K-A)) << endl;
    }

    else
    {
        cout << A-K << " " << B << endl;
    }

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    S = Scanner.string()
    T = Scanner.string()
    dp = [[0 for _ in range(3100)] for _ in range(3100)]
    for i in range(len(S)):
        for j in range(len(T)):
            dp[i+1][j + 1] = max(dp[i+1][j + 1], dp[i+1][j])
            dp[i+1][j + 1] = max(dp[i+1][j + 1], dp[i][j+1])
            if S[i] == T[j]:
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
    ans = ""
    i, j = len(S), len(T)
    while i > 0 and j > 0:
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            ans = S[i-1] + ans
            i -= 1
            j -= 1
    print(ans)
    return


if __name__ == "__main__":
    main()


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

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int flag =0,m;
        for(int i=1;i<=9;i++)
        {
            if(n%i==0)
            {
                m =n/i;
                for(int j=1;j<=9;j++)
                {
                    if((m%j==0)&&(m/j==1))
                        flag =1;
                }
            }
        }
        if(flag)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n, k = MAP()
p = LIST()
psum = [0 for _ in range(n - k + 1)]
for i in range(k):
    psum[0] += (p[i] + 1) / 2
for i in range(1, n - k + 1):
    psum[i] = psum[i - 1] + (p[i + k - 1] + 1) / 2 - (p[i - 1] + 1) / 2
print(max(psum))

Measured memory_bytes: 97024
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) //printf(f,##__VA_ARGS__),fflush(stdout)

typedef long long ll;

namespace IO {
	const int L=1<<15;
	char buf[L],*ps,*pt;
	inline char getc(){
		if(ps==pt){
			pt=(ps=buf)+fread(buf,1,L,stdin);
			if(ps==pt)return EOF;
		}
		return *ps++;
	}
	template<typename T>
	inline void read(T&x){
		char c;
		x=0;
		for(c=getc();c<'0'||c>'9';c=getc());
		while(c>='0'&&c<='9') {
			x=x*10+(c-'0'),c=getc();
		}
	}
	char t[55],o[L],*tp=o;
	inline void flush(){
		fwrite(o,1,tp-o,stdout);
		tp=o;
	}
	inline void putc(char c){
		*tp++=c;
		if(tp==o+L)flush();
	}
	inline void print(int x){
		int k=0;
		while(x)t[k++]=x%10,x/=10;
		while(k)putc('0'+t[--k]);
	}
}
using IO::read;
using IO::print;
using IO::putc;

const int N=1e5+50,oo=1e9+2;

struct I { int x[3]; } a[N];
int n,cnt[3];
ll ans,tot,sum,res1[N],res2[N];

bool cmp(I &u,I &v){ return -u.x[0]+u.x[1]<-v.x[0]+v.x[1]; }

priority_queue<int,vector<int>,greater<int>> q;

int main(int argc,char  *argv[]){
#ifdef CURIOUSCAT
	freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	read(cnt[0]),read(cnt[1]),read(cnt[2]);
	n=cnt[0]+cnt[1]+cnt[2];
	rep(i,1,n){
		lop(k,0,3)read(a[i].x[k]); 
		a[i].x[0]-=a[i].x[2];
		a[i].x[1]-=a[i].x[2];
		ans+=a[i].x[2];
	}
	sort(a+1,a+n+1,cmp);
	rep(i,1,n)Pr("(%d,%d)\n",a[i].x[0],a[i].x[1]); 
	rep(i,1,cnt[0]-1){
		q.push(a[i].x[0]);
		sum+=a[i].x[0];
	}
	rep(i,cnt[0],n-cnt[1]){
		q.push(a[i].x[0]);
		sum+=a[i].x[0]; 
		while(q.size()>cnt[0]){
			int x=q.top(); 
			q.pop(); 
			sum-=x;
		}
		res1[i]=sum;
		Pr("res1[%d]=%d\n",i,res1[i]); 
	}
	sum=0;
	while(!q.empty())q.pop();  
	dec(i,n,n-cnt[1]+2){
		q.push(a[i].x[1]);
		sum+=a[i].x[1];
	}
	dec(i,n-cnt[1]+1,cnt[0]+1){
		q.push(a[i].x[1]);
		sum+=a[i].x[1];
		while(q.size()>cnt[1]){
			int x=q.top(); 
			q.pop(); 
			sum-=x;
		}
		res2[i]=sum;
		
		Pr("res2[%d]=%d\n",i,res2[i]); 
	}
	rep(i,cnt[0],n-cnt[1]){
		cmax(tot,ans+res1[i]+res2[i+1]);
	}
	printf("%lld\n",tot);
	return 0; 
}

Measured memory_bytes: 2688
#include <cstdio>
#include <climits>
#include <cmath>
#include <algorithm>

using namespace std;

using ll = long long;

inline
int getDigit(ll num)
{
    return static_cast<int>(floor(log10(num))) + 1;
}


inline
int F(ll A, ll B)
{
    return max(getDigit(A), getDigit(B));
}

int main()
{
    ll N;
    scanf("%lld\n", &N);
    const ll sqrtN = static_cast<ll>(floor(sqrt(N)));
    int result = INT_MAX;
    for (ll A = 1; A <= sqrtN; ++A){
        const ll B = N / A;
        if (A * B != N) continue;
        result = min(F(A, B), result);
    }
    printf("%d\n", result);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

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

    vec<int> a(N);
    rep(i, N) {
        cin >> a[i];
        --a[i];
    }
    int now = a[0];
    int count = 1;
    ++N;
    while(--N) {
        if(now == 1) {
            cout << count << endl;
            return 0;
        }
        now = a[now];
        ++count;
    }
    cout << -1 << endl;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};


int main() {
    int h,w,k;
    cin>>h>>w>>k;
    auto vec=make_vec<char>(h,w);
    int sy,sx;
    rep(i,h) rep(j,w) {
        cin>>vec[i][j];
        if(vec[i][j]=='S') {
            sy=i;
            sx=j;
        }
    }
    
    vector<vector<int>> d(h,vector<int>(w,INF));
    queue <pair<int,int>> q;
    
    q.push(make_pair(sy,sx));
    d[sy][sx]=0;
    
    while(sz(q)) {
        pair<int,int> now=q.front(); q.pop();
        
        rep(i,4) {
            int ny = now.first + dy[i];
            int nx = now.second + dx[i];
            
            if(!(0<=ny && ny<h && 0<=nx && nx<w)) continue;
            if(vec[ny][nx]=='.' && d[ny][nx]==INF) {
                q.push({ny,nx});
                d[ny][nx] = d[now.first][now.second] + 1;
            }
        }
    }

    int ans=INF;
    rep(i,h) rep(j,w) {
        if(d[i][j]<=k) {
            chmin(ans,(i+k-1)/k);
            chmin(ans,(j+k-1)/k);
            chmin(ans,(h-1-i+k-1)/k);
            chmin(ans,(w-1-j+k-1)/k);
        }
    }
    cout<<ans+1<<endl;
}

Measured memory_bytes: 3456
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			int M = sc.nextInt();
			int[] h = new int[H];
			int[] w = new int[W];
			Set<Integer> hset = new HashSet<>();
			Set<Integer> wset = new HashSet<>();
			Set<Point> pset = new HashSet<>();
			for (int i = 0; i < M; i++) {
				int tmph = sc.nextInt() - 1;
				int tmpw = sc.nextInt() - 1;
				h[tmph]++;
				w[tmpw]++;
				hset.add(tmph);
				wset.add(tmpw);
				pset.add(new Point(tmph, tmpw));
			}
			Set<Integer> hmax = new HashSet<>();
			Set<Integer> wmax = new HashSet<>();
			int maxh = 0;
			int maxw = 0;
			for (int hh : hset) {
				int tmp = h[hh];
				if (tmp > maxh) {
					hmax.clear();
					hmax.add(hh);
					maxh = tmp;
				} else if (tmp == maxh) {
					hmax.add(hh);
				}
			}
			for (int ww : wset) {
				int tmp = w[ww];
				if (tmp > maxw) {
					wmax.clear();
					wmax.add(ww);
					maxw = tmp;
				} else if (tmp == maxw) {
					wmax.add(ww);
				}
			}
			int cnt = 0;
			for (Point p : pset) {
				if (hmax.contains(p.h) && wmax.contains(p.w)) {
					cnt++;
				}
			}
			if (cnt == hmax.size() * wmax.size()) {
				System.out.println(maxh + maxw - 1);
			} else {
				System.out.println(maxh + maxw);
			}
		}
	}

	static class Point {
		int h;
		int w;

		public Point(int h, int w) {
			this.h = h;
			this.w = w;
		}
	}
}

Measured memory_bytes: 160652
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int H,W;
  cin>>H>>W;
  char A[H+1][W+1];
  for(int i=1; i<=H; ++i){
    for(int j=1; j<=W; ++j){
      cin>>A[i][j];
    }
  }
  for(int i=1; i<=2*H; ++i){
    for(int j=1; j<=W; ++j){
      cout<<A[(i+1)/2][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;
 
typedef int64_t i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	i64 from, to, cost;
	edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
	edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

// 多重vectorを可変引数テンプレートで http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
//

#pragma endregion

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s, t, u;
    cin >> s >> t;
    i64 a, b;
    cin >> a >> b;
    cin >> u;
    if(s == u) --a;
    if(t == u) --b;
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdlib> 
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
using namespace std;

int main() {
	int n;
	cin >> n;
	string str;
	str = to_string(n);
	
	for (int i = 0; i < str.size(); i++) {
		if (str.at(i) == '9') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
from itertools import combinations_with_replacement

n, m, q = [int(x) for x in input().split()]
c_list = [[int(x) for x in input().split()] for _ in range(q)]

ans = 0
for temp in list(combinations_with_replacement(range(1, m + 1), n)):
    d_sum = 0
    for a, b, c, d in c_list:
        if temp[b - 1] - temp[a - 1] == c:
            d_sum += d
    if d_sum > ans:
        ans = d_sum
print(ans)

Measured memory_bytes: 21484
#include <iostream>
#include <string>
#include <map>

using namespace std;

const string STBL1 = " ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string CODE1[] = {
"101", "000000", "000011", "10010001", "010001", "000001", "100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000",
};
const string STBL2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";

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

    map<char,string> dict;
    for(int i = 0; i < 32; ++i) {
        dict[STBL1[i]] = CODE1[i];
    }

    string line;
    while(getline(cin, line)) {
        string codestr;
        for(string::const_iterator it = line.begin(); it != line.end(); ++it) {
            codestr += dict[*it];
        }
        codestr += string((5-codestr.size()%5) % 5, '0');
        string res;
        for(int i = 0; i < codestr.size(); i += 5) {
            const string num = codestr.substr(i, 5);
            int val = 0;
            for(int j = 0; j < 5; ++j) {
                val <<= 1;
                val += num[j]-'0';
            }
            res += STBL2[val];
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
string s;
int now=0,ans=0;
int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif
    cin>>s;
    for(char ch:s){
        if(ch=='R') ++now;
        else now=0;
        ans=max(ans,now);
    }
    cout<<ans<<'\n';
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N,D;
    cin>>N>>D;

    int x[N],y[N];
    rep(i,N){
        cin>>x[i]>>y[i];
    }

    int ans=0;
    rep(i,N){
        int sum=x[i]*x[i]+y[i]*y[i];
        if(D*D>=sum)ans++;
    }
    cout << ans << endl;

    



}


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

int main() {
  string c[3];

  for (int i = 0; i < 3; i++) {
    cin >> c[i];
  }
  cout << c[0].at(0) << c[1].at(1) << c[2].at(2) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin>>N>>M;
  priority_queue<int>re;
  for(int i=0;i<N;i++)
    {
    int64_t a;
    cin>>a;
  re.push(a);
  }
for(int i=0;i<M;i++)
{
 int x=re.top();
  re.pop();
  re.push(x/2);
}
  int64_t d=0;
  for(int i=0;i<N;i++)
  {
  d=d+re.top();
    re.pop();
  }
cout<<d;
}




Measured memory_bytes: 892
#include<cstdio>
#include<iostream>
using namespace std;
long long n,k,ans;
int main()
{
	cin>>n>>k;
	if(k==0)
	{
		cout<<n*n<<endl;
		return 0;
	}
	for(int i=k+1;i<=n;i++)
	{
		ans+=(n/i)*(i-k)+max((n%i-k+1),(long long)0);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pii pair<int,int>
#define reset(x,n) memset((x),(n),sizeof(x))
#define all(n) (n).begin(),(n).end()
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0);
long double dp[305][305][305];
bool used[305][305][305];
int cnt[4];
int n;
int t;
long double godp(int a,int b,int c){
	if(used[a][b][c])return dp[a][b][c];
	used[a][b][c]=1;
	long double tcnt=a+b+c;
	dp[a][b][c]=n*1.0/tcnt;
	if(a)dp[a][b][c]+=(a*1.0/tcnt*godp(a-1,b+1,c));
	if(b)dp[a][b][c]+=(b*1.0/tcnt*godp(a,b-1,c+1));
	if(c)dp[a][b][c]+=(c*1.0/tcnt*godp(a,b,c-1));
	return dp[a][b][c];
}
int main(){
	IOS
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>t;
		cnt[t]++;	
	}
	used[0][0][0]=1;
	cout<<fixed<<setprecision(10)<<godp(cnt[3],cnt[2],cnt[1])<<'\n';
}


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


Measured memory_bytes: 3084
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

void print_ALDS1_02B(int A[], int n) {
	for (int i = 0; i < n; ++i) {
		if (i != 0)
			cout << " " << A[i];
		else
			cout << A[i];
	}
	cout << endl;
}

int main() {

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

	int A[n];
	for (int i = 0; i < n; ++i) {
		scanf("%d", A + i);
	}

//selectionSort
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		bool flag = false;
		int min = i;
		for (int j = i + 1; j < n; ++j) {
			if (A[j] < A[min]) {
				min = j;
				flag = true;
			}
		}
		if (flag) {
			swap(A[min], A[i]);
			++cnt;
		}
	}
	print_ALDS1_02B(A, n);
	cout << cnt << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull; 
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)

template <class T, class U> ostream& operator<< (ostream &out, pair<T,U> c) { out << "(" << c.first << " "; out << c.second << ")"; return out; }
template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T> ostream& operator<< (ostream &out, set<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
const double PI  = 3.141592653589793238463;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, a , b, s = 0;
    cin >> n;
    while(n--){
        cin >> a >> b;
        s += b - a +1;
    }
    cout << s;
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
 
using namespace std;
 
int main() {
    int N, K;
    cin >> N >> K;
 
    double logK = log2(K);
 
    double ans = K <= N ? (double)(N - K + 1) / (double)N : 0.0;
 
    for (int i = 1; i <= min(K - 1, N); ++i) {
        int y = ceil(logK - log2(i));
        ans += 1 / (double)(N * pow(2, y));
    }
 
    printf("%.11lf\n", ans);
 
    return 0;
}


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

# define ll long long 
# define VI vector<int>
# define VLL vector<ll>
# define PII pair<int,int> 
# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ld long double
# define FOR(i,a,b) for(int i = a ; i < b ; ++i)
# define RFOR(i,a,b) for(int i = a ; i >= b ; --i)
# define all(a) a.begin(),a.end() 
const int MxN = 200001 ; 
const int MOD = 1e9 + 7 ; 

/* VARIABLES */
int n, k ;  
/* END OF VARIABLES */


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ;  
	
	cin >> n >> k ; 
	if(k%2 != 0) {
		ll ans =0 ; 
		FOR(i,1,n+1) {
			if(i%k==0)
				ans++;
		}
		cout << ans*ans*ans ; 
	} else {
		ll ans = 0 ,cnt=0; 
		FOR(i,1,n+1) {
			if(i%k==0 )
				ans++;
			if(i%k == (k/2))
				cnt++;
		}
		//cout << cnt ; 
		cout << (ll)ans*ans*ans + cnt*cnt*cnt  ; 
	}

	
	return 0 ; 
}



Measured memory_bytes: 3560
#include <stdio.h>
#include <string.h>

int main(){
    char s0[100];
    char s1[7];
    fgets(s0, 100, stdin);
    int n = 0;
    int r = 0;
    for(int i = 0; i<100; i++){
        if(s0[i] == '\0'){
            n = i-1;
            break;
        }
    }
    for(int i = 0; i < 7; i++){
        s1[i] = s0[i];
    }
    if(strcmp(s1,"keyence") == 0) r = 1;
    
    s1[6] = s0[n-1];
    if(strcmp(s1,"keyence") == 0) r = 1;
    
    s1[5] = s0[n-2];
    if(strcmp(s1,"keyence") == 0) r = 1;

    s1[4] = s0[n-3];
    if(strcmp(s1,"keyence") == 0) r = 1;

    s1[3] = s0[n-4];
    if(strcmp(s1,"keyence") == 0) r = 1;
    
    s1[2] = s0[n-5];
    if(strcmp(s1,"keyence") == 0) r = 1;

    s1[1] = s0[n-6];
    if(strcmp(s1,"keyence") == 0) r = 1;

    s1[0] = s0[n-7];
    if(strcmp(s1,"keyence") == 0) r = 1;

    if (r == 1)
    printf("%s\n", "YES");
    else
    printf("%s\n", "NO");
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

using namespace std;

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



Measured memory_bytes: 2600
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

int main() {
	lint N, Q;
	cin >> N >> Q;
	vector<priority_queue<lint>>A(N);
	int a, t, x;
	rep(i, Q) {
		cin >> a;
		if (a == 0) {
			cin >> t >> x;
			A[t].push(x);
		}
		else if (a == 1) {
			cin >> t;
			if (!A[t].empty()) {
				cout << A[t].top() << endl;
			}
		}
		else if (a == 2) {
			cin >> t;
			if (!A[t].empty()) {
				A[t].pop();
			}
		}
	}
}




Measured memory_bytes: 5148
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
// IO
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
#define pd(a) printf("%d ", a)
#define pld(a) printf("%d\n", a)
#define pda(a, n) fo(i, n) pd(a[i])
#define pl printf("\n")
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b) 
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
// math
const ll mod = 1e9+7;
template<typename T> T gcf(T a, T b) {return (b == 0) ? a : gcf(b, a%b);} 
template<typename T> T lcm(T a, T b) {return (a*b)/gcf(a, b);}
template<typename T> T sumTo(T x) {return x * (x+1) / 2;}
template<typename T> T sumSquaresTo(T x) {return x * (x+1) * (2*x+1) / 6;}
template<typename T> T ceilDiv(T n, T d) {return (n+d-1)/d;}

void solve() {
    int n; sc(n);
    int a[n], b[n-1];
    sca(b, n-1);
    a[0] = b[0];
    a[1] = b[0];
    fo1(i, n-2) {
        a[i] = min(a[i], b[i]);
        a[i+1] = b[i];
    }
    int ans = 0;
    for (int x: a) ans += x;
    cout << ans;
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

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

    int n; cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];

    int ans = 0;
    if (p[n - 1] == n) {
        swap(p[n - 1], p[n - 2]);
        ans++;
    }

    for (int i = 0; i < n - 1; i++) {
        if (p[i] == i + 1) {
            swap(p[i], p[i + 1]);
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[200009], b[200009], imos[100009], bit[100009]; vector<int> g[100009], gs[100009];
void add(int pos, int val) {
	for (int i = pos + 1; i <= 100000; i += i & (-i)) bit[i] += val;
}
int sum(int pos) {
	int ret = 0;
	for (int i = pos; i >= 1; i -= i & (-i)) ret += bit[i];
	return ret;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i]; a[i]--; b[i] -= 2;
		imos[a[i]]++;
		imos[b[i] + 1]--;
		g[b[i]].push_back(i);
		gs[a[i]].push_back(i);
	}
	for (int i = 0; i < 100000; i++) imos[i + 1] += imos[i];
	int rb = *max_element(imos, imos + 100000), ra = 0;
	for (int i = 0; i <= 100000; i++) {
		for (int j : gs[i]) add(i, 1);
		for (int j : g[i]) add(a[j], -1), add(i, 1);
		for (int j : g[i]) ra = max(ra, sum(i + 1) - sum(a[j]));
	}
	cout << ra << ' ' << rb << endl;
	return 0;
}

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

using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;

template<typename C>
i64 Size(const C& c) { return static_cast<i64>(c.size()); }

template<typename C>
void Sort(C &c) { std::sort(c.begin(), c.end()); }

template<typename C>
void SortR(C &c) { std::sort(c.rbegin(), c.rend()); }

template<typename T, typename U, typename Comp=std::less<>>
bool ChMax(T& x_max, const U& x, Comp comp={}) {
  if(comp(x_max, x)) {
    x_max = x;
    return true;
  }
  return false;
}

template<typename T, typename U, typename Comp=std::less<>>
bool ChMin(T& x_min, const U& x, Comp comp={}) {
  if(comp(x, x_min)) {
    x_min = x;
    return true;
  }
  return false;
}

struct ProconInit {
  static constexpr int IOS_PREC = 15;
  static constexpr bool AUTOFLUSH = false;

  ProconInit() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(IOS_PREC);
    if (AUTOFLUSH) std::cout << std::unitbuf;
  }
} PROCON_INIT;

i64 gcd(i64 x, i64 y) { return (x % y) ? gcd(y, x % y) : y; }

void solve() {
  i64 k; std::cin >> k;

  i64 sum = 0;
  for (i64 i = 1; i <= k; i++) {
    for (i64 j = 1; j <= k; j++) {
      for (i64 l = 1; l <= k; l++) {
        sum += gcd(gcd(i, j), l);
      }
    }
  }

  std::cout << sum << "\n";
}

signed main() {
  solve();

  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair<int, int> pii;  // pair<int, int> に pii という別名を付ける
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<string> C(N);
  for(int i=0;i<N;i++){
    cin >> C.at(i);
  }
  int ac = 0;
  int wa = 0;
  int tle = 0;
  int re = 0;
  for (int i = 0; i < N; i++){
    if(C.at(i) == "AC"){
      ac ++;
    }
    else if(C.at(i) == "WA"){
      wa ++;
    }
    else if(C.at(i) == "TLE"){
      tle ++;
    }
    else{
      re ++;
    }
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

Measured memory_bytes: 6320
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int H, W, D;
    cin >> H >> W >> D;
    vector<vector<int>> A(H, vector<int>(W));
    cin >> A;
    vector<int> dist(H * W, 0);
    map<int, pii> p;
    REP(i, H) REP(j, W) p[A[i][j] - 1] = {i, j};

    REPF(i, D, H * W) {
        auto d = [&](pii a, pii b) {
            return abs(a.first - b.first) + abs(a.second - b.second);
        };
        dist[i] = dist[i - D] + d(p[i-D], p[i]);
    }

    int Q;
    cin >> Q;
    while (Q--) {
        int L, R;
        cin >> L >> R;
        L--, R--;
        cout << dist[R] - dist[L] << endl;
    }
    return 0;
}



Measured memory_bytes: 8192
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

bool comp(pair<ll,ll> a, pair<ll,ll> b){
	return a.second > b.second;
}
int main(void){
	ll n,k;
	cin>>n>>k;
	vector<pair<ll,ll> > sushi(n);
	rep(i,n)cin>>sushi[i].first>>sushi[i].second;
	sort(sushi.begin(), sushi.end(),comp);
	
	//rep(i,n)cout<<sushi[i].first<<","<<sushi[i].second<<endl;

	//最初のポイントの計算
	ll ans=0,base=0;
	ll num[n+1];
	rep(i,n)num[i+1]=0;
	rep(i,k){
		base+=sushi[i].second;
		num[sushi[i].first]++;
	}
	ll kind=0;
	rep(i,n)
		if(num[i+1]!=0)kind++;
	ans=base+kind*kind;
	//kind種類の寿司が入ってる時の最大値
	
	ll pivot=k;
	//i個目を抜いて新しい種類を入れて高いスコアが出せるか
	for(int i=k-1;i>-1;i--){
		//2個以上でなければ取る意味ない
		if(num[sushi[i].first]>=2){
			for(int j=pivot;j<n;j++){
				//新しい種類しか取る必要なし
				if(num[sushi[j].first]==0){
					base = base-sushi[i].second+sushi[j].second;
					kind++;
					//cout<<"base: "<<base<<",kind: "<<kind<<endl;
					if(ans < base+kind*kind)ans = base+kind*kind;
					num[sushi[i].first]--;
					num[sushi[j].first]++;
					pivot=j+1;
					break;
				}
			}
		}
	}

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


Measured memory_bytes: 2560