akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll,ll> pll;
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define rep(i, n) for (ll i = 0; i < ll(n); i++)

const ll mod = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    // init struct with "n" of "nCk" (maximum number in other words)
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    // c(n,k) returns mint that contains nCk (mod p (= 1e9+7)) in x
    // i.e.) mint num = c(n,k), then num.x == nCk (mod p (= 1e9+7))
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }

    // nPk - permutation
    mint p(int n, int k) {
        return fact[n] * ifact[n - k];
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vl c(n);
    rep(i, n) cin >> c[i];
    sort(c.begin(), c.end());

    mint ans;
    for (int i = 0; i < n; i++) {
        ans += mint(c[i]) * mint(n - i + 1);
    }
    ans *= mint(4).pow(n - 1);
    cout << ans.x << endl;
}

Measured memory_bytes: 4756
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste
// #include "UnionFind.h"
// #include "power.h"

signed main() {
    int x, y;
    cin >> x >> y;

    int answer = INF;
    for (int i = 0; i <= 1; ++i) {
        for (int j = 0; j <= 1; ++j) {
            int a = (i == 0) ? x : -x;
            int b = (j == 0) ? y : -y;
            if (a <= b) answer = min(answer, b - a + i + j);
        }
    }
    cout << answer << endl;
}

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

using namespace std;

int main(){
    int h, w;
    string ary[30][30];
    string str[30] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
    cin >> h >> w;
    for (int i = 1; i <= h; i++) {
        for(int j = 1 ; j <= w ; j++){
            cin >> ary[i][j];
        }
    }
    for(int i = 1 ; i <= h ; i++){
        for(int j = 1 ; j <= w ; j++){
            if(ary[i][j] == "snuke"){
                cout << str[j-1] << i << '\n';
            }
        }
    }
}

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

namespace ALDS1_2_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var itemNum = int.Parse(Console.ReadLine());
            var numArray = Console.ReadLine().Split(' ').Select(x => int.Parse(x));
            var result = BubbleSort(numArray);

        }

        static List<T> BubbleSort<T>(IEnumerable<T> target) where T : IComparable
        {
            var result = new List<T>(target);
            var exchangeCount = 0;
            for (int i = 0; i < result.Count - 1; i++)
            {
                for (int j = result.Count - 1; j > i; j--)
                {
                    if (result[j].CompareTo(result[j - 1]) < 0)
                    {
                        var tmp = result[j];
                        result[j] = result[j - 1];
                        result[j - 1] = tmp;
                        exchangeCount++;
                    }
                }
            }
            Console.WriteLine(string.Join(" ", result));
            Console.WriteLine(exchangeCount);
            return result;
        }
    }
}



Measured memory_bytes: 18296
N = int(input())
S = input()

same = False
while not same:
  same = True
  i = 0
  while i+1 < N:
    if S[i] == S[i+1]:
      S = S[:i] + S[i+1:]
      N -= 1
      same = False
    else:
      i += 1

print(len(S))

Measured memory_bytes: 3400
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;

#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif
#define out(v) cout<<v<<"\n"
#define _overload3(_1,_2,_3,name,...) name
#define _all1(a) (a).begin(),(a).end()
#define _all2(a,n) (a),(a)+n
#define all(...) _overload3(__VA_ARGS__,42,_all2,_all1,)(__VA_ARGS__)
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

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

  int k = 0;
  rep(i, N) {
    int A;
    cin >> A;
    if (k + 1 == A) ++k;
  }
  if (k == 0)
    cout << -1 << "\n";
  else
    cout << N-k << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll long long
#define pb push_back
//#define f first
//#define s second
//#define mp make_pair
#define gg return 0;
#define pii pair < int, int>
 
using namespace std;
 
const int maxn = 132675;
const int INF = (int)1e9;
 
ll a,b[maxn],c,d,cnt,e[(int)2e3 + 1][(int)2e3 + 1],cost[maxn],tout[maxn],mn = INF,mx = -INF,l,r;
 
ll x[maxn],y[maxn],x2[maxn],y2[maxn];
 
bool u[maxn], m, f;
 
vector <int> v;
 /*
void forn( int s, int f, int inter){
	for(int i = s; i <= f; i += inter){
		b[i] = i;
	}
}
*/ 
ll ans;
 
ll pref;
 
//vector <int> g[maxn],d[maxn];
 
ll lvlc,lvl[maxn];
/*
void dfs(int v){
	lvlc++;
	lvl[v] = lvlc;
	d[lvl[v]].pb(v);
	u[v] = 1;
	for(int i = 0; i < g[v].size(); ++i){
		int to = g[v][i];
		if(!u[to]){
			dfs(to);
		}
	}
	lvlc--;
}*/

map <int, int> col; 
 
char ch;

string s; 

int main()
{
	cin >> s;
	for(int i = s.size() - 2; i >= 0; --i){
		if(s[i] != s[i + 1]){
			cnt++;
			s[i + 1] = s[i];
			f = 1;
		}
		else if(s[i] == s[i + 1] && f){
			s[i + 1] = s[i];
		}
	}
	//cout << s;
	cout << cnt;
	gg
}

Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main() {
    const int MAX_S = 1000;
    string s1, s2;
    cin >> s1 >> s2;
    int n = s1.size(), m = s2.size();
    int dp[MAX_S + 1][MAX_S + 1];
    for (int i = 0; i <= n; ++i) {
        dp[i][0] = i;
    }
    for (int j = 0; j <= m; ++j) {
        dp[0][j] = j;
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            int cost = s1[i - 1] == s2[j - 1] ? 0 : 1;
            dp[i][j] = min(dp[i - 1][j] + 1,
                           min(dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost));
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}



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

using namespace std;
int n, m, ans, h[100005], a[100005], b[100005], c[100005];
int main()
{
    cin>> n>> m;
    for(int i=1; i<=n; i++) cin>> h[i];
    for(int i=1; i<=m; i++){
        cin>> a[i]>> b[i];
        if(h[a[i]] == h[b[i]]){
            c[a[i]]=-1;
            c[b[i]]=-1;
        }
        else if(h[a[i]] < h[b[i]]) c[a[i]]=-1;
        else c[b[i]]=-1;
    }
    for(int i=1; i<=n; i++)
        if(c[i]!=-1)
            ans++;
    cout<< ans;
    return 0;
}

Measured memory_bytes: 5228
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>

using namespace std;

int main() {
    

    int n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    long ans1;
    long ans2;
    if(n%a == 0){
        ans1 = n/a * b;
    }else{
        ans1 = (n/a+1) * b;
    }
    if(n%c == 0){
        ans2 = n/c*d;
    }else{
        ans2 = (n/c+1)*d;
    }
    cout << min(ans1,ans2) << endl;

}


Measured memory_bytes: 3096
#include<stdio.h>
int main(void)
{
	int W, a, b,i,count = 0;
	scanf("%d %d %d", &W, &a, &b);
	if (a < b)
	{
		a = a + W;
		for (i = a; i < b; i++)
		{
			count += 1;
		}
	}
	else
	{
		b = b + W;
		for (i = b; i < a; i++)
		{
			count += 1;
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 128
// 尺取り法を使った解法
#include <bits/stdc++.h>
using namespace std;

const int MOD = 1e9+7;

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

  int64_t min_sum = 0;
  int64_t max_sum = 0;
  for (int i = 0; i < K; i++)
  {
    min_sum += i;
    min_sum %= MOD;
    max_sum += N - i;
    max_sum %= MOD;
  }

  int64_t ans = 0;
  for (int i = K; i <= N + 1; i++)
  {
    ans += max_sum - min_sum + 1;
    min_sum += i;
    max_sum += N - i;
    ans %= MOD;
    min_sum %= MOD;
    max_sum %= MOD;
  }
  if (ans < 0)
  {
    ans += MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>

int main()
{
  int A, B, C;
  std::cin >> A >> B >> C;

  std::string judge = "NO";
  for (int i = 0; i <= A*B; i += A) {
    if (i % B == C) {
      judge = "YES";
    }
  }

  std::cout << judge << std::endl;
}


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

int n;
char S[50][51];

int comp(const void *p1, const void *p2) { return *(const char*)p1 - *(const char *)p2; }
int min(int a, int b) { return a < b ? a : b; }

void make_string(char str1[], char str2[]) {
	int index1 = 0, index2 = 0, index = 0;
	int len1 = strlen(str1);
	int len2 = strlen(str2);
	char tmp[51];

	while (1) {
		if (str1[index1] == str2[index2]) {
			tmp[index++] = str1[index1];
			index1++;
			index2++;
		}
		else if (str1[index1] > str2[index2])
			index2++;
		else 
			index1++;

		if (index1 >=  len1 || index2 >= len2)
			break;
	}
	tmp[index] = '\0';
	memcpy(str1, tmp, index + 1);
}

int main(void) {
	int i;
	char ans[50];

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s", S[i]);
		qsort(S[i], strlen(S[i]), sizeof(char), comp);
	}

	memcpy(ans, S[0], strlen(S[0]));
	for (i = 1; i < n; i++)
		make_string(ans, S[i]);

	printf("%s\n", ans);
	return 0;
}

Measured memory_bytes: 128
/* ex 5_4
   terakura */

#include <stdio.h>
#define SIZE 100


int main(void){
    char name[SIZE], *ptr, count1 = 0, count2 = 0;

    //入力
    scanf("%s", name);

    ptr = name;

    //*ptrがヌル文字になるまでポインターを動かす
    while(*ptr){

        //部分文字列の長さを数える
        while(*ptr == 'A'|| *ptr == 'C'|| *ptr =='G'|| *ptr =='T'){
            count1 += 1;
            ptr++;
        }

        //文字列の長さが大きい方を記憶させる
        if(count1 > count2){
            count2 = count1;
        }

        //カウンターをリセット
        count1 = 0;

        ptr++;
    }

    //出力
    printf("%d\n", count2);

    return 0;
}


Measured memory_bytes: 1724
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define reps(i, n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define repi(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
vector<int> data(100010,-1);

int root(int x){
    return (data[x] < 0)? x : data[x]=root(data[x]);
}

bool unite(int x, int y){
    x=root(x);
    y=root(y);
    if( x != y ){
        if( data[y] < data[x] ) swap(x, y);
        data[x] += data[y];
        data[y] = x;
    }
    return x!=y;
}

bool find(int x, int y){
    return root(x) == root(y);
}

int size(int x){
    return -data[ root(x) ];
}

int main(){
    ll n,m;
    cin>>n>>m;
    vector<int> a(m),b(m);
    rep(i,m) {
        cin>>a.at(i)>>b.at(i);
        a.at(i)--;
        b.at(i)--;
    }
    reverse(all(a)); reverse(all(b));
    vector<ll> ans;
    ll now=n*(n-1)/2;
    rep(i,m){
        ans.push_back(now);
        int A=a.at(i),B=b.at(i);
        
        if(root(A)==root(B)) continue;
        
        ll size_A=size(A),size_B=size(B);
        now-=size_A*size_B;
        unite(A,B);
    }
    
    reverse(all(ans));
    rep(i,m) cout<<ans.at(i)<<endl;
    
}


Measured memory_bytes: 3444
N, T = map(int, input().split())
dishes = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
"""
dp[i][j]: 0~i番目までの料理でj分以内に完食できる美味しさの合計の最大値
"""
dp = [[0] * 3100 for _ in range(3100)]
ans = 0
for i in range(1, N+1):
    for j in range(1, T):
        dp[i][j] = dp[i-1][j]
        ans = max(ans, dp[i][j] + dishes[i-1][1])
        if j - dishes[i-1][0] >= 0:
            dp[i][j] = max(dp[i][j], dp[i-1][j-dishes[i-1][0]] + dishes[i-1][1])

print(ans)


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n, k;
    cin >> n >> k;
    vector<ll> v(n);
    for(auto& i : v) cin >> i;

    sort(rall(v));
    ll ans = 0;

    cout << accumulate(v.begin() + min(n,k), v.end(), 0LL) << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
#define N 1005
#define LL long long

int x,y,z,k;
LL maxsum;
LL a[N],b[N],c[N];
int fa,fb,fc;
LL cal(int aa,int bb,int cc)
{
	return a[aa]+b[bb]+c[cc];
}
struct comb
{
	int a,b,c;
	comb(int x,int y,int z)
	{
		a=x;
		b=y;
		c=z;
	}
	bool operator<(const comb& x) const
	{
		return cal(a,b,c)<cal(x.a,x.b,x.c);
	}	
};
priority_queue<comb> q;

void dig(int typ)
{
	(!typ)?fa++:(typ==1)?fb++:fc++;
	for(int i=0;i<=((!typ)?fb:(typ==1)?fc:fa);i++)
	for(int j=0;j<=((!typ)?fc:(typ==1)?fa:fb);j++)
		q.push((!typ)?comb(fa,i,j):(typ==1)?comb(j,fb,i):comb(i,j,fc));
} 

int main()
{
	
	cin>>x>>y>>z>>k;
	for(int i=0;i<x;i++)
		cin>>a[i];
	for(int i=0;i<y;i++)
		cin>>b[i];
	for(int i=0;i<z;i++)
		cin>>c[i];
	sort(a,a+x);
	reverse(a,a+x);
	sort(b,b+y);
	reverse(b,b+x);
	sort(c,c+z);
	reverse(c,c+x);
	
	q.push(comb(0,0,0));
	while(k--)
	{
		comb p=q.top();
		cout<<a[p.a]+b[p.b]+c[p.c]<<'\n';
		q.pop();
		if(p.a==fa && fa!=x-1) dig(0);
		if(p.b==fb && fb!=y-1) dig(1);
		if(p.c==fc && fc!=z-1) dig(2);
	}
		
	return 0;
}

Measured memory_bytes: 25064
#include<bits/stdc++.h>
using namespace std;
#define bye return 0
#define Yes cout << "Yes" << "\n"
#define No  cout << "No" << "\n"
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
//#define push push_back
//#define endl cout << "\n"
typedef long long ll;

int main(){ 
	//map<string, int> m;
	int t;
	// cin >> t;
	// while(t--){
		
	
	// }

	int a;
	cin >> a;

	if(a>=400 && a<=599) cout << "8" << endl;
	else if(a>=600 && a<=799) cout << "7" << endl;
	else if(a>=800 && a<=999) cout << "6" << endl;
	else if(a>=1000 && a<=1199) cout << "5" << endl;
	else if(a>=1200 && a<=1399) cout << "4" << endl;
	else if(a>=1400 && a<=1599) cout << "3" << endl;
	else if(a>=1600 && a<=1799) cout << "2" << endl;
	else if(a>=1800 && a<=1999) cout << "1" << endl;
   bye;
}
 

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

using namespace std;

int main(){
    string S;
    cin >> S;
    string s[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    for(int i=0;i<7;i++){
        if(S==s[6-i]){
            cout << i+1 << endl;
        }
    }
}

Measured memory_bytes: 256
#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>;

struct UnionFind {
  vector<int> par;

  UnionFind(int n) : par(n, -1) {}

  int root(int x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = root(par[x]);
  }

  bool issame(int x, int y) { return root(x) == root(y); }

  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);  // merge technique
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  int size(int x) { return -par[root(x)]; }
};

using pint = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    uf.merge(a, b);
  }

  ll ans = 0;
  rep(i, n) {
    ll mem = uf.size(i);
    ans = max(ans, mem);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4028
#include<cstdio>
#include<map>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
map<string,int> m;
int n;
int main(){
    scanf("%d",&n);
    for(register int i = 1;i <= n;++i){
        char cmd[7],s[5];
        scanf("%s",cmd);
        scanf("%s",s);
        if(cmd[0] == 'f'){
            if(m[s] == 13) printf("yes\n");
            else printf("no\n");
        }
        else{
            m[s] = 13;
        }
    }
    return 0;
}


Measured memory_bytes: 47552
#include <vector>
#include <algorithm>
#include <utility>
#include <iostream>
#include <tuple>
using namespace std;

const int INF = 1 << 29;
int dp[1010][1010];

int main() {
  int N; cin >> N;
  vector< pair<int, int> > probs;
  for(int i=0; i<N; i++) {
    int a, b; cin >> a >> b;
    probs.emplace_back(b, a);
  }

  sort(probs.begin(), probs.end());
  fill(dp[0], dp[N+1], INF);
  dp[0][0] = 0;
  for(int i=0; i<N; i++) {
    int fa_other, tm;
    tie(fa_other, tm) = probs[i];
    for(int j=0; j<=i; j++) {
      int cur_tm = dp[i][j];
      int nxt_tm = cur_tm + tm;
      if(nxt_tm <= fa_other) {
        dp[i+1][j+1] = min(dp[i+1][j+1], nxt_tm);
      }
      dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
    }
  }

  for(int i=N; i>=0; i--) {
    if(dp[N][i] != INF) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 3160
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N,M,X;
  cin >> N >> M >> X;
  int cost[N+1] = {};
  for(int i=0;i<M;i++){
    int a;
    cin >> a;
    cost[a] = 1;
  }

  int sum[N+2];
  sum[0] = 0;
  for(int i=1;i<=N+1;i++){
    sum[i] = sum[i-1] + cost[i-1];
  }

  cout << min(sum[N+1]-sum[X+1] , sum[X]-sum[0]) << endl;
  return 0;
}

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

#define ll long long
#define fast_in_out  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const double pi = acos(-1);

int main()
{
    fast_in_out;
    int a,b,h,m;
    cin >> a >> b >> h >> m;
    double angleHour1 = pi * (1.0 / 6) * h;
    double angleHour2 = pi * (1.0 / 360) * m;
    double angleMin = pi * (1.0 / 30) * m;
    double c = a * a;
    c += (b * b);
    c -= (2 * a * b * cos(angleHour1 + angleHour2 - angleMin));
    printf("%.20lf",sqrt(c));
}


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

const int N=105,M=1e5+5;
int a[N];
bool f[M];

int main() {
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	
	int n,k; scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	f[0]=0;
	for(int i=1;i<=k;++i) {
		f[i]=1;
		for(int j=1;j<=n&&i>=a[j];++j) f[i]&=f[i-a[j]];
		f[i]^=1;
		//cerr<<f[i]<<' ';
	}
	puts(f[k] ? "First" : "Second");
	
	return 0;
}


Measured memory_bytes: 384
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")
 
#include <bits/stdc++.h>
using namespace std;
 
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ost tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define    int                      long long int
#define    ld                       long double
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL),cout.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int ttt; cin >> ttt; while(ttt--)
#define    ff                       first
#define    ss                       second
#define    all(container)            container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    sp(x)                    setprecision(x)
#define    bp(x)                    __builtin_popcount(x)
#define    endl                     "\n"

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    speed upp
    string s,t;
    cin>>s>>t;
    int n=sz(s),m=sz(t);
    if(n==m-1)
    {
        int c=1;
        f(i,0,n-1)
            if(s[i]!=t[i])
                c=0;
        if(c)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
    else    
        cout<<"No";
;}


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




int 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 t,k;

    cin>>t>>k;
   int count=0;
   for(int i=0;i<t;i++)
   {
    int first;
    cin>>first;
    if(first>=k)
      count++;
   }
   cout<<count<<endl;
    return 0;
    
}

Measured memory_bytes: 3664
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque




def main():
    num = int(input())
    data = list(map(int, input().split()))
    ans = data[0] + data[-1]
    for i in range(num - 2):
        ans += min(data[i], data[i + 1])
    print(ans)





if __name__ == '__main__':
    main()



Measured memory_bytes: 38508
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 2e5;
int n, A[N], t[N];
ll k;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  FOR(i, 0, n){
    cin >> A[i];
    A[i]--;
  }
  int s=0, c=0;
  while(true){
    s++;
    if(t[c]){
      k %= s-t[c];
    }else{
      t[c] = s;
    }
    if(!k) break;
    k--;
    c = A[c];
  }
  cout << c+1 << endl;
}

Measured memory_bytes: 5176
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[100007];
int main(){
	scanf("%s",s);int l=strlen(s),f=0;
	if(s[0]==s[l-1])f=1;
	puts((l+f)&1?"First":"Second");
	return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramD
    {
        private class Edge
        {
            public int From {get;set;}
            public int To {get;set;}
            public long Value {get;set;}
        }
        static void Main()
        {
            var n = NextInt;
            var matrix = Enumerable.Range(0, n).Select(_ => new List<Edge>()).ToArray();

            for (int i = 0; i < n - 1; i++)
            {
                int u = NextInt - 1, v = NextInt - 1, w = NextInt;
                matrix[u].Add(new Edge{From = u, To = v, Value = w});
                matrix[v].Add(new Edge{From = v, To = u, Value = w});
            }

            var distance = Enumerable.Repeat(-1L, n).ToArray();
            distance[0] = 0;
            var queue = new Queue<int>();
            queue.Enqueue(0);
            while (queue.Any())
            {
                var tmp = queue.Dequeue();

                foreach (var edge in matrix[tmp].Where(e => distance[e.To] == -1))
                {
                    queue.Enqueue(edge.To);
                    distance[edge.To] = (distance[edge.From] + edge.Value) % 2;
                }
            }

            System.Console.WriteLine(string.Join("\n", distance));
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 41532
while (ln = gets.chomp) != '0 0' do
  n, x = ln.split.map(&:to_i)
  a1 = 1
  a2 = 2
  a3 = 3
  cnt = 0
  while true do
    cnt += 1 if a1 + a2 + a3 == x
    # puts "#{a1} + #{a2} + #{a3} = " + (a1+a2+a3).to_s
    if a3 >= n
      if a2 + 1 == a3
        if a1 + 1 == a2
          break
        else
          a1 += 1
          a2 = a1 + 1
          a3 = a1 + 2
        end
      else
        a2 += 1
        a3 = a2 + 1
      end
    else
      a3 += 1
    end
  end
  puts cnt
end

Measured memory_bytes: 6100
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int mod = 1000000007;

int choose(int n, int a) {
    int x = 1, y = 1;
    rep(i, a) {
        x *= n - i;
        y *= i + 1;
    }
    return x / y;
}

int main(){
    int n, m;
    cin >> n >> m;
    int ans = 0;
    ans += choose(n, 2);
    ans += choose(m, 2);
    cout << ans << endl;
    return 0;
}


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

int main()
{
	std::string s[3];
	while( std::cin >> s[0], s[0][0] - '0' )
	{
		for( int i = 1; i != 3; ++i )
			std::cin >> s[i];

		for( int i = 0; i != 3; ++i )
		{
			int pt[2] = { 0, 0 };
			
			for( int j = 1; j != s[i].size(); ++j )
				++pt[s[i][j]-'A'];

			if( i + 1 < 3 )
				++pt[s[i+1][0]-'A'];
			else
				++( pt[0] > pt[1] ? pt[0] : pt[1] );

			std::cout << pt[0] << ' ' << pt[1] << std::endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1184
N = int(input())

memory = dict()
result = 0

for i in range(10):
    for j in range(10):
        memory[(i,j,)] = 0

for i in range(1, N + 1):
    if i >= 100000:
        memory[(i//100000, i%10,)] += 1
    elif i >= 10000:
        memory[(i//10000, i%10,)] += 1
    elif i >= 1000:
        memory[(i//1000, i%10,)] += 1
    elif i >= 100:
        memory[(i//100, i%10,)] += 1
    elif i >= 10:
        memory[(i//10, i%10,)] += 1
    else:
        memory[(i, i,)] += 1

for i in range(10):
    for j in range(10):
        result += memory[(i,j,)] * memory[(j,i,)]

print(result)

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

int N;

void visit(vector< vector<int> > &Graph, vector< vector<int> > &weight, vector<int> &ans, int parent)
{
	for(int i=0;i<Graph[parent].size();i++){
		int u = Graph[parent][i];
		int w = weight[parent][i];
		if(ans[u] == 0){
			if(w%2 == 0){
				ans[u] = ans[parent];
			}else{
				ans[u] = -1*ans[parent];
			}
			visit(Graph, weight, ans, u);
		}
	}
}

int main()
{
	cin >> N;

	vector< vector<int> > Graph;
	Graph.resize(N);
	vector< vector<int> > weight;
	weight.resize(N);

	vector<int> ans(N, 0);

	for(int i=0;i<N-1;i++){
		int a,b,w;
		cin >> a >> b >> w;
		Graph[a-1].push_back(b-1);
		Graph[b-1].push_back(a-1);
		weight[a-1].push_back(w);
		weight[b-1].push_back(w);
	}

	ans[0] = -1;
	visit(Graph, weight, ans, 0);

	for(int i=0;i<N;i++){
		if(ans[i] == -1){
			cout << '0' << endl;
		}else{
			cout << '1' << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 14080
#include <bits/stdc++.h>
#define int   long long
#define vi   vector<int>
#define pii  pair<int,int>
#define pss  pair<string,string>
#define psi  pair<string,int>
#define vpii  vector<pair<int,int> >
#define vpss  vector<pair<string,string> >
#define vpsi  vector<pair<string,int> >
#define pb   push_back
#define mp   make_pair
#define ff   first
#define ss   second
#define fast  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f(i,a,b)  for(int i=a;i<=b;i++)
#define rf(i,a,b)  for(int i=a;i>=b;i--)
#define out(v,n)   f(i,0,n-1)cout<<v[i]<<" ";cout<<endl;
#define in(v,n)   f(i,0,n-1)cin>>v[i];
using namespace std;
signed main()
{
    fast
    int n; cin>>n;
    map<pair<int,int> ,int> m;
    f(i,1,n)
    {
        int z=i;
        int x=z%10;
        while(z>9){z=z/10;}
        int y=z;
        m[mp(y,x)]++;
    }
    map<pair<int,int> ,int> ::iterator it;
    int s=0;
    for(it=m.begin();it!=m.end();it++)
    {
        s+=it->ss*m[mp(it->ff.ss,it->ff.ff)];
    }
    cout<<s;
}


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

using namespace std;
typedef long long ll;

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

    ll answer = 1;

    ll last = n;

    for (ll i = 1; i < n; i++)
    {
        if (i > last || i * i > n)
        {
            break;
        }

        if (n % i == 0)
        {
            if (i < n - i)
            {
                answer = (i - 1) + (n / i - 1);
                last = n / i;
            }
            else
            {
                break;
            }
        }
    }

    cout << answer << endl;

    // bool flg = false;

    // for (int i = 1; i <= 9; i++)
    // {
    //     if (n % i == 0)
    //     {
    //         if ((n / i) >= 1 && (n / i) <= 9)
    //         {
    //             flg = true;
    //             break;
    //         }
    //     }
    // }

    // if (!flg)
    // {
    //     cout << "No" << endl;
    // }
    // else
    // {
    //     cout << "Yes" << endl;
    // }

    // for (int i = 0; i < n; i++)
    // {
    //     cin >> a[i];
    // }

    // vector<ll> a;
    // for (int i = 0; i < n; i++)
    // {
    //     int j;
    //     cin >> j;
    //     a.push_back(j);
    // }

    //sort(a,a+n); ソート
}


Measured memory_bytes: 256
import java.io.*;


public class Main {

  static int a[] = {
    1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
  };
  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in = br.readLine().split(" ");
    int k = Integer.parseInt(in[0]);

    br.close();

    System.out.println(a[k-1]);
  }
}

Measured memory_bytes: 21204
#include <iostream>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main() {
  int n, x;
  cin >> n >> x;
  int S = 0;
  rep(i, n) {
    int L;
    cin >> L;
    S += L;
    if(S > x) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << n + 1 << endl;
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int n, a, b, str=0;

	cin>> n;

	rep(i, n){
		cin >> a >> b;
		if(a==b) str++;
		else str=0;
		if(str==3){
			cout<< "Yes" <<endl;
			return 0;
		}
	}

	cout<< "No" << endl;
 
	return 0;
}

Measured memory_bytes: 3620
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>

int main()
{
    int n,s[105];
    while(~scanf("%d",&n))
    {
        int d,x,s1[105];
        scanf("%d%d",&d,&x);
        for(int i=0;i<n;i++)
        {
            scanf("%d",&s[i]);
            s1[i]=1;
            for(int j=1;;j++)
            {
                if(s[i]*j+1<=d)
                    s1[i]++;
                else
                    break;
            }
        }
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum=sum+s1[i];
        }
        sum=sum+x;
        printf("%d\n",sum);
    }
    return 0;
}




Measured memory_bytes: 128
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize
    };

    let res = n.pow(3);
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


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

//ABC167D
//ABC167C
//ABC167B
int main(void) {
  int a, b, c, n, k, i, cou=0, tmp;
  scanf(" %d %d %d %d", &a, &b, &c, &k);

  if(a>=k) printf("%d", k);
  else if(a+b>=k) printf("%d", a);
  else printf("%d", a-(k-a-b));
}

Measured memory_bytes: 1732
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

from itertools import permutations

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def f(n):
        if n == 1:
            return 1
        return n*f(n-1)
    n = I()
    p = LIR(n)
    ans = 0
    for k in permutations([i for i in range(n)],n):
        for i in range(n-1):
            ans += ((p[k[i]][0]-p[k[i+1]][0])**2+(p[k[i]][1]-p[k[i+1]][1])**2)**0.5
    print(ans/f(n))
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 41712
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

int main(){
	long n;
	scanf(" %ld", &n);
	int ans=0;
	while(1){
		if(pow(3,ans-1)<n && n<=pow(3,ans)) break;
		++ans;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 1224
#include <stdio.h>

int main(){

  int m,f,r,sum;
  sum=0;
  while(1){
    scanf("%d%d%d",&m,&f,&r);
    if(m==-1 && f==-1 && r==-1)break;
    sum=m+f;
    if(m==-1 || f==-1)printf("F\n");
    else if(sum>=80)printf("A\n");
    else if(sum>=65)printf("B\n");
    else if(sum>=50 || r>=50)printf("C\n");
    else if(sum>=30)printf("D\n");
    else printf("F\n");
  }
  return 0;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

void solve()
{
    string s; cin >> s;
    for(int i = 0; i < s.length(); i += 2) cout << s[i];
    cout << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();

    return 0;
}

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

#define INF 0x3f3f3f3f
#define eps 1e-6

typedef long long LL;
const double pi = acos(-1.0);
const long long mod = 1e9;
using namespace std;

int N,K;
LL T[100005];

int check(LL P)
{
    int i = 0;
    for(int j = 0;j < K;j++)
    {
        LL S = 0;
        while(S + T[i] <= P)
        {
            S += T[i];
            i++;
            if(i == N)
                return N;
        }
    }
    return i;
}

int solve()
{
    LL l = 0,r = 100000 * 10000;
    LL mid;
    while(r - l > 1)
    {
        mid = (l + r) / 2;
        int v = check(mid);
        if(v >= N)
            r = mid;
        else
            l = mid;
    }
    return r;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("int.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    cin >> N >> K;
    for(int i = 0;i < N;i++)
        cin >> T[i];
    LL ans = solve();
    cout << ans << endl;
    return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll h,w;	cin>>h>>w;
	if(h==1||w==1) cout<<"1"<<endl;
	else if(h*w%2)	cout<<(h*w+1)/2<<endl;
	else cout<<h*w/2<<endl;


    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
// #include <iomanip>
// std::cout << std::fixed << std::setprecision(5);

int main()
{
    int n, k;
    std::string s;
    std::cin >> n >> k >> s;
    s[k-1] = s[k-1] + ('a' - 'A');
    std::cout << s << std::endl;
    return 0;
}

Measured memory_bytes: 256
using System;

class GoodInteger {
    static void Main(string[] args)
    {
        var num = Console.ReadLine();

        if(num[1] == num[2])
        {
            if(num[0] == num[1] || num[2] == num[3])
            {
                Console.WriteLine("Yes");
                return;
            }

        }

        Console.WriteLine("No");

        return;
    }

}

Measured memory_bytes: 11092
n=int(input())
t,a=map(int,input().split())
ans=1
anst=100000000000
List = list(map(int,input().split()))
for i in range(n):
    if(anst>abs(a-(t-List[i]*0.006))):
        ans=i+1
        anst=abs(a-(t-List[i]*0.006))
print(ans)

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll H, W;
    cin >> H >> W;

    REP(i, H){
        vector<char> w(W);
        REP(i, W){
            cin >> w[i];
            cout << w[i];
        }
        cout << endl;
        REP(i, W){
            cout << w[i];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
A=list(map(int,input().split()))
candidate=[]

candidate.append(abs(A[1]-A[0])+abs(A[2]-A[1]))
candidate.append(abs(A[2]-A[1])+abs(A[0]-A[2]))
candidate.append(abs(A[0]-A[2])+abs(A[1]-A[0]))

candidate.append(abs(A[0]-A[1])+abs(A[2]-A[0]))
candidate.append(abs(A[1]-A[2])+abs(A[0]-A[1]))
candidate.append(abs(A[2]-A[0])+abs(A[1]-A[2]))
print(min(candidate))


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

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int ans = 0;
    rep(i,a+1) rep(j,b+1) rep(k,c+1) if(500*i+100*j+50*k == x) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ios>//左右揃え
#include<iomanip>//setwで幅指定

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007LL

int main(void) {
    long n, a, b;
    cin >> n >> a >> b;
    long ans = a * (n / (a + b));
    long tmp = n % (a + b);
    if (tmp >= a) cout << ans + a << endl;
    else cout << ans + tmp << endl;
}

Measured memory_bytes: 256
//#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 100000000
using namespace std;
using ll = long long;


int main() {
	int d, g;
	cin >> d >> g;
	vector<int> p(d), c(d);
	int ans = INF;
	rep(i, d) {
		cin >> p[i] >> c[i];
	}
	//問題のセットをすべて解くか解かないかでbit全探索
	rep(i, 1 << d) {
		bitset<10> bit(i);
		int scr = 0, tmp = 0;
		rep(j, d) {
			if (bit[j]) {
				scr += 100 * p[j] * (j + 1) + c[j];
				tmp += p[j];
			}

		}
		if (i != (1 << d) - 1) {
			int j = d - 1;
			while (bit[j] && j > 0)j--;
			int pj = p[j];
			while (scr < g && pj > 1) {
				scr += 100 * (j + 1);
				tmp++;
				pj--;
			}
		}
		if (scr >= g) {
			ans = min(tmp, ans);
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 3628
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

N = 3*10**5

*p, = range(N)
size = [1]*N
def root(x):
    if x == p[x]:
        return x
    p[x] = y = root(p[x])
    return y
def unite(x, y):
    px = root(x); py = root(y)
    if px == py:
        return 0
    sx = size[px]; sy = size[py]
    if sy < sx:
        p[py] = px
        size[px] += sy
    else:
        p[px] = py
        size[py] += sx
    return 1

n,m = na()
ans = 0

for i in range(m):
    a,b = na()
    unite(a,b)

print(max(size))

Measured memory_bytes: 84892
N=int(input())
A=[]
x=[[] for i in range(N)]
y=[[] for i in range(N)]
for i in range(N):
    A.append(int(input()))
    for j in range(A[i]):
        a,b=map(int,input().split())
        x[i].append(a)
        y[i].append(b)
ans=0
for i in range(1,2**N):
    tmp=[0]*N
    t=1
    cnt=0
    for j in range(N):
        if((i>>j)&1):
            tmp[j]=1
    for j in range(N):
        if(tmp[j]==0):
            continue
        for h in range(A[j]):
            if(tmp[x[j][h]-1]!=y[j][h]):
                t=0
                break
        cnt+=1
        if(t==0):
            cnt=0
            break
    ans=max(ans,cnt)
print(ans)

Measured memory_bytes: 3064