akhauriyash/Code-Regression huggingface dataset:
mod = 10 ** 9 + 7

def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res

def modinv(a, mod):
    return modpow(a, mod - 2, mod)

n = int(input())
a = list(map(int, input().split()))
invsum = [0]
for i in range(n):
    invsum.append((invsum[i] + modinv(i + 1, mod)) % mod)
ans = 0
for i in range(1, n + 1):
    ans = (ans + a[i - 1] * (invsum[i] + invsum[n + 1 - i] - 1) % mod) % mod
for i in range(2, n + 1):
    ans = ans * i % mod
print(ans)

Measured memory_bytes: 14480
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


//——————— comre(n);　→　nCk=com(n,k) —————————————————

vector<ll> fact, fact_inv, inv;
/*  comre :二項係数のための前処理
    計算量:O(n)
*/
void comre(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}
/*  com :modでの二項係数を求める(前処理 comre が必要)
    計算量:O(1)
*/
ll com(ll n, ll k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}


int main() {
  ll n,k;
  cin>>n>>k;

  repo(i,k+1){
    if(n-k<i-1) cout << 0 << endl;
    else {
    comre(k-1);
    comre(n-k+1);
    cout << (com(k-1,i-1)*com(n-k+1,i))%mod << endl;
    }
  }

}

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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef priority_queue< int, vector< int >, greater< int > >  minHeap;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bug(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

inline int addmod(lli x,lli y)
{
    return (x%mod + y%mod)%mod;
}
inline int submod(lli x,lli y)
{
    return (x%mod - y%mod + mod)%mod;
}
inline int mulmod(lli x,lli y)
{
    return (x%mod * y%mod)%mod;
}


inline int nextSubMask(int i, int mask)
{
    return (i-1)&mask;   /// returns next  submask
}

template<typename T>
void we_r_done(T mssg)
{
    cout<<mssg;
    exit(0);
}
const int N = 2e5 + 6;
vector<int>tree[N];
int du[N] , dv[N];

void dfsu(int x , int p){

    for(int u : tree[x]){
        if(p != u){
            du[u] = du[x] + 1;
            dfsu(u,x);
        }
    }
}

void dfsv(int x , int p){

    for(int u : tree[x]){
        if(p != u){
            dv[u] = dv[x] + 1;
            dfsv(u,x);
        }
    }
}

int main()
{
    ///freopen("output.txt","w",stdout);
    //freopen("input.txt","r",stdin);
    FastIO;

    int n,u,v;
    while(cin>>n){
        cin>>u>>v;

        for(int i=1; i<=n; i++){
            tree[i].clear();
            du[i] = dv[i] = 0;
        }

        for(int i=1; i<n; i++){
            int x,y;
            cin>>x>>y;
            tree[x].pb(y);
            tree[y].pb(x);
        }

        du[u] = dv[v] = 0;
        dfsu(u,u);
        dfsv(v,v);
        int ans = 0;
        for(int i=1; i<=n; i++){

            if(dv[i]>du[i])ans = max(ans , dv[i]-1);

        }
        cout<<ans<<endl;
    }

    return 0;
}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?
///sort(atoz(v), [](const data x, const data y){return (x.a==y.a?x.b>y.b : x.a<y.a);});


Measured memory_bytes: 12672
def main():
    MOD = 10 ** 9 + 7

    N = int(input())
    *A, = map(int, input().split())

    ans = 0
    s = A[0]
    for i in range(1, N):
        ans = (ans + s * A[i]) % MOD
        s = (s + A[i]) % MOD
    print(ans)


if __name__ == '__main__':
    main()


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

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

typedef struct
{
	float x, y;
} point;

bool isOrthogonal(point A, point B, point C, point D)
{
	if( (-A.x + B.x) * (-C.x + D.x) + (-A.y + B.y) * (-C.y + D.y) == 0 )
	{
		return true;
	}
	return false;
}

int main()
{
	point A, B, C, D;
	
	while( scanf("%f%f%f%f%f%f%f%f", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y, &D.x, &D.y) != EOF )
	{
		printf("%s\n", isOrthogonal(A, B, C, D) ? "YES" : "NO");
	}
	return (0);
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int d[52];
unordered_set<int> S,T;

int main(){
  cin>>n;
  REP(i,n)cin>>d[i];
  // if(n>=24){
  //   puts("0");
  //   return 0;
  // }
  S.insert(1);
  REP(i,n){
    int amsk = 1<<d[i];
    int bmsk = 1<<((24-d[i])%24);
    for(int x : S){
      if((x&amsk)==0){
        T.insert(x|amsk);
      }
      if((x&bmsk)==0){
        T.insert(x|bmsk);
      }
    }
    S.swap(T);
    T.clear();
  }
  int ans = 0;
  for(int x : S){
    vi v;
    REP(i,24)if((x>>i)&1){
      v.push_back(i);
    }
    int tmp = 252;
    REP(i,v.size()){
      int s = v[i];
      int t = v[(i+1)%v.size()];
      CHMIN(tmp, (t-s+24)%24);
    }
    CHMAX(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int x, a, b;
  cin >> x >> a >> b;
  if(abs(x-a) < abs(x-b)){
    cout << "A" << endl;
  }else{
    cout << "B" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b;
	cin>>a>>b;
	if(a==0||b==0)
	  {
	  	printf("Zero");
	  	return 0;
	  }
	if(a<0&&b>0)
	  {
	  	printf("Zero");
	  	return 0;
	  }
	if(a>0)
	  {
	  	printf("Positive");
	  	return 0;
	  }
	if(b<0)
	  {
	  	if((b-a+1)%2==1)
	  	  printf("Negative");
	  	else
	  	  printf("Positive");
	  }
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  string s, t; cin >> s >> t;

  for(int i=0;i<n;++i) {
    cout << s[i] << t[i];
  }
  cout << endl;

}


Measured memory_bytes: 256
package main

import("fmt")

func main(){
  var n int
  fmt.Scan(&n)
  
  d:=make([]int,n)
  for i:=range d{
    fmt.Scan(&d[i])
  }
  ans:=0
  for i:=0; i<n; i++{
    for j:=i+1; j<n; j++{
      ij:=d[i]*d[j]
      ans+=ij
    }
  }
  fmt.Print(ans)
} 

Measured memory_bytes: 512
n = int(input())
s = list(input())

a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

def find_alp(c, n):
    index = a.find(c)
    if index + n > 25:
        return a[index + n - 26]
    else:
        return a[index + n]

for j, c in enumerate(s):
    s[j] = find_alp(c, n)

print("".join(s))


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

using namespace std;

#define pb            push_back
#define mp            make_pair
#define po            pop_back
#define fi            first
#define se            second
#define mxn           100005
#define ll            long long int
#define ldb           long double
#define fr(i,a,b,k)   for(int i=a ; i<b ; i+=k)
#define frr(i,a,b,k)  for(int i=a ; i>b ; i-=k)
#define all(v)        v.begin(),v.end()
#define endl          "\n"
#define deg(x)        cout<<endl<<#x<<" = "<<(x)<<endl;
#define casep(x)      cout<<"Case #"<<(x)<<": ";
#define fast          ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

typedef pair<int,int> pp;
typedef vector<int> vi;
typedef vector<pp> vpp;
typedef vector<vi> vvi;

const int inf = INT_MAX;

ll power(int a, int n, int mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
int gcd(int a,int b){ return __gcd(a,b);}
int lcm(int a,int b){return a*b/__gcd(a,b);}
vector<vector<int>> adj;
bool visited[mxn];


void solve(ll test){

    string s;
    cin >> s;

    ll sum = 0;

    for(ll i=0 ; i<s.length() ; i++) {
        sum += (s[i]-'0');
    }

    if(sum%9 == 0)cout << "Yes";
    else cout << "No";

}

int main(){

    fast;
    int t=1;
    // cin >> t;
    for(int i=1 ; i<=t ; i++){
        solve(i);
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<int, int>, // change type
//        null_type,
//        less<pair<int, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)(x).size()
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
const double PI = 3.14159265358979323846;
const double eps = (1e-8);




int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
 //   freopen("input.txt", "r", stdin);
//    freopen("facebook.txt", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    if (k <= (n+1)/2)
        cout << "YES";
    else
        cout << "NO";
    return 0;
}

Measured memory_bytes: 384
class arrayList():
    def __init__(self):
       self.L = []

    def pushBack(self, x):
        self.L.append(x)

    def dump(self):
        print(" ".join(map(str, self.L)))

    def clear(self):
        self.L.clear()

n,queries = map(int, input().split())
parentList = {}
for i in range(queries):
    q, t, *x = map(int, input().split())
    if parentList.get(t) == None:
        parentList[t] = arrayList()

    if q == 0:
        parentList[t].pushBack(x[0])
    elif q == 1:
        parentList[t].dump()
    elif q == 2:
        parentList[t].clear()




Measured memory_bytes: 60412
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <math.h>
typedef long long ll;
using namespace std;

int main() {
	string s;
	cin>>s;
	ll n=s.length();
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			if(s[i]==s[j]){
				cout << "no"<<endl;
				return 0;
			}
		}
	}
	cout << "yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
def solve():
  n = int(input())
  if n == 0:
    exit()
  C = [c for c in input().split()]

  V = [0] * 26

  for i, c in enumerate(C, 1):
    V[ord(c) - ord('A')] += 1
    maxi = 0
    ma1 = 0
    ma2 = 0
    for j, v in enumerate(V):
      if v > ma1:
        ma1, ma2 = v, ma1
        maxi = j
      elif v > ma2:
        ma2 = v

    if ma1 - ma2 > n - i:
      print(chr(ord('A') + maxi), i)
      return

  print('TIE')

while True:
  solve()


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

int main(){
    int K, N;
    cin >> K >> N;
    int A[N];
    int a[N];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    for (int i = 0; i < N - 1; i++)
    {
        a[i] = A[i+1] - A[i];
    }
    a[N-1] = A[0] + K - A[N-1];

    int max = 0;
    for (int i = 0; i < N; i++)
    {
        if (max < a[i])
        {
            max = a[i];
        }
    }
    
    cout << K - max << endl;

    return 0;

}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int DigitsSum(int num){
	int digits;
	int sum = 0;
	while (num) {
		digits = num % 10;
		sum += digits;
		num /= 10;
	}
	return sum;
}

struct Hd {
	unsigned long num;
	int order;
};

int main() {
	/*Sort*/
	//vector<int> a(N);
	//for (int i = 0; i < N; i++) cin >> a[i]
	//sort(a.begin(), a.end() , greater<int>());

	int N,K;
	cin >> N >> K;

	
	
	vector<unsigned long> H(N);
	//vector<struct Hd> H_sort(N);
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	if (N <= K) {
		cout << 0;
		exit(0);
	}
	//for (int i = 0; i < N; i++) { 
	//	H_sort[i].num = H[i]; 
	//	H_sort[i].order = i;
	//}

	long long sum = 0;
	sort(H.begin(), H.end(), greater<unsigned int>());
	for (int i = K; i < N; i++) {
		sum += H[i];
	}


	cout << sum;
	return 0;
}


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

int o[5011][5];

int yoko(int L,int R){
	for(int i = 5010 ; i > 0 ; i--){
		int f = 0;
		for(int j = L ; j <= R ; j++){
			if( o[i-1][j] ){
				f = 1;
			}
		}
		if( f ){
			for(int k = L ; k <= R ; k++)
				o[i][k] = 1;
			return 0;
		}
	}
	for(int i = L ; i <= R ; i++)
		o[0][i] = 1;
}
int tate(int x,int l){
	for(int i = 5010 ; i > 0 ; i--){
		int f = o[i-1][x];
		if( f ){
			for(int j = 0 ; j < l ; j++)
				o[i+j][x] = 1;
			return 0;
		}
	}
	
	for(int i = 0 ; i < l ; i++) o[i][x] = 1;
}
int eraser(){
	vector<int> v[5];
	for(int i = 0 ; i <= 5010 ; i++){
		if( o[i][0] && o[i][1] && o[i][2] && o[i][3] && o[i][4] ){
			o[i][0] = o[i][1] = o[i][2] = o[i][3] = o[i][4] = 0;
		}
		if( o[i][0] || o[i][1] || o[i][2] || o[i][3] || o[i][4] ){
			for(int j = 0 ; j < 5 ; j++)
				v[j].push_back(o[i][j]);
		}
	}
	for(int i = 0 ; i < 5011 ; i++)
		for(int j = 0 ; j < 5 ; j++)
			o[i][j] = 0;
	for(int i = 0 ; i < v[0].size() ; i++)
		for(int j = 0 ; j < 5 ; j++){
			o[i][j] = v[j][i];
		}
	
}
int main(){
	int n;
	while(cin >> n && n){
		for(int i = 0 ; i < 5011 ; i++)
			for(int j = 0 ; j < 5 ; j++)
				o[i][j] = 0;
		
		for(int i = 0 ; i < n ; i++){
			int d,l,x;
			cin >> d >> l >> x;
			x--;
			if( d == 1 ){
				yoko(x,x+l-1);
			}else{
				tate(x,l);
			}
			eraser();
		}
		int ans = 0;
		for(int i = 0 ; i < 5011 ; i++)
			for(int j = 0 ; j < 5 ; j++)
				ans += o[i][j];
		cout << ans << endl;
	}
}

Measured memory_bytes: 1476
# https://atcoder.jp/contests/exawizards2019/tasks/exawizards2019_b

import itertools
import collections
import bisect

def main():
    N = int(input())
    S = list(input())
    print("Yes" if S.count('R') > S.count('B') else "No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var A = AB[0];
            var B = AB[1];

            var output = Math.Max(A, B);
            output += output == A ? Math.Max(A - 1, B) : Math.Max(A, B - 1);
            Console.Write(output);
        }
    }
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

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

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
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...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
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);
}

//main code

int main(int argc, char const* argv[])
{
	int n,m;
	cin >> n >> m;
	map<int,priority_queue<LL>> mp; // key:市番号, val:年代のqueue
	VL p(m), y(m);
	for (int i = 0; i < m; i++) {
		cin >> p[i] >> y[i];
	}
	for (int i = 0; i < m; i++) {
		mp[p[i]].push(y[i]);
	}
	map<PLL,int> ans; // key:{市番号, 年代}, val: 順番
	for (auto&& var : mp) {
		auto &pq = var.second;
		for (int i = pq.size();!pq.empty(); i--) {
			ans[{var.first, pq.top()}] = i;
			pq.pop();
		}
	}
	for (int i = 0; i < m; i++) {
		cout << setfill('0') << right << setw(6) << p[i];
		cout << setfill('0') << right << setw(6) << ans[{p[i], y[i]}];
		cout << endl;
	}
	return 0;
}


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

int e[100][100];

void f(int d,int w){
  for(int i=0;i<d;i++){
    for(int j=0;j<w;j++){
      cin>>e[i][j];
    }
  }

  int ans=0;

  for(int x=0;x<w;x++){
    for(int y=0;y<d;y++){
      for(int xx=x+2;xx<w;xx++){
        for(int yy=y+2;yy<d;yy++){
          int mi=10;
          for(int i=y;i<=yy;i++){
            for(int j=x;j<=xx;j++){
              
              if(y<i&&i<yy&&x<j&&j<xx) continue;
              mi=min(mi,e[i][j]);
            }
          }
          int ma=0;
          for(int i=y+1;i<yy;i++){
            for(int j=x+1;j<xx;j++){
                ma=max(ma,e[i][j]);
            }
          }
          int res=0;
          if(mi-ma<=0) continue;
          for(int i=y+1;i<yy;i++){
            for(int j=x+1;j<xx;j++){
              res+=mi-e[i][j];
            }
          }
          ans=max(ans,res);
        }
      }
      
    }
  }

  cout<<ans<<endl;
}


main(){
  int d,w;
  while(true){
    cin>>d>>w;
    if(d==0) break;
    f(d,w);
  }
}




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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

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

  string s, t;
  cin >> s >> t;

  int ans = 0;
  rep(i, 0, s.size()) ans += s[i] != t[i];
  cout << ans << '\n';
  return 0;
}

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

const int INF = 1e9;

int main() {
  int n, k;
  cin>>n>>k;
  int v[n];
  for (int i=0; i<n; i++) cin>>v[i];
  long long l_acc[n+1];
  l_acc[0] = 0;
  for (int i=0; i<n; i++) {
    l_acc[i+1] = l_acc[i] + v[i];
  }
  long long r_acc[n+1];
  r_acc[0] = 0;
  for (int i=0; i<n; i++) {
    r_acc[i+1] = r_acc[i] + v[n-i-1];
  }

  long long ans = 0;
  for (int l=0; l<=min(n, k); l++) {
    for (int r=0; r+l<=min(n, k); r++) {
      long long tmp = l_acc[l] + r_acc[r];
      vector<int> minus;
      for (int i=0; i<l; i++) {
        if (v[i] < 0) {
          minus.push_back(v[i]);
        }
      }
      for (int i=0; i<r; i++) {
        if (v[n-i-1] < 0) {
          minus.push_back(v[n-i-1]);
        }
      }
      sort(minus.begin(), minus.end());
      for (int i=0; i<min((int)minus.size(), k-r-l); i++) {
        tmp -= minus[i];
      }
      ans = max(ans, tmp);
    }
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

ll dp[1010][10010]={};

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll h,n;cin>>h>>n;
  V<ll> a(n),b(n);
  rep(i,0,n)cin>>a[i]>>b[i];

  rep(i,0,1010)rep(j,0,10010)dp[i][j]=LINF;
  dp[0][0]=0;

  rep(i,0,n){
    rep(j,0,10008){
      ll nex=min(j+a[i],10000ll);
      
      chmin(dp[i+1][j],dp[i][j]);
      chmin(dp[i+1][nex],dp[i][j]+b[i]);
      if(j-a[i]>=0)chmin(dp[i+1][j],dp[i+1][j-a[i]]+b[i]);
    }
  }

  ll ans=LINF;
  rep(i,h,10008){
    chmin(ans,dp[n][i]);
  }
  cout<<ans<<ENDL;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 79232
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <deque>
std::vector<std::string > ans;
int N;

void dfs(std::string s, int ok_count){
  if (s.length()==N){
    ans.push_back(s);
  } else {
    std::string temp;
    temp = s;
    for (int i=0; i<=ok_count; i++){
      s = temp;
      s+=(char)('a'+i);
      dfs(s,std::max(ok_count,i+1));
    }
  }
  return;
}

int main(){
  scanf("%d", &N);
  std::string S;
  S+='a';
  dfs(S, 1);
  /*std::cout << ans.size() << std::endl;
  std::sort(ans.begin(), ans.end());
  ans.erase(unique(ans.begin(), ans.end()), ans.end());
  std::cout << ans.size() << std::endl;*/
  for (int i=0; i<ans.size(); i++){
    std::cout << ans[i] << std::endl;
  }
  return 0;
}


Measured memory_bytes: 4724
n,k=map(int,input().split())
a=list(map(int,input().split()))
f=list(map(int,input().split()))
a.sort()
f.sort(reverse=1)
su=ok=ng=0
for i in range(n):
  ok=max(ok,a[i]*f[i])
  su+=a[i]
if su<=k:print(0);exit()
while ng+1<ok:
  mid=(ok+ng)//2
  h=0
  for i in range(n):
    r=a[i]-(mid//f[i])
    if (r<0):
      r=0
    h+=r
  if h<=k:ok=mid
  else:ng=mid
print(ok)

Measured memory_bytes: 119500
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
typedef pair<ll, ll> LP;
 
ll POW(ll m,ll n)
{
  if(n<0) return 0;
  if(n==0) return 1;
  return m*POW(m,n-1)%MOD;
}
 
ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
 
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a, ll m) {
    ll x, y;
    extGCD(a, m, x, y);
    return mod(x, m);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return m%MOD*COM(m-1,n)%MOD*modinv(m-n,MOD)%MOD;
}
 
int main()
{
  ll a,b,c;
  cin >> a >> b >> c;
  printf("%lld",a+b+c+9*max({a,b,c}));
}

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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

int main()
{
    canhazfast();

    int n, l, s = 0, d = 1e9;

    cin >> n >> l;
    for (int i = 0; i < n; ++i) {
        int a = l+i;
        s += a;
        if (abs(d) > abs(a)) d = a;
    }
    cout << s-d << '\n';

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(S: str):
    if S == "RRR":
        print(3)
    elif S == "SRR" or S == "RRS":
        print(2)
    elif S.count("R") == 2 or S.count("R") == 1:
        print(1)
    else:
        print(0)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Measured memory_bytes: 61700
#include<iostream>
#include<deque>
#include<algorithm>
#include<numeric>
using namespace std;
int n;
deque<int> s, s10;
int ret = 0;
int main(void) {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		if (tmp % 10 == 0)
			s10.push_back(tmp);
		else {
			s.push_back(tmp);
			ret += tmp;
		}
	}
	sort(s.begin(), s.end());
	sort(s10.begin(), s10.end());
	if (s.size() != 0) {
		ret += accumulate(s10.begin(), s10.end(), 0);
	}
	while (s.size() > 0) {
		if (ret % 10 == 0) {
			ret -= s.front();
			s.pop_front();
		}
		else break;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        hh: [u32;n]
    }
    let mut vv = vec![0;n];
    let mut cnt = 0;
    loop {
        let mut p = std::usize::MAX;
        for i in 0..n {
            if vv[i] != hh[i] {
                p = i;
                break;
            }
        }
        if p == std::usize::MAX {
            break;
        }
        for i in p..n {
            if vv[i] == hh[i] {
                break;
            }
            vv[i] += 1;
        }
        cnt += 1;
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4352
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include<unordered_map>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) vdeb(da[i]);
    std::cout << std::endl;
}

using namespace std;
typedef pair<Pii,Pii> P;

int n,m,q; 
vector<P> da(50);

int dfs(int now, vector<int> &ans){
    if(now==0){
        // vdeb(ans);
        int ret = 0;
        rip(i,q,0){
            if(ans[da[i].first.second]-ans[da[i].first.first] == da[i].second.first) ret += da[i].second.second;
        }
        return ret;
    }
    else{
        int gg = (ans.size())?ans.back():1, ret = 0;
        rip(i,m+1, gg){
            ans.push_back(i);
            chmax(ret, dfs(now-1, ans));
            ans.pop_back();
        }
        return ret;
    }
}

int main(){
    cin >> n >> m >> q;
    rip(i,q,0) cin >> da[i].first.first >> da[i].first.second >> da[i].second.first >> da[i].second.second;
    rip(i,q,0) da[i].first.second--, da[i].first.first--;
    vector<int> ans(0);
    cout << dfs(n, ans) << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {

    int N; cin >> N;
    vector<vi> abc(N, vi(3)); rep(i, N) cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
    vector<vi> dp(N, vi(3, 0));

    rep (i, N-1) {

        rep (j, 3) {

            rep (k, 3) {

                if (j == k) continue;

                dp[i+1][j] = max(dp[i+1][j], dp[i][k] + abc[i][k]);

            }
            // cout << dp[i+1][j] << endl;

        }
    }

    int ans = 0; rep (i, 3) ans = max(ans, dp[N-1][i] + abc[N-1][i]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> arr(N);
    set<int> values;
    for(int i = 0; i < N; i++){
        cin >> arr[i];
        values.insert(arr[i]);
    }

int backet_size = 200010;
vector<int> backet(backet_size);
    for(int i = 0; i < N; i++) backet[arr[i]]++;
    sort(backet.begin(), backet.end(), greater<int>());


    int balls = 0;
    for (int i = 0; i < K;i++){
        balls += backet[i];
}

    cout << N - balls << endl;

}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int64_t INF = (1 << 20);
int64_t N, MAXN = 10010;
vector< vector < pair<int64_t, int64_t> > > Edges(MAXN);

void dijkstra()
{
  priority_queue<pair<int64_t, int64_t>, vector<pair<int64_t, int64_t> >, greater<pair<int64_t, int64_t > > > PQ;
  vector<int64_t> Color(MAXN, 0), D(MAXN, INF); // 各点を無限大にする。

  D.at(0) = 0; // 始点を0とする。
  PQ.push(make_pair(0, 0));
  Color.at(0) = 1; // グレーの状態に

  while (!PQ.empty())
  {
    pair<int64_t, int64_t> f = PQ.top();
    PQ.pop();
    int64_t u = f.second; // 未決定の中で、最短経路の頂点
    Color.at(u) = 2;      // 決定済とする
    if (D.at(u) < f.first)
      continue;
    for (int i = 0; i < Edges.at(u).size(); i++)
    {
      int64_t v = Edges.at(u).at(i).first; // uからの辺の終点
      if (Color.at(v) == 2)
        continue;
      if (D.at(v) > D.at(u) + Edges.at(u).at(i).second) // uを経由した場合の距離
      {
        D.at(v) = D.at(u) + Edges.at(u).at(i).second;
        PQ.push(make_pair(D.at(v), v)); // 頂点vの暫定での距離、頂点vをペアにする
        Color.at(v) = 1;                // グレーにする
      }
    }
  }
  for (int i = 0; i < N; i++)
    cout << i << ' ' << (D.at(i) == INF ? -1 : D.at(i)) << endl;
}

int main()
{
  cin >> N;
  int k, u, v, c;
  for (int i = 0; i < N; i++)
  {
    cin >> u >> k;
    for (int j = 0; j < k; j++)
    {
      cin >> v >> c;
      Edges.at(u).push_back(make_pair(v, c));
    }
  }

  dijkstra();
}



Measured memory_bytes: 3404
import sys
import numpy as np


n, k = map(int,input().split())

a = np.array(sorted(list(map(int, input().split()))))
f = np.array(sorted(list(map(int, input().split())), reverse=True))

asum = a.sum()

l,r = 0, 10**13
while l != r:
    mid = (l+r)//2

    can = (asum - np.minimum(mid//f, a).sum()) <= k

    if can:
        r = mid
    else:
        l = mid +1

print(l)

Measured memory_bytes: 37292
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>

using namespace std;


int main() {
    int n, k;
    cin >> n >> k;
    map<int, int> m;
    for(int i = 0; i < k; i++){
        int d;
        cin >> d;
        for(int i = 0; i < d; i++){
            int x;
            cin >> x;
            m.insert(make_pair(x, x));
        }
    }
    cout << n - m.size() << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n;
  in(n);
  out("ABC");
  out(n);
  memi;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}

fn main() {
    let (a, b, _, k) = read!(i32, i32, i32, i32);
    if k <= a {
        println!("{}", k);

    } else if k <= a+b {
        println!("{}", k-b);

    } else {
        println!("{}", a - (k - a - b));
    }
}


Measured memory_bytes: 2164
#include<stdio.h>

int main() {
   int N;
   int s = 0;
   int max = 0;
   scanf("%d", &N);
   int L[N];
   for(int i = 0; i < N; i++) {
      scanf("%d", &L[i]);
   }
   for(int i = 0; i < N; i++) {
      if(max <= L[i]) {
         max = L[i];
      }
      s += L[i];
   }
   if(s-max > max) {
      printf("Yes\n");
   } else {
      printf("No\n");
   }
}


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

using namespace std;

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

    vector<long long> vt(n);
    for (int i = 0; i < n; ++i) {
        cin >> vt[i];
    }
    sort(vt.begin(), vt.end());

    long long ans = 0;
    for (int i = 0; i < n; ++i) {//一番短いもの
        for (int j = i + 1; j < n; ++j) {//二番目に短いもの
            auto itr = lower_bound(vt.begin(), vt.end(), vt[i] + vt[j]);
            ans += distance(vt.begin() + j + 1, itr);
        }
    }

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


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long a, b, h;
    scanf("%ld%ld%ld", &a, &b, &h);

    printf("%ld\n", (a+b)*h/2);

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
 
typedef long long int ll;
void hack(ll n)
{
    if(n==124)
    cout<<"hacked";   
}
ll gcd(ll a,ll b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
ll mod=998244353;
ll mod1=1e9+6;
#define int ll
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0) return power(a*a%mod,b/2);
    else return a*power(a*a%mod,b/2)%mod;
}
ll power1(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0) return power(a*a%mod1,b/2);
    else return a*power(a*a%mod1,b/2)%mod1;
}
void show(vector <pair<int,int>> v)
{
    for(int i=0;i<v.size();++i) cout<<v[i].first<<" "<<v[i].second<<" ";
        cout<<endl;
}
#define endl '\n'


int32_t main()
{
    IOS
   
 
    int a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b));
}


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

int main()
{
  ll K, N;
  cin >> K >> N;

  ll *As = new ll[N];
  REP(i, N)
  {
    cin >> As[i];
  }

  ll ans = (K - As[N - 1]) + As[0];
  ll m = ans;
  REP(i, N - 1)
  {
    ll d = As[i + 1] - As[i];
    ans += d;

    if (m < d) m = d;
  }
  ans -= m;

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

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

int main(void){
	int n,k;
	cin>>n>>k;
	vector<int> h(n);
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	sort(h.begin(),h.end());
	long long cnt=0;
	for(int i=n-k-1;i>=0;i--){
		cnt+=h[i];
	}
	cout<<cnt<<'\n';

	

	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

int N;
int A[2];
int ans, las = 0;

int main() {
	register int i;
	scanf("%d", &N);
	for(i = 1; i <= N; ++i) {
		scanf("%d", A + (i & 1));
		if(i > 1) {
			if(A[i & 1] == A[i & 1 ^ 1]) continue;
			if(las == 0) {las = A[i & 1] > A[i & 1 ^ 1] ? 2 : 1; continue;}
			if(A[i & 1] > A[i & 1 ^ 1] && las != 2) ++ans, las = 0;
			else if(A[i & 1] < A[i & 1 ^ 1] && las != 1) ++ans, las = 0;
		}
	}
	printf("%d\n", ans + 1);
	return 0;
}

Measured memory_bytes: 128
/********************************************************
  **░██████╗██╗░░░░░░█████╗░██╗░░░██╗██╗░█████╗░░██████╗░**
  **██╔════╝██║░░░░░██╔══██╗██║░░░██║██║██╔══██╗██╔════╝░**
  **╚█████╗░██║░░░░░███████║╚██╗░██╔╝██║██║░░╚═╝██║░░██╗░**
  **░╚═══██╗██║░░░░░██╔══██║░╚████╔╝░██║██║░░██╗██║░░╚██╗**
  **██████╔╝███████╗██║░░██║░░╚██╔╝░░██║╚█████╔╝╚██████╔╝**
  **╚═════╝░╚══════╝╚═╝░░╚═╝░░░╚═╝░░░╚═╝░╚════╝░░╚═════╝░**
  *********************************************************/

#include <bits/stdc++.h>
using namespace std;


#define ll                          long long
#define ld                          long double

#define forn(i,n)                   for(int i=0;i<n;++i)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend();
#define isSubstring(s1,s2)          s1.find(s2) != std::string::npos
	
#define pb                          push_back
#define pf                          push_front
#define mp                          make_pair
#define fr                          first
#define sc                          second

#define vpi                         <vector<pair<int,int>>
#define vi                          vector<int>
#define sz(a)                       (int)a.size()

#define   endl                       "\n"
#define     nl                       cout<<"\n";
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define MN                           INT_MIN
#define MX                           INT_MAX

bool isPrime(ll n){if(n<2)return false;for(ll x = 2;x*x <=n;x++){if(n%x == 0)return false;}return true;}
bool isPerfectSquare(long double x){long double sr=sqrt(x);return((sr-floor(sr))==0);}
int gcd(int a, int b){if(a==0)return b;if(b==0) return a;if(a==b)return a;if(a>b)return gcd(a-b,b);return gcd(a,b-a);}
int32_t main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	int need;
	for(int i = 0;i<sz(s);i++)
	{
		need = n;
		while(need--)
		{
			if(s[i]  != 'Z')
			{
				s[i]++;
			}else{
				s[i] = 'A';
			}
		}
	}
	cout << s << endl;
}
	

Measured memory_bytes: 3740