akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(2)
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <list>
#include <climits>
#include <bitset>
#include <fstream>
#include <algorithm>
#include <functional>
#include <stack>
#include <string>
#include <cmath>
#define fi first
#define se second
#define re register
#define ls i << 1
#define rs i << 1 | 1
#define pb push_back
#define pii pair<int,int>
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007

#define int long long

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);

inline int rd(){
  int x = 0, f = 1; char ch = getchar();
  while (ch < '0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
  while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
  return x * f;
}

void out(int a) {
  if (a < 0) putchar('-'), a = -a;
  if (a >= 10) out(a / 10);
  putchar(a % 10 + '0');
}
const int maxn = 2e5+10;
int a[maxn];
signed main(){
//int main() {
  int n = rd();
  for (int i = 1; i <= n; i++) a[i] = rd();
  int ans = 0;
  for (int i = 2; i <= n; i++) {
    if (a[i] - a[i-1] < 0) {
      ans += a[i-1]-a[i];
      a[i] = a[i-1];
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 5136
X = int(input())

if 400 <= X <600:print("8")
elif 600<=X<800:print('7')
elif 800<=X<1000:print('6')
elif 1000<=X<1200:print('5')
elif 1200<=X<1400:print('4')
elif 1400<=X<1600:print('3')
elif 1600<=X<1800:print('2')
elif 1800<=X<2000:print('1')


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

#define rep(i,a,b)     for(int i=a;i<(b);i++)
#define lop(n)         for(int i=0;i<n;i++)
#define revlop(n)      for(int i=n-1;i>=0;i--)
#define trav(a,x)      for(auto &a :x)
#define all(x)         begin(x),end(x)
#define mod            1000000007
#define inf            1e18
#define ps(x,y)        fixed<<setprecision(y)<<x
#define w(x)           int x; cin>>x;

#define pb             push_back
#define mp             make_pair
#define lb             lower_bound
#define ub             upper_bound
#define bs             binary_search
#define F              first
#define S              second

typedef long long                ll;
typedef vector<int>              vi;
typedef pair<int, int>           pii;
typedef vector<pair<int, int>>   vpii;
typedef vector<pair<ll, ll>>     vpll;
int a[200001];
void solve()
{
  int n;
  cin >> n;

  rep(i, 0, n)
  cin >> a[i];

  int lar = a[0];
  ll sum = 0;
  rep(i, 1, n) {
    if (a[i] >= lar)
      lar = a[i];
    else
      sum += lar - a[i];
  }

  cout << sum;
}

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

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int test = 1;
  //cin >> test;

  while (test--)
  {
    solve();
    cout << "\n";
  }

  return 0;
}

Measured memory_bytes: 4324
s=input()
N=s.count("N")
W=s.count("W")
S=s.count("S")
E=s.count("E")
if N==0 and S==0:
    if E==0 and W==0:
        print("Yes")
    elif E>0 and W>0:
        print("Yes")
    else:
        print("No")
elif N>0 and S>0:
    if E==0 and W==0:
        print("Yes")
    elif E>0 and W>0:
        print("Yes")
    else:
        print("No")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

#include <bits/stdc++.h>

using namespace std;

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

	int n;
	cin >> n;
	string s;
	cin >> s;

	int ans = 0;
	rep2(i, 1, n - 1) {
		if (s[i - 1] == 'A' && s[i] == 'B' && s[i +	1] == 'C')
			ans++;
	}
	cout << ans << endl;
}

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

int main()
{
    
    string s;
    ll i,c,ans,q,n;
    c=0,ans=0;
    cin>>n>>q;
    cin>>s;
    ll a[n+1]={0};
    for(i=0;i<n-1;i++)
    {
    	if(s[i]=='A' && s[i+1]=='C')
    	{
    		a[i+1]=1;
    	}
    }
    for(i=1;i<=n;i++)
    {
    	a[i]+=a[i-1];
    }
    for(i=0;i<q;i++)
    {
    	ll l,r;
    	cin>>l>>r;
    	cout<<a[r-1]-a[l-1]<<endl;
    }
}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n);
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); ++i)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)          (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)          (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define mp                  make_pair

typedef long long ll;
typedef unsigned long long ull;

#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)

#ifdef _DEBUG
#define pf printf
#define pr(n) do { cout << #n " = " << (n) << endl; } while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#endif

void solve(int n){
    int t[100][100];
    int x = n/2-1, y = n/2;
    memset(t, 0, sizeof(t));
    REP(i,n*n){
        x++; y++;
        x = (x + n) % n; y = (y + n) % n;
        while(t[y][x] != 0){
            x--; y++;
            x = (x + n) % n; y = (y + n) % n;
        }
        t[y][x] = i + 1;
    }
    REP(y,n){
        REP(x,n) printf("%4d", t[y][x]);
        cout << endl;
    }
}

int main(){
    int n;
    while(cin >> n, n) solve(n);
    return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#define cnt(s,c) count(begin(s), end(s), c)

int main() {
  int n;
  string s;
  cin >> n >> s;
  auto r = cnt(s, 'R');
  auto g = cnt(s, 'G');
  auto b = cnt(s, 'B');
  auto ans = r * g * b;
  for (int j = 1; j < n; j++) {
    for (int i = 0; i < j; i++) {
      int k = 2 * j - i;
      if (k >= n) continue;
      if (s[i] == s[j]) continue;
      if (s[j] == s[k]) continue;
      if (s[k] == s[i]) continue;
      ans --;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main(){

  int y, m, d;
  string g;

  while(1){

    cin >> g ;
    if(g == "#")
      break;

    cin >> y >> m >> d;

    if(g!="HEISEI" || y<1 || y>100 || m<1 || m>12 || d<1 || d>31)
      break;

    if((y>31) || (y==31 && m>4)){
      y=y-30;
      g="?";
    }
    
    cout << g << " " << y << " " << m << " " << d <<endl;
  }
}



Measured memory_bytes: 3188
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

int main(void) {
	int n,m;
	cin >> n >> m;
	int student[51][2];
	int point[51][2];
	for(int i=0; i<n; i++){
		cin >> student[i][0] >> student[i][1];
	}
	for(int i=0; i<m; i++){
		cin >> point[i][0] >> point[i][1];
	}

	int dis,ans;
	for(int i=0; i<n; i++){
		dis=1000000000,ans=-1;
		for(int j=0; j<m; j++){
			if(dis>abs(point[j][0]-student[i][0])+abs(point[j][1]-student[i][1])){
				dis=abs(point[j][0]-student[i][0])+abs(point[j][1]-student[i][1]);
				ans=j;
			}
		}
		cout << ans+1 << endl;
	}
	return 0;
}

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>;

int main(){
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double h_theta = 2.0 * M_PI / 12.0 * (h+m/60.0);
    double m_theta = 2.0 * M_PI * m / 60.0;
    double h_x = a*cos(h_theta);
    double h_y = a*sin(h_theta);
    double m_x = b*cos(m_theta);
    double m_y = b*sin(m_theta);
    double dis = sqrt(pow((h_x-m_x),2)+pow((h_y-m_y),2));
    printf("%.10f\n", dis);
    return 0;
}

Measured memory_bytes: 4056
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next()), w = Integer.parseInt(sc.next());
        boolean[][] s = new boolean[h][w];
        for (int i = 0; i < h; i++) {
            String str = sc.next();
            for (int j = 0; j < w; j++) {
                if ('.' == str.charAt(j)) {
                    s[i][j] = true;
                }
            }
        }

        int[][] l = new int[h][w];
        int[][] r = new int[h][w];
        int[][] u = new int[h][w];
        int[][] d = new int[h][w];

        for (int j = 0; j < w; j++) {
            for (int i = 0; i < h; i++) {
                if (s[i][j]) {
                    if (j == 0) {
                        l[i][j] = 1;
                    } else {
                        l[i][j] = l[i][j - 1] + 1;
                    }
                }
                if (s[i][w - 1 - j]) {
                    if (j == 0) {
                        r[i][w - 1 - j] = 1;
                    } else {
                        r[i][w - 1 - j] = r[i][w - j] + 1;
                    }
                }
            }
        }

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (s[i][j]) {
                    if (i == 0) {
                        d[i][j] = 1;
                    } else {
                        d[i][j] = d[i - 1][j] + 1;
                    }
                }
                if (s[h - 1 - i][j]) {
                    if (i == 0) {
                        u[h - 1 - i][j] = 1;
                    } else {
                        u[h - 1 - i][j] = u[h - i][j] + 1;
                    }
                }
            }
        }

        int result = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                result = Math.max(result, l[i][j] + r[i][j] + d[i][j] + u[i][j] - 3);
            }
        }

        System.out.println(result);

    }
}


Measured memory_bytes: 109228
s = list(map(int, input().split()))
a = s[0]
b = s[1]
c = s[2]
k = s[3]

a_b = a+b
a_b_c = a+b+c

if k < a:
  print(k)
elif k < a_b:
  print(a)
elif k < a_b_c:
  print(a - c + (a_b_c-k))
else:
  print(a-c)

Measured memory_bytes: 9216
import math

n = int(input())
zero = 0
total_dictionary = {0: 1}
total = 0

for i in input().split():
  total += int(i)
  zero += total_dictionary.get(total,0)
  if total in total_dictionary:
    total_dictionary[total] += 1
  else:
    total_dictionary[total] = 1

print(zero)


Measured memory_bytes: 45440
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi

MOD = 10 ** 9 + 7
INF = 10 ** 18

N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for _ in range(N)]

C = [ca[0] for ca in CA]
A = [ca[1:] for ca in CA]

ans = INF
for i in range(2 ** N):
    cnt = [0] * M
    tmp = 0
    for j in range(N):
        if i >> j & 1:
            for k in range(M):
                cnt[k] += A[j][k]
            tmp += C[j]
    flag = 1
    for k in range(M):
        if cnt[k] < X:
            flag = 0
            break
    if flag:
        ans = min(ans, tmp)
        
print(ans if ans != INF else -1)

Measured memory_bytes: 74408
#include <iostream>
#include <stdlib.h>
#include <vector> //vector
#include <algorithm> //sort()

#include <cstdlib>
#include <typeinfo>
#include <string>
#include <sstream>      // std::ostringstream
// std::vector<std::string> StringSplit(const std::string &str, char sep)
// {
//     std::vector<std::string> v;
//     std::stringstream ss(str);
//     std::string buffer;
//     while( std::getline(ss, buffer, sep) ) {
//         v.push_back(buffer);
//     }
//     return v;
// }

using namespace std;

template<class T> inline bool chmin(T& a, T b);
template<class T> inline bool chmax(T& a, T b);

int64_t a, b, c, d, i, j, k, n;
int64_t ans;

int main(){
//////////////////////////////////////////////////////

    //cin >> n;

    // cout << "n:" << n << endl;

    string s;

    cin >> s;

    string first = s.substr(0,2);
    string last = s.substr(2,2);

    int fi = atoi(first.c_str());
    int li = atoi(last.c_str());


    bool fmonthflag = 0;
    bool lmonthflag = 0;
    bool fyearflag = 0;
    bool lyearflag = 0;

    //cout <<fi << ","<< li <<endl;
    if (fi >= 1 && fi <= 12)
    {
        fmonthflag = true;
        //cout <<"fmonth"<<endl;
    }
    if (li >= 1 && li <= 12)
    {
        lmonthflag = true;
        //cout <<"lmonth"<<endl;
    }

    if (fmonthflag && lmonthflag)
    {
        cout << "AMBIGUOUS" << endl;
    }
    else if (fmonthflag && !lmonthflag)
    {
        cout << "MMYY" << endl;
    }
    else if (!fmonthflag && lmonthflag)
    {
        cout << "YYMM" << endl;
    }
    else
    {
        cout << "NA" << endl;
    }


    // sort(input.begin() , input.end());

    // uint64_t max = numeric_limits<uint64_t>::max();


    //////////////////////////////////////////////////////
    // DP

    // // 無限大の値
    // const uint64_t INF = (uint64_t)1 << 60;
    // //const int64_t NINF = -1 * ((int64_t)1 << 60 );

    // // DP テーブル
    // uint64_t dp[100010];

    // //DPテーブル初期化（最小化用）
    // for (int i = 0; i < 100010; ++i)
    // {
    //     //dp[i] = INF;
    //     dp[i] = 0;
    // } 

    // // 初期条件
    // dp[0] = 0;

    // // ループ
    // for (int i = 1; i <= n; ++i) {
    //     //chmin( dp[i], dp[i - 1] + abs( input[i] - input[i - 1] ));
    //     //if (i < 2)continue;
    //     //chmin( dp[i], dp[i - 2] + abs( input[i] - input[i - 2] ));



    //     // chmax ( dp [i] , dp[i - 1]);
    //     // chmax ( dp [i] , dp[i - 1] + input[i]);
    //     // cout << "dp[" << i <<"] = " << dp[i] << endl;

    // }



//////////////////////////////////////////////////////

    //cout << fi << endl;

    //cout << dp[n] << endl;

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


//最小化用関数
template<class T> inline bool chmin(T& a, T b)
{
    if (a > b) 
    {
        a = b;
        return true;
    }
    return false;
}

//最大化関数
template<class T> inline bool chmax(T& a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

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

using namespace std;

int main(){
    int64_t n, k;
    cin >> n >> k;
    vector<int> A(n);
    copy_n(istream_iterator<int>(cin), n, A.begin());

    vector<int> visited(n, -1);
    int cur = 0;
    int cnt = 0;
    while (true){
        cur = A[cur] - 1;
        cnt++;
        if (visited[cur] != -1)
            break;
        if (cnt == k)
            break;
        visited[cur] = cnt;
    }

    if (cnt == k){
        cout << cur + 1 << endl;
        return 0;
    }

    k -= visited[cur];
    k %= (cnt - visited[cur]);

    for (int i = 0; i < k; i++){
        cur = A[cur] - 1;
    }

    cout << cur + 1 << endl;
}

Measured memory_bytes: 4844
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

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

int main(){
	ll N;
	set<char> S;
	cin >> N;
	rep(i, 0, N){
		char s;
		cin >> s;
		S.insert(s);
	}
	if (S.size() == 4){
		cout << "Four" << endl;
	}
	else{
		cout << "Three" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
l = input()

if l == "abc":
    print("Yes")
elif l == "acb":
    print("Yes")
elif l == "bac":
    print("Yes")
elif l == "bca":
    print("Yes")
elif l == "cab":
    print("Yes")
elif l == "cba":
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
/************************************/
/* NoobM							*/
/* File Name : chaa.cpp				*/
/* Date : 13.07.2020 02:37:00 +06	*/
/************************************/

#include <bits/stdc++.h>

#define rr(i, b)    for (int i = 0; i < int(b); i++)
#define vi(n, a) vector <int> a(n); rr(i, n) cin >> a[i]
#define pvec(a) rr(i, a.size()) cout << a[i] << " "; cout << endl
#define bug(x) cout << #x << " " << x << endl
#define ll long long
#define vii vector <int>

using namespace std;

void solve() {
	int n;
	cin >> n;
	
	int x = ceil(n/1.08);
	int k = x * 1.08;
	
	if(k == n)cout << x << endl;
	else cout << ":(" << endl;
}
 
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
	
	int t = 1;
	//cin >> t;
	
	while (t--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 3628
#include<cstdio>
#include<unordered_map>
using namespace std;

int main() {
	unordered_map<long long, int> m;
	int n;
	scanf("%d", &n);
	long long sum = 0;
	m[sum] = 1;
	for(int i=0;i<n;i++) {
		int a;
		scanf("%d", &a);
		sum += a;
		if(m.find(sum) == m.end()) m[sum] = 1;
		else m[sum] += 1;
	}
	long long count = 0;
	for(auto iter=m.begin();iter != m.end();iter++) {
		count += iter->second * (long long)(iter->second - 1) / 2;
	}
	printf("%lld\n", count);
	return 0;
}



Measured memory_bytes: 8520
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pr pair<int,int>
vector<pr> vec[200001],_left,_right;
int mid;
vector<pr> dfs(int id,int from){
    //cout<<id<<" "<<from<<endl;
    vector<pr> lc,rc,now;
    int cl=-1,cr;
    if(vec[id].size()==1&&from){
        now.push_back(make_pair(0,0));
        return now;
    }
    for(int i=0;i<vec[id].size();i++){
        pr l=vec[id][i];
        if(l.first==from) continue;
        vector<pr> t=dfs(l.first,id);//返回的(a,b)的a递增，因而b递减
        if(cl<0) lc=t,cl=l.second;
        else rc=t,cr=l.second;
    }
    int j=0;
    for(int i=0;i<lc.size();i++){//选取起点在左子树，满足条件的、最优的(a,b)，新的(a,b)=(lc[i].first,rc[i].second)
        while(j+1<rc.size() && lc[i].second+rc[j+1].first+cl+cr<=mid) j++;//寻找rc中满足条件的b最小的(a,b)。因为a相同时只取最小的b
        if(rc.size()&&lc[i].second+rc[j].first+cl+cr<=mid) _left.push_back(make_pair(lc[i].first+cl,rc[j].second+cr));//前面的(a,b)肯定会比当前的要差，因此不用查找rc[1~j-1]
    }
    j=0;
    for(int i=0;i<rc.size();i++){//选取起点在右子树，满足条件的、最优的(a,b)，新的(a,b)=(rc[i].first,lc[i].second)
        while(j+1<lc.size() && rc[i].second+lc[j+1].first+cl+cr<=mid) j++;
        if(lc.size()&&rc[i].second+lc[j].first+cl+cr<=mid) _right.push_back(make_pair(rc[i].first+cr,lc[j].second+cl));
    }
    //此时的_left和_right一定是有序的，现在要合成一个a递增，递减的数组
    int l=0,r=0,last=0x7FFFFFFFFFFFFFFF;
    while(l<_left.size()||r<_right.size()){//类似归并排序的思想
        if(l<_left.size()&&(r>=_right.size()||_left[l]<=_right[r])){
            if(_left[l].second<last){//为了保证now里都是最优，b要递减
                last=_left[l].second;
                now.push_back(_left[l]);
            }
            l++;
        }
        else{
            if(_right[r].second<last){
                last=_right[r].second;
                now.push_back(_right[r]);
            }
            r++;
        }
    }
    _left.clear(),_right.clear();
    return now;
}
signed main(){
    int n;
    cin>>n;
    for(int i=2;i<=n;i++){
        int a,v;
        scanf("%lld%lld",&a,&v);
        vec[a].push_back(make_pair(i,v));
        vec[i].push_back(make_pair(a,v));
    }
    int l=0,r=17179869184;
    while(r-l>1){
        mid=(l+r)/2;
        //cout<<l<<" "<<mid<<" "<<r<<endl;
        if(!dfs(1,0).empty()) r=mid;
        else l=mid;
    }
    mid=l;
    if(!dfs(1,0).empty()) cout<<l;
    else cout<<r;
}

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

using namespace std; 
#define fr for(int i = 0;i < n;i++)
#define pb push_back
void printVector(vector<char>x){
    for(auto i:x){
        cout << i << " ";
    }
    cout << endl;
}


int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    string str;
    
    int k,n;
    cin >> k;
    cin >> str;
    n = str.length();
    if(n > k){
    for (int i = 0; i < k; i++)
    {
        cout << str[i];
    }
    cout << "..." << endl;
    }
    else
    {
        cout << str << endl;
    }
    
    //if(n > k) cout << "..." << endl;
    


}

Measured memory_bytes: 3652
#include <iostream>
                    #include<cmath>
                    #include<string>
                    using namespace std;
                    int main()
                    {
                       long long int n,k,x,y;
                      cin>>n>>k>>x>>y;
                      if(n>k)
                      {  long long int h=n-k;
                      long long int u=(k*x)+(h*y);
                      cout<<u;
                      }
                      else
                        cout<<x*n;
                        
                    }

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  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
  };
  cin >> k;
  cout << a[k - 1] << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}



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

#pragma warning(disable : 4996)

using namespace std;

int n; string S, T;

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

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

		int s = 0, t = 0;

		int pos = 0;

		while (pos < S.size())
		{
			int mult = 1;

			if (isdigit(S[pos]))
			{
				mult = S[pos] - 48; pos++;
			}

			switch (S[pos])
			{
			case 'm': s += mult * 1000; break;
			case 'c': s += mult * 100; break;
			case 'x': s += mult * 10; break;
			case 'i': s += mult * 1; break;
			}

			pos++;
		}

		pos = 0;

		while (pos < T.size())
		{
			int mult = 1;

			if (isdigit(T[pos]))
			{
				mult = T[pos] - 48; pos++;
			}

			switch (T[pos])
			{
			case 'm': t += mult * 1000; break;
			case 'c': t += mult * 100; break;
			case 'x': t += mult * 10; break;
			case 'i': t += mult * 1; break;
			}

			pos++;
		}

		t += s;

		int r = 1000;

		while (r > 0)
		{
			if (t / r)
			{
				if ((t / r) != 1)
				{
					printf("%d", t / r);
				}

				switch (r)
				{
				case 1000: printf("m"); break;
				case 100: printf("c"); break;
				case 10: printf("x"); break;
				case 1: printf("i"); break;
				}
			}

			t = t % r; r /= 10;
		}

		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long

int main(){
	string S, T;
	cin >> S >> T;
	vector<vector<int>> Al(26);
	// -97
	int ss = S.size(), ts = T.size();
	ll a, let = -1, sen = 0;
	for (int i = 0;i < ss;i++) {
		Al[(int)S[i] - 97].push_back(i);
	}
	for (int i = 0;i < ts;i++) {
		a = T[i] - 97;
		auto it = upper_bound(all(Al[a]), let);
		if (it == Al[a].end()) {
			let = -1;
			sen++;
			it = upper_bound(all(Al[a]), let);
			if (it == Al[a].end()) {
				cout << -1 << endl;
				return 0;
			}
			else
				let = *it;
		}
		else {
			let = *it;
		}
	}
	//cout << sen << " " << let << endl;
	cout << sen * ss + let + 1 << endl;
}

Measured memory_bytes: 1216
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

class BIT():
    # A1 ... AnのBIT(1-indexed)
    def __init__(self, n):
        self.n = n
        self.BIT = [0] * (n + 2)

    # A1 ~ Aiまでの和 O(logN)
    def query(self, idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx & (-idx)
        return res_sum

    # Ai += x O(logN)
    def update(self, idx, x):
        # print(idx)
        while idx <= self.n:
            # print(idx)
            self.BIT[idx] += x
            idx += idx & (-idx)
        return

    def show(self):
        print(self.BIT)


def solve():
    n,m,q = getList()
    bt = BIT(n+1)
    sya = [defaultdict(int) for i in range(n+1)]
    for i in range(m):
        a,b = getList()
        sya[a][b] += 1
        bt.update(b, 1)

    si = []
    for i in range(q):
        l, r = getList()
        si.append((l, r, i))

    si.sort()
    ans = [0 for i in range(q)]

    cur = 1
    for ss in si:
        l, r, id = ss
        while(l > cur):
            for kk, vv in sya[cur].items():
                bt.update(kk, -vv)
                n -= vv
            cur += 1
        ans[id] = bt.query(r)

    print(*ans, sep="\n")





def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 106088
function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n};

(() => {
    const [ a, b, c, d ] = readMany(4)
    let ans = 0

    for (let i = 0; i <= 100; i += 1) {
        if (
            (a <= i && i <= b) &&
            (c <= i && i <= d)
        ) {
            ans += 1
        }
    }

    console.log(ans ? ans - 1 : 0)
})()


Measured memory_bytes: 7372
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	if (A + B >= C) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
}


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

int main(void){
    int n, m, a, sum=0, c=0;
    cin >> n >> m;
    vector<int> count(1001);
    for(int i=0; i<n; i++){
        cin >> a;
        count[a]++;
        sum += a;
    }
    for(int i=1001; i>=((sum%(4*m)==0)?sum/(4*m):sum/(4*m)+1); i--){
        if(count[i] == 1) c++;
        if(c == m){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}

Measured memory_bytes: 3604
a,b = map(int, input().split())
sum = 0

if a - b == 0:
    sum = a+b
elif a+1 > b:
    sum = a+(a-1)
elif a - b == 1 or b - a == 1:
    sum = a+b
else:
    sum = b+(b-1)

print(sum)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define fs first
#define sc second
#define MAXN 100005
#define LIMIT 1500
#define LOGN 1048575
#define ll long long
#define pb push_back
#define ld long double
#define eps 1e-6
#define endl '\n'
#define lc 2*pos
#define rc 2*pos+1
using namespace std;
ll n,m;
ll arr[MAXN],pref[MAXN];
pair<ll,ll>oper[MAXN];
int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
	cin>>n>>m;
	ll sum=0;
	rep(i,n){
		cin>>arr[i];
		sum+=arr[i];
	}
	sort(arr,arr+n);
	rep(i,m)cin>>oper[i].sc>>oper[i].fs;
	sort(oper,oper+m,greater<pair<ll,ll>>());
	int j=0;
	bool b=0;
	rep(i,m){
		rep(k,oper[i].sc){
			if(oper[i].fs<=arr[j]||j==n){
				b=1;
				break;
			}
			sum+=oper[i].fs-arr[j];
			j++;
		}
		if(b)break;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <math.h>

int main() {
  double r, a, b;
  scanf("%lf", &r);
  a = (double)M_PI * r * r;
  b = (double)M_PI * r * 2;
  printf("%f %f\n", a, b);
  return 0;
}


Measured memory_bytes: 2124
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int Q = sc.nextInt();
    int[] T = new int[Q];
    int[] F = new int[Q];
    char[] C = new char[Q];
    for (int i = 0; i < Q; i++) {
      T[i] = sc.nextInt();
      if (T[i] == 2) {
        F[i] = sc.nextInt();
        C[i] = sc.next().charAt(0);
      }
    }
    sc.close();

    char[] pre = new char[Q];
    char[] suf = new char[Q];
    int preB = Q - 1;
    int sufE = 0;

    boolean rev = false;
    for (int i = 0; i < Q; i++) {
      if (T[i] == 1) {
        rev = rev ? false : true;
      } else if (T[i] == 2) {

        if (F[i] == 1) {
          if (rev) {
            suf[sufE++] = C[i];
          } else {
            pre[preB--] = C[i];
          }
        } else if (F[i] == 2) {
          if (rev) {
            pre[preB--] = C[i];
          } else {
            suf[sufE++] = C[i];
          }
        }
      }
    }

    StringBuilder ans = new StringBuilder()
        .append(pre, preB + 1, pre.length - preB - 1)
        .append(S)
        .append(suf, 0, sufE)
        ;
    if (rev)
      ans.reverse();
    System.out.println(ans);
  }
}

Measured memory_bytes: 143676
#include<stdio.h>
int main(void){
    float xa,ya,xb,yb,xc,yc,xd,yd;
    double a1,a2;
    double s,l,t,u;
    while(scanf("%f",&xa) != EOF){
        scanf("%f%f%f%f%f%f%f",&ya,&xb,&yb,&xc,&yc,&xd,&yd);
        s = xb - xa;
        l = yb - ya;
        t = xd - xc;
        u = yd - yc;
         
        /*a1 = (double)((yb -ya) / (xb - xa));
        a2 = (double)((yd -yc) / (xd - xc));*/
        if(l * u == -1 * s * t){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
    return 0;
}

Measured memory_bytes: 608
#include <stdio.h>

int main(){
    int a, b;

    int plus, minus, multiple;

    scanf("%d %d", &a, &b);

    plus = a + b;
    minus = a - b;
    multiple = a * b;

    int biggest = plus;
    if(minus > biggest)biggest = minus;
    if(multiple > biggest)biggest = multiple;

    printf("%d", biggest);

    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector <int>;
using vvi = vector <vi>;

signed main() {
	int n;
	cin >> n;
	set <int> st;
	rep (i, n) {
		int a;
		cin >> a;
		st.insert(a);
	}
	cout << st.size() << endl;
}

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

const ll INF = 1e18L;
int main() {
  int a,b,q;
  cin >> a >> b >> q;
  vector<ll> s(a),t(b);
  rep(i,a) cin >> s[i];
  rep(i,b) cin >> t[i];
  rep(qi,q){
    ll x;
    cin >> x;
    auto d = [&](ll p){ return abs(x-p); };
    int i = lower_bound(s.begin(),s.end(),x) - s.begin();
    int j = lower_bound(t.begin(),t.end(),x) - t.begin();
    ll ans = INF;
    ll ns = i<a?s[i]:INF;
    ll ps = i>0?s[i-1]:-INF;
    ll nt = j<b?t[j]:INF;
    ll pt = j>0?t[j-1]:-INF;
    ans = min(ans,d(max(ns,nt)));
    ans = min(ans,d(min(ps,pt)));
    ans = min(ans,min(d(ps),d(nt))*2 + max(d(ps),d(nt)));
    ans = min(ans,min(d(ns),d(pt))*2 + max(d(ns),d(pt)));
    cout << ans << endl;
  }
}

Measured memory_bytes: 2944
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int h,w,n,ans[105][105]={},a[10005]={},now=1;
  cin >> h >> w >> n;
  for(int i=1; i<=n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      if(i%2==0) {
        ans[i][j]=now;
        a[now]--;
        if(!a[now]) {
          now++;
        }
      }
      else {
        ans[i][w-j-1]=now;
        a[now]--;
        if(!a[now]) {
          now++;
        }
      }
    }
  }
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <tuple>
#include <list>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cstring>
#include <cstdlib>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

#define xx first
#define yy second
#define $1 first
#define $2 second

void solveCase() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	map < ll, ll > mp;
	ll n; cin >> n;
	vector<int> v; v.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i]; mp[v[i]]++;
	}
	ll comb = 0;
	for (auto it = mp.begin(); it != mp.end(); it++) {
		comb+=((*it).second*((*it).second - 1)) / 2;
	}
	for (int i = 0; i < n; i++) {
		cout << comb - (mp[v[i]] - 1) << "\n";
	}
}

int main() {

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	solveCase();
}

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

int main() {
    int64_t A,B,N;
    cin >> A >> B >> N;
    
    int64_t x=0;
    if(N < B-1) x = N;
    else x = B - 1; 
    printf("%ld\n", (-A*(x%B)%B + A*(x%B)) / B);
    return 0;
}

Measured memory_bytes: 3724
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define INF 1000000007
#define MOD 1000000007
#define MAX_N 105
#define MAX_W 100005

ll dp[MAX_N][MAX_W];//0:海,1:山,2:宿題,dp[i][j] = iをj日目に行う時の幸福度
ll weight[MAX_N];
ll value[MAX_N];

int main(){

    ll n;
    cin >> n;
    ll ans = INF;
    for(ll i = 1;i*i <= n;i++){
        ll left,right;
        left = i;
        if(n%i == 0){
            left = i;
            right = n/i;
            string s = to_string(left);
            string t = to_string(right);
            //cout << i << " " << s << " " << t << " " << s.size() << " " << t.size() << endl;
            ans = min(ans,(ll)max(s.size(),t.size()));
        }
    }
    cout << ans << endl;


    return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
const ll INF = 1e15;

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

  ll n = 1;
  while (true) {
    if (n * (n + 1) / 2 >= x) {
      cout << n << endl;
      return 0;
    }
    ++n;
  }

  return 0;
}

Measured memory_bytes: 256
import itertools
n=int(input())
a="".join(list(input().split()))
b="".join(list(input().split()))
l=itertools.permutations(map(str,range(1,n+1)))
ans=0
for i,j in enumerate(l):
  if a=="".join(list(j)):
    ans+=i
  if b=="".join(list(j)):
    ans-=i
print(abs(ans))

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    int n,m;
    cin >> n;
    int T[n];
    rep(i,n) cin >> T[i];
    cin >> m;
    int P[m],X[m];
    rep(i,m) cin >> P[i] >> X[i];
    rep(i,m){
        ll out = 0;
        rep(j,n){
            if(j==P[i]-1) out += X[i];
            else out += T[j];
        }
        cout << out << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;

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

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

int main(void){
    // Your code here!
    ll n;
    cin >> n;
    ll t[101];
    for(int i=0; i<n; i++){
        cin >> t[i];
    }
    ll ans = t[0];
    ll temp = lcm(t[1], t[0]);
    if(n == 1){
        cout << ans << '\n';
        return 0;
    }
    else if(n==2){
        cout << temp <<  '\n';
        return 0;
    }
    
    for(int i=2; i<n; i++){
        ans = lcm(t[i], temp);
        temp = ans;
    }
    
    cout << ans <<'\n';
    
}


Measured memory_bytes: 256
import math
from itertools import accumulate

# エラトステネスの篩
def eratosthenes(n): 
    prime_list = []
    num_list=[i for i in range(2, n+1)] # 2以上n以下の整数を並べる
    limit = math.sqrt(n)
    while True:
        if limit <= num_list[0]:
            return prime_list + num_list
        prime_list.append(num_list[0])
        num_list = [e for e in num_list if e % num_list[0] != 0] # 倍数をふるい落とす

max_lr = 100000
er_list = eratosthenes(max_lr)

count = [0] * max_lr
for i in range(len(er_list)):
    if (er_list[i]+1)//2 in er_list:
        count[er_list[i]] = 1

# 累積和            
count = list(accumulate(count)) 

Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(count[r]-count[l-1])

Measured memory_bytes: 14496
#include<bits/stdc++.h>
using namespace std;
void fl()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
int main()
{
//  fl();
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a+b+c>=22)
		printf("bust\n");
	else
		printf("win\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;

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

  vector<pair<int, int>> vec(N);
  REP(i, N) cin >> vec[i].first >> vec[i].second;
  sort(ALL(vec));

  vector<vector<int>> dp(6010, vector<int>(6010, -1));
  dp[0][0] = 0;


  REP(i, N) REP(j, T+1){
    if(dp[i][j] < 0) continue;
    chmax(dp[i+1][j], dp[i][j]);
    if(j < T) chmax(dp[i+1][j+vec[i].first], dp[i][j]+vec[i].second);
  }

  int ans = 0;
  REP(i, N+1) REP(j, 6010) chmax(ans, dp[i][j]);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 282752
#include <cstdio>
#include <set>
#include <utility>
#include <numeric>
#include <vector>
#include <map>
#include <deque>
using namespace std;
int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    vector<vector<pair<int, int>>> adj(n);
    map<pair<int, int>, int> mp;
    for(int i = 0; i < m; i++) {
        int p, q, c;
        scanf("%d %d %d", &p, &q, &c);
        p--, q--;
        if(!mp.count(make_pair(p, c))) {
            mp[make_pair(p, c)] = adj.size();
            adj[p].push_back(make_pair(adj.size(), 1));
            adj.emplace_back(1, make_pair(p, 1));
        }
        if(!mp.count(make_pair(q, c))) {
            mp[make_pair(q, c)] = adj.size();
            adj[q].push_back(make_pair(adj.size(), 1));
            adj.emplace_back(1, make_pair(q, 1));
        }
        int pp = mp[make_pair(p, c)];
        int qq = mp[make_pair(q, c)];
        adj[pp].emplace_back(qq, 0);
        adj[qq].emplace_back(pp, 0);
    }
#if 0
    for(int i = 0; i < (int) adj.size(); i++) {
        printf("adj[%d]={", i);
        for(auto p : adj[i])
            printf("(%d, %d)", p.first, p.second);
        printf("}\n");
    }
#endif
    // dijkstra 0 -> n - 1
    vector<int> dis(adj.size(), 9999999);
    vector<bool> vis(adj.size());
    deque<int> dq;
    dis[0] = 0;
    dq.push_back(0);
    while(!dq.empty()) {
        int v = dq.front();
        dq.pop_front();
        if(vis[v])
            continue;
        vis[v] = true;
        for(auto e : adj[v]) {
            if(dis[e.first] > dis[v] + e.second) {
                dis[e.first] = dis[v] + e.second;
                if(e.second)
                    dq.push_back(e.first);
                else
                    dq.push_front(e.first);
            }
        }
        if(v == n - 1) {
            printf("%d\n", dis[n - 1] / 2);
            return 0;
        }
    }
    puts("-1");
}



Measured memory_bytes: 57448
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int dp[1<<15][15] = {0};
int V, E;
vector<int> v[15];
int w[15][15];
const int INF = 1000000000;

int main() {
  cin >> V >> E;
  rep(i, E) {
    int s, t, d;
    cin >> s >> t >> d;
    v[s].push_back(t);
    w[s][t] = d;
  }

  for(int bit = 0; bit < (1<<V); bit++) {
    for(int i = 0; i < V; i++) {
      dp[bit][i] = INF;
    }
  }
  dp[0][0] = 0;

  for(int bit = 0; bit < (1<<V); bit++) {
    for(int i = 0; i < V; i++) {
      if((bit & (1<<i)) || (bit == 0 && i == 0)) {
        for(int j = 0; j < v[i].size(); j++) {
          int nx = v[i][j];
          if(!(bit & (1<<nx))) {
            int nbit = bit + (1<<nx);
            dp[nbit][nx] = min(dp[bit][i] + w[i][nx], dp[nbit][nx]);
          }
        }
      }
    }
  }

  // cout << dp[2][1] << endl;
  if(dp[(1<<V)-1][0] == INF) cout << -1 << endl;
  else cout << dp[(1<<V)-1][0] << endl;
  return 0;
}


Measured memory_bytes: 5000
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed _main(){
  int N; cin >> N;
  vv<int> A(N+1);
  for(int i=2;i<=N;i++){
    int a; cin >> a;
    A[a].push_back(i);
  }
  for(int i=1;i<=N;i++){
    cout << A[i].size() << endl;
  }
  return 0;
}


Measured memory_bytes: 14188
import java.util.*;
public class Main {

    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       String code = sc.nextLine();
       String match = "CODEFESTIVAL2016"; 
       int result = 0;
       for(int i=0; i< code.length(); i++){
           if(code.charAt(i) != match.charAt(i)){
               result++;
           }
       }
       System.out.println(result);
    }
}


Measured memory_bytes: 9676
#include "bits/stdc++.h"
using namespace std;
struct ${$(){ios_base::sync_with_stdio(0);cin.tie(0);}}$;

const int N = 200005;

int main() {
   string s;
   cin >> s;
   int ans = 0;
   for(int i = 0; i < 6; i++) {
      ans += s[i] == '1';
   }
   return cout << ans << endl, 0; 
   return 0;
}


Measured memory_bytes: 256
n,y=gets.chomp.split(" ").map(&:to_i)
found = false
catch(:break_loop) do
  (0..n).each do|ichiman|
    (0..n-ichiman).each do |gosen|
      sen = n - ichiman - gosen
      total = ichiman * 10000 + gosen * 5000 + sen * 1000
      if total == y
        puts "#{ichiman} #{gosen} #{sen}"
        found = true
        throw :break_loop
      end
    end
  end
end
puts '-1 -1 -1' unless found


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
const ll MOD=1000000007;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    rep (i,N){
        cin >> a[i];
    }
    int ans=0;
    rep (i,N-1){
        if (a[i]==a[i+1]){
            ans++;
            i++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256