akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define ALL(x) (x).begin(),(x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	fill((T*)array, (T*)(array + N), val);
}

const ll INF = 1e18;

int main() {
	IOS;
	int a[3];
	REP(i, 3)cin >> a[i];
	sort(a, a + 3);
	int ans = a[2] * 10 + a[1] + a[0];
	dump(ans);
	return 0;
}

Measured memory_bytes: 892
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> H(N), W(N);
	rep(i, 0, N)cin >> H[i] >> W[i];
	int C[4][4];
	int goals[3] = {};
	rep(i, 0, 4)rep(j, 0, 4) {
		char c; cin >> c;
		if (c == 'R')
			C[i][j] = 0;
		else if (c == 'G')
			C[i][j] = 1;
		else
			C[i][j] = 2;
		goals[C[i][j]] |= 1 << (i * 4 + j);
	}
	vector<int> stamps;
	auto inrange = [&](int i, int j) {return 0 <= i && i < 4 && 0 <= j && j < 4; };
	rep(s, 0, N) {
		rep(i, -3, 4)rep(j, -3, 4) {
			int mask = 0;
			rep(ci, i, i + H[s])rep(cj, j, j + W[s]) {
				if (!inrange(ci, cj))continue;
				mask |= (1 << (ci * 4 + cj));
			}
			stamps.push_back(mask);
		}
	}
	queue<int> q;
	q.push(0);
	const int INF = 100;
	vector<int> dp(1 << 16, INF);
	dp[0] = 0;
	int fin = (1 << 16) - 1;
	while (q.size()) {
		int now = q.front(); q.pop();
		rep(c, 0, 3) {
			for (auto stamp : stamps) {
				int next = (~stamp & now) | (goals[c] & stamp);
				if (dp[next] != INF)continue;
				dp[next] = dp[now] + 1;
				if (next == fin) {
					cout << dp[fin] << endl;
					return 0;
				}
				q.push(next);
			}
		}
	}

	return 0;
}


Measured memory_bytes: 3404
if __name__ == '__main__':
    N = int(input())
    X = list(map(int, input().split()))
    x = sorted(X[:])
    min_median = x[int(N/2-1)]
    max_median = x[int(N/2)]
    for i in range(N):
        if X[i] <= min_median:
            print(max_median)
        else:
            print(min_median)
 

Measured memory_bytes: 26772
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  vector<int> a(3);
  rep(i,3) cin >> a[i];
  sort(a.begin(),a.end());
  int ans = 1e9;
  do {
    ans = min(ans,abs(a[2]-a[1])+abs(a[1]-a[0]));
  } while (next_permutation(a.begin(),a.end()));
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

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

    vector<string> s(N+10); rep(i,N) cin >> s[i];

    vector<int> alp(26, 0);

    string t;

    map<string,ll> m;

    ll ans = 0;

    rep(i,N)
    {
        rep(j,26) alp[j] = 0;
        t = "";

        rep(j,10)
        {
            alp[(int)s[i][j] - (int)'a']++;
        }
        rep(j,26)
        {
            rep(k,alp[j]) t += (char)(j+(int)'a');
        }

        m[t]++;
    }

    ll n;
    for (auto x: m)
    {
        n = x.second;
        ans += n * (n-1) / 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 19840
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
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
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s1, s2, s3 = input().split()

print((s1[0]+s2[0]+s3[0]).upper())


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

int compare_int(const void *a, const void *b){
    if(*(int*)a > *(int*)b) return 1;
    return -1;    
}

int main(){

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

    int zero_count=0;
    for(int i=0;i<n;i++){
        if(a[i]==0){zero_count++;}
    }
    if(zero_count==n){
        printf("Yes\n");
        return 0;
    }

    qsort(a,n,sizeof(int),compare_int);

    if(zero_count!=0 && n/3==zero_count){
        int p=a[n/3];
        for(int i=n/3;i<n;i++){
            if(p!=a[i]){
                printf("No\n");
                return 0;
            }
        }
        printf("Yes\n");
        return 0;
    }


    int p=a[0];
    int count=0;
    for(int i=0;i<n;i++){
        if(p==a[i]){
            count++;
        }else{
            if(count!=n/3){
                printf("No\n");
                return 0;
            }else{
                count=1;
                p=a[i];
            }
        }
    }

    if(((a[0]^a[n/3])^a[n-1])==0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
struct point{
	char c;
	int a;
}p[100];
string word[100];
int n;
void BubbleSort(){
	point a[100];
	memcpy(a,p,sizeof(a));
	for(int i=0;i<n;i++)
		for(int j=n-1;j>i;j--)
			if(a[j].a<a[j-1].a)swap(a[j],a[j-1]);
	for(int i=0;i<n-1;i++){
		cout<<a[i].c<<a[i].a<<' ';
	}cout<<a[n-1].c<<a[n-1].a<<endl;
	string s[100];	
	for(int i=0;i<=9;i++)s[i]="";
	for(int i=0;i<n;i++)
		s[a[i].a]+=a[i].c;
	int flag=0;
	for(int i=0;i<=9;i++)
		if(s[i]!=word[i])
			flag=1;
	if(flag)cout<<"Not stable"<<endl;
	else cout<<"Stable"<<endl;
}
void SelectionSort(){
	point a[100];
	memcpy(a,p,sizeof(a));
	for(int i=0;i<n;i++){
		int mini=i;
		for(int j=i;j<n;j++){
			if(a[j].a<a[mini].a)mini=j;
		}swap(a[i],a[mini]);
	}
	for(int i=0;i<n-1;i++){
		cout<<a[i].c<<a[i].a<<' ';
	}cout<<a[n-1].c<<a[n-1].a<<endl;
	string s[100];	
	for(int i=0;i<=9;i++)s[i]="";
	for(int i=0;i<n;i++)
		s[a[i].a]+=a[i].c;
	int flag=0;
	for(int i=0;i<=9;i++)
		if(s[i]!=word[i])
			flag=1;
	if(flag)cout<<"Not stable"<<endl;
	else cout<<"Stable"<<endl;
}
int main(){
//	freopen("a.txt","r",stdin);
	cin>>n;
	for(int i=0;i<=9;i++)word[i]="";
	getchar();
	for(int i=0;i<n;i++){
		cin>>p[i].c>>p[i].a;
		word[p[i].a]+=p[i].c;
		getchar();
	}
	BubbleSort();
	SelectionSort();
	return 0;
} 


Measured memory_bytes: 3156
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7
int min(ll x, ll y){
    if(x < y)return x;
    else return y;
}
int compare_int(const void *c, const void *d){
    ll *C = (ll *)c;
    ll *D = (ll *)d;
    if(*C < *D)return 1;
    if(*C > *D)return -1;
    return 0;
}
ll xCy(int x, int y){
    ll ans = 1;
    for(int i = 0;i < y;i++){
        ans *= (x-i);
        ans /= (i+1);
    }
    return ans;
}
int main(void){
    int n, a, b;
    scanf("%d %d %d", &n, &a, &b);
    ll v[n];
    for(int i = 0;i < n;i++){
        scanf("%lld", &v[i]);
    }
    qsort(v, n, sizeof(ll), compare_int);
    long double ave = 0;
    for(int i = 0;i < a;i++){
        ave += v[i];
    }
    ave /= (double)a;
    ll aa = v[a-1];
    int j = a-2;
    int in = 1;
    while(j >= 0){
        if(v[j]==aa)in++;
        else break;
        j--;
    }
    int flag = 0;
    if(j==-1)flag = 1;
    j = a;
    int out = 0;
    while(j < n){
        if(v[j]==aa)out++;
        else break;
        j++;
    }
    ll count = 0;
    if(flag){
        if(a + out > b){
            for(int i = a;i <= b;i++){
                count += xCy(a+out, i);
            }
        }else{
            for(int i = a;i <= a+out;i++){
                count += xCy(a+out, i);
            }
        }
    }else{
        count += xCy(in + out, in);
    }
    printf("%Lf\n%lld\n", ave, count);
    return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const int mod = 1e9+7;
// int 1e9+7 double 1e-12 long long 1e18

#define rep(i, a, b) for(int (i) = (a); (i) < (b);++i)

int main(){
  ll N;
  cin >> N;
  // ll a[N];
  // rep(i,0,N)cin >> a[i];
  if (N % 2 == 0)
  {
    cout << N << endl;
  }else{
    cout << N * 2 << endl;
  }

  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>

using namespace std;
long long dp[101][100001],i,q,k,n,w[101],v[101];
int main()
{
  cin>>n>>k;
   for(i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }
   for(int i=0;i<=100000;i++){
        for(int j=0;j<=n;j++)
            dp[j][i]=INT_MAX;
    }
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=100000;j++){
            dp[i+1][j]=min(dp[i][j],dp[i+1][j]);
            if(j+v[i]<=100000){
                dp[i+1][j+v[i]]=min(dp[i+1][j+v[i]],dp[i][j]+w[i]);
            }
        }
    }
   long long ans=0;
   for(q=100000;q>=0;q--)
   {
      if(dp[n][q]<=k){cout<<q;return 0;}
   }
   cout<<ans;
    return 0;
}


Measured memory_bytes: 79104
N, K = map(int, input().split())
A = []

for i in range(N):
    a, b = map(int, input().split())
    A.append([a,b])

A.sort(key = lambda x:x[0])

sum_b = 0
i = 0

while True:
    sum_b += A[i][1]
    if sum_b >= K:
        print(A[i][0])
        exit()
    else:
        i += 1


Measured memory_bytes: 21248
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cmath>

#define mst(a,b)memset(a, b, sizeof(a))
#define repi(a,b)for(int i = a; i < b; i++)
#define repj(a,b)for(int j = a; j < b; j++)
#define pii pair<int,int>

#ifdef LOCAL
#define fre()freopen("in.txt","r",stdin)
#endif
#ifndef LOCAL
#define fre()
#endif

//static int x = []() {
//	std::ios::sync_with_stdio(false);
//	std::cin.tie(NULL);
//	return 0;
//}();

#define FASTIO
#ifdef FASTIO
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//#define scanf abcabc
//#define printf abcabc
#endif
//#ifndef FASTIO
//#define cin abcabc
//#define cout abcabc
//#endif

typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;

using namespace std;


struct aa {
	int a, f;
	bool operator<(const aa& rhs)const {
		return a < rhs.a;
	}
}cao[2100];
int main() {
	int n, L; cin >> n >> L;
	int sum = 0;
	repi(1, n + 1) {
		cao[i].a = L + i - 1;
		sum += cao[i].a;
		if (cao[i].a < 0) {
			cao[i].a = -cao[i].a;
			cao[i].f = -1;
		}
		else cao[i].f = 1;
	}
	sort(cao + 1, cao + n + 1);
	cout << (sum - cao[1].a * cao[1].f) << endl;
	return 0;
}

Measured memory_bytes: 256
a,b,m = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(m)]

da = {}
for i in range(a):
    da[i+1] = al[i]
db = {}
for i in range(b):
    db[i+1] = bl[i]

res = min(al)+min(bl)
for x,y,c in xyc:
    res = min(res, da[x]+db[y]-c)

print(res)


Measured memory_bytes: 100024
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

fn main() {
    input! {
        N: usize,
        As: [i64; N],
    }

    let s: i64 = As.iter().sum::<i64>() / 2;
    let mut ss: i64 = 0;
    for i in (0..N - 1).step_by(2) {
        ss += As[i];
    }

    let last = s - ss;

    let mut anss: Vec<i64> = vec![-1; N];
    anss[N - 1] = last * 2;
    anss[0] = (As[N - 1] - anss[N - 1] / 2) * 2;

    for i in 1..N - 1 {
        anss[i] = (As[i - 1] - anss[i - 1] / 2) * 2;
    }

    for &ans in anss.iter() {
        print!("{} ", ans);
    }
    println!("");
}


Measured memory_bytes: 4548
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;

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

	for (int i = 1; i < 50000; i++)
	{
		int y = i * 1.08;
		if (y == n) {
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int h, n;
   cin >> h >> n;
   int sum = 0;
   rep(i, 0, n) {
      int a;
      cin >> a;
      sum += a;
   }
   if (sum >= h)
      cout << "Yes" << endl;
   else
      cout << "No" << endl;

   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PII pair<int, int>
#define LL long long
using namespace std;
const LL INF = 1e18;
const int MAXN = 1000005;

int N, a[MAXN], h[MAXN];
LL dp[MAXN];

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

	cin >> N;
	for (int i = 1; i <= N; i++) cin >> h[i];
	for (int i = 1; i <= N; i++) cin >> a[i];
	
	map<int, int> mque;
	mque.insert({0, 0}); // Assume h[0] = dp[0] = 0;
	for (int i = 1; i <= N; i++) {
	      auto it = mque.upper_bound(h[i]);	
	      dp[i] = dp[prev(it)->second] + a[i]; 
	      while (it != mque.end() && dp[i] >= dp[it->second]) {
	            it = mque.erase(it);	
	      }
	      mque.insert({h[i], i});
	}
	cout << dp[mque.rbegin()->second] << "\n";
	



	return 0;
}

Measured memory_bytes: 19456
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}



int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> A(n+1,0);
    for(int i=0;i<m;i++){
        ll a;
        cin>>a;
        A[a]=1;
    }
    vector<ll> dp(n+1,0);
    dp[0]=1;
    if(A[1]==0){dp[1]=1;}
    for(int i=2;i<=n;i++){
        if(A[i]==0){dp[i]=dp[i-1]+dp[i-2]; dp[i]%=MOD;}
    }
    cout<<dp.back()<<endl;
    
    
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

typedef long long ll;

int main() {
    string s;
    ll k, cnt = 1;
    cin >> s >> k;
    char prev = s.at(0);
    vector<ll> d;
    for (ll i = 1; i < ll(s.size()); ++i) {
        if (prev == s.at(i)) ++cnt;
        else {
            d.push_back(cnt);
            cnt = 1;
        }
        prev = s.at(i);
    }
    d.push_back(cnt);
    if (d.size() == 1) {
        cout << s.size() * k / 2;
    } else if (s.front() == s.back()) {
        cout << d.front() / 2 + accumulate(d.begin() + 1, d.end() - 1, 0LL, [](ll init, ll i) { return init += i / 2; }) * k + (d.front() + d.back()) / 2 * (k - 1) + d.back() / 2;
    } else {
        cout << accumulate(d.begin(), d.end(), 0LL, [](ll init, ll i) { return init += i / 2; }) * k;
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD=1e9+7;
int pw(int n,int k){
  if(k<0)return pw(n,k+MOD-1);
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}
std::vector<int> Factorial(5e6),Finverse(5e6);
void Cinit(){// limit is 5e6 /// write pw /// this takes 792ms at AtCoder
  Factorial[0]=1;
  for(int i=1;i<5e6;i++)Factorial[i]=Factorial[i-1]*i%MOD;
  for(int i=0;i<5e6;i++)Finverse[i]=pw(Factorial[i],MOD-2);
}
int nCk(int n,int k){
  if(n<k)return 0;if(k<0)return 0;
  if(!Factorial[0])Cinit();
  int res=Factorial[n];
  res*=Finverse[k];res%=MOD;
  res*=Finverse[n-k];res%=MOD;
  return res;
}
void adjust(int &a){
  a%=MOD;a+=MOD;a%=MOD;
}
void add(int &a,int b){
  adjust(a);adjust(b);
  a+=b;if(a>MOD)a-=MOD;
}
int kakeru(int a,int b){
  adjust(a);adjust(b);
  return (a*b)%MOD;
}
int kakeru(int a,int b,int c){
  return kakeru(kakeru(a,b),c);
}
int n,ans;
int f(int a){
  return kakeru(nCk(n-1,a+1),Factorial[n-a-2],Factorial[a-1]);
}
int g(int a){
  return kakeru(nCk(n-1,a),Factorial[n-a-1],Factorial[a-1]);
}

signed main(){
  Cinit();
  cin>>n;
  vector<int> v(n),w(n+1,0);
  for(int i=0;i<n;i++)cin>>v[i];
  for(int i=0;i<n;i++)w[i+1]=v[i]+w[i];
  for(int j=1;j<n-1;j++)add(ans,kakeru((w[n-1]-w[n-j-1])-(w[j]-w[0]),f(j)));
  for(int j=1;j<n;j++)add(ans,kakeru(v[n-1]-v[n-j-1],g(j)));
  cout<<ans<<endl;
}


Measured memory_bytes: 80000
fun main(args : Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
    val pAndY = mutableListOf<Triple<Int, Int, Int>>()
    (1..M).forEachIndexed { index, i ->
        val (p, y) = readLine()!!.split(" ").map { it.toInt() }
        val pair = Triple(index, p, y)
        pAndY.add(pair)
    }

    pAndY.sortBy { it.third }

    val nums : Array<String?> = Array(M) { init -> null }
    val pToCountMap : MutableMap<Int, Int> = mutableMapOf()
    pAndY.forEach {
        val index = it.first
        val p = it.second
        val preCount = pToCountMap.get(p)
        var count: Int
        if (preCount == null) {
            count = 1
        } else {
            count = preCount + 1
        }
        pToCountMap.set(p, count)

        val num = p.toString().padStart(6, '0') + count.toString().padStart(6, '0')
        nums[index] = num
    }

    nums.forEach {
        println(it!!)
    }
}


Measured memory_bytes: 106008
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;

int main(){

    string S;
    int Q;

    cin >> S >> Q;

    int i;
    bool rev = true; //状態が2つしかない時に使う,trueかfalseしかない

    for(i=0;i<Q;i++){
            int T;
            cin >> T;

            if(T==1){
                //reverse(S.begin(),S.end());     //ひっくり返す(通常盤)
                rev = !rev;

            }else{
                int F;
                char C;
                cin >> F >> C;
                if(F==1){
                    if(rev) {
                        S.insert(S.begin(),C); //先頭にCを加える
                    }else{
                        S.insert(S.end(),C); // けつにCを加える
                    }
                }else{
                    if(rev) {
                        S.insert(S.end(),C); //先頭にCを加える
                    }else{
                        S.insert(S.begin(),C); // けつにCを加える
                }
            }
        }
    }

    if(!rev){
        reverse(S.begin(),S.end());
    }
    cout << S << endl;
}

Measured memory_bytes: 900
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	N, A, B := sc.NextInt(), sc.NextInt(), sc.NextInt()

	if (A-B)%2 == 0 {
		fmt.Println(abs((A+B)/2 - A))
	} else {
		if A-1 < N-B {
			// 6 1 4 -> 2
			// 6 2 3 -> 2
		} else {
			// 6 3 6 -> 2
			// 6 3 4 ->3
			A, B = N-B+1, N-A+1
		}
		fmt.Println(((B-(A-1))+1)/2 + A - 1)

	}
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cmath> 
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <numeric> 
#include <iomanip>
#include <map> 
#include <stack>
#include <sstream>
#define sz(x) ((int)(x).size())
#define full(a) a.begin(), a.end()
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define pii pair<int, int>
#define trav(a,x) for (auto& a : x)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const int MAX = 1e6;
long long max(long long a, long long b) { if (a > b)return a; else return b; }
long long min(long long a, long long b) { if (a < b)return a; else return b; }
const int MAXC = 1e5;
int a[100005];
/*int gcd (int a, int b) {
    return b ? gcd (b, a % b) : a;
}
std::vector<int> fractionSum(std::vector<int> a, std::vector<int> b) {
    vector<int> ne{a[0] * b[1] + b[0] * a[1], a[1] * b[1]};
    int k = gcd(ne[0], ne[1]);
    ne[0] /= k;
    ne[1] /= k;
    return ne;
}
*/
  		     	/*ll n, k;
		std::cin >>  n;
		std::vector <int> v(n);
			for (ll i = 0; i < n; i++)
			{
					std::cin >> v[i];
			}
		std::sort(v.begin(), v.end());*/
/*void sortString(string &str)
{
	sort(str.begin(), str.end());
	cout << str;
}*/


int main() {

	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	if (s[n - 1] == 's')
	{
		cout << s << "es";
	}
	else
	{
		cout << s << 's';
	}
	 return 0;
					
}

	

  

 

Measured memory_bytes: 3032
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int n,m;
    in(n,m);
    ll ans;
    if(n==m){
        ans=2;
    }else if(n==m-1||m==n-1){
        ans=1;
    }else{
        ans=0;
    }
    do{
        ans*=(ll)n;
        ans%=MOD;
    }while(--n);
    do{
        ans*=(ll)m;
        ans%=MOD;
    }while(--m);
    out(ans);
}


Measured memory_bytes: 3840
local ffi=require"ffi"
N=io.read"*n"
W=io.read"*n"
w,v={},{}for i=1,N do
w[i]=io.read"*n"
v[i]=io.read"*n"end

dp={[0]={}}
for i=0,W do dp[0][i]=0 end

for i=1,N do
dp[i]={}
for j=0,W do
if(j<w[i])then dp[i][j]=dp[i-1][j]
else dp[i][j]=math.max(dp[i-1][j-w[i]]+v[i],dp[i-1][j])end
end
end
print(dp[N][W])

Measured memory_bytes: 104340
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define pb push_back
#define mp make_pair
#define M 1101
#define MOD 1000000007
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define repl(i,l,r) for(long long i=l;i<=r;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define ins insert
#define inf INT_MAX
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
const int maxn=123456;
int n,m;
int a[maxn];
vpi p(maxn);
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m;
    rep(i,0,n-1)
    {
      cin>>a[i];
    }
    rep(i,0,m-1)
    {
        cin>>p[i].se>>p[i].fi;
    }
    sort(a,a+n);
    sort(allr(p));
    int r=0,y=0;
    ll sum=0;
    for(int i=0;i<m;i++)
    {
        while(a[r]<p[i].fi && r<p[i].se + y && r<n)
        {
            a[r]=p[i].fi;
            r++;
        }
        y=r;
    }
    rep(i,0,n-1)
    {
        sum+=a[i];
    }
    cout<<sum<<"\n";


    return 0;
}


Measured memory_bytes: 1664
// https://youtu.be/pKOPnK1JPLE?t=1885

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

int main() {
    int n;
    ll d, a;
    cin >> n >> d >> a;
    vector<P> p(n);
    rep(i, n) cin >> p[i].first >> p[i].second;
    sort(p.begin(), p.end());
    ll total = 0; // 累積和により現在有効な爆弾によるダメ―ジの総和を記憶する
    queue<pair<ll, ll>> q; // 設置積みの爆弾の右端点と与えるダメージの組のキュー
    ll ans = 0;
    rep(i, n) {
        ll x = p[i].first, h = p[i].second;
        // 有効でなくなる爆弾の分をpopしてtotalからも除く
        while (q.size() > 0 && q.front().first < x) {
            total -= q.front().second;
            q.pop();
        }
        h -= total;
        if (h > 0) {
            // 新しく爆弾を仕掛ける
            ll num = (h + a - 1) / a;
            ans += num;
            ll damage = num * a;
            total += damage;
            q.emplace(x + 2 * d, damage);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3456
import operator
class SegmentTree:
    def __init__(self, size, default, op = operator.add):
        self.size = 1
        while self.size < size:
            self.size *= 2
        self.dat = [default for i in range(self.size*2-1)]
        self.op = op

    def update(self, i, x):
        i += self.size - 1
        self.dat[i] = x
        while i > 0:
            i = (i - 1) // 2
            self.dat[i] = self.op(self.dat[i*2+1], self.dat[i*2+2])

    def add(self, i, x):
        i += self.size - 1
        self.dat[i] = self.op(self.dat[i], x)
        while i > 0:
            i = (i - 1) // 2
            self.dat[i] = self.op(self.dat[i], x)

    def get(self, a, b, k = None, l = None, r = None):
        if k is None:
            k = 0
            l = 0
            r = self.size

        if r <= a or b <= l:
            return None

        if a <= l and r <= b:
            return self.dat[k]

        res_l = self.get(a, b, k*2+1, l, (l+r)//2)
        res_r = self.get(a, b, k*2+2, (l+r)//2, r)
        if res_l is None:
            return res_r
        if res_r is None:
            return res_l
        return self.op(res_l, res_r)


def gcd(a,b):
    if a == 0:
        return b
    if b == 0:
        return a
    return gcd(b%a, a)

n = int(input())
a = list(map(int, input().split()))
seg = SegmentTree(n,0,gcd)
for i in range(n):
    seg.update(i,a[i])
ans = 1
for i in range(n):
    seg.update(i,0)
    ans = max(ans, seg.get(0,n))
    seg.update(i,a[i])
print(ans)


Measured memory_bytes: 124380
#include<stdio.h>

int main(){
    char s[100];
    int i;
    int count;
    int flag = 1;

    scanf("%s", s);

    for(i = 0; s[i] != '\0'; i++);

    count = i;

    for(i = 0; i < count; i++){
        if(s[i] == 'L' || s[i] =='R'){
            if(i % 2 == 1){
                if(s[i] == 'L'){
                    flag = 1;
                }else{
                    flag =0;
                    break;
                }
            }else{
                if(s[i] == 'R'){
                    flag = 1;
                }else{
                    flag =0;
                    break;
                }
            }
        }
    }

    if(flag == 1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N,M;cin>>N>>M;
	int b,c; int A[M],C[M] = {};
	rep(i,0,M){
		cin>>A[i]>>b;
		rep(j,0,b){ cin>>c; C[i] |= (1<<c-1); }
	}
	int dp[1<<N]; dp[0] = 0;
	rep(i,1,1<<N) dp[i] = inf;
	rep(i,0,1<<N)rep(j,0,M){
		dp[i|C[j]] = min(dp[i|C[j]], dp[i] + A[j]);
	}
    if(dp[(1<<N)-1] == inf) cout<<-1<<endl;
    else cout<<dp[(1<<N)-1]<<endl;
}

Measured memory_bytes: 256
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, m = readmi()
a = readl()
d = defaultdict(int)
k = []
for i in a:
    k.append((i, 1))
for i in range(m):
    x, y = readmi()
    k.append((y, x))
count = 0
k.sort(reverse=True)
index = 0
while(n > 0):
    x, y = k[index]
    count += min(y * (x), n * (x))
    n = max(n - y, 0)
    index += 1
print(count)

Measured memory_bytes: 30836
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

//テ・ツ個コテゥツ鳴鄭[a,b]テ」ツ?ィテ・ツ個コテゥツ鳴釘[c,d]テ」ツ?ョテゥツ鳴「テ、ツソツ?
int intervalState(int a, int b, int c, int d){
    if(a <= c && b <= c) return 0;            //A < B
    else if(a >= d && b >= d) return 1;       //A > B
    else if(a <= c && d <= b) return 2;     //A -> B
    else if(c < a && b < d) return 3;       //B -> A
    else if(a <= c && b < d) return 4;      //A <= B
    else if(c < a && d <= b) return 5;      //A >= B
    return -1;
}

bool check(vector<pair<int,int>> v, pair<int,int> p){
    rep(i,v.size()){
        //cout << v[i].first << ' ' << v[i].second<< endl;
        int tmp = intervalState(v[i].first,v[i].second,p.first,p.second);
        if(not(tmp == 0 || tmp == 1)) return false;
    }
    return true;
}

int main(){
    int n;
    while(cin >> n,n){
        pair<int,int> p[10005];
        rep(i,n){
            int h, m, s;
            char g;
            cin >> h >> g >> m >> g >> s;
            int x = h * 60 * 60 + m * 60 + s;

            cin >> h >> g >> m >> g >> s;
            int y = h * 60 * 60 + m * 60 + s;

            p[i] = make_pair(x,y);
        }
        sort(p, p + n);

        vector<pair<int,int>> v[10005];
        rep(i,n){
            int j = 0;
            //cout << p[i].first << ' ' << p[i].second << endl;
            while(true){
                if(v[j].empty()) {
                    v[j].emplace_back(p[i]);
                    break;
                }else{
                    if(check(v[j],p[i])){
                        v[j].emplace_back(p[i]);
                        break;
                    }else{
                        j++;
                    }
                }
            }
        }
        int ans = 0;
        rep(i,10001){
            if(v[i].empty()) break;
            ans++;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3428
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using D = double;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int a, b;

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

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

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int K; cin >> K;
	priority_queue<int, vector<int>, greater<int> > pq;
	for (int i=1; i<=9; i++) pq.push(i);
	int cnt = 0;
	while (cnt < K-1){
		int cur = pq.top();
		pq.pop();
		cnt++;
		int ld = cur%10;
		if (ld!=0) pq.push(cur*10+ld-1);
		pq.push(cur*10+ld);
		if (ld!=9) pq.push(cur*10+ld+1);
	}
	cout << pq.top();
}


Measured memory_bytes: 2420
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: u64, a: u64, b: u64
    }

    println!("{}", std::cmp::min(n*a, b));
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int N=5002;
const int mod=1e9+7;
int com[N],fact[N],dp[2][N],cnt_ver,cnt_edge,pw[N];
bool used[N];
vector<int> adj[N];
void add(int &x,int y){
	x+=y;
	if(x>=mod){
		x-=mod;
	}
}
void sub(int &x,int y){
	x-=y;
	if(x<0){
		x+=mod;
	}
}
int mul(int x,int y){
	return (1ll*x*y)%mod;
}
void dfs(int x){
	used[x]=true;
	cnt_ver++;
	for(int i:adj[x]){
		cnt_edge++;
		if(used[i]){
			continue;
		}
		dfs(i);
	}
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,sz=0,ans=0,cnt=0;
	cin>>n;
	fact[0]=pw[0]=1;
	for(i=1;i<=n;i++){
		cin>>j;
		if(j!=-1){
			adj[i].push_back(j);
			adj[j].push_back(i);
		}
		fact[i]=mul(fact[i-1],i);
		pw[i]=mul(pw[i-1],n-1);
	}
	for(i=1;i<=n;i++){
		if(!used[i]){
			cnt_ver=cnt_edge=0;
			dfs(i);
			cnt_edge/=2;
			if(cnt_ver-1==cnt_edge){
				sz++;
				com[sz]=cnt_ver;
			}
			else{
				cnt++;
			}
		}
	}
	dp[0][0]=1;
	for(i=1;i<=sz;i++){
		for(j=0;j<=i;j++){
			dp[i&1][j]=mul(dp[1-i%2][j],n-1);
			add(dp[i&1][j],mul(dp[1-i%2][j-1],com[i]));
		}
	}
	add(ans,mul(cnt,pw[sz]));
	for(i=2;i<=n;i++){
		add(ans,mul(dp[sz%2][i],fact[i-1]));
	}
	for(i=1;i<=sz;i++){
		add(ans,mul(com[i]-1,pw[sz-1]));
	}
	cnt_ver=ans;
	ans=mul(pw[sz],n);
	sub(ans,cnt_ver);
	cout<<ans;
}

Measured memory_bytes: 3972
#include<stdio.h>
int selectionSort(int A[],int N);
  
  int main(){
  int A[100],N,i,count;
  scanf("%d",&N);
  for(i=0;i<N;i++)scanf("%d",&A[i]);
  count = selectionSort(A,N);
  for(i=0;i<N;i++){
    if(i > 0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",count);

  
  return 0;
}
int selectionSort(int A[],int N){
  int minj,i,j,count = 0,a;
  for (i = 0 ; i < N-1 ;i++){
    minj = i;
    for(j = i ; j < N ; j++){
    if( A[j] < A[minj] ) minj = j;
  }
  a = A[i];
  A[i] = A[minj];
  A[minj] = a;
  if( i != minj)count++;
}
return count;
}



Measured memory_bytes: 2108
#include <cstdio>

bool isInArray(int x, int array[], int size) {
  for(int i = 0; i < size; i++) {
    if(x == array[i]) {
      return true;
    }
  }
  return false;
}


int main(void) {
  int n, q;
  int num;

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

  scanf("%d", &q);
  int x;
  num = 0;
  for(int i = 0; i < q; i++) {
    scanf("%d", &x);
    if(isInArray(x, S, n)) {
      num++;
    }
  }

  printf("%d\n", num);
  return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#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(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    int k;
    string s;
    cin >> k >> s;
    if (sz(s) <= k)
        cout << s << endl;
    else
        cout << s.substr(0, k) << "..." << endl;
}

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

#define fastIO ios_base::sync_with_stdio(false)
#define forI0N(i, a, b) for(int i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
    fastIO;
    int N, W;
    cin >> N >> W;

    int w, v;
    vector<vector<ull>> DP(N + 1, vector<ull>(W + 1));
    forI0N(i, 1, N + 1) {
        cin >> w >> v;
        forI0N(_w, 1, W + 1) {
            if (w <= _w) DP[i][_w] = max(v + DP[i - 1][_w - w], DP[i - 1][_w]);
            else DP[i][_w] = DP[i - 1][_w];
        }
    }

    cout << DP[N][W];
}

Measured memory_bytes: 80256
/*
ex4_2
tomatokan
*/
#include<stdio.h>
#include<math.h>

int main(void){
    int hour,minute,hand_hour,hand_minute;
    double angle=0;
    scanf("%d",&hand_hour);
    scanf("%d",&hand_minute);
    scanf("%d",&hour);
    scanf("%d",&minute);
    minute=minute+60*hour;
    angle=minute*11.0*atan(1.0)/90.0;/*時針と分針の間の角度(ラジアン)*/
    printf("%.10f\n",sqrt(hand_hour*hand_hour+hand_minute*hand_minute-2.0*hand_hour*hand_minute*cos(angle)));/*余弦定理より*/
    return 0;
}

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


int main(void){
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; i++){
    cin >> p[i];
  }
  int count = 0;
  for(int i = 1; i < n - 1; i++){
    if(p[i - 1] < p [i] && p[i] < p[i + 1]) count++;
    else if(p[i + 1] < p[i] && p[i] < p[i - 1])count++;
  }
  cout << count;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

string s;

int main() {
	cin >> s;
	if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') {
		cout << 3 << endl;
	}
	else if ((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')) {
		cout << 2 << endl;
	}
	else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 3616
///                                   ahmocs
#include <bits/stdc++.h>
typedef long long ll;
#define ahmocs  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const ll N=2e3+5, OO=1e18;
using namespace std;
int ret[3005][3005];
string a,b;
int solve(int idxa, int idxb){
    if (idxa==a.length() || idxb==b.length())
        return 0;
    int cnt = 0;
    if (~ret[idxa][idxb]) return ret[idxa][idxb];
    if (a[idxa] == b[idxb])
        cnt= solve(idxa + 1 , idxb + 1) + 1;
    if (a[idxa] != b[idxb])
        cnt=max(solve(idxa+1,idxb), solve(idxa,idxb+1));
    ret[idxa][idxb]=cnt;
    return cnt;
}
void build (int idxa, int idxb)
{
    if (idxa>=a.length() || idxb>=b.length())
        return;
    if (a[idxa] == b[idxb])
        cout<<a[idxa],build(idxa+1,idxb+1);
    else
    {
        if (solve(idxa+1,idxb) == ret [idxa][idxb])
            build(idxa+1,idxb);
        else
            build(idxa,idxb+1);
    }
}
int main()
{
    ahmocs
    memset(ret, -1, sizeof ret);
    cin>>a>>b;
    solve(0,0);
    build(0,0);
    return 0;
}


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

int main (){
    int N ;
    cin >> N ;
    vector<int> A(N) ;
    int count = 0 ;
    int counteve= 0 ;
    rep(i,N){
        cin >> A.at(i) ;
        count += A.at(i) ;
        if( i%2 == 1 ) counteve += A.at(i) ;  
    }
    vector<int> ans(N) ;
    ans[0] = count - 2*counteve ;
    rep(i,N-1) ans[i+1] = 2*A[i] - ans [i] ;
    rep(i,N) cout << ans[i] << endl;
}

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

int used[8];
int n, m;
vector<vector<int>> edge;

int dfs(int cur){
  bool flag = true;
  int res = 0;
  for(int i = 1; i < n; i++){
    if(used[i] == 0) flag = false;
  }
  if(flag) return 1;
  for(int i = 0; i < edge[cur].size(); i++){
    if(used[edge[cur][i]]) continue;
    used[edge[cur][i]] = 1;
    res += dfs(edge[cur][i]);
    used[edge[cur][i]] = 0;
  }
  return res;
}

int main(){
  cin >> n >> m;
  edge.resize(n);
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  used[0] = 1;
  cout << dfs(0) << endl;
  return 0;
}


Measured memory_bytes: 256