akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty())return out;
    constexpr bool is_vector_v = is_vector<T>::value;
    if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
    else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
    return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
    IOS;
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> a(q);
    vector<int> b(n,0);
    REP(i,q){
        cin >> a[i];
        a[i]--;
        b[a[i]]++;
    }
    REP(i,n){
        if(q-k<b[i]){
            put("Yes");
        }else{
            put("No");
        }
    }
    return 0;
}


Measured memory_bytes: 1408
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <math.h>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;

const int MAX_N = 2000000;

char c[MAX_N];

int solve(int N) {
   int l = 0, r = N - 1;
   int res = 0;
   while (l < r) {
      if (c[l] == 'R') {
         l++;
         continue;
      }
      if (c[r] == 'W') {
         r--;
         continue;
      }
      if (c[l] == 'W' && c[r] == 'R') {
         res++;
         l++;
         r--;
      }
   }
   return res;
}

int main() {

   int N;
   scanf("%d", &N);
   scanf("%s", c);

   int ans = solve(N);
   printf("%d\n", ans);

   return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ull n;
    string s="";
    cin>>n;
    while(n>0)
    {
        if(n%26==0)
            {s='z'+s;n-=1;}
        else
            {char x=((n%26)-1)+'a';s=x+s;}

        n/=26;
    }
        cout<<s;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素

int main(){
    int n;
    cin>>n;
    vector<ll> a(n),b(n);
    rep(i,n){
        cin>>a[i]>>b[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
//    double left,right;
    ll left,right;
    ll ans=0;
    if(n%2==1){
        left=a[n/2];
        right=b[n/2];
        ans=right-left+1;
    }
    else{ 
        left=(a[n/2]+a[n/2-1]);
        right=(b[n/2]+b[n/2-1]);
        ans=right-left+1;
        }
    
    cout<<ans<<endl;
    return 0;
}

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

int main(){

int k,s;
  int count=0;
  cin >> k >> s;
  for(int i=0;i<=k;i++){
   for(int j=0;j<=k;j++){
     if(s-i-j>=0 && s-i-j<=k)count++;
   }
  }
  cout << count << endl;
}

Measured memory_bytes: 3620
N=int(input())
dp=[]
for j in range(N+1):
    dp.append([0,0,0])

for i in range(N):
    a,b,c = map(int,input().split())
    if i == 0:
        dp[i+1][0] = dp[i][0]+a
        dp[i+1][1] = dp[i][1]+b
        dp[i+1][2] = dp[i][2]+c
    else:
        dp[i+1][0] = max(dp[i][1]+a, dp[i][2]+a)
        dp[i+1][1] = max(dp[i][0]+b, dp[i][2]+b)
        dp[i+1][2] = max(dp[i][0]+c, dp[i][1]+c)

# print(dp,sep="\n")
print(max(dp[N][0],dp[N][1],dp[N][2]))


Measured memory_bytes: 59424
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int ll
#define all int i=0; i<n; i++
#define pb push_back
#define pf push_front
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int> >
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define mod 1000000007
#define INF 0x3f3f3f3f3f
#define mp make_pair
#define pii pair<int,int>
#define T int t;cin>>t;while(t--)
#define I 
#define think 
#define we 
#define should 

bool sortinrev(const pair<ll,ll> &a,  
               const pair<ll,ll> &b) 
{ 
       return (a.first > b.first); 
}
int abso(int k){
	if(k==0)return 0;
	else if(k<0) return -1*k;
	else return k;
}
int factors(int n){
	int ans = 0;
	for(int i=1; i<=sqrt(n); i++){
		if(n%i==0){
			if(i != n/i)ans+=2;
			else ans++;
		}
	}
	return ans;
}
int32_t main() 
{ 
	int r,c;
	cin>>r>>c;
	int dp[r][c];
	int p[r][c];
	for(int i=0; i<r; i++){
		for(int j=0; j<c; j++){
			char k;
			cin>>k;
			if(k=='.')p[i][j]=1;
			else p[i][j] = 0;
			dp[i][j] = 0;
		}
	}
	if(p[1][0]==0)dp[1][0]=0;
	else dp[1][0] = 1;
	if(p[0][1]==0)dp[0][1]=0;
	else dp[0][1] = 1;
	
	for(int i=2; i<r; i++){
		if(p[i][0]==0){
			dp[i][0] = 0;
		}
		else dp[i][0] = dp[i-1][0];
		//cout<<i<<" "<<0<<" "<<dp[i][0]<<endl;
	}
	for(int i=2; i<c; i++){
		if(p[0][i]==0){
			dp[0][i] = 0;
		}
		else dp[0][i] = dp[0][i-1];
		//cout<<0<<" "<<i<<" "<<dp[0][i]<<endl;
	}
	
	for(int i=1; i<r; i++){
		for(int j=1; j<c; j++){
			if(p[i][j]==0){
				dp[i][j] = 0;
			}
			else dp[i][j] = dp[i-1][j] + dp[i][j-1];
			//cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
			dp[i][j]%=mod;
		}
	}
	cout<<dp[r-1][c-1]<<endl;
}



Measured memory_bytes: 15872
N = gets.to_i
s = Array.new
for i in 0..N-1
    s[i] = gets.chomp
end
M = gets.to_i
t = Array.new
for i in 0..M-1
    t[i] = gets.chomp
end
a = Array.new
b = Array.new
for i in 0..N-1
    a[i] = s.count(s[i])-t.count(s[i])
end
for i in 0..M-1
    b[i] = s.count(t[i])-t.count(t[i])
end

if a.max > 0 || b.max > 0
    if a.max >= b.max 
        puts a.max
    else 
        puts b.max
    end
else
    puts 0
end


Measured memory_bytes: 3836
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define pb push_back
#define pp(a, b) pair <a, b>
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define itr iterator
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
 
 
using namespace __gnu_pbds;
using namespace std;
 
template <class T> T printr(T p){ cout << p << '\n'; return 0; }
template <class T> T printe(T p){ cout << p << '\n'; exit(0); }
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
 
 
//template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update>  
    ordered_set;  
 
#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif
 
ll power(ll x, ll y, ll p){ 
   ll res = 1;
   x = x % p;  
   while (y > 0) {
      if (y & 1) 
         res = (res * x) % p; 
      y = y >> 1;
      x = (x * x) % p; 
   }
   return res;
}
 
const ll INF = (ll)(8e18);
const ll MOD = (ll)(1e9 + 7);
const ll HMOD = (ll)4222234727;
const ll hashprime = (ll)31;
 
const int maxn = 10010;

ll dp[(int)(1e3) + 10][maxn];
ll a[maxn], b[maxn];

int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ll h,n; cin >> h >> n;
  	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];
    for(int i = 1; i <= h; i++) dp[0][i] = INF;
  	for(int i = 1; i <= n; i++){
      for(int j = 1; j <= h; j++){
        if(j < a[i]){
          dp[i][j] = min(dp[i - 1][j], b[i]);
          continue;
        }
        dp[i][j] = min(dp[i - 1][j], dp[i][j - a[i]] + b[i]);
      }
    }
    ll ans = INF;
    for(int i = 1; i <= n; i++){
        ans = min(ans, dp[i][h]);
    }
    cout << ans << '\n';
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}


Measured memory_bytes: 78592
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
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; }
signed main(void){
    int n; string s; cin>>n>>s;
    rep(i,s.size()){
        int x = s[i] + n;
        if((char)x > 'Z') x -= 26;
        cout<<(char)x;
    }
    cout<<endl;
}


Measured memory_bytes: 256
main :: IO ()
main = do
  [a, b] <- map read . words <$> getLine :: IO [Int]
  let str1 = foldr (++) "" $ map (\_ -> show a) [1..b] :: String
  let str2 = foldr (++) "" $ map (\_ -> show b) [1..a] :: String
  putStrLn $ if length str1 >= length str2 then str1 else str2

Measured memory_bytes: 508
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;



int main(){

  int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  int dx,dy;
  dx = x2-x1;
  dy = y2-y1;
  int x3,x4,y3,y4;
  x3 = x2-dy;
  y3 = y2+dx;
  dx = x3-x2;
  dy = y3-y2;
  x4 = x3-dy;
  y4 = y3+dx;
  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;

  return 0;
}

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

bool gay[301][301];

signed main () {
    int n;
    cin >> n;
    int a[n][n], g[n][n];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
            g[i][j] = a[i][j];
        }
    }
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j)
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
        }
    }
    bool uneq = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) 
            uneq = uneq || (g[i][j] != a[i][j]);
    }
    if (uneq)
        cout << "-1\n";
    else {
        for (int k = 0; k < n; ++k) {
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) 
                    gay[i][j] = gay[i][j] || ((a[i][j] == a[i][k] + a[k][j]) && (k != i) && (k != j));
            }
        }
        int64_t ans = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (!gay[i][j])
                    ans += a[i][j];
            }
        }
        ans >>= 1;
        cout << ans << '\n';
    }
}


Measured memory_bytes: 1024
N, K = map(int, input().split())
h = list(map(int, input().split())) + [0]*101010

dp = [float("inf")]*101010
dp[0] = 0

for i in range(N):
    for k in range(1, K+1):
        dp[i+k] = min(dp[i+k], dp[i] + abs(h[i+k] - h[i]))
    # print(dp)
print(dp[N-1])

Measured memory_bytes: 57312
import java.util.*;
import java.io.*;

class Main {

	void solve() {

		int a = inint();
		if (a < 1200) out.println("ABC");
		else if (a < 2800) out.println("ARC");
		else out.println("AGC");
		
	}
	
	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);
	
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}
	
	public int inint() {
		return in.nextInt();
	}
	
	public String instr() {
		return in.next();
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}
	
	public char[] incharar() {
		return in.next().toCharArray();
	}
	
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
const int INF = 1e9;
using namespace std;

signed main() {
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    int ans1=100*a,ans2=0;
    rep(i,31) rep(j,31) rep(k,101) rep(l,101){
        int water = 100*(i*a+j*b);
        int sugar = k*c+l*d;
        if(sugar<=water/100*e &&water+sugar<=f){
            if(ans2*(water+sugar)<ans1*sugar){
                ans1=water+sugar;
                ans2=sugar;
            }
        }
    }
    cout << ans1 << " " << ans2 << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int i,k,a,b;
	bool right=0;
	scanf("%d%d%d",&k,&a,&b);
	for(i=a;i<=b;i++)
		if(i%k==0)
			right=1;
	if(right)
		puts("OK");
	else
		puts("NG");
}


Measured memory_bytes: 1664
#include <stdio.h>

int main(){
  int S[10000];
  int T[500];
  int n, q, i, j, count = 0;

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

  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&T[i]);
  }

  //excution
  for(i = 0; i < q; i++){
    for(j = 0; j < n; j++){
      if(S[j] == T[i]){
	count++;
	break;
      }
    }
  }

  //output
  printf("%d\n",count);

  return 0;
}



Measured memory_bytes: 2104
# Problem E - Dividing Chocolate

# input
H, W, K = map(int, input().split())
board = [['']*W for i in range(H)]
for i in range(H):
    s = list(input())
    for j in range(W):
        board[i][j] = s[j]

# initialization
min_divide = 10**10
s = [0]*(H-1) # 横線の入り方 0:無 1:有
is_ok = True

# search
for i in range(2**(H-1)): # bit全探索
    # sの初期化
    h_count = 0
    w_count = 0
    for j in range(H-1):
        if ((i>>j)&1):
            s[j] = 1
            h_count += 1
        else:
            s[j] = 0

    # 列の全探索
    s_score = [0]*H # 各区域のスコア
    s_cur = [0]*H
    for j in range(W):
        c = 0
        s_cur = [0]*H

        for k in range(H):
            if board[k][j]=='1':
                s_cur[c] += 1

            # Kを超えていないかのチェック
            if s_cur[c]>K:
                is_ok = False
                break

            # 次の遷移先(横線の有無でグループが別れる)
            if k+1<H:
                if s[k]==1:
                    c += 1
        # Kを超えていたらループ中止
        if not is_ok:
            break
        # 前の列のグループと足してみてKを超えていないかチェック
        # 超えていれば縦線分割を施す
        group_smaller = True
        if j>0:
            for c_num in range(c+1):
                if s_score[c_num]+s_cur[c_num]>K:
                    group_smaller = False
        else:
            group_smaller = True

        if group_smaller:
            for c_num in range(c+1):
                s_score[c_num] += s_cur[c_num]
        else:
            w_count += 1
            for c_num in range(c+1):
                s_score[c_num] = s_cur[c_num]

    if not is_ok:
        is_ok = True
        continue

    # for c_num in range(h_count+1):
    #     if s_score[c_num]>K:
    #         h_count = 10 ** 6

    # 縦線と横線の合計でmin_divideを更新
    min_divide = min(min_divide, w_count + h_count)

# output
print(min_divide)


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

int isPerfect(int x) {
  int sum = 0;
  for(int i = 1; ; i++) {
    if(x % i == 0) {
      int a = x / i;
      if(a == i) {
	if(i != x) sum += i;
	break;
      }
      if(a < i) break;

      if(a != x) sum += a;
      sum += i;
    }
  }
  return x - sum;
}

int main() {
  while(1) {
    int N;
    cin >> N;
    if(N == 0) break;

    int ans = isPerfect(N);
    if(ans > 0) cout << "deficient number" << endl;
    else if(ans == 0) cout << "perfect number" << endl;
    else if(ans < 0) cout << "abundant number" << endl;
  }
  return 0;
}

Measured memory_bytes: 856
import Control.Monad
import Debug.Trace

main = do
  n <- read <$> getLine :: IO Int
  txys <- replicateM n $
    (\(t:x:[y]) -> (t,x,y)) . map readInt . words <$> getLine
  printAnsLn $  solve $ (0,0,0) : txys

solve (_:[]) = True
solve txys @ ((t1,x1,y1):(t2,x2,y2):_) =
--  traceShow (txys,difft,dist) $
  if isPossible then solve (tail txys)
  else False
  where
    difft = t2 - t1
    dist = x2-x1 + y2-y1
    isPossible = difft>=dist && ((dist-difft) `mod` 2==0)
    
  
readInt :: String -> Int
readInt = read

printAnsLn b = putStrLn $ if b then "Yes" else "No"


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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, K;
    cin >> n >> K;
    int max_num = (n - 1) * (n - 2) / 2;
    if (K > max_num) {
        cout << -1 << endl;
        return 0;
    }

    vector<P> v;
    for (int i = 1; i < n; i++) {
        for (int j = 1; j < i; j++) {
            v.emplace_back(j + 1, i + 1);
        }
    }

    vector<P> ans;
    for (int i = 1; i < n; i++) {
        ans.emplace_back(1, i + 1);
    }

    for (int i = 0; i < max_num - K; i++) {
        ans.push_back(v[i]);
    }

    cout << ans.size() << endl;
    for (P& p : ans) {
        cout << p.first << " " << p.second << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <numeric>
#include <cmath>

void print(std::vector<int> readVec){
    std::for_each(readVec.begin(), readVec.end(), [](int i){
        std::cout << i << " ";
        });
    std::cout << std::endl;
}

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

    std::vector<int> vec(n, 0);
    for(int i = 1; i < n; ++i){
        vec.at(i) = 1 + vec.at(i - 1);
    }

    std::vector<std::pair<double, double>> pos(n);
    for(int i = 0; i < n; ++i){
        double x, y;
        std::cin >> x >> y;
        pos.at(i) = std::make_pair(x, y);
    }

    int count = 0;
    bool flg = true;
    std::vector<double> dists;
    while(flg){
//        print(vec); // <- here the print fuction is called.
        double dist = 0;
        for(int i = 0; i < n - 1; ++i){
            int start = vec.at(i), end = vec.at(i + 1);
            double x = pos.at(start).first - pos.at(end).first; 
            double y = pos.at(start).second - pos.at(end).second; 
            dist += std::sqrt(std::pow(x, 2) + std::pow(y, 2));
        }
//        std::cout << dist << std::endl;
        dists.push_back(dist);

        flg = std::next_permutation(vec.begin(), vec.end());
    }

    std::cout << std::fixed << std::setprecision(7);
    std::cout << std::accumulate(dists.begin(), dists.end(), 0.0) / dists.size() << std::endl;

    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define Vi vector<int>
#define Vl vector<long long>
#define pb(a) push_back(a)

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000001;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dp[394][394]={};
int s[394],l[394],p[394];
int ans[394]={};

int main() {

	int n,m;
	cin>>n;
	rep(i,n)cin>>s[i+1]>>l[i+1]>>p[i+1];
	for(int i=1; i<n+1; i++){
		for(int k=s[i]; k<=l[i]; k++)dp[k][i]=p[i];
		for(int j=1; j<394; j++){
			dp[j][i]=max(dp[j][i],dp[j][i-1]);
			for(int x=s[i]; x<=l[i]; x++){
				if(j+x>393||dp[j][i]==0)break;;
				dp[j+x][i]=max(dp[j+x][i],dp[j][i]+p[i]);
			}
		}
	}
	cin>>m;
	rep(i,m){
		int w;
		cin>>w;
		ans[i]=dp[w][n];
		if(ans[i]==0){
			cout<<"-1"<<endl;
			return 0;
		}
	}
	rep(i,m)cout<<ans[i]<<endl;

	return 0;
}



Measured memory_bytes: 3708
table = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
    b, f, r, v = map(int, input().split())
    table[b-1][f-1][r-1] = table[b-1][f-1][r-1] + v
for i in range(4):
    for j in range(3):
        for k in range(10):
            print(" ", end="")
            print(table[i][j][k], end="")
        print()
    if i != 3:
        print("####################")



Measured memory_bytes: 5636
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		final char[] SUIT = {'S', 'H', 'C', 'D'};
		boolean[][] taroHas = new boolean[4][13];
		int n = scanner.nextInt();
		
		for (int i = 0; i < n; i++) {
			char s = scanner.next().charAt(0);
			int r = scanner.nextInt();
			
			for (int j = 0; j < 4; j++) {
				if (s == SUIT[j]) {
					taroHas[j][r - 1] = true;
					break;
				}
			}
		}
		
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 13; j++) {
				if (!taroHas[i][j])
					System.out.println(SUIT[i] + " " + (j + 1));
			}
		}
	}

}



Measured memory_bytes: 26272
N = int(input())
h = list(map(int, input().split(" ")))
c=[0]*N
c[1]=abs(h[1]-h[0])
for i in range(2, N):
    c[i] = min(c[i-1] + abs(h[i]-h[i-1]), c[i-2] + abs(h[i] - h[i-2]))
print(c[N-1])


Measured memory_bytes: 13928
// #include "stdio.h"
// int main()
// {
//     int n;
//     int m;

//     scanf("%d %d",&n,&m);

//     int a[n];
//     int b[n];
//     int temp=0;

//     for (int i = 0; i < n; i++)
//     {
//         scanf("%d %d",&a[i],&b[i]);
//     }
    
//     // for (int i = 0; i < n-1; i++)
//     // {
//     //     if(a[i]<a[i+1]){
//     //         temp=a[i];
//     //         a[i]=a[i+1];
//     //         a[i+1]=temp;
//     //         temp=b[i];
//     //         b[i]=b[i+1];
//     //         b[i+1]=temp;
//     //     }
//     // }
//     int flag=1;

//     while(flag==1){
//         flag=0;
//         for (int i = 0; i < n-1; i++)
//         {
//             if(a[i]<a[i+1]){
//                 flag=1;
//                 temp=a[i];
//                 a[i]=a[i+1];
//                 a[i+1]=temp;
//                 temp=b[i];
//                 b[i]=b[i+1];
//                 b[i+1]=temp;
//             }
//         }
//     }

//     int total=0;
//     int k=m;
//     int i=0;

//     int u=0;
//     while(k>0){
//         k=k-b[i];
//         i++;
//     }

//     for (int j = 0; j < i; ++i)
//     {
//         total=total+a[j]*b[j];
//         u=m-b[j];
//     }
//     total=total+a[i]*u;
//     printf("%d\n",total);
//     return 0;
// }

#include <stdio.h>
int main(int argc, char const *argv[])
{
    int n;
    scanf("%d",&n);
    char str[n];
    scanf("%s",&str);
    int rcount=0;
    int bcount=0;
    for (int i = 0; i < n; ++i)
    {
        if (str[i]=='R')
        {
            rcount++;
        }else if (str[i]=='B')
        {
            bcount++;
        }
    }
    if (rcount>bcount)
    {
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int a, b;
  char c;
  cin >> a >> c >> b;
  cout << (c == '+' ? a + b : a - b) << endl;

  return 0;
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 100000000
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	return sc
}()

/////////////////////////////////////////
///////////////// Input /////////////////
/////////////////////////////////////////
// Input number
func scanIntNum() (num int) {
	sc.Scan()

	num, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return num
}

func scanIntNums() (nums []int) {
	sc.Scan()
	numString := strings.Split(sc.Text(), " ")

	nums = make([]int, len(numString))
	var err error

	for i := 0; i < len(nums); i++ {
		nums[i], err = strconv.Atoi(numString[i])
		if err != nil {
			panic(err)
		}
	}
	return nums
}

func main() {
	K := scanIntNum()
	inputs := scanIntNums()
	A := inputs[0]
	B := inputs[1]

	for i := A; i <= B; i++ {
		if i%K == 0 {
			fmt.Println("OK")
			return
		}
	}
	fmt.Println("NG")
}


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

class bil{
    public:
    int aa[3][10]={};
};


int main(){
    bil first,second,third,forth;
     int n,*b,*f,*r,*v;
    cin >> n;
    b = new int [n];
    f = new int [n];
    r = new int [n];
    v = new int [n];
 
    for (int i = 0; i < n; i++){
        cin >> b[i] >> f[i] >> r[i] >> v[i];
    }
    for (int i = 0; i < n; i++){
        if(b[i] == 1){
            first.aa[f[i]-1][r[i]-1] += v[i];
        }
        if(b[i] == 2){
            second.aa[f[i]-1][r[i]-1] += v[i];
        }
        if(b[i] == 3){
            third.aa[f[i]-1][r[i]-1] += v[i];
        }
        if (b[i] == 4){
            forth.aa[f[i]-1][r[i]-1] += v[i];
        }
    }
    for  (int i = 0; i < 4; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 10; k++){
                if (i == 0){
                    cout << " " << first.aa[j][k];
                }
                if (i == 1){
                    cout << " " << second.aa[j][k];
                }
                if (i == 2){
                    cout << " " << third.aa[j][k];
                }
                if (i == 3){
                    cout << " " << forth.aa[j][k];
                }
            }
            cout << endl;
        }
        if( i != 3){
        cout << "####################" << endl;
        }
    }




}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
ll const INF = 1ll<<61;
ll const MOD = 1e9+7;
double pi = 3.141592653589793238;
set<ll> a;
vector<ll> dp;

ll rec(int i) {
  if (dp[i] < INF) return dp[i];
  if (i == 0) return 1;
  if (a.find(i) != a.end()) return dp[i] = 0;

  ll res = 0;
  res += rec(i-1) % MOD;
  if (i > 1) res += rec(i-2) % MOD;

  return dp[i] = res % MOD;
}

int main() {
  ll n, m;
  cin >> n >> m;
  rep(i, m) {
    ll tmp;
    cin >> tmp;
    a.insert(tmp);
  }
  dp.assign(n+1, INF);

  cout << rec(n) << endl;
  // rep(i, n+1) cout << dp[i] << endl;

  return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
void lcs( string X, string Y, int m, int n ) 
{ 
   int L[m+1][n+1]; 
  
   /* Following steps build L[m+1][n+1] in bottom up fashion. Note 
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
  
   // Following code is used to print LCS 
   int index = L[m][n]; 
  
   // Create a character array to store the lcs string 
   char lcs[index+1]; 
   lcs[index] = '\0'; // Set the terminating character 
  
   // Start from the right-most-bottom-most corner and 
   // one by one store characters in lcs[] 
   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1]; // Put current character in result 
          i--; j--; index--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  
   // Print the lcs 
   cout << lcs; 
} 
int main(){
 	string a,b;
 	cin >> a >> b;
 	int m = a.size();
 	int n = b.size();
 	lcs(a,b,m,n);
	
	
}

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

using namespace std;


int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    int cs[26] = { 0 };
    memset(cs, 0, sizeof(cs));
    char max_c;
    int max_v = -1;
    bool isSolved = false;
    for (int i = 0; i < n; i++) {
      char c;
      cin >> c;
      int a = c - 'A';
      if (isSolved) {
        continue;
      }
      cs[a]++;
      if (max_v < cs[a]) {
        max_v = cs[a];
        max_c = c;
      }
      if (cs[a] > n / 2) {
        isSolved = true;
        cout << c << " " << (i + 1) << endl;
        continue;
      }

      bool flag = true;

      for (int j = 0; j < 26; j++) {
        if (j == max_c - 'A') {
          continue;
        }
        if (cs[j] + (n - i - 1) >= max_v) {
          flag = false;
          break;
        }
      }

      if (flag) {
        isSolved = true;
        cout << max_c << " " << (i + 1) << endl;
        continue;
      }
    }
    if (!isSolved) {
      cout << "TIE" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3096
#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 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 VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<(_loop_int)v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

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



int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int h,w,k;
    cin>>h>>w>>k;
    vector<vector<char>> m(h, vector<char>(w,'.'));
    REP(i,h){
        REP(j,w){
            cin>>m[i][j];
        }
    }

    int ans=0;

    for(int banh=0; banh<(1<<h); banh++){
        for(int banw=0; banw<(1<<w); banw++){

            int cnt = 0;
            REP(i,h){
                REP(j,w){
                    if( banh & (1<<i) ) continue;
                    if( banw & (1<<j) ) continue;
                    if(m[i][j]=='#') {
                        //DEBUG2(i,j);
                        cnt++;
                    }
                }
            }

            if(cnt==k) ans++;

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

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

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

    map<int, bool> numbers;
    int a;
    for (auto i = 0; i < n; i++) {
        cin >> a;
        auto itr = numbers.find(a);
        if(itr != numbers.end()) numbers.erase(itr);
        else numbers[a] = true;
    }

    cout << numbers.size() << endl;
    return 0;
}

Measured memory_bytes: 4864
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main ()
{
	int n, k;
	while (readf (" %s %s", &n, &k) > 0)
	{
		readln;
		auto a = readln.split.map !(to !(int)).array;
		a[] -= 1;
		auto g = new int [] [n];
		foreach (i; 0..n)
		{
			g[a[i]] ~= i;
		}
		debug {writeln (g);}

		auto d = new int [n];

		int res = (a[0] != 0);

		void recur (int v)
		{
			d[v] = 0;
			foreach (u; g[v])
			{
				if (u != 0)
				{
					recur (u);
					d[v] = max (d[v], d[u] + 1);
				}
			}
			if (v != 0 && d[v] % k == k - 1 && a[v] != 0)
			{
				assert (d[v] == k - 1);
				a[v] = 0;
				res += 1;
				d[v] = -1;
			}
		}

		recur (0);
		debug {writeln (d);}
		writeln (res);
	}
}


Measured memory_bytes: 17596
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;

int keta(int n){
    int a=0;
    while(n>0){
        n/=10;
        a++;
    }
    return a;
}
int main(){
    int n, ans;
    cin >> n;
    ans=0;
    for(int i=1; i<=n; i++){
        if(keta(i)%2==1){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}


 main()

{
    fast
    int n,a,b;
    cin>>n>>a>>b;
    if(a>b)
    {
        cout<<"0"<<endl;
        return 0;
    }
    if(a==b)
    {
        cout<<"1"<<endl;
        return 0;
    }
    if(n==1)
    {
        cout<<"0"<<endl;
        return 0;
    }
    int ses;
    ses=(n-2)*(b-a)+1;
    cout<<ses<<endl;
    return 0;

}





































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

int main(){
    int n;
    cin >> n;
    vector<double> v(n);
    for(int i = 0; i < n; i++){
        cin >> v.at(i);
    }
    
    sort(v.begin(), v.end());
    
    double ave = v.at(0);
    
    for(int i = 1; i < n; i++){
        ave = (ave + v.at(i)) / 2;
    }
    
    cout << ave << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() int64 {
	sc.Scan()
	data, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return data
}

func main() {
	n := nextLine()
	args := []int64{nextLine(), nextLine(), nextLine(), nextLine(), nextLine()}

	min := int64(0)

	for _, arg := range args {
		if min == int64(0) || min > arg {
			min = arg
		}
	}

	time := int64(math.Ceil(float64(n)/float64(min)) + 4)

	fmt.Print(time)
}

Measured memory_bytes: 640
n,m,Q=map(int,input().split())
d=[[0]*(n+1) for i in range(n+1)]
for i in range(m):
    l,r=map(int,input().split())
    d[l][r]+=1
for i in range(1,n+1):
    for j in range(1,n+1):
        d[i][j]+=d[i][j-1]
pq=[list(map(int,input().split())) for i in range(Q)]
for u in pq:
    p,q=u
    ans=0
    for i in range(p,q+1):
        ans+=d[i][q]
    print(ans)

Measured memory_bytes: 79320
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <iomanip>
#include <stack>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
const ll INF = 1LL << 50;

int solve();

int main(void) {
	while (solve()) {}
	return 0;
}

int solve() {

	int N;
	cin >> N;

	int m = -1, M = 10001;

	for (int i = 0; i < N; i++) {
		int j;
		cin >> j;
		m = max(j, m);
		M = min(j, M);
	}

	cout << abs(m - M) << endl;

	return 0;
}

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

int main(){
    double pai=3.141592653589;
    int m,h,l;
    char s[200];
    string ans,tmp1,tmp2;
    for(;;){
        scanf("%s",&s);
        tmp1=s;
        if(tmp1=="-"){
            break;
        }
        scanf("%d",&m);
        l=tmp1.length();
        for(int i=0;i<m;i++){
            scanf("%d",&h);
            ans="";
            ans.assign(tmp1,h,l-h+1);
            tmp2.assign(tmp1,0,h);
            ans+=tmp2;
            tmp1=ans;
        }
        printf("%s\n",ans.c_str());
    }
    return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N;
vector<ll> tv[202020];
ll i, j, k;
ll anss[202020];
ll bfs(ll s){
    queue<pll> q;
    q.push({s,1});
    ll i;
    while(q.size()){
        auto qa = q.front();
        q.pop();
        
        ll a = qa.first;
        ll c = qa.second;
        anss[a] = c+1;
        fornum(i,0,tv[a].size()){
            ll b = tv[a][i];
            if(anss[b])
                continue;
            q.push({b, c ^ 1});
        }
    }
}
int main(){
    scanf("%lld", &N);
    fornum(i,1,N){
        ll a, b;
        scanf("%lld%lld", &a,&b);
        tv[a].push_back(b);
        tv[b].push_back(a);
    }

    bfs(1);
    fornum(i,0,N){
        //cout << anss[i + 1] << " ";
        if(anss[i+1]==2){
            --j;
        }else{
            ++j;
        }
    }
    //cout << endl;
    if (abs(j)<=N/3)
    {
        k = 1;
        if(j<0){
            k = 2;
        }
        ll a1 = (N + 2) / 3, a2 = (N + 1) / 3, a3 = N / 3;
        fornum(i,1,N+1){
            if(anss[i]==k){
                if(a1>0){
                    anss[i] = a1 * 3 - 2;
                    --a1;
                }else{
                    anss[i] = a3 * 3;
                    --a3;
                }
            }else if(anss[i]==3-k){
                if(a2>0){
                    anss[i] = a2 * 3 - 1;
                    --a2;
                }else{
                    anss[i] = a3 * 3;
                    --a3;
                }
            }
        }
    }else{
        k = 1;
        if(j<0){
            k = 2;
        }
        ll a1 = (N + 2) / 3, a2 = (N + 1) / 3, a3 = N / 3;
        fornum(i,1,N+1){
            if(anss[i]==k){
                if(a1>0){
                    anss[i] = a1 * 3 - 2;
                    --a1;
                }else if(a2>0){
                    anss[i] = a2 * 3 - 1;
                    --a2;
                }else{
                    anss[i] = a3 * 3;
                    --a3;
                }
            }else if(anss[i]==3-k){
                anss[i] = a3 * 3;
                --a3;
            }
        }
    }

    fornum(i,0,N){
        printf("%lld ", anss[i + 1]);
    }
    
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 1e5+10;

int N, M;
int A[MAX], B[MAX], C[MAX];

ll solve() {
    sort(A, A+N);
    priority_queue<ii> que;
    REP (i, M) que.push(MP(C[i], B[i]));
    que.push(MP(-1, MAX));
    ii cand = que.top();
    que.pop();
    int idx = N-1;
    ll res = 0;
    REP (i, N) {
        if (A[idx] > cand.first) {
            res += A[idx];
            idx--;
        } else {
            res += cand.first;
            cand.second--;
            if (cand.second == 0) {
                cand = que.top();
                que.pop();
            }
        }
    }
    return res;
}

int main() {
    cin >> N >> M;
    REP (i, N) cin >> A[i];
    REP (i, M) cin >> B[i] >> C[i];
    cout << solve() << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int d, t, s;
  cin >> d >> t >> s;
  if (s*t >= d) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void)
{
    int i,j,k,N,f=0;
    int A[3][3];
    int b[20];

    scanf("%d %d %d",&A[0][0], &A[0][1], &A[0][2]);
    scanf("%d %d %d",&A[1][0], &A[1][1], &A[1][2]);
    scanf("%d %d %d",&A[2][0], &A[2][1], &A[2][2]);

    scanf("%d",&N);

    for(i=0; i<N; i++){
        scanf("%d",&b[i]);

    }

    for(i=0; i<3; i++){
        for(j=0; j<3; j++){
            for(k=0; k<N; k++){
                if(b[k] == A[i][j]){
                    A[i][j] = -1;
                }
            }
        }
    }

    if(A[0][0] == -1){
        if((A[0][1] == -1)&&(A[0][2] == -1)){
            f=1;
        } else if((A[1][0] == -1)&&(A[2][0] == -1)){
            f=1;
        } else if((A[1][1] == -1)&&(A[2][2] == -1)){
            f=1;
        }
    }
    if(A[1][1] == -1){
        if((A[0][1] == -1)&&(A[2][1] == -1)){
            f=1;
        } else if((A[1][0] == -1)&&(A[1][2] == -1)){
            f=1;
        } else if((A[0][2] == -1)&&(A[2][0] == -1)){
            f=1;
        }
    }
    if(A[2][2] == -1){
        if((A[0][2] == -1)&&(A[1][2] == -1)){
            f=1;
        } else if((A[2][0] == -1)&&(A[2][1] == -1)){
            f=1;
        }
    }

    if(f==0){
        printf("No\n");
    } else {
        printf("Yes\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
//#include <bits/stdc++.h>
// AtCoder提出用
using namespace std;

int main()
{
	int n;
	cin >> n;
	int a[200005] = {0}, ans[200005] = {0};
	for (int i = 1; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i < n; i++) {
		ans[a[i]]++;
	}
	for (int i = 1; i < n+1; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 5192
#include<bits/stdc++.h>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	ll a,b;
	cin >> a >> b;
	
	if( b == 100 )
		b++;

	if( a == 0 )
		cout << b;
	else if( a == 1 )
		cout << b*100;
	else
		cout << b*10000;

	cout << endl;
	ret 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int s;
	cin >> s;
	vector<int> vec = { s };
	set<int> se = { s };
	int i = 0;
	while (true) {
		if (vec.at(i) % 2 == 0) {
			vec.push_back(vec.at(i) / 2);
			se.insert(vec.at(i) / 2);
		}
		else {
			vec.push_back((vec.at(i) * 3) + 1);
			se.insert((vec.at(i) * 3) + 1);
		}
		if (se.size() == vec.size()) {}
		else {
			cout << i + 2;
			break;
		}
		i++;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) begin(x), end(x)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

ll dp[200005];

int main(){
  const ll mod=998244353;
  int n,k;
  cin>>n>>k;
  ll l[15],r[15];
  rep(i,k){
    cin>>l[i]>>r[i];
  }
  dp[0]=1;
  rep(i,n-1){
    rep(j,k){
      if(i+l[j]<=n-1) dp[i+l[j]]=(dp[i+l[j]]+dp[i])%mod;
      if(i+r[j]+1<=n-1) dp[i+r[j]+1]=(dp[i+r[j]+1]-dp[i])%mod;
    }
    if(i!=0) dp[i+1]=(dp[i+1]+dp[i])%mod;
    /*
    rep(i,n){
      cout<<dp[i]<<' ';
    }
    */
  }

  if(dp[n-1]<0) dp[n-1]+=mod;
  cout<<dp[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 5192