akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    string S;
    cin >> S;
    lint num_chars = S.size();
    lint ans = 0;
    range(split, 0, 1 << (num_chars - 1)) {
        lint sum = 0;
        string cur_digits(1, S.at(0));
        range(i, 0, num_chars - 1) {
            if ((split >> i) & 1) {
                sum += stoll(cur_digits);
                cur_digits = S.substr(i + 1, 1);
            } else {
                cur_digits.push_back(S.at(i + 1));
            }
        }
        sum += stoll(cur_digits);
        // cout << sum << "\n";
        ans += sum;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#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 = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
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 (a > b) { a = b; return true; } return false; }
int insertionSort(vector<int>&a, int g) {
	int ret(0);
	rep(i, g, a.size()) {
		int j = i - g;
		int v = a[i];
		while (0 <= j&&a[j] > v) {
			a[j + g] = a[j];
			ret++;
			j -= g;
		}
		a[j + g] = v;
	}
	return ret;
}
void shellSort(vector<int>&a) {
	vector<int>g;
	for (int x = a.size(); x > 0; x >>= 1)g.emplace_back(x);
	dump(g);
	int cnt(0);
	cout << g.size() << endl;
	rep(i, 0, g.size()) {
		cout << g[i] << ((i == g.size() - 1) ? '\n' : ' ');
		cnt += insertionSort(a, g[i]);
	}
	cout << cnt << endl;
	rep(i, 0, a.size())cout << a[i] << endl;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> a(N); rep(i, 0, N) { cin >> a[i]; }
	shellSort(a);
	return 0;
}

Measured memory_bytes: 6572
#include <bits/stdc++.h>
#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(){
	int n,T;
	cin >> n >> T;
	int ans = 10000000;
	rep(i,n){
		int c,t;
		cin >> c >> t;
		if(t <= T) ans = min(c,ans);
	}
    if(ans == 10000000){
        cout << "TLE" << endl;
        return 0;
    }
	cout << ans << endl;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

#define BIT_N 333
typedef long long ll;
typedef pair<ll,ll> P;
typedef bitset<BIT_N> Bit;
vector<int> baseNum;

ll pow_two[BIT_N];

vector<Bit> gauss(vector<Bit> &v, ll &ran){
	ran = 0;
	REP(i,BIT_N) {
		int pla = -1;
		for(int j = ran;j < v.size();j++){
			if(v[j][i] == 1){
				pla = j;
				break;
			}
		}
		
		if(pla != -1){
			swap(v[ran], v[pla]);
			for(int j = 0;j < v.size();j++){
				if(j != ran && v[j][i] == 1)v[j] ^= v[ran];
			}
			ran++;
		}
	}
	return v;
}

int main(){
	
	pow_two[0] = 1;
	REP(i,BIT_N - 1)pow_two[i+1] = pow_two[i] * 2 % MOD;
	
	vector<Bit> v;
	ll n, m;cin >> n >> m;
	REP(i,n){
		Bit now;
		REP(j,m){
			int a;cin >> a;
			if(a)now[j] = 1;
		}
		v.PB(now);
	}
	
	ll ran = 0;
	ll ans = 0;
	gauss(v, ran);
	
	cout << ((pow_two[n] - pow_two[n - ran] + MOD) % MOD) * pow_two[m-1] % MOD << endl;
	
	return 0;
}


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

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

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

n = INT()
l = 0
r = n - 1
print(l, flush=True)
ltmp = STR()
if ltmp == 'Vacant':
    exit()
print(r, flush=True)
rtmp = STR()
if rtmp == 'Vacant':
    exit()
for i in range(2, 20):
    c = (l + r) // 2
    print(c, flush=True)
    tmp = STR()
    if tmp == 'Vacant':
        exit()
    if c % 2 == l % 2:
        if tmp == ltmp:
            l = c
            ltmp = tmp
        else:
            r = c
    else:
        if tmp == ltmp:
            r = c
        else:
            l = c
            ltmp = tmp

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

using namespace std;

#define INF (1ll << 62)
#define pb push_back
#define ii pair<int,int>
#define OK cerr <<"OK"<< endl
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define endl '\n'

int dp[3002][3002][2];
vector<int> arr;

int f(int l, int r, int player) {

	if(l > r)
		return 0;

	int &ret = dp[l][r][player];
	if(ret != -1)
		return ret;

	if(player == 1) {

		return ret = min(-arr[l] + f(l + 1, r, player ^ 1), -arr[r] + f(l, r - 1, player ^ 1)); 

	} else {
		return ret = max(arr[l] + f(l + 1, r, player ^ 1), arr[r] + f(l, r - 1, player ^ 1));
	}
}

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

  memset(dp, -1, sizeof dp);

  int n;

  cin >> n;

  arr.resize(n);

  for(int &x: arr)
  	cin >> x;

  cout << f(0, n-1, 0) << endl;

}

Measured memory_bytes: 141312
function Main(input) {
    var data = input.split("\n")
    var answer = false;
	for(var i=1; i<=9;i++){
		if(data[0]/i <=9 && data[0]%i===0 ){
			answer = true;
		}
	}
	if(answer) {
		console.log('Yes');
	}else{
		console.log('No')
	}
}
 
// Don't edit this line!
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>

#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[]) {
	unordered_map<string, int> um;
	um["SUN"] = 7;
	um["SAT"] = 1;
	um["FRI"] = 2;
	um["THU"] = 3;
	um["WED"] = 4;
	um["TUE"] = 5;
	um["MON"] = 6;
	string s;
	cin >> s;
	cout << um[s] << endl;



}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n;
  ll k;
  cin >> n >> k;
  VL as(n);
  FOR(a,as) {
    cin >> a;
  }
  VI pop(40, 0);
  FOR(a,as) {
    REP(i,0,40) {
      if ((a >> i) & 1) {
        pop[i]++;
      }
    }
  }
  ll maxf = 0;
  FOR(a,as) {
    maxf += a ^ k;
  }
  REP(i,0,40) {
    if (!((k >> i) & 1)) {
      continue;
    }
    ll f = 0;
    REP(j,0,40) {
      if (j < i) {
        f += max(pop[j], n - pop[j]) * (1ll << j);
      } else if (j == i) {
        f += pop[j] * (1ll << j);
      } else {
        if ((k >> j) & 1) {
          f += (n - pop[j]) * (1ll << j);
        } else {
          f += pop[j] * (1ll << j);
        }
      }
    }
    maxf = max(maxf, f);
  }
  cout << maxf << endl;

  return 0;
}


Measured memory_bytes: 1024
//#include "bits/stdc++.h"

#include <iostream>
#include <vector>
// #include <map>
// #include <string>
// #include <algorithm>
// #include <numeric>
// #include <limits>

using namespace std;

int main() {
	int n;
	cin >> n;
	switch (n) {
		case 0:
		case 2:
			cout << 1 << endl;
			break;
		case 1:
			cout << 2 << endl;
			break;
		default :
			cout << 0 << endl;
			break;
	}

	//std::cout << "\e[38;5;0m\e[48;5;40m --- end ---  \e[m" << std::endl; // debug
	return 0;
}

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

const int INF = 1e9;

int main() {
  // 入力
  int n, m, x;
  cin >> n >> m >> x;
  vector<vector<int>> a(n, vector<int>(m + 1));
  int m2 = m + 1;
  rep(i, n) rep(j, m2) cin >> a[i][j];
  vector<int> ans(n, INF);
  for (int bit = 0; bit < (1 << n); ++bit) {
    int sum[m] = {0};
    int c = 0;
    for (int i = 0; i < n; ++i) {
      if (bit & (1 << i)) {
        rep(k, m) sum[k] += a[i][k + 1];
        c += a[i][0];
      }
    }

    bool ok = true;

    rep(t, m) {
      if (sum[t] < x) ok = false;
    }
    if (ok) ans.push_back(c);
  }

  int mn = INF;
  rep(i, ans.size()) mn = min(mn, ans[i]);

  if (mn != INF) {
    cout << mn << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h> 
using namespace std; 
#define M 1e9+7
#define int long long
#define lli long long int
#define I 10e5

int32_t main() 
{ 
   ios_base::sync_with_stdio(false);cin.tie(NULL); 
   
   #ifndef ONLINE_JUDGE 
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout); 
   #endif
   int n, w;
   cin>>n>>w;
   int sum = 0;
   int prev, curr;
   vector<int> wt(n), v(n);
   for(int i=0;i<n;i++)
   {
      cin>>wt[i]>>v[i];
   }
   int dp[n+1][w+1];
   for(int i=0;i<=n;i++)
   {
      dp[i][0] = 0;
   }
   for(int i=0;i<=w;i++)
   {
      dp[0][i] = 0;
   }
   for(int i=1;i<=n;i++)
   {
      for(int j=0;j<=w;j++)
      {
         if(wt[i-1]<=j)
         {
            dp[i][j] = max(dp[i-1][j], v[i-1] + dp[i-1][j-wt[i-1]]);
         }
         else
         {
            dp[i][j] = dp[i-1][j];
         }
      }
   }
   cout<<dp[n][w]<<endl;
   cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; 
   return 0; 
}

Measured memory_bytes: 82548
//6:48
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;
ll max(ll a, ll b){return(a>b)?a:b;}
ll min(ll a, ll b){return(a<b)?a:b;}
ll abss(ll a){return(a<0)?-a:a;}

ll gcd(ll a, ll b){
        if(b > a){
                ll tmp = b;
                b = a;
                a = tmp;
        }
        if(b == 0) return a;
        else return gcd(b, a%b);
}
ll lcm(ll a, ll b){
        ll gcdi = gcd(a,b);
        return a/gcdi*(b);
}

int main(){
        ll N;
        scanf("%lld",&N);

        int m = (int)sqrt(2*N);
        if((m)*(m-1) >= 2*N){ printf("%d\n",m-1);}
        else if((m+1)*(m) >= 2*N){ printf("%d\n",m);}
        else if((m+2)*(m+1) >= 2*N){ printf("%d\n",m+1);}
}

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

using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const int inf = 1e9+7;
const int mod = 1e9+7;

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

    vector<int>p(n);
    rep(i,n)cin>>p[i];

    int ans=0;

    rep(i,n){
        if(p[i]==i+1){
            swap(p[i],p[i+1]);
            ans++;
        }
    }

    if(p[n-1]==n)ans++;

    cout<<ans<<endl;
}


Measured memory_bytes: 3780
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    u32 n, ma, mb;
    cin >> n >> ma >> mb;
    vector<vector<int>> dp(500, vector<int>(500, INF));
    dp[0][0] = 0;
    int x = 0, y = 0;
    for (int i = 0; i < n; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        for (int j = x; j >= 0; --j) {
            for (int k = y; k >= 0; --k) {
                dp[j+a][k+b] = min(dp[j+a][k+b], dp[j][k]+c);
            }
        }
        x += a, y += b;
    }
    int ans = INF;
    for (int i = 1; i <= x; ++i) {
        for (int j = 1; j <= y; ++j) {
            if(i*mb == j*ma) ans = min(ans, dp[i][j]);
        }
    }
    cout << (ans == INF ? -1 : ans) << "\n";
    return 0;
}


Measured memory_bytes: 1280
N, A, B, C = [int(x) for x in input().split()]
l = [int(input()) for _ in range(N)]
INF = 10**9


def recur(i, a, b, c, cost):
    if i == N:
        if a*b*c == 0:
            return INF
        else:
            return cost + abs(A-a) + abs(B-b) + abs(C-c) - 30

    cand1 = recur(i+1, a+l[i], b, c, cost + 10)
    cand2 = recur(i+1, a, b+l[i], c, cost + 10)
    cand3 = recur(i+1, a, b, c+l[i], cost + 10)
    cand4 = recur(i+1, a, b, c, cost)
    return min([cand1, cand2, cand3, cand4])


print(recur(0, 0, 0, 0, 0))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
#define double long double
const int mod=1000000007,MAX=10005,INF=1<<29;
vector<pair<int,pair<int,int>>> G[MAX];
int dis[MAX],cost[MAX];

void dijkstra(int u){
    dis[u]=0;
    cost[u]=0;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> PQ;
    
    PQ.push(make_pair(0,u));
    while(!PQ.empty()){
        ll a=PQ.top().first;
        int b=PQ.top().second;
        PQ.pop();
        if(dis[b]<a) continue;
        for(int i=0;i<G[b].size();i++){
            int c=G[b][i].first;
            int d=G[b][i].se.fi;
            int e=G[b][i].se.se;
            if(dis[c]>dis[b]+d){
                dis[c]=dis[b]+d;
                cost[c]=e;
                PQ.push(make_pair(dis[c],c));
            }else if(dis[c]==dis[b]+d){
                chmin(cost[c],e);
            }
        }
    }
    return;
}//a,dが長さ

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N,M;cin>>N>>M;
        if(N+M==0) break;
        for(int i=0;i<N;i++){
            G[i].clear();
            dis[i]=INF;
            cost[i]=INF;
        }
        
        for(int i=0;i<M;i++){
            int a,b,c,d;cin>>a>>b>>c>>d;
            a--;b--;
            G[a].push_back({b,{c,d}});
            G[b].push_back({a,{c,d}});
        }
        
        dijkstra(0);
        
        int ans=0;
        for(int i=0;i<N;i++) ans+=cost[i];
        
        cout<<ans<<endl;
    }
}





Measured memory_bytes: 5160
fn main() {
    proconio::input! {
        n: usize,
        k: i64,
        a: [i64; n]
    };
    let mut l = 0;
    let mut r = 1000000000;
    while r - l > 1 {
        let mid = (l + r) / 2;
        let cut = a.iter().fold(0, |s, x| s + (x-1)/mid);
        if cut <= k {
            r = mid;
        } else {
            l = mid;
        }
    }
    println!("{}", r);
}


Measured memory_bytes: 5388
#include <iostream>
#include <vector>

using namespace std;

#define INF (1 << 30)

struct Node {
    int id;
    int cost;
    vector<int> next_node;
    vector<int> next_cost;
} node[1000];

int main() {
    int v, e, r, s, t, d;

    cin >> v >> e >> r;
    for (int i = 0; i < v; i++) {
        node[i].id = i;
        node[i].cost = INF;
    }
    for (int i = 0; i < e; i++) {
        cin >> s >> t >> d;
        node[s].next_node.push_back(t);
        node[s].next_cost.push_back(d);
    }

    int count = 0;
    bool update, next[v] = { false };
    next[r] = true;
    node[r].cost = 0;
    while (1) {
        if (count >= v) {
            cout << "NEGATIVE CYCLE\n";
            return 0;
        }
        update = false;
        for (int i = 0; i < v; i++) {
            if (next[i] == false) {
                continue;
            }
            int size = node[i].next_node.size();
            for (int j = 0; j < size; j++) {
                int to = node[i].next_node[j];
                next[to] = true;
                if (node[to].cost > node[i].cost + node[i].next_cost[j]) {
                    node[to].cost = node[i].cost + node[i].next_cost[j];
                    update = true;
                }
            }
        }
        if (update == false) {
            break;
        }
        count++;
    }
    for (int i = 0; i < v; i++) {
        if (next[i] == false) {
            cout << "INF\n";
        }
        else {
            cout << node[i].cost << endl;
        }
    }

    return 0;
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

int main() {
  int N;
  cin >> N;
  vector< int > d[300000];
  for(int i = 0; i < N; i++) {
    int M;
    cin >> M;
    while(M--) {
      int x;
      cin >> x;
      d[i].emplace_back(x);
    }
  }

  priority_queue< int, vector< int >, greater< int > > que;
  int64 ret = 0;
  for(int i = 0; i < N; i++) {
    que.emplace(d[i][0]);
    ret += d[i][0];
    for(int j = 1; j < d[i].size(); j++) {
      auto p = que.top();
      que.pop();
      auto nxt = max(d[i][j], p);
      ret += nxt - p;
      que.emplace(nxt);
    }
  }
  cout << ret << endl;
}



Measured memory_bytes: 21212
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
    S = list(input())

    acgt = ['A', 'G', 'C', 'T']
    cnt = 0
    ans = 0
    for s in S:
        if s in acgt:
            cnt += 1
        else:
            ans = max(ans, cnt)
            cnt = 0
    print(max(ans, cnt))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define TIN(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

void solve()
{
    IN(n, k);
    VIN(ll, p, n); rep(i, n) --p[i];
    VIN(ll, c, n);
    set<ll> s;
    rep(i, n) s.emplace(i);
    V<V<ll>> v;
    while (!s.empty()) {
        V<ll> w;
        int x = *(s.begin());
        ll q = 0;
        w.push_back(0);
        while (true) {
            x = p[x];
            if (!s.erase(x)) break;
            q += c[x];
            w.push_back(q);
        }
        v.push_back(w);
    }
    ll res = 0;
    for (auto&& w : v) {
        ll ans = 0;
        ll las = w.back();
        rep(i, w.size()) {
            reps(j, i+1, w.size()) {
                ll t = k - (j - i);
                if (t < 0) continue;
                ll can = t / (w.size() - 1);
                chmax(ans, w[j]-w[i]+(las > 0 ? las*can : 0));
            }
        }
        rep(i, w.size()) {
            reps(j, i, w.size()) {
                ll t = k - (i + w.size() - 1 - j);
                if (t < 0) continue;
                ll can = t / (w.size() - 1);
                chmax(ans, w[i]+las-w[j]+(las > 0 ? las*can : 0));
            }
        }
        chmax(res, ans);
    }
    if (res == 0) {
        res = -1LL << 55;
        rep(i, n)
            chmax(res, c[i]);
    }
    cout << res << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int MAXN = 1e5+5;
const ll p = 1e9+7;
const ll inf = (1<<30);
 
string s;
ll v[MAXN], dp[MAXN][3], part[MAXN][3][3], r[MAXN][3], n;
vector<int> pos[3];
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> s;
	n = s.length();
	v[0] = 0;
	for (int i = 1; i <= n; ++i)
		v[i] = (v[i-1] + 1 + (s[i-1] == 'b'))%3;
	n++;
	for (int i = 0; i < n; ++i)
		pos[v[i]].push_back(i);
 
	for (int i = n-1; i >= 0; --i) {
		for (int j = 0; j < 3; ++j) {
			if (v[i] == j)
				r[i][j] = i;
			else
				r[i][j] = max(i+1LL, r[i+1][j]);
		}
	}
 
	dp[0][0] = 1;
	for (int i = 1; i < n; ++i) {
		for (int j = 0; j < 3; ++j)
			for (int k = 0; k < 3; ++k) {
				if (v[i] != k && v[i-1] == j)
					part[i][j][k] = (part[i-1][j][k] + dp[i-1][j])%p;
				else
					part[i][j][k] = part[i-1][j][k];
			}
		for (int j = 0; j < 3; ++j) {
			if (v[i] == j)
				continue;
			//find the range of j that "project" onto i
			int k = 3-v[i]-j;
			//j -> k -> v[i]
			int lo = 0, hi = pos[j].size();
			//find first guy who is >= i;
			if (pos[j].size() == 0)
				continue;
			while (lo != hi) {
				int mid = (lo+hi)/2;
				int x = pos[j][mid];
				if (r[x][k] >= i) {
					hi = mid;
					continue;
				}
				if (r[r[x][k]][v[i]] >= i)
					hi = mid;
				else
					lo = mid+1;
			}
			if (lo == pos[j].size())
				continue;
			int val1 = pos[j][lo];
			lo = -1, hi = pos[j].size()-1;
			//find last guy who is <= i
			while (lo != hi) {
				int mid = (lo+hi+1)/2;
				int x = pos[j][mid];
				if (r[x][k] > i) {
					hi = mid-1;
					continue;
				}
				if (r[r[x][k]][v[i]] > i)
					hi = mid-1;
				else
					lo = mid;
			}
			if (lo == -1)
				continue;
			int val2 = pos[j][lo];
			if (val1 > val2)
				continue;
			dp[i][v[i]] = (dp[i][v[i]] + part[val2+1][j][v[i]] + p - part[val1][j][v[i]])%p;
		}
		dp[i][v[i]] = (dp[i][v[i]] + dp[i-1][v[i-1]])%p;
	}
 
	ll ans = 0;
	int g = -1;
	for (int i = n-3; i >= 0; --i)
		if (v[i] + v[n-1] + v[n-2] == 3) {
			g = i;
			break;
		}
	if (g == -1) {
		cout << 1 << endl;
		return 0;
	}
	for (int i = 1; i < n; ++i)
		if (v[i] == v[n-1])
			ans = (ans + dp[i][v[i]])%p;
	cout << ans << endl;
}

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

using ll=long long;
using namespace std;

#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}

const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int x;
    int i = 1;
    while (true){
        cin >> x;
        if(x == 0){
            break;
        }
        cout << "Case " << i << ": " << x << endl;
        i++;
    }
}


Measured memory_bytes: 3080
/*********************
*  Author: xuziyuan  * 
*********************/
 
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
 
using namespace std;
 
const LL MOD=1e9+7;

int n;
string s;
map <string,int> mp;
vector <pair <int,string> > v;

int main()
{
	cin>>n;
	rep(i,n)
	{
		cin>>s;
		mp[s]++;
	}
	for(map <string,int>::iterator it=mp.begin();it!=mp.end();it++) v.pb(mpr(-(it->se),it->fi));
	sort(v.begin(),v.end());
	int val=v[0].fi;
	rep(i,v.size())
	{
		if(v[i].fi==val) cout<<v[i].se<<endl;
		else break;
	}
	return 0;
}

Measured memory_bytes: 29552
function main(input){

    out='Yes';
    inputArray = input.split('\n');
    leng = inputArray[0].length;
    S = inputArray[0];
    T = inputArray[1];

    for(i=0;i<leng;i++){
        if(S[i]!=T[i]){
            out='No';
        }        
    }
  
  console.log(out);
 
}
 
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29616
#include<stdio.h>

int main()
{
    char s[3];
    scanf("%s",s);
    if(s[0]==s[1] && s[1]==s[2])
        printf("No");
    else if(s[0]!=s[1] || s[1]!=s[2])
        printf("Yes");
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;

typedef pair<ll, ll> P;

const int MOD = 1000000007;
const ll INF = 1LL << 60;


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

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main(int argc, char**argv){
    string a, b, c;
    cin >> a >> b >> c;

    if (a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) cout << "YES" << endl;
    else cout << "NO" << endl;


    return 0;
}





















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

int main(){
    int k, q;
    cin >> k >> q;

    vector<long long int> d(k);
    for(int i=0; i<k; i++){
        cin >> d[i];
    }

    for(int i=0; i<q; i++){
        int n, x, m;
        cin >> n >> x >> m;

        long long int xn = x, ans = n-1;
        for(int i=0; i<k; i++){
            xn += (((n-1)-i) + k - 1) / k * (d[i] % m);
            if(d[i] % m == 0){
                ans -= (((n-1)-i) + k - 1) / k;
            }
        }
        cout << ans - (xn / m - x / m) << endl;
    }
    return 0;
}

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

int main(){
  string N;
  cin >> N;
  int m=0;
  for(int i=0; i<N.size(); i++){
    m += (int)N[i] - '0';
    m %= 9;
  }
  if(m%9 == 0) cout << "Yes";
  else cout << "No";
  return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k, a, b;
    cin >> k >> a >> b;
    ll ans = 0;
    if (b - a > 2) {
        if (a <= k - 1) {
            if ((k - a + 1) % 2 == 0) {
                ans += b + (k - a - 1) / 2 * (b - a);
            } else {
                ans += b + ((k - a - 2) / 2) * (b - a) + 1;
            }
        } else {
            ans += k + 1;
        }
    } else {
        ans += k + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();

        System.out.println(solve(A, B));

        sc.close();
    }

    static int solve(int A, int B) {
        return (B % A == 0) ? (A + B) : (B - A);
    }
}

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

using namespace std;



int main()
{
    int n,h;
    cin>>n;
    vector<int>vec;
    int dp[n];
    for(int i=0;i<n;i++)
    {
        cin>>h;
        vec.push_back(h);
    }

    for(int i=0;i<n;i++)
    {
        dp[i]=10000000000;
    }
    dp[0]=0;
    for (int i=0;i<n;i++)
    {
        for(int j=1;j<3;j++)
        {
            if (i+j<n)
            {
                dp[i+j]=min(dp[i+j],dp[i]+abs(vec[i]-vec[i+j]));
            }
        }
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1144
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

int solve(int l, int r, int d)
{
  int result = 0;
  for (int i = d; i <= r; i += d) {
    if (i < l) continue;
    ++result;
  }
  return result;
}

int main()
{
  int l, r, d;
  std::cin >> l >> r >> d;

  std::cout << std::setprecision(20);
  std::cout << solve(l, r, d) << std::endl;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[100],b;
	a[5] = 0;
	a[7] = 0;
	for(int i=1;i<=3;i++){
		scanf("%d",&b);
		a[b]++;
	}
	if(a[5] == 2 && a[7] == 1){
		printf("YES");
	}
	else{
		printf("NO");
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int A,B,C;
 cin >> A >> B >> C;
 if (A == B && A == C) {
   cout << "No" << endl;
 } else if (A == B || B == C || A == C) {
   cout << "Yes" << endl;
 } else {
   cout << "No" << endl;
 }
 
  } 

 

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

using namespace std;

int main(int argc, const char *argv[]) {
  long long n;
  cin >> n;

  string ans;
  while (n > 0) {
    long long d = n % 26;
    n--;
    n /= 26;
    if (d == 0) {
      ans += 'z';
    } else {
      ans += 'a' + (d - 1);
    }
  }

  reverse(ans.begin(), ans.end());
  cout << ans << '\n';
  return 0;
}

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

int main(){
  int sum = 0;
  int a;
  int n,m;
  int i;

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

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

  if(m - sum >= 0) printf("%d\n", m - sum);

  else printf("-1\n");

  return 0;
}


Measured memory_bytes: 1728
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  char c;
  cin >> c;
  string s = "aeiou";

  for(char h: s){
    if(h==c){
      print("vowel");
      return 0;
    } 
  }
  print("consonant");

}


Measured memory_bytes: 256
// problem: "https://atcoder.jp/contests/abc156/tasks/abc156_d"

#include<bits/stdc++.h>
#define ll long long
#define p (ll)(1e9+7)

using namespace std;

ll power(ll a,ll n)
{
    if(!n)
        return 1;

    ll b = 1;
    if(n%2)
        b = a;

    ll ans = power(a,n/2);

    ans = ((ans*ans)%p * b)%p;

    return ans;
}

ll nCr(ll n,ll r)
{
    ll a,b,i;

    a = 1;
    for(i=1;i!=r+1;i++)
        a = (a*i)%p;

    b = 1;
    for(i=n;i>=n-r+1;i--)
        b = (b*i)%p;

    ll ans = (b * power(a,p-2))%p;

    return ans;
}

int main()
{
    ll n,a,b;
    cin>>n>>a>>b;

    ll ans = (power(2,n)-1)%p;      // define
    ans = (ans+2*p - nCr(n,a) - nCr(n,b))%p;        // define

    cout<<ans;

    return 0;
}


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

namespace ABC096 {
	class ABC096_A {
		static void Main(string[] args) {
			var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			var a = input[0];
			var b = input[1];
			Console.WriteLine(a <= b ? a : a - 1);
		}
	}
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n;
    string s;
    cin >> n >> s;
    int l = 0;
    int r = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == ')') {
            if (l > 0) {
                l = l - 1;
            } else {
                r = r + 1;
            }
        } else if (s[i] == '(') {
            l = l + 1;
        }
    }
    for (int i = 0; i < r; i++) cout << '(';
    cout << s;
    for (int i = 0; i < l; i++) cout << ')';
    cout << endl;
}


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

using namespace std;

using ll = long long;

constexpr ll INF = 1e18;

struct Dinic {
    using T = ll;

    struct Edge {
        int to;
        T cap;
        int rev;  //行き先、容量、逆辺
        Edge(int to, T cap, int rev) : to(to), cap(cap), rev(rev) {}
    };

    vector< vector<Edge> > G;
    vector<int> level, iter;

private:
    void bfs(int s) {
        fill(level.begin(), level.end(), -1);
        queue<int> que;
        level[s] = 0;
        que.push(s);
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            for (const Edge& e : G[v]) {
                if (e.cap > 0 && level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }

    T dfs(int v, int t, T f) {
        if (v == t) return f;
        for (int& i = iter[v]; i < G[v].size(); i++) {
            Edge& e = G[v][i];
            if (e.cap > 0 && level[v] < level[e.to]) {
                T d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

public:
    Dinic(int V) : G(V), level(V, -1), iter(V, 0) {}

    void add_edge(int from, int to, T cap) {
        G[from].push_back(Edge(to, cap, G[to].size()));
        G[to].push_back(Edge(from, 0, G[from].size() - 1));
    }

    T max_flow(int s, int t) {
        T flow = 0;
        while (true) {
            bfs(s);
            if (level[t] < 0) return flow;
            fill(iter.begin(), iter.end(), 0);
            T f;
            while ((f = dfs(s, t, INF)) > 0) {
                flow += f;
            }
        }
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    Dinic dinic(n + 2);

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        if (a >= 0) {
            ans += a;
            dinic.add_edge(0, i + 1, a);
        } else {
            dinic.add_edge(i + 1, n + 1, -a);
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = i * 2; j <= n; j += i) {
            dinic.add_edge(j, i, INF);
        }
    }
    
    ans -= dinic.max_flow(0, n + 1);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
def action_north(pos)
	pos[:top], pos[:down], pos[:north], pos[:south] =
		pos[:south], pos[:north], pos[:top], pos[:down]
end

def action_south(pos)
	pos[:top], pos[:down], pos[:north], pos[:south] =
		pos[:north], pos[:south], pos[:down], pos[:top]
end

def action_east(pos)
	pos[:top], pos[:down], pos[:east], pos[:west] =
		pos[:west], pos[:east], pos[:top], pos[:down]
end

def action_west(pos)
	pos[:top], pos[:down], pos[:east], pos[:west] =
		pos[:east], pos[:west], pos[:down], pos[:top]
end

def action_right(pos)
	pos[:north], pos[:south], pos[:east], pos[:west] =
		pos[:west], pos[:east], pos[:north], pos[:south]
end

def action_left(pos)
	pos[:north], pos[:south], pos[:east], pos[:west] =
		pos[:east], pos[:west], pos[:south], pos[:north]
end


pos = Hash.new
while num = gets.to_i do
	exit if num == 0

	pos = {
					top: 1,
					down: 6,
					north: 5,
					south: 2,
					east: 3,
					west: 4}
	sum = pos[:top]
	
	num.times do
		case gets.chomp
		when "North" then action_north(pos)
		when "South" then action_south(pos)
		when "East" then action_east(pos)
		when "West" then action_west(pos)
		when "Right" then action_right(pos)
		when "Left" then action_left(pos)
		end
		sum += pos[:top]
	end	
	puts sum

	pos.clear	# ハッシュの初期化
end

Measured memory_bytes: 6116
#include "bits/stdc++.h"

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main(){
	string s;
	cin>>s;
	int k=0,u=0,c=0,p=0;
	rep(i,s.size()){
		if(s[i]=='K')k++;
		if(s[i]=='U')u++;
		if(s[i]=='P')p++;
		if(s[i]=='C')c++;
	}

	cout<<min(min(k,u),min(p,c))<<endl;

}

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

int gcd(int a, int b) {
  if(a < b) gcd(b, a);
  int r;
  while((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int k;
  scanf("%d", &k);
  long long o = 0;
  for(int i = 1; i <= k; i++)
    for(int j = 1; j <= k; j++)
      for(int l = 1; l <= k; l++) o += gcd(i, gcd(j, l));
  printf("%lld\n", o);
}

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

int gcd(int a,int b){
  int r=a%b;
  while(r>0){
    a=b;b=r;r=a%b;
  }
  return b;
}

void run(void){
  int n;
  scanf("%d",&n);
  int v=(n-1)%8;
  int cnt=0;
  if(v>=6){
    for(int i=2;cnt<n;i++) if(i%2==0 || i%3==0) cnt++,printf("%d ",i);
    printf("\n");
    return;
  }
  int sum=0;
  int i;
  for(i=2;cnt<n-1;i++){
    if(i%2==0 || i%3==0){
      printf("%d ",i);
      cnt++;
      sum+=i;
    }
  }
  if(sum%6==5){
    for(i=7;1;i+=6){
      if(gcd(sum,i)>1){
	printf("%d\n",i);
	return;
      }
    }
  } else {
    for(;1;i++){
      if((sum+i)%6==0 && gcd(sum,i)>1){
	printf("%d\n",i);
	return;
      }
    }
  }
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define first fi;
#define second se;
using namespace std;
typedef pair<int, int> P;

int n;

signed main(){
    cin >> n;
    vector<string> s(n);
    rep(i, 0, n) cin >> s[i];
    bool f = true;
    rep(i, 0, n) rep(j, 0, n) if(s[i][j] == '#') f = false;
    if(f){
        cout << -1 << endl;
        return 0;
    }
    int k = 0;
    rep(i, 0, n){
        bool f = false;
        rep(j, 0, n){
            if(s[j][i] == '.') f = true;
        }
        if(f) k++;
    }
    int MIN = 1e9;
    rep(i, 0, n){
        int tmp = 0;
        rep(j, 0, n){
            if(s[i][j] == '.') tmp++;
        }
        bool f = false;
        rep(j, 0, n){
            if(s[j][i] == '#') f = true;
        }
        if(!f) tmp++;
        MIN = min(MIN, tmp);
    }
    cout << MIN + k << endl;
}

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

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int main(){
    string o,e;
    cin >> o >> e;
    for(int i=0;i<e.size();i++){
        cout << o[i] << e[i];
    }
    if(o.size()!=e.size()) cout << o[o.size()-1];
    cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<atcoder/fenwicktree>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
typedef vector<int > vi;
typedef vector<pair<int, int > > vp;
int main(){
	//m containers ai matchboxes bi matches
	//burglar bag n matchboes
	int n,m;
	cin>>n>>m;
	fenwick_tree<ll > fw(n);
	int q;
	ll a,b;
	rep(i,n){
		cin>>a;
		fw.add(i,a);
	}
	while(m--){
		cin>>q>>a>>b;
		if(q==0){
			fw.add(a,b);
		}
		else{
			cout<<fw.sum(a,b)<<'\n';
		}
	}

}

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

int main() {

	int n; string s; cin >> n >> s;
	string abc = "ABC";
	int ans = 0;
	for (int i = 0; i < n - 2; i++) {
		string tmp = s.substr(i, 3);
		if (tmp == abc) ans++;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>

char tuyo[5000][5000];
int kazu[5000];

int main()
{
	int n,m;
	scanf("%d",&n);
	scanf("%d",&m);
	for(int i = 0; i < n; i++)
	{
		for(int ii = 0; ii < n; ii++)
		{
			tuyo[i][ii] = 1;
		}
	}
	for(int i = 0; i < m; i++)
	{
		int w,l;
		scanf("%d %d",&w,&l);
		tuyo[l - 1][w - 1] = 0;
	}
	for(int i = 0; i < n; i++)
	{
		kazu[i] = 0;
		for(int ii = 0; ii < n; ii++)
		{
			kazu[i] += tuyo[i][ii];
		}
	}
	bool w = false;
	for(int i = 0; i < n; i++)
	{
		bool max = false;
		int maxb;
		for(int ii = 0; ii < n; ii++)
		{
			if(kazu[ii] == n)
			{
				if(max)
				{
					w = true;
				}
				maxb = ii;
				max = true;
			}
		}
		for(int ii = 0; ii < n; ii++)
		{
			if(tuyo[maxb][ii] == 1 && tuyo[ii][maxb] == 0)
			{
				tuyo[ii][maxb] = 1;
				kazu[ii]++;
			}
		}
		kazu[maxb] = -10000;
		printf("%d\n",maxb + 1);
	}
	if(w)
	{
		printf("1\n");
	}
	else
	{
		printf("0\n");
	}
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 25472
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int xa[8001][17000];//xa[a][b]:= a番目まで見てbに到達できる数
int ya[8001][17000];//ya[a][b]:= a番目まで見てbに到達できる数
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int gap = 8000+1;
	int x,y;
	string s;
	cin >> s;
	cin >> x >> y;
	int n = s.size();
	int xp = 0;
	vector<int> xf,yf;
	int p = n;
	for(int i=0;i<n;i++){
		if(s[i]=='F')xp++;
		else {
			p = i+1;
			break;
		}
	}
	int f = 1;
	// f = 0 のとき x軸を向いている
	// f = 1 のとき y軸を向いている
	for(int i=p;i<n;i++){
		int cnt = 0;
		while(s[i]=='F'){
			cnt++;
			i++;
		}
		if(cnt){
			if(f){
				yf.push_back(cnt);
			}else{
				xf.push_back(cnt);
			}
		}
		f++;
		f%=2;
	}
	xa[0][xp+gap] = 1;
	for(int i=1;i<=xf.size();i++){
		int flex = xf[i-1];
		for(int j=0;j<=16000;j++){
			if(xa[i-1][j]){
				xa[i][j+flex] = 1;
				xa[i][j-flex] = 1;
			}
		}
	}
	ya[0][gap] = 1;
	for(int i=1;i<=yf.size();i++){
		int flex = yf[i-1];
		for(int j=0;j<=16000;j++){
			if(ya[i-1][j]){
				ya[i][j+flex] = 1;
				ya[i][j-flex] = 1;
			}
		}
	}
	if(xa[xf.size()][x+gap] && ya[yf.size()][y+gap])cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 266624
MOD = 998244353
import bisect
import sys
input = sys.stdin.buffer.readline
N = int(input())

XR = []
for i in range(N):
    X,D = map(int,input().split())
    XR.append((X,X+D))

XR.sort()
X, R = map(list,zip(*XR))

#inds = np.searchsorted(X,R,side='left')-1
inds = [bisect.bisect_left(X,r)-1 for r in R]

l = 2**((N-1).bit_length())
data = [0] * l + inds + [0] * (l-N)
for i in range(l-1,0,-1):
    data[i] = max(data[2*i],data[2*i+1])

def set(i,val):
    i += l
    data[i] = val
    i //= 2
    while i > 0:
        data[i] = max(data[2*i], data[2*i+1])
        i //= 2
def get(i,j):
    i += l
    j += l
    s = data[i]
    while j-i > 0:
        if i & 1:
            s = max(s,data[i])
            i += 1
        if j & 1:
            s = max(s,data[j-1])
            j -= 1
        i//=2
        j//=2
    return s

for i in range(N-1,-1,-1):
    set(i,get(i,inds[i]+1))
#print(data)
#print(data[l:])

dp = [0]*(N+1)
dp[N] = 1
for i in range(N-1,-1,-1):
    dp[i] = (dp[i+1] + dp[data[l+i]+1]) % MOD
#print(dp)
print(dp[0])




Measured memory_bytes: 113332
#include<iostream>

using namespace std;
int main(){
long long a,b,c,k,ans;
  ans=0;
  cin>>a>>b>>c>>k;
  for(int i=0;i<k;i++){
  	if(a>0){
    ans++;
      a--;
    }
    else if(b>0){b--;}
    else{ans--;}
  }
  cout<<ans;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, count;
  cin >> N;
  
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
  	cin >> H.at(i);
  }
  
  for(int i = 1; i < N; i++){
    bool flg = true;
    
    for(int j = 0; j < i; j++){
      if(H.at(i) < H.at(j)){
        flg = false;
      }
    }
    
    if(flg) count++;
  }
  
  cout << count + 1 << endl;
}

Measured memory_bytes: 256