akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
   
    
    string s;
    cin>>s;
    
    string a=s.substr(0,4);
    int aa=atoi(&a[0]);
    string b=s.substr(5,2);
    int bb=atoi(&b[0]);
    string c=s.substr(8,2);
    int cc=atoi(&c[0]);
    //cout<<aa<<bb<<cc<<endl;
    if(aa<=2019){
        if(bb<=4&&cc<=30){
            cout<<"Heisei"<<endl;
        }else{
            cout<<"TBD"<<endl;
        }
    }else{
        cout<<"TBD"<<endl;
    }
return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;

public class Main {

	public static void main(String[] args) throws IOException,NumberFormatException{
		try {
		   FastScanner sc=new FastScanner();
		   int n=sc.nextInt();
		   System.out.println(n>=30?"Yes":"No");
		}
		catch(Exception e) {
			return ;
		}

	}
	public static boolean isDigit(long n) {
		int count9=0;
		while(n!=0) {
			long temp=n%10;
			if(temp==0)
				return false;
			if(temp==9)
				count9++;
			n/=10;
		}
		if(count9>=1) {
			return true;
		}
		return false;
	}
	public static long prod(long n) {
		long prod=1;
		while(n!=0) {
			prod=prod*(n%10);
			n/=10;
		}
		return prod;
	}
	
	public static long LCM(long a,long b) {
			return (a*b)/GCD(a,b);
	}
	public static long GCD(long a,long b) {
		if(b==0)
			return a;
		return GCD(b,a%b);
	}
    
	public static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try { 
                                      st=new StringTokenizer(br.readLine());				               
                              } catch (IOException e) {}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		
	}
}


Measured memory_bytes: 32768
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)

int main()
{
	ll n;

	cin >> n;

	vector<pair<ll,ll>> a(n);

	forll(i, 0, n)
	{
		cin >> a[i].first;
		a[i].second = i;
	}
	
	sort(a.begin(), a.end());
	a.push_back({-1,-1});

	ll count = 0,sum=0;
	vector<pair<ll,ll>> numCount(n);

	forll(i, 0, a.size()-1)
	{
		if (a[i].first == a[i + 1].first)
		{
			count++;
			sum += count;
		}
		else
		{
			numCount[a[i].first-1]={ sum,count };
			sum = 0;
			count = 0;
		}
	}

	a.pop_back();

	vector<pair<ll, ll>> b(n);
	sum = 0;

	forll(i, 0, n)
		sum += numCount[i].first;

	forll(i, 0, n)
	{
		b[i].first=a[i].second;
		b[i].second = a[i].first;
	}

	sort(b.begin(), b.end());

	forll(i, 0, b.size())
	{
		ll ans = 0;

		ans = sum-numCount[b[i].second - 1].second;

		cout << ans << endl;
	}
}

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

using namespace std;
const int INF = 1e9+7;
int main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;
    cin>>n;
    cin>>k;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    vector<int> dp(n,INF);
    dp[0]=0;
    
    for(int i=0;i<n;i++){
        for(int j=i+1;j<=i+k;j++){
            if(j<n){
                dp[j] = min(dp[j], dp[i] + abs(h[i]-h[j]));
            }
        }
    }
    cout<<dp[n-1]<<"\n";
    return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

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

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

void solve()
{
    int n,m,x;
    cin>>n>>m>>x;
    vector<vi> v(n,vi(m+1));
    for(int i=0;i<n;i++) {
        cin>>v[i][0];
        for(int j=1;j<=m;j++) {
            cin>>v[i][j];
        }
    }

    int ans=1e9;
    for(int i=0;i<1<<n;i++) {
        vector<int> z;
        for(int j=0;j<n;j++) {
            if(i>>j&1) {
                z.pb(j);
            }
        }
        vector<int> res(m);
        int MM=0;
        for(int it:z) {
            for(int j=0;j<m;j++) {
                res[j]+=v[it][j+1];
            }
            MM+=v[it][0]; 
        }
        int cnt=0;
        for(int j=0;j<m;j++) {
            if(res[j]>=x) {
                cnt++;
            }
        }
        if(cnt==m) {
            ans=min(MM,ans);
        }
    }
    if(ans==1e9) {
        cout<<-1;
    }
    else {
        cout<<ans;
    }
}

int main()
{
    fastio;
    int t;

    t = 1;
    //cin >> t;
    //int test=t;
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

Measured memory_bytes: 3648
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    int i = a+b;
    int j = c+d;
    if (i == j){
      System.out.println("Balanced");
    }else if (i < j){
      System.out.println("Right");
    }else{
      System.out.println("Left");
    }
  }
}


Measured memory_bytes: 35812
while True:
    a, o, b=input().split()
    a=int(a)
    b=int(b)
    if o=='?':
        break
    if o=='+':
        print(a+b)
    if o=='-':
        print(a-b)
    if o=='*':
        print(a*b)
    if o=='/':
        print(a//b)


Measured memory_bytes: 5592
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

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

const int MAX_N = 100050;
int N;

int A[MAX_N];

int val_left[MAX_N], val_right[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N;

    for (int i = 1; i <= N; i++) {
        std::cin >> A[i];
    }

    val_left[1] = A[1];
    val_right[N] = A[N];

    for (int i = 2; i <= N; i++) {
        val_left[i] = gcd(val_left[i-1], A[i]);
    }

    for (int i = N - 1; 1 <= i; i--) {
        val_right[i] = gcd(val_right[i+1], A[i]);
    }

    int ret = std::max(val_right[2], val_left[N-1]);

    for (int i = 2; i <= N - 1; i++) {
        ret = std::max(ret, gcd(val_left[i-1], val_right[i+1]));
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 1536
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    s = SR(n)
    m = []
    x = []
    for si in s:
        l = 0 # )
        r = 0 # (
        for i in si:
            if i == ")":
                if r:
                    r -= 1
                else:
                    l += 1
            elif i == "(":
                r += 1
        if r > l:
            m.append((l, r))
        else:
            x.append((r, l))
    m.sort()
    x.sort(reverse=True)
    tmp = 0
    for l, r in m:
        if tmp - l < 0:
            print("No")
            return
        else:
            tmp -= l
            tmp += r
    for r, l in x:
        if tmp - l < 0:
            print("No")
            return
        else:
            tmp -= l
            tmp += r
    if tmp == 0:
        print("Yes")
    else:
        print("No")
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 196516
n=int(input())
nums=list(map(int,input().split()))

k=0
for i in range(len(nums)-1):
    for j in range(len(nums)-1,i,-1):
        if nums[j]<nums[j-1]:
            nums[j],nums[j-1]=nums[j-1],nums[j]
            k+=1

print(*nums)
print(k)

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

using namespace std;

int main() 
{
    int n, x, y, i;
    scanf("%d", &n);
    
    set<int> s;
    
    for(i = 0; i < n; i++)
    {
        scanf("%d %d", &x, &y);
        
        if(x == 0)
        {
            s.insert(y);
            printf("%d\n", (int)s.size());
        }
        else if(x == 1)
        {
            printf("%d\n", s.find(y) != s.end() ? 1 : 0);
        }
        else if(x == 2)
        {
            auto it = s.find(y);
            if(it != s.end())
                s.erase(s.find(y));
        }
    }
    
    return 0;
}


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

int main(){
	int N, A, i, f = 0;
	scanf("%d", &N);
	for(i = 0; i < N; i++){
		scanf("%d", &A);
		if(A % 2 == 1){
			f = 1;
		}
	}
	if(f == 0){
		printf("second\n");
	}
	else{
		printf("first\n");
	}
	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }




//---------- セグ木 ----------
const int  SEG_MAX = (1 << 20); //1<<17 = 2^17 = 131072
int seg[SEG_MAX * 2] = { 0 };

//[a,b]にxを加算 (節点kをベースに[l,r]に足す)
void add(int a, int b, int x, int k = 0, int l = 0, int r = SEG_MAX - 1)
{
	if (a <= l && r <= b)
	{
		seg[k] = max(seg[k], x);
	}
	else
	{
		int l0 = l;
		int r0 = l + (r - l) / 2;
		int l1 = r0 + 1;
		int r1 = r;
		if (a <= r0)
		{
			int kk = 2 * k + 1;
			add(a, b, x, kk, l0, r0);
		}
		if (l1 <= b)
		{
			int kk = 2 * k + 2;
			add(a, b, x, kk, l1, r1);
		}
	}
}
int get(int index)
{
	int sum = 0;
	int k = SEG_MAX - 1 + index; //根
	while (true)
	{
		sum = max(sum, seg[k]);
		if (k == 0) break;
		k = (k - 1) / 2;
	}
	return sum;
}


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

	REP(n, N)
	{
		int a;
		cin >> a;

		int l = max(0LL, a - K);
		int r = a + K;

		add(l, r, get(a) + 1);
	}

	int ans = 0;
	for (int i = 0; i <= 300000; i++)
	{
		ans = max(get(i), ans);
	}
	cout << ans << endl;
}



Measured memory_bytes: 10672
s = int(input())

def f(num):
    if num % 2 == 0:
        return num // 2
    else:
        return (3 * num) + 1

a = []
a.append(s)

for i in range(1000000):
    tmp = f(a[i])
    if tmp in a:
        ans = i
        break
    else:
        a.append(tmp)

print(ans+2)

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

typedef unsigned long long int LL;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	double r;
	while (cin >> r)
		cout << r * 8.0 * atan(1.0) << endl;
}

Measured memory_bytes: 3784
#include <iostream>
#include <cstdio>
#include <algorithm>
#define MAXN (1000 + 5)
#define LL long long
#define pii pair<LL, LL>
#define mkp make_pair
using namespace std;
int n, k, a[MAXN], cnta, cnts;
LL ans = 0;
pii sora[MAXN * MAXN], ta[MAXN * MAXN]; // ta: first: 0/1: 未/已被删除, second: 值; sora: first: 0/1: 当前位是/不是1, second: 下标
bool cando(int x) {
	sort(ta + 1, ta + cnta + 1);
	cnts = 0;
	for (int i = 1; i <= cnta; i++)
		if (!ta[i].first)
			sora[++cnts] = mkp(((ta[i].second & (1ll << x)) > 0) ? 0 : 1, i);
		else
			break;
	sort(sora + 1, sora + cnts + 1);
	int re = 0;
	for (int i = 1; i <= cnts; i++)
		if (!sora[i].first)
			++re;
		else
			break;
	return (re >= k);
}
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		ta[++cnta] = mkp(0, a[i]);
		for (int j = i - 1; j >= 1; j--)
			++cnta, ta[cnta] = mkp(0, ta[cnta - 1].second + a[j]);
	}
	for (int i = 60; i >= 0; i--)
		if (cando(i)) {
			for (int j = cnts; j >= 1; j--)
				if (sora[j].first)
					ta[sora[j].second].first = 1;
				else
					break;
			ans |= (1ll << i);
		}
	printf("%lld", ans);
	return 0;
}


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

int main(){
  string S1, S2, S3;
  string s1, s2, s3;
  cin >> S1 >> S2 >> S3;
  s1 = S1.at(0);
  s2 = S2.at(0);
  s3 = S3.at(0);
  cout << s1+s2+s3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
int n, d;
vpii v[30];
map<int, int> b, e;
si ss;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> d;
  FOR(i, 0, n){
    int s, t, c;
    cin >> s >> t >> c;
    c--;
    v[c].pb(mp(s, t));
  }
  FOR(i, 0, 30){
    if(sz(v[i]) == 0) continue;
    sort(rng(v[i]));
    int s = v[i].begin()->fi, t = s;
    v[i].pb(mp(iinf, iinf));
    each(itr, v[i]){
      if(t == itr->fi){
        t = itr->se;
      }else{
        ss.insert(s);
        ss.insert(t);
        if(b.find(s) == b.end()) b[s] = 0;
        b[s]++;
        if(e.find(t) == e.end()) e[t] = 0;
        e[t]++;
        s = itr->fi;
        t = itr->se;
      }
    }
  }
  ll ans = 0, c = 0;
  each(itr, ss){
    if(b.find(*itr) != b.end()) c += b[*itr];
    maxs(ans, c);
    if(e.find(*itr) != e.end()) c -= e[*itr];
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    map<int, int> funami;
    rep(i, n) {
        Int(tmp);
        funami[tmp]++;
    }

    int ans = 0;
    for (auto i = funami.begin(); i != funami.end(); i++) {
        if (i->fir < i->sec) {
            ans += i->sec - i->fir;
        } else if (i->fir > i->sec) {
            ans += i->sec;
        }
    }
    cout << ans << endl;


    return 0;
}




Measured memory_bytes: 6272
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  [a,b] <- readInts
  print $ (a+b+1) `div` 2

Measured memory_bytes: 380
def solve(n, s):
    ans = 0
    for v in range(1000):
        p = 0
        for x in str(v).zfill(3):
            p = s.find(x, p)
            if p < 0:
                break
            p += 1
        ans += int(p > 0)
    return ans

assert solve(4, "0224") == 3
assert solve(6, "123123") == 17
assert solve(19, "3141592653589793238") == 329

n = int(input())
s = input()
print(solve(n, s))

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

using namespace std;

int main(){
	vector<string> words;
	int n;
	bool ok = true;
	cin >> n;
	for(int i = 0; i < n; i++){
		string str;
		cin >> str;
		if(find(words.begin(), words.end(), str) != words.end()){
			ok = false; continue;
		}
		words.push_back(str);
	}

	for(int i = 0; i < words.size() - 1; i++){
		int l = words[i].length();
		if(words[i][l - 1] != words[i + 1][0]) ok = false;
	}

	cout << (ok ? "Yes" : "No") << '\n';
}

Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
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; }
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
ll n, h;
vector<ll> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >>h >>n;
    ll sum=0;
    for (int i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        a.push_back(temp);
        sum+=temp;
    }
    if(h>sum){
        return no,0;
    }
    yes;
}



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

int compare(const void *p,const void *q){
  return *(int*)q-*(int*)p;
}

int main(){
  int i,n,k;
  scanf("%d %d",&n,&k);
  int x,a[n+1];
  for(i=0;i<=n;i++) a[i]=0;
  for(i=0;i<n;i++){
    scanf(" %d",&x);
    a[x]++;
  }
  qsort(a,n+1,sizeof(int),compare);
  int z=0;
  for(i=0;i<=n;i++){
    if(i==k) break;
    z+=a[i];
  }
  printf("%d",n-z);
  return 0;
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(a) cout<<#a<<":"<<a<<endl;
const int INF=0x3f3f3f3f;
const int N=1e6+7;
const int mod=1e9+7;
int maxn,minn;
int T,n;
int dp[N][5];

int main(){
	int a,b,c;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a>>b>>c;
		dp[i][1]=max(dp[i-1][2]+a,dp[i-1][3]+a);
		dp[i][2]=max(dp[i-1][1]+b,dp[i-1][3]+b);
		dp[i][3]=max(dp[i-1][1]+c,dp[i-1][2]+c);
	}
	maxn=0;
	for(int i=1;i<=3;i++){
		maxn=max(maxn,dp[n][i]);
	}
	cout<<maxn<<endl;
	
	

	return 0;
}





Measured memory_bytes: 2176
// Problem : A - αlphabet
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define fi first
#define se second
#define pb push_back
 
#define ll long long
#define pii pair<int, int>
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    char c; cin >> c;
    if('a' <= c) cout << 'a';
    else cout << 'A';
}



Measured memory_bytes: 3636
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <tuple>
#include <vector>

template <class... Ts> using tuple_t = std::tuple<Ts...>;
template <class T, class U> using map_t = std::map<T, U>;
template <class T, class U> using pair_t = std::pair<T, U>;
template <class T> using vector_t = std::vector<T>;
template <class T> using set_t = std::set<T>;

int min(const vector_t<int> &nums) {
  int min_ = std::numeric_limits<int>::max();
  for (auto &i : nums)
    if (min_ > i)
      min_ = i;
  return min_;
}

int max(const vector_t<int> &nums) {
  int max_ = std::numeric_limits<int>::min();
  for (auto &i : nums)
    if (max_ < i)
      max_ = i;
  return max_;
}
int start[500][500];
int ranges[500][500];
int main() {
  int N,M,Q,L,R,p,q;
  std::cin>>N>>M>>Q;
  for(int i=0;i<M;++i)
  {
    std::cin>>L>>R;
    start[L-1][R-1]++;
  }
  for(int i=0;i<N;++i){
    for(int j=0;j+i<N;++j){
      if(i==0)
        ranges[j][j+i]=start[j][j+i];
      else
        ranges[j][j+i]=start[j][j+i] + ranges[j][j+i-1]+ranges[j+1][j+i]-ranges[j+1][j+i-1];
    }
  }
  for(int i=0;i<Q;++i)
  {
    std::cin>>p>>q;
    std::cout<<ranges[p-1][q-1]<<std::endl;
  }

  return 0;
}


Measured memory_bytes: 2816
import itertools

n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = sorted(l1)
l = list("")
for i in itertools.permutations(l3):
    l.append(list(i))
print(abs(l.index(l1) - l.index(l2)))

Measured memory_bytes: 10228
# https://tjkendev.github.io/procon-library/python/graph/scc.html
# 強連結成分分解(SCC): グラフGに対するSCCを行う
# 入力: <N>: 頂点サイズ, <G>: 順方向の有向グラフ, <RG>: 逆方向の有向グラフ
# 出力: (<ラベル数>, <各頂点のラベル番号>)
def scc(N, G, RG):
    order = []
    used = [0]*N
    group = [None]*N
    def dfs(s):
        used[s] = 1
        for t in G[s]:
            if not used[t]:
                dfs(t)
        order.append(s)
    def rdfs(s, col):
        group[s] = col
        used[s] = 1
        for t in RG[s]:
            if not used[t]:
                rdfs(t, col)
    for i in range(N):
        if not used[i]:
            dfs(i)
    used = [0]*N
    label = 0
    for s in reversed(order):
        if not used[s]:
            rdfs(s, label)
            label += 1
    return label, group

N, M = map(int, input().split())
E1 = [[] for _ in range(N+1)]
E2 = [[] for _ in range(N+1)]
for _ in range(M):
    a, b = map(int, input().split())
    E1[a].append(b)
    E2[b].append(a)
label, group = scc(N+1, E1, E2)
for g in group[1:]:
    ans = []
    for n, gg in enumerate(group[1:], 1):
        if g == gg:
            ans.append(n)
    print(" ".join(map(str, ans)))



Measured memory_bytes: 8564
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <numeric>

int main()
{
	std::vector<std::vector<int>> input;
	std::vector<int> height_width(2);

	std::cin >> height_width[0] >> height_width[1];
	
	while (height_width[0] != 0 || height_width[1] != 0)
	{
		input.push_back(height_width);
		std::cin >> height_width[0] >> height_width[1];
	}

	size_t size = input.size();
	for (size_t i = 0; i < size; i++)
	{
		for (int j = 0; j < input[i][0]; j++)
		{
			for (int k = 0; k < input[i][1]; k++)
			{
				std::cout << "#";
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
	}
	return 0;
}


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

typedef pair<int, int> P;
 
int main(){
  int a, b;
  cin >> a >> b;
  if(a>b){
    int tmp = b;
    b=a;
    a=tmp;
  }
  int ans = abs(a-b);
  if(ans%2!=0){
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }else{
    ans = a+ans/2;
    cout << ans << endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>

using namespace std;
int main(){

long long n,x;
cin >>n>>x;
long long a[n];
for(int i=0;i<n;i++){
  cin >>a[i];
}
long long sum=0;
for(int i=0 ;i<n-1;i++){
  if(a[i]+a[i+1]>x && x-a[i]>=0){
    sum+=(a[i+1]+a[i])-x;
    a[i+1]-=(a[i+1]+a[i])-x;
  }
  else if(a[i]+a[i+1]>x && x-a[i]<0){
    sum+=(a[i+1]+a[i])-x;
    a[i+1]=0;
  }
  else continue;
}
cout <<sum<<endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main () {
    int A, B;
    scanf("%d %d", &A, &B);

    int sum = A + B;
    int sub = A - B;
    int mul = A * B;

    printf("%d\n", sum > sub && sum > mul ? sum : sub > mul ? sub : mul);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
 
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector 
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007
#define precise cout.precision(18)
// #define f first
// #define s second



int main(){
 
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	//  #endif
    FAST

ll n,m;
cin>>n>>m;
ve <ll> c(n,0);
ve <ll> p(n,0);
FOR(i,0,m){
	ll x;
	string v;
	cin>>x>>v;
	x--;
	if(v=="AC")
	c[x]=1;
	else{
		if(c[x]==0)
			p[x]+=1;
	}
}
ll ans1=0,ans2=0;
FOR(i,0,n){
	ans1+=c[i];
	if(c[i]==1)
	ans2+=p[i];
}
cout<<ans1<<" "<<ans2;



return 0;
}
 

Measured memory_bytes: 1792
import math
n,d = input().split()
n = int(n)
d = int(d)
count = 0
while(n>0):
    a,b = input().split()
    a = int(a)
    b = int(b)
    if math.sqrt(a*a+b*b)<=d:
        count+=1
    n-=1
print(count)

Measured memory_bytes: 9152
#include <stdio.h>
int main (void)
{
double r;
double a, b;
scanf("%lf",&r) ;
a=r*r*3.14159265358979323846 ;
b=2*r*3.14159265358979323846 ;
printf("%lf %lf \n",a,b) ;
return 0;
}

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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

ll x,y;

int main(){
  cin >>x>>y;
  if(abs(x-y)<=1){
    cout <<"Brown"<<endl;
  }else{
    cout << "Alice" <<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
#include <cassert>
#include <memory>
using namespace std;
typedef long long ll;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

int main ()
{
    string s;
    cin >> s;

    if (s == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }

    return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1<<(n))
#define popcount(n) (__builtin_popcountll(n))

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

using namespace std;

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

bool check(int n,int ban){
	string s=to_string(n);
	for(auto &c:s){
		if(ban&bit(c-'0')) return false;
	}
	return true;
}

int main(void){
	int n,k,ban=0;
	cin >> n >> k;
	
	rep(i,k){
		int d;
		cin >> d;
		ban|=bit(d);
	}

	int ans=n;
	while(1){
		if(check(ans,ban)) break;
		ans++;
	}

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

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

int main(){
    string s;
    cin>>s;
    int k;
    cin>>k;
    int a[s.size()];
    int sum=0;
    for(int i=0;i<s.size();i++){
        a[i]=s[i]-'a';
        if(a[i]){
            if(26-a[i]<=k){
                k-=(26-a[i]);
                a[i]=0;
            }
        }
    }
    k%=26;
    if(k){
        a[s.size()-1]=(a[s.size()-1]+k)%26;
    }
    for(int i=0;i<s.size();i++)cout<<char(a[i]+'a');
    cout<<endl;
    return 0;
}

Measured memory_bytes: 4096
x,a,b,i;
main(c)
{for(;scanf("%d%d",&a,&b),a;){x&&puts("");c=0;for(x=i=a;i<=b;i++)if(i%400==0||(i%100&&i%4==0))c=printf("%d\n",i);c||puts("NA");}exit(0);}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 N;
  cin >> N;
  i64 ans = 0;
  for (i64 i = 1; i <= N; ++i) {
    for (i64 j = i; j <= N; j += i) {
      ans += j;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3648
#include<cstdio>
main(){int a,b,c,d=0;while(scanf("%d%d",&a,&b),c=a){d++&&puts("");for(;a<=b;a++)c*=printf(a%4<1&&a%25|a%16<1?"%d\n":0,a)<0;c&&puts("NA");}}

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

int main()
{
    int n;
    cin >> n;
    int limit[n];
    int x[n][n];
    int y[n][n];

    for (int i=0;i<=n-1;i++)
    {
        cin >> limit[i];
        for (int j=0;j<=limit[i]-1;j++)
        {
            cin >> x[i][j] >> y[i][j];
        }
    }

    int ans=0;
    for (int q=0;q<=pow(2,n)-1;q++)
    {
        bitset<15> alpha(q);
        bool ok=true;
        for (int i=0;i<=n-1;i++)
        {
            // we are considering the bit id person
            if (alpha[i]==1)
            {
                // person is honest
                for (int j=0;j<=limit[i]-1;j++)
                {
                    if ((y[i][j]==1)&&(alpha[x[i][j]-1]==0))
                    {
                        ok=false;
                        goto drain;
                    }
                    else if ((y[i][j]==0)&&(alpha[x[i][j]-1]==1))
                    {
                        ok=false;
                        goto drain;
                    }
                }
            }
        }

        goto drain;
        drain:
        if (ok==true)
        {
            ans=max((int)ans,(int)alpha.count());
        }
    }

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

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

using namespace std;
int main()
{
	int n, i;
    cin >> n;
    int a, b, c;

    while (true)
    {
        i = n;
        a = i % 10;
        i /= 10;
        b = i % 10;
        i /= 10;
        c = i % 10;
        if (a == b && b == c && a == c)
        {
            cout << n << endl;
            break;
        }
        n++;
    }
	return 0;
}

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

int main(){
    ll k,n,i,l,m; vector<ll>a;
    cin>>k>>n;
    for(i=0;i<n;i++) {cin>>l; a.pb(l);}
    l=a[n-1]-a[0];
    for(i=1;i<n;i++)
    {
        m=a[i-1]+(k-a[i]);
        l=min(l,m);
    }
    cout<<l;
    return 0;
}


Measured memory_bytes: 5336
#include <bits/stdc++.h>
#define INF 2147483647
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define MAX 100005
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

int cnt[MAX];
vector<string> vs;

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;

    cin>>n;
    map<string, int> MP;
    string str;
    int idx = 1;
    for(int i = 0; i < n; i++){
        cin>>str;
        sort(str.begin(), str.end());
        if(MP[str] == 0){
            MP[str] = idx++;
            vs.pb(str);
        }
        cnt[MP[str]]++;
    }
    ll res = 0;
    for(int i = 0; i < vs.size(); i++){
        ll x = cnt[MP[vs[i]]];
        res += (x * (x - 1)) / 2LL;
    }

    cout<<res<<endl;

    return 0;
}



Measured memory_bytes: 17012
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007;
#define INF (1<<28)
#define int long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)
signed main(){
  int n;
  cin>>n;
  vector<int> v;
  v.push_back(-1);
  lp(i,n){
    int hoge;
    cin>>hoge;
    v.push_back(hoge);
  }
  if(n%2==1){
    for(int i=n;i>0;i-=2){
      if(i!=n) cout<<" ";
      cout<<v[i];
    }
    for (int i=2;i<n;i+=2){
      cout<<" "<<v[i];
    }
    cout<<endl;
  }
  else{
    for(int i=n;i>0;i-=2){
      if(i!=n) cout<<" ";
      cout<<v[i];
    }
    for (int i=1;i<n;i+=2){
      cout<<" "<<v[i];
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
int main(){
   int n;
   cin >> n;
   vector<string>s(n);
   for(int i=0;i<n;i++){
      cin >> s[i];
      sort(s[i].begin(),s[i].end());
   }
   sort(s.begin(),s.end());
   long long ans=0;
   long long cnt =1;
   for(int i=0;i<n-1;i++){
      
      if(s[i] == s[i+1] ){
         cnt ++;
      }
      else {
         ans += cnt*(cnt-1)/2;
         cnt =1;
      }
   }
   ans += cnt*(cnt-1)/2;
   cout << ans << endl;
}

Measured memory_bytes: 7296
let n, m = Scanf.scanf "%d %d\n" (fun n m -> n, m)

let h = Array.init n (fun _ -> Scanf.scanf " %d" (fun i -> i))

let h' = Array.make n 0

let rec f i =
  if i < m then (
    let a, b = Scanf.scanf "\n%d %d" (fun a b -> a - 1, b - 1) in
    if h'.(a) < h.(b) then h'.(a) <- h.(b);
    if h'.(b) < h.(a) then h'.(b) <- h.(a);
    f (i + 1)
  )

let rec g i ans =
  if i = n then ans
  else
    if h'.(i) < h.(i) then g (i + 1) (ans + 1)
    else g (i + 1) ans

let () =
  f 0;
  Printf.printf "%d\n" (g 0 0)


Measured memory_bytes: 7508
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int N;
vector<long long int> a;

long long int ans;

int main()
{
	cin >> N;
	a = vector<long long int>(N);
	for (int i = 0; i < N; i++){
		cin >> a[i];
	}
	
	ans = 0;
	while (true){
		sort(a.begin(), a.end(), greater<long long int>());
		
		if (a[0] < N) break;
		
		long long int cnt = a[0] / N;
		long long int dist = a[0] - a[1];
		
		if (dist < cnt){
			cnt = dist + 1;
		}
		
		a[0] -= cnt * N;
		for(int i = 1; i < N; i++){
			a[i] += cnt;
		}
		
		if (cnt < 0) {
			cout << "Error" << endl;
			break;
		}
		
		ans += cnt;
	}
	
	printf("%lld\n", ans);
	
	return 0;
}


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

int binarySearch(int, int);

int *array;

int main(){
  int i, j, key, n1, n2, sum = 0;

  scanf("%d",&n1);
  array = malloc((n1 + 1)* sizeof(int));
  for(i = 0; i < n1; i++){
    scanf("%d",&array[i]);    
  }
  scanf("%d",&n2);
  for(i = 0; i < n2; i++){
    scanf("%d",&key);
    if(binarySearch(key, n1)){
      sum++;
    } 
  }
  printf("%d\n",sum);
  
  return 0;
}

int binarySearch(int key, int n1){
  int left = 0;
  int right = n1;
  int mid;

  while(left < right){
    mid = (left + right) / 2;
    if(key == array[mid]){
      return 1;
    }
    if(key > array[mid]){
      left = mid + 1;
    }
    else if(key < array[mid]){
      right = mid;
    }
  }
  return 0;
}



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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n,t;
	cin>>n>>t;
	vector<P> meal(n);
	rep(i,n)cin>>meal[i].first>>meal[i].second;

	sort(all(meal));

	vector<vector<int>> dp(n+1,vector<int>(t,0));


	rep(i,n){
		repr(j,t-1,0){
			dp[i+1][j] = dp[i][j];
			if(j+meal[i].first>=t) continue;
			else dp[i+1][j+meal[i].first] = max(dp[i+1][j+meal[i].first],dp[i][j]+meal[i].second);
		}
	}

	// rep(i,n+1){
	// 	rep(j,t){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// 	cout<<endl;
	// }

	int ans=0;
	int last=0;
	repr(i,n,1){
		ans = max(ans, dp[i][t-1] + last);
		last = max(last,meal[i-1].second);
	}

	cout<<ans<<endl;

	return 0;
}

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

ll val[4],N,memo;
int key;

void getMin(int limit) {
    memo = val[0];
    key = 0;
    for (int i = 1; i < limit; i++) {
        if (memo * pow(2, 3 - key) > val[i] * pow(2, 3 - i)) {
            memo = val[i];
            key = i;
        }
    }
}

int main(void) {
    ll vol,num;
    ll ans = 0;;
    for (int i = 0; i < 4; i++) cin >> val[i];
    cin >> N;
    N *= 4;
    key = 4;
    while (N != 0) {
        getMin(key);
        vol = pow(2, key);
        num = N / vol;
        N -= vol * num;
        ans += memo * num;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const double EPS = 1e-10;

int main() {
	ll A, B;
	int K;
	cin >> A >> B >> K;
	for (int i = 0; i < K; i++) {
		if (i % 2 == 0) {
			if (A % 2) A--;
			B += A / 2;
			A /= 2;
		}
		else {
			if (B % 2) B--;
			A += B / 2;
			B /= 2;
		}
	}
	cout << A << " " << B << endl;
}

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

static const int MAX = 100000;

int n, num;
vector<int> V[MAX];
int prenum[MAX], lowest[MAX], parent[MAX];
bool B[MAX];

void dfs(int cur, int pre) { //dfs??¨?????????prenum, lowest, parent????¨????
	prenum[cur] = lowest[cur] = num++;
	B[cur] = true;

	int next;
	for (int i = 0; i < V[cur].size(); i++) {
		next = V[cur][i];
		if (!B[next]) {
			parent[next] = cur;
			dfs(next, cur);
			lowest[cur] = min(lowest[cur], lowest[next]); //?????????????°?????????????????°????????????°??????
		} else if (next != pre) {
			lowest[cur] = min(lowest[cur], prenum[next]); //back-edge
		}
	}
}

void artPoint() {
	set<int> ap;
	int np = 0;
	for (int i = 1; i < n; i++) {
		int p = parent[i];
		if (p == 0) np++; //root?????\?¶???????????????°
		else if (prenum[p] <= lowest[i]) {
			ap.insert(p);
		}
	}
	if (np > 1) ap.insert(0);
	for (set<int>::iterator it = ap.begin(); it != ap.end(); it++) {
		cout << *it << endl;
	}
}

int main() {
	int e;
	cin >> n >> e;
	int s, t;
	for (int i = 0; i < e; i++)	{
		cin >> s >> t;
		V[s].push_back(t);
		V[t].push_back(s);
	}

	for (int i = 0; i < n; i++)	{
		B[i] =  false;
	}

	num = 1;
	dfs(0, -1); //next?????¶???prev???????????????

	artPoint();

	return 0;
}

Measured memory_bytes: 5124
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int s = 0, t = 0, e = 0, d = 0;
		int[] a = new int[3];
		while (true) {
			for (int i = 0; i < 3; i++) {
				a[i] = scanner.nextInt();
			}
			Arrays.sort(a);
			if (a[0] + a[1] > a[2]) {
				s++;
				if (a[0] * a[0] + a[1] * a[1] > a[2] * a[2]) {
					e++;
				}
				else if (a[0] * a[0] + a[1] * a[1] < a[2] * a[2]) {
					d++;
				}
				else {
					t++;
				}
			}
			else {
				break;
			}
		}
		System.out.println(s + " " + t + " " + e + " " + d);
	}

}



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

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

    int L, R;
    L = A + B;
    R = C + D;

    if (L > R)
    {
        cout << "Left" << endl;
    }
    else if (L == R)
    {
        cout << "Balanced" << endl;
    }
    else
    {
        cout << "Right" << endl;
    }
}

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

namespace atcoderbc138
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            double[] A = Console.ReadLine().Split().Select(double.Parse).ToArray();
            double rs = A.Aggregate(0.0, (x,y) => x + 1.0 / y);
            Console.WriteLine(1 / rs);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
#define ii pair<int,int>
#define mp make_pair
#define All(v) v.begin(),v.end()
using namespace std;
int main()
{
   int n;
   cin>>n;
   int a[n] , b[n];
   ll sum1 = 0 , sum2 = 0;
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
       sum1+=a[i];
   }
   for(int  i=0;i<n;i++)
   {
       cin>>b[i];
       sum2+=b[i];
   }
   if(sum1 > sum2)
   {
       cout<<"No";
   }
   else
   {
       ll cnt1 = 0 , cnt2 = 0;
       for(int i=0;i<n;i++)
       {
           if(a[i] < b[i])
           {
               int dis = (b[i]-a[i]);
               cnt1+=(dis/2);
              
           }
           else if(a[i] > b[i])
           {
               cnt2+=(a[i]-b[i]);
           }
       }
       if(cnt1 < cnt2)
        cout<<"No";
       else
        cout<<"Yes";
   }
}


Measured memory_bytes: 384
n = int(input())
flag = 0
a = 0
for i in range(1, 1000):
    if n == a:
        flag = 1
        ans = i-1
        break
    else:
        a += i

if flag == 0:
    print("No")
else:
    print("Yes")
    print(ans+1)
    ans = [[] for j in range(ans+1)]

    l = 1
    c = len(ans)-1
    s = -1
    for i in range(len(ans)):
        for j in range(len(ans)-c-1):
            ans[i].append(ans[j][s])
        for j in range(c):
            ans[i].append(l)
            l += 1
        c -= 1
        s += 1

    for i in range(len(ans)):
        print(len(ans[i]), " ".join(map(str, ans[i])))


Measured memory_bytes: 8948
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
using namespace std;

#define MAX 102

int n;

vector<long long int> v;
vector<long long int> vv;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		v.push_back(a);
	}
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		vv.push_back(a);
	}
	for (int i = 1; i < v.size(); i++) {
		v[i] += v[i - 1];
	}
	long long int ans = 0;
	long long int rr = 0;
	for (int i = vv.size() - 1; i >= 0; i--) {
		rr += vv[i];
		ans = max(ans, rr + v[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

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

	vector<int> e[51];

	for (auto i = 0; i < M; ++i)
	{
		int a, b;
		cin >> a >> b;

		e[a].push_back(b);
		e[b].push_back(a);
	}

	auto count = 0;
	for (auto i = 1; i <= N; ++i)
	{
		for (int to : e[i])
		{
			if (i > to)
			{
				continue;
			}

			auto isLoop = false;

			bool used[51];
			memset(used, 0, sizeof(used));
			used[i] = true;
			stack<int> toList;
			toList.push(to);
			while (!toList.empty())
			{
				auto n = toList.top();
				toList.pop();
				if (used[n])
				{
					continue;
				}
				used[n] = true;

				for (int next : e[n])
				{
					if (next == i && n != to)
					{
						isLoop = true;
						break;
					}

					if (used[next])
					{
						continue;
					}

					toList.push(next);
				}

				if (isLoop)
				{
					break;
				}
			}

			if (!isLoop)
			{
				++count;
			}
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256