akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
const ld eps = 1e-8, pi = acos(-1.0);

bool eq(ld a, ld b) {
	return abs(a - b) < eps;
}

using Point = complex<ld>;
class Line {
public:
	Point a, b;
	Line() : a(0, 0), b(0, 0) {}
	Line(Point _a, Point _b) : a(_a), b(_b) {}
};
ld dot(Point a, Point b) {
	return real(conj(a) * b);
}

ld cross(Point a, Point b) {
	return imag(conj(a) * b);
}

int ccw(Point a, Point b, Point c) {
	b -= a, c -= a;
	if (cross(b, c) > eps) return 1;
	if (cross(b, c) < -eps) return -1;
	if (dot(b, c) < 0) return 2;
	if (norm(b) < norm(c)) return -2;
	return 0;
}

bool isis_ll(Line l, Line m) {
	return abs(cross(l.b - l.a, m.b - m.a)) > eps;
}

bool isis_ls(Line l, Line s) {
	return (cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps);
}

bool isis_lp(Line l, Point p) {
	return abs(cross(l.b - p, l.a - p)) < eps;
}

bool isis_sp(Line s, Point p) {
	return abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps;
}

Point proj(Line l, Point p) {
	ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
	return l.a + t * (l.a - l.b);
}

Point is_ll(Line s, Line t) {
	Point sv = s.b - s.a, tv = t.b - t.a;
	assert(cross(sv, tv) != 0);
	return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}

bool isis_ss(Line s, Line t) {
	if (isis_ll(s, t)) return isis_ls(s, t) && isis_ls(t, s);
	return isis_sp(s, t.a) || isis_sp(s, t.b) || isis_sp(t, s.a);
}

ld dist_lp(Line l, Point p) {
	return abs(p - proj(l, p));
}

ld dist_ll(Line l, Line m) {
	return isis_ll(l, m) ? 0 : dist_lp(l, m.a);
}

ld dist_ls(Line l, Line s) {
	return isis_ls(l, s) ? 0 : min(dist_lp(l, s.a), dist_lp(l, s.b));
}

ld dist_sp(Line s, Point p) {
	Point r = proj(s, p);
	return isis_sp(s, r) ? abs(r - p) : min(abs(s.a - p), abs(s.b - p));
}

ld dist_ss(Line s, Line t) {
	if (isis_ss(s, t)) return 0;
	return min({ dist_sp(s, t.a), dist_sp(s, t.b), dist_sp(t, s.a), dist_sp(t, s.b) });
}
int main()
{
	int N, M, L;
	cout << fixed << setprecision(15);
	cin.sync_with_stdio(false);
	while (cin >> N >> M >> L, N || M || L) {
		vector<vector<ld>> dis(N, vector<ld>(N, 10000000000));
		for (int i = 0; i < N; i++) {
			dis[i][i] = 0;
		}
		vector<vector<Point>> seg(N, vector<Point>(5));
		vector<vector<Line>> segd(N, vector<Line>(5));
		vector<ld> x(N), y(N), a(N), r(N);
		for (int i = 0; i < N; i++) {
			cin >> x[i] >> y[i] >> a[i] >> r[i];
			for (int j = 0; j < 5; j++) {
				seg[i][j] = Point(x[i], y[i]) + Point(cosl((90 + a[i] + 72 * j) / 180.0 * pi), sinl((90 + a[i] + 72 * j) / 180.0 * pi)) * r[i];
			}
			for (int j = 0; j < 5; j++) {
				segd[i][j] = Line(seg[i][j], seg[i][(j + 2) % 5]);
			}
		}
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				for (int ii = 0; ii < 5; ii++) {
					for (int jj = 0; jj < 5; jj++) {
						dis[j][i] = dis[i][j] = min(dis[j][i], min(dis[i][j], dist_ss(segd[i][ii], segd[j][jj])));
					}
				}
			}
		}
		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
				}
			}
		}
		cout << dis[M - 1][L - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
int H, W; string s;
int main() {
	cin >> H >> W;
	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) {
			cin >> s;
			if(s == "snuke") cout << (char)(j + 65) << i + 1 << endl;
		}
	}
}

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

using namespace std;

const int N = 2e5 + 5;
int n, cnt[N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n;
    for(int i = 1; i <= n - 1; i++){
        int x;
        cin >> x;
        cnt[x]++;
    }
    for(int i = 1; i <= n; i++){
        cout << cnt[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 4436
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#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 FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }



int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
        map<int,int> odd,even;
        FOR(i,0,n) {
            int a; cin >> a;
            if (i & 1)
                odd[a]++;
            else
                even[a]++;
        }
        vector<PII> A,B;
        FOR_ALL(x,odd)
            A.push_back(PII(x->second,x->first));
        FOR_ALL(x,even)
            B.push_back(PII(x->second,x->first));
        sort(ALL(A)); reverse(ALL(A));
        sort(ALL(B)); reverse(ALL(B));
        int ans = n;
        /* we only need to exam to top 2*2 */
        FOR(i,0,min(2,int(A.size()))) FOR(j,0,min(2,int(B.size()))) {
            const int c1 = A[i].first;
            const int v1 = A[i].second;
            const int c2 = B[j].first;
            const int v2 = B[j].second;
            int res = n - c1 - c2;
            if (v1 == v2)
                res += min(c1,c2);
            ans = min(ans,res);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 6140
#include<stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int cnt=0;
  for(int i=1;i<=n;i++){
    int a;
    scanf("%d",&a);
    if(i != a){
      cnt++;
    }
  }
  if(cnt <= 2){
    printf("YES");
  }else{
    printf("NO");
  }

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
inline char nchar() {
	static const int bufl=1<<20;
	static char buf[bufl],*a=NULL,*b=NULL;
	return a==b && (b=(a=buf)+fread(buf,1,bufl,stdin),a==b)?EOF:*a++;
}
inline int read() {
	int x=0,f=1;
	char c=nchar();
	for (;!isdigit(c);c=nchar()) if (c=='-') f=-1;
	for (;isdigit(c);c=nchar()) x=x*10+c-'0';
	return x*f;
}
const int maxn=2e3+1;
const int maxl=4e6+1;
typedef bitset<maxl> bit;
bit f;
int n,sum=0,cnt[maxn];
int main() {
	f[0]=true;
	n=read();
	int mx=0;
	for (int i=1;i<=n;++i) {
		int x=read();
		sum+=x;
		++cnt[x];
		if (x>mx) mx=x;
	}
	for (int i=1;i<=mx;++i) {
		for (int j=0;cnt[i];++j) {
			int k=min(cnt[i],1<<j);
			f|=f<<(k*i);
			cnt[i]-=k;
		}
	}
	for (int i=(sum+1)/2;i<=sum;++i) if (f[i]) {
		printf("%d\n",i);
		break;
	}
	return 0;
}


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

using namespace std;
#define ll long long
#define mod 1000000007

ll n, dp[10001][101][2], d;
vector<ll> v;

ll solve(ll i, ll m, ll bo) {
    if (i == n && !m) {
        return 1;
    } else if (i == n) return 0;

    if (dp[i][m][bo] != -1) return dp[i][m][bo];
    ll ans = 0;
    for (int j = 0; j <= (bo ? v[i] : 9); j++) {
        ans = (ans + solve(i + 1, (j + m) % d, bo && j == v[i])) % mod;
    }
    dp[i][m][bo] = ans;
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    memset(dp, -1, sizeof(dp));

    string s;
    cin >> s;
    n = s.length();
    cin >> d;

    for (char c : s) {
        v.push_back(c - 48);
    }

    ll ans = solve(0, 0, 1) - 1;
    if (ans < 0) {
        ans += mod;
    }
    cout << ans;
}


Measured memory_bytes: 20344
#include<stdio.h>
#include<math.h>
int main(void)
{
    int a,i;
    double b,c,d,x[1000];
    while(scanf("%d",&a),a){
        b=0;d=0;
        for(i=0;i<a;i++){
            scanf("%lf",&x[i]);
            b += x[i];
//printf("x[%d]%f b%f\n",i,x[i],b);        
        }
        b /= (double)a;
        for(i=0;i<a;i++){
            c=0;
            c = x[i]-b;
            d += c * c;
//printf("c%f d%f\n",c,d);        
        }
        d /= (double)a;
        printf("%f\n",sqrt(d));
    }
    return 0;
}

Measured memory_bytes: 664
import java.util.*

fun main(args:Array<String>){
    val n = readLine()!!.toInt()
    val k = readLine()!!.toInt()
    val x = readLine()!!.toInt()
    val y = readLine()!!.toInt()
    println(if(n <= k) n * x else k * x + (n - k) * y)
}


Measured memory_bytes: 33720
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // int n;
    // cin >> n;
    set<int> s;
    int q, a, b;
    cin >> q;
    rep(i, q) {
        cin >> a >> b;
        if(a == 0) {
            s.insert(b);
            cout << s.size() << "\n";
        } else {
            cout << (s.find(b) != s.end()) << "\n";
        }
    }
}



Measured memory_bytes: 12488
#include <iostream>
#include <stdio.h>
#define MAX 100


struct Card {
    char value;
    char mark;
};


bool isStable(Card c1[], Card c2[], int n) {
    for (int i = 0; i < n; i++) {
        if (c1[i].mark != c2[i].mark) {
            return false;
        }
    }
    return true;
}

void bubbleSort( Card card[], int n ) {
    int flag = 1;
    int index = 0;
    while (flag) {
        flag = 0;
        for ( int j = n-1; j > index; j-- ) {
            if ( card[j].value < card[j-1].value ) {
                std::swap(card[j], card[j-1]);
                flag = 1;
            }
        }
        index ++;
    }
}

void selectionSort(Card card[], int n) {
    for ( int i = 0; i < n - 1; i++ ) {
        int minj = i + 1;
        for ( int j = i + 1; j < n; j++ ) {
            if ( card[minj].value > card[j].value ) {
                minj = j;
            }
        }
        if ( card[i].value > card[minj].value ) {
            std::swap(card[i], card[minj]);
        }
    }
}



int main() {
    int n;
    Card A[MAX], B[MAX];
    scanf( "%d\n", &n );
    
    for ( int i = 0; i < n; i++ ) {
        std::cin >> A[i].mark;
        std::cin >> A[i].value;
    }
    for (int i = 0; i < n; i++) {
        B[i] = A[i];
    }
    
    bubbleSort(A, n);
    for ( int i = 0; i < n; i++ ) {
        if ( i ) std::cout << " ";
        std::cout << A[i].mark << A[i].value;
    }
    std::cout << std::endl;
    std::cout << "Stable" << std::endl;
    
    selectionSort(B, n);
    for ( int i = 0; i < n; i++ ) {
        if ( i ) std::cout << " ";
        std::cout << B[i].mark << B[i].value;
    }
    
    std::cout << std::endl;
    if (isStable(A, B, n)) std::cout << "Stable" << std::endl;
    else std::cout << "Not stable" << std::endl;
    
    return 0;
}

Measured memory_bytes: 3160
n, k = gets.chop.split.map{ |x| x.to_i}

a = gets.chop.split.map{ |x| x.to_i}

h = Hash.new(0)

n.times do |i|
  h[a[i]] += 1
end

arr = h.to_a.sort_by!{|x| x[1]}

if arr.size <= k
  p 0
else
  # 取り除いた行（種類）
  tmp = 0
  # 取り除いた数
  ans = 0

  arr.each do |val|
    tmp += 1
    ans += val[1]
    break if arr.size - tmp == k
  end
  p ans
end

Measured memory_bytes: 43784
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	vi a(5);
	rep(i, 5) cin >> a[i];
	rep(i, 5) if(!a[i]){
		cout << i + 1 << endl;
		return 0;
	}
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

// --------------------------------------------------------------------------------
#define fastio	ios_base::sync_with_stio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long 
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define deb(name,value) cout <<"->>  "<<name<< "= " <<value<<" "
#define frepi(a,b,k) for(int i=a;i<=b;i+=k)
#define frepj(a,b,k) for(int j=a;j<=b;j+=k)
// --------------------------------------------------------------------------------

bool palind(string s)
{
	int n=s.size();
	for(int i=0;i<=n/2;++i)
	{
		if(s[i]!=s[n-i-1])
			return false;
	}
	return true;
}

void solve_main()
{
    string s;cin>>s;
    int n = s.size();
    string s1 = s.substr(0,(n-1)/2);
    string s2 = s.substr((n+3)/2-1,(n-3)/2+1);
    if(palind(s1) && palind(s2) && palind(s))
    	cout<<"Yes";
    else
    	cout<<"No";
}

int main()
{
	// #ifndef ONLINE_JUDGE
 //    	freopen("/home/suryakant/input.txt","r",stdin);
 //        freopen("/home/suryakant/output.txt","w",stdout);
 //    #endif
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve_main();
    }
    
}

Measured memory_bytes: 3588
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

import sys
input = sys.stdin.buffer.readline
N,M = map(int,input().split())
uf = UnionFind(N)
for i in range(M):
    A,B = map(int,input().split())
    uf.union(A-1,B-1)
ans = 0
for i in uf.roots():
    ans = max(uf.size(i),ans)
print(ans)


Measured memory_bytes: 87084
import os
import sys

aa = input().strip().split()
h = int(aa[0])
w = int(aa[1])
a = [list(input().strip()) for _ in range(h)]
r = [[False for _ in range(i)] for i in [h, w]]

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            r[0][i] = True
            r[1][j] = True

for i in range(h):
    if r[0][i]:
        for j in range(w):
            if r[1][j]:
                sys.stdout.write(a[i][j])

        sys.stdout.write(os.linesep)


Measured memory_bytes: 3828
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int X, Y;
    string ans="No";
    cin >> X >> Y;
    for(int i=0;i<=X;i++){
        int f=i*4+(X-i)*2;
        if(f==Y){
            ans = "Yes";
            break;
        }
    }
    cout << ans;
}


Measured memory_bytes: 3624
<?php
  fscanf(STDIN,"%d%d",$n,$m);
  
  for($i=0; $i<$n; $i++){
      fscanf(STDIN,"%d%d",$a[],$b[]);
  }
  
  for($i=0; $i<$m; $i++){
      fscanf(STDIN,"%d%d",$c[],$d[]);
  }
  
  
  for($i=0; $i<$n; $i++){
      $cp = 0;
      $pre_dis = abs($a[$i]-$c[0])+abs($b[$i]-$d[0]);
      for($j=0; $j<$m; $j++){
          $dis = abs($a[$i]-$c[$j])+abs($b[$i]-$d[$j]);
          if($dis < $pre_dis){
              $pre_dis = $dis;
              $cp = $j;
          }
      }
      echo ($cp+1)."\n";
  }

Measured memory_bytes: 4604
#include <stdio.h>
#include <string.h>

int main(void){
    int n;
    scanf("%d",&n);
    char s[n+1];
    scanf("%s",s);
    int i,cnt;
    for(i=0;i<n-2;i++){
        if(s[i]=='A'){
            if(s[i+1]=='B'){
                if(s[i+2]=='C'){
                    cnt++;
                }
            }
        }
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#define ll long long int
#define all(x) x.begin(), x.end()
#define pb push_back
#define se second
#define fi first
using namespace std;
typedef pair<ll,ll> pll;

const int N = 1e5+5;
int a[N],n;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin>>n;
    for(int i=0;i<n;i++){
        int x; cin>>x;
        a[x] ++;
    }
    int maxc=0,ans=0;
    for(int i=0;i<N;i++){
        int val = 0;
        if(i==0){
            val = a[i] + a[i+1];
        }
        else if(i == N-1){
            val = a[i] + a[i-1];
        }
        else{
            val = a[i-1] + a[i] + a[i+1];
        }
        if(val >= maxc){
            ans = i;
            maxc = val;
        }
    }
    cout<<maxc<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll  long long
#define pp pair<int,int>
#define ppn pair<pp,int>
#define F first
#define S second
#define N 200005
#define mod 1000000007
#define pi 3.14159265358979323846
 
using namespace std;
 
 
int main()
{
 
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
   int n;
   cin>>n;
   vector<ll>v(n);
   for(int i=0; i<n; i++)cin>>v[i];
   sort(v.rbegin(),v.rend());
   ll ans = v[0];
   int i=n-2, j=1;
   int k = n/2;
   while(i){
    if(i>=2){
            ans+=2*v[j++];
            i-=2;
    }
    else {
            ans+=v[j++];
            break;
            }
 
   }
   cout<<ans<<endl;
}

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

bool input(std::string&);
char convert2Small(char);

int main() {

	std::string str;
	std::string word ;
	int strLen;
	int wordLen;
	unsigned count = 0;

	std::cin >> word;
	wordLen = word.length();
	
	while (input(str))
	{
		strLen = str.length();
		if (strLen == wordLen)
		{
			for (size_t i = 0; i < strLen; i++)
			{
				char smallstr = convert2Small(str[i]);
				char smallword = convert2Small(word[i]);
				if (smallstr != smallword)
				{
					break;
				}
				if (i == strLen - 1)
				{
					count++;
				}
			}
		}
	}
	std::cout << count << "\n";
	return 0;
}

bool input(std::string& str) {
	std::cin >> str;
	if (str == "END_OF_TEXT")
	{
		return false;
	}
	return true;
}
char convert2Small(char chara) {
	if (chara >= 'A' && chara <= 'Z')
	{
		chara -= 'A' - 'a';
	}
	return chara;
}


Measured memory_bytes: 3176
N, K = map(int,input().split())

d_list = []
A_list = []

for i in range(K):
    d = int(input())
    d_list.append(d)
    A = list(map(int, input().split()))
    A_list.append(A)

person = [0 for i in range(N)]

for i in range(K):
    for j in range(d_list[i]):
        person[A_list[i][j]-1] += 1

print(person.count(0))

Measured memory_bytes: 9200
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <queue>

using ll = long long;

using namespace std;

set<int> G[2][200010];

int main() {
    int n, m;
    string s;
    cin >> n >> m >> s;
    s = '-' + s;
    for (int i=0, a, b; i<m; i++) {
        cin >> a >> b;
        G[(s[a] == 'A')][b].insert(a);
        G[(s[b] == 'A')][a].insert(b);
    }
    int cnt=n;
    bool visited[n+1];
    fill(visited, visited+n+1, false);
    queue<int> q;
    for (int i=1; i<=n; i++)
        if (G[0][i].empty() || G[1][i].empty()) {
            q.push(i);
            cnt--;
            visited[i] = true;
        }

    while (!q.empty()) {
        int t = q.front(); q.pop();
        for (int i=0; i<2; i++) {
            for (auto g:G[i][t]) {
                if (visited[g]) continue;
                G[(s[t] == 'A')][g].erase(t);
                if (G[(s[t] == 'A')][g].empty()) {
                    q.push(g);
                    visited[g] = true;
                    cnt--;
                }
            }
        }
    }
    cout << (cnt > 0 ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 37852
import collections

n = int(input())
s = []
for i in range(n):
    si = input()
    s.append(si)
    
s.sort()
counted = collections.Counter(s)
M = max(counted.values())

ms = [k for k, v in counted.items() if v == M]
ms.sort()

for i in range(len(ms)):
    print(ms[i])

Measured memory_bytes: 102736
#ifdef __GNUC__
#include <bits/stdc++.h>
#endif // __GNUC_

namespace yaito {
    template<class T, class Func>
    class segmentTree {
    private:
        std::vector<T> data;
        size_t size;
        Func func;

        int get(size_t l, size_t r, size_t k, size_t left, size_t right) const {
            if (right <= l || r <= left)return 0;
            if (l <= left && right <= r)return data[k];
            T a = get(l, r, k * 2 + 1, left, (left + right) / 2);
            T b = get(l, r, k * 2 + 2, (left + right) / 2, right);
            return func(a, b);
        }

    public:
        template<class Itr>
        segmentTree(Itr first, Itr last, Func func, T init) : func(func) {
            size_t dif = std::distance(first, last);
            size = 1;
            while (size < dif)size <<= 1;
            data.resize(2 * size - 1, init);
            for (size_t i = 0; i < dif; ++i, ++first)update(i, *first);
        }

        void update(size_t i, int value) {
            i += size - 1;
            data[i] = value;
            while (i > 0) {
                i = (i - 1) / 2;
                data[i] = func(data[i * 2 + 1], data[i * 2 + 2]);
            }
        }

        T get(size_t l, size_t r) const {
            return get(l, r, 0, 0, size);
        }

        void show()const {
            for (size_t i = 0; i < 2 * size - 1; ++i) {
                std::cout << data[i] << ", ";
                if (!((i + 2) & (i + 1)))std::cout << '\n';
            }
        }

    };

    template<class T, class Itr, class Func>
    auto make_segmentTree(Itr first, Itr last, Func func, T init) {
        return segmentTree<T, Func>(first, last, func, init);
    }

}

int main() {

    int N, Q;
    std::string S;
    std::cin >> N >> Q;
    std::cin >> S;
    std::vector<int> ACs(N, 0);
    for (int i = 1; i < N; ++i)if (S[i - 1] == 'A' && S[i] == 'C')ACs[i] = 1;
    auto seg = yaito::make_segmentTree(ACs.begin(), ACs.end(), [](int a, int b) {return a + b; }, 0);
    for (int i = 0; i < Q; ++i) {
        int l, r;
        std::cin >> l >> r;
        std::cout << seg.get(l, r) << std::endl;
    }

}

Measured memory_bytes: 2432
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    double n, d;
    cin >>n >>d;
    cout <<ceil(n/((2*d) + 1));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    string n;
    cin >> n;
    if(n[0] == '7' || n[1] == '7' || n[2] == '7') out("Yes");
    else out("No");
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <utility>
using namespace std;

constexpr int varc = 625;
pair<bool, bitset<varc>> solve_linear_eq_F2(vector<bitset<varc+1>> g, int varnum){
    int n = g.size();
    for(int i=0, p=0; i<n and p<varc+1; i++, p++){
        for(int j=i+1; j<n; j++){
            if(g[j][p] == 1){
                swap(g[i], g[j]);
                break;
            }
        }
        if(g[i][p] == 0){
            i--;
            continue;
        }
        for(int j=i-1; j<n; j++){
            if(j != i and g[j][p] == 1){
                g[j] ^= g[i];
            }
        }
    }
    
    bool has_sol = true;
    bitset<varc> res, decided;
    for(int i=n-1; i>=0; i--){
        int right = g[i][varnum];
        vector<int> vars;
        for(int j=0; j<varnum; j++){
            if(g[i][j]==1){
                if(decided[j]==1 and res[j]==1){
                    right ^= 1;
                }else if(decided[j]==0){
                    vars.push_back(j);
                }
            }
        }
        for(int j: vars){
            res[j] = 0;
            decided[j] = 1;
        }
        if(right==1){
            if(vars.empty()){
                has_sol = false;
                break;
            }else{
                res[vars[0]] = 1;
            }
        }
    }
    return make_pair(has_sol, res);
}

int main(){
    while(1){
        int m,n,d;
        cin >> m >> n >> d;
        if(m == 0) break;
        
        vector<vector<int>> s(n, vector<int>(m));
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                cin >> s[i][j];
            }
        }
        vector<bitset<varc+1>> g(n*m);
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                g[i*m+j][i*m+j] = 1;
                g[i*m+j][n*m] = s[i][j];
                for(int k=0; k<n; k++){
                    for(int l=0; l<m; l++){
                        if(abs(i-k) + abs(j-l) == d){
                            g[i*m+j][k*m+l] = 1;
                        }
                    }
                }
            }
        }     
        auto ret = solve_linear_eq_F2(g, n*m);
        cout << ret.first << endl;
    }
    return 0;
}



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

using namespace std;

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

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

vector<int> x[100001];
int used[100001];
int ok[100001];

struct UF{
  vector<int> data;
  UF(int size) : data(size, -1){}
  bool set(int x, int y){
    x=root(x);y=root(y);
    if(x!=y){
      if(data[y] < data[x])swap(x,y);
      data[x] += data[y];data[y]=x;
    }
    return x!=y;
  }
  bool find(int x,int y){
    return root(x) == root(y);
  }

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

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



int main(void){
  int n, m, k, l;
  
  queue<int> q;
  cin >> n >> m;
  UF uf(100001);

  rep(i,n){
    cin >> k;
    vector<int> tmp;
    rep(j,k){
      cin >> l;
      l--;
      tmp.push_back(l);
      used[l]= 1;
    }

    rep(j,k-1){
      uf.set(tmp[j], tmp[j+1]);
    }
  }
  int cnt = 0;

  rep(i, m){
    if(used[i])cnt++;
  }

  if( uf.size(l) == cnt){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
int xy[6],k; 
int main()
{
	for(int i=0;i<5;i++)
		cin>>xy[i];
	cin>>k;
	sort(xy,xy+5);
	if(xy[4]-xy[0]>k)
		cout<<":(";
	else
		cout<<"Yay!";	
		return	0;	
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << 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; }

int N,a,b,c;

int main(){
    cin>>N;
    int dp[3][N+1];
    rep(i,3){
        dp[i][0]=0;
    }
    repi(i,1,N+1){
        cin>>a>>b>>c;
        dp[0][i] = max(dp[1][i-1]+b,dp[2][i-1]+c);
        dp[1][i] = max(dp[0][i-1]+a,dp[2][i-1]+c);
        dp[2][i] = max(dp[1][i-1]+b,dp[0][i-1]+a);
    }
    out(max(dp[0][N],max(dp[1][N],dp[2][N])));
}


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

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

int main(){
  int H, W;
  vector<vector<int>> A(1010, vector<int>(1010, 1e7));
  queue<pair<int,int>> Q;

  cin >> H >> W;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      char c; cin >> c;
      if(c == '#'){
        A[i][j] = 0;
        Q.push(make_pair(i,j));
      }
    }
  }

  while(!Q.empty()){
    int x = Q.front().first, y = Q.front().second;
    Q.pop();

    for(int i=0; i<4; i++){
      int nx = x + dx[i], ny = y + dy[i];
      if(0 <= nx && nx < H && 0 <= ny && ny < W){
        if(A[nx][ny] > A[x][y] + 1){
          A[nx][ny] = A[x][y] + 1;
          Q.push(make_pair(nx,ny));
        }
      }
    }
  }

  int ans = 0;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      //cout << A[i][j];
      ans = max(ans, A[i][j]);
    }
    //cout << endl;
  }

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

Measured memory_bytes: 12432
#include<bits/stdc++.h>
using namespace std;
#define int64 long long int
int main(){
	int n;
	ios::sync_with_stdio(false);
	cin >> n;
	int64 sum = 0, z = (int64)2e18, res = 0;
	for(int i=1; i<=n; i++){
		int64 cur, pro;
		cin >> cur >> pro;
		z = min(z, sum - cur);
		sum += pro;
		res = max(res, sum - cur - z);
	}
	cout << res <<endl;
	return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define PB emplace_back
#define ALL(x) (x).begin(),(x).end()
#define endl '\n'

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int,int>;
using pll = pair<ll,ll>;

constexpr int IN = 102;
constexpr int INF = 1e9+5;
constexpr int INI = -1;

double a[IN];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    double n, ans=0;
    cin >> n;
    for(int i=0; i<n; ++i) cin >> a[i];
    for(int i=0; i<n; ++i)
        ans += 1/a[i];
    cout << 1/ans;
    return 0;
}


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



int main(){
    ll a, b, x; cin >> a >> b >> x;
    a += x;
    b += x;
    ll ans = b / x - (a-1) / x;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int m, f, r;

  while(1) {
    cin >> m >> f >> r;
    if(m == -1 && f == -1 && r == -1) break;

    if(m == -1 || f == -1) cout << "F";
    else if(m + f >= 80) cout << "A";
    else if(m + f >= 65) cout << "B";
    else if(m + f >=50) cout << "C";
    else if(m + f >= 30) {
      if(r >= 50) cout << "C";
      else cout << "D";
    }
    else cout << "F";

    cout << "\n";
  }
  
  return 0;
}



Measured memory_bytes: 3056
N = 10100
ps = []

isp = Array.new(N,true)
(2..N).step 2 do |i|
  isp[i] = false
end
(3..N).step(2) do |i|
  next unless isp[i]
  ps << i
  ((i+i)..N).step(i) do |j|
    isp[j] = false
  end
end

while (n=gets.to_i)!=0
  ans = -1
  (ps.length-1).times do |i|
    if ps[i+1] > n
      break
    end
    if ps[i]+2 == ps[i+1]
      ans = i
    end
  end
  puts ps[ans,2].join(' ')
end

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

int main() {
  int N, i, count=0;
  
  cin >> N;
  
  vector<int> D(2*N);
  
  for(i=0;i<2*N;i++) cin >> D[i];
  
  for(i=0;i<N;i++){
    if(D[2*i]==D[2*i+1])count+=1;
    else count=0;
    if(count==3){
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

int n;
string s;
vector<char> r;

bool set_or_check(int i) {
  int prev = i-1 == -1 ? n-1 : i-1;
  int next = i+1 ==  n ?   0 : i+1;

  assert(r[i] != 'Z');
  if(r[next] == 'Z') { // set
    if ((s[i] == 'o' && r[i] == 'S') || (s[i] == 'x' && r[i] == 'W'))
      r[next] = r[prev];
    else
      r[next] = r[prev] == 'W' ? 'S' : 'W';
    return true;
  }
  else { // check
    if ((s[i] == 'o' && r[i] == 'S') || (s[i] == 'x' && r[i] == 'W'))
      return r[next] == r[prev];
    else
      return r[next] != r[prev];
  }
}

void chain() {
  rep(i, 1, n-2) assert(set_or_check(i));
  if(!set_or_check(n-2) || !set_or_check(n-1)) return;

  rep(i,n) cout << r[i];
  cout << endl;
  exit(0);
}

int main() {
  //https://atcoder.jp/contests/arc069/tasks/arc069_b
  cin >> n >> s;
  r.resize(n);

  char sw[] = {'S' ,'W'};
  for(char z : sw) {
    if((s[0] == 'o' && z=='S') || (s[0] == 'x' && z == 'W')) {
      FILL(r, 'Z');
      r[0] = z, r[1] = r[n-1] = 'S';
      chain();

      FILL(r, 'Z');
      r[0] = z, r[1] = r[n-1] = 'W';
      chain();
    }
    else {
      FILL(r, 'Z');
      r[0] = z, r[1] = 'S', r[n-1] = 'W';
      chain();

      FILL(r, 'Z');
      r[0] = z, r[1] = 'W', r[n-1] = 'S';
      chain();
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 3812
#include <stdio.h>

int main(void)
{
	int a[100];
	int N,i,count;
	
	scanf("%d", &N);
	
	count = 0;
	for(i = 0; i < N; i++)
	{
		scanf("%d", &a[i]);
	}
	
	for(i = 0; i < N-1; i++)
	{
		if(a[i] == a[i+1])
		{
			a[i+1] = 10001;
			count++;
		}
	}
	
	printf("%d", count);
	
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pii pair<int,int>
using namespace std;
int main()
{
    fast;
   
    ll x,k,d;
    cin>>x>>k>>d;
    if(x==0)
    {
    	if(k%2==0) cout<<"0";
    	else cout<<x+d;
    }
    else if(x>0)
    {
    	ll ha = x/d;
    	if(ha>=k) cout<<x-k*d;
    	else
    	{
    		if((ha&1) == (k&1)) cout<<x-ha*d;
    		else cout<<abs(x - (ha+1) * d);
    	}
    }
    else
    {
    	ll ha = abs(x)/d;
    	if(ha>=k) cout<<abs(x+k*d);
    	else
    	{
    		if((ha&1) == (k&1)) cout<<abs(x+ha*d);
    		else cout<<abs(x + (ha+1) * d);
    	}
    }
}

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

	public static void main(String[] args) 
	{
         Scanner sc=new Scanner(System.in);
         int array[]=new int[3];
         for(int i=0;i<3;i++)
        	 array[i]=sc.nextInt();
         find(array);
	}

	private static void find(int[] array) 
	{	
		int count=0;
		for(int i=0;i<2;i++)
		{
			for(int j=i+1;j<3;j++)
			{
				if(array[i]==array[j])
					count++;
			}
		}
		if(count==1)
			System.out.println("Yes");
		else 
			System.out.println("No");
		
		
	}

}


Measured memory_bytes: 21716
s = sorted(input())
t = sorted(input())[::-1]
Ls= []
Lt= []

if len(s)<len(t) and set(s) == set(s)&set(t):
    print("Yes")
else:
    for i in s:
        Ls.append(i)
    Ls = "".join(Ls)
    for i in t:
        Lt.append(i)
    Lt = "".join(Lt)
    L = [Ls,Lt]
    L = sorted(L)
    if L[0]==L[1]:
        print("No")
    elif L[0]==Ls:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<queue>
using namespace std;
int main()
{
  char a[3][3];
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      cin>>a[i][j];
  cout<<a[0][0]<<a[1][1]<<a[2][2];
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
long long h,m;
char s;
int main()
{
    scanf("%lld %c %lld",&h,&s,&m);
    if(s=='+')
    {
        printf("%lld\n",h+m);
    }
    else
    {
         printf("%lld\n",h-m);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;

typedef pair<int,int> P;
template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  int n;  //セグ木の幅
  F f;  //モノイドの作用
  T ti;  //初期値
  vector<T> dat;  //セグ木で使う配列 一番上に使われるのがdat[1] 一番下の段の左端がdat[n]
  SegmentTree(){};
  SegmentTree(F f,T ti):f(f),ti(ti){}  //fがモノイドとしての作用、tiが単位元

  void init(int n_){  //ただの初期化
    n=1;
    while(n<n_) n<<=1;  //nが実際にとる２べきの幅
    dat.assign(n<<1,ti);  //dat配列は幅の２倍あってその全てにtiを代入
  }

  void build(const vector<T> &v){  //vector vに合わせた初期化
    int n_=v.size();
    init(n_);
    for(int i=0;i<n_;i++) dat[n+i]=v[i];  //v[i]を一番子の所に代入
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);  //iの子供は2*i、2*i+1
  }

  void set_val(int k,T x){  //（0-indexedで）kにxを代入
    dat[k+=n]=x;
    while(k>>=1)  //kがどんどん自分の親になっていく、0になったらおしまい
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
  }

  T query(int a,int b){  //[a,b)の範囲のモノイドの作用を返す
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);  //左端を使いたくなるのはブロックが奇数の時
      if(r&1) vr=f(dat[--r],vr);  //右端〃偶数の時（開区間なのでr:奇数で反応）
    }
    return f(vl,vr);
  }

  template<typename C>
  int find(int st,C &check,T &acc,int k,int l,int r){  //dat[k]:[l,r)の間にいるenを返す
    //下のfind用なので先にそっち読むべき
    //accはst~lとかで確定している値
    if(l+1==r){  //答えがちゃんと存在するならこのlが答え
      acc=f(acc,dat[k]);
      return check(acc)?k-n:-1; //入るならk-n(==l)を、入らないなら-1を返す
    }
    int m=(l+r)>>1;  //にぶたんのそれ
    if(m<=st) return find(st,check,acc,(k<<1)|1,m,r);  //mがstより後ろなら明らかにl=m;
    if(st<=l&&!check(f(acc,dat[k]))){  //今見てるk全部でもダメ(mだと足りないのでl=mにする）
      acc=f(acc,dat[k]);  //kは全部accに加えた上で-1を返す
      return -1;
    }
    int vl=find(st,check,acc,(k<<1)|0,l,m);  //まず[l,m)の中にenがいるか探す
    if(~vl) return vl;  //いたならそれを返す(if(~vl)は-1以外にのみ反応する)
    return find(st,check,acc,(k<<1)|1,m,r);  //いなかったら[m,r)の中にenがいるのでそれを返す
    //acc=f(acc,dat[k]);がここで効いてる
  }

  template<typename C>
  int find(int st,C &check){
    //check(f(dat[st]~dat[en-1]))=false,check(f(dat[st]~dat[en]))＝trueとなるenを返す
    T acc=ti;
    return find(st,check,acc,1,0,n);
  }
};

template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}
int dp[7000];
/*
3000以内で3000個頼む
最後の一個をどれにするかはどうしよう
全部の中で一番長いやつが最後に食べるやつだから、dpしつつ現時点でのそっちのmaxを食べさせればいい
*/

signed main(){
  int n,t;cin>>n>>t;
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++)cin>>a[i]>>b[i];
  for(int i=1;i<3005;i++)dp[i]=-INF;
  vector<P> v(n);
  for(int i=0;i<n;i++)v[i]=P(a[i],b[i]);
  sort(v.begin(),v.end());
  int ans=0;
  vector<int> k(n);
  for(int i=0;i<n;i++)k[i]=v[i].second;
  auto f=[](int a,int b){return max(a,b);};
  SegmentTree<int> seg(f,0);
  seg.build(k);
  for(int i=0;i<n;i++){
    for(int j=3000;j>=0;j--)chmax(dp[j+v[i].first],dp[j]+v[i].second);
    int tmp=0;
    for(int j=0;j<t;j++)chmax(tmp,dp[j]);
    chmax(ans,tmp+seg.query(i+1,n));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 384
///
// File:  a.go
// Author: ymiyamoto
//
// Created on Sun Mar 25 18:42:19 2018
//
package main

import (
	"fmt"
)

func main() {
	matrix := make([]string, 3)
	for i := 0; i < 3; i++ {
		fmt.Scan(&matrix[i])
	}
	for i := 0; i < 3; i++ {
		fmt.Print(string(matrix[i][i]))
	}
	fmt.Println()
}


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

/*
ナップサック問題
dp[i][j]:品物v[0]~v[i-1]までを使って重さをj以下にするときの価値の最小値
dp[i][j]=
max(dp[i-1][j], dp[i-1][j-v[i].first]+v[i].second)
ただし、j<v[i].firstのときはdp[i-1][j]をそのまま返す
*/

void solve(){
    int n,w;
    cin >> n >> w;
    vector<pair<ll,ll>> v;
    rep(i,n){
        ll a,b;
        cin >> a >> b;
        v.emplace_back(make_pair(a,b));
    }
    ll dp[110][w+10];
    rep(i,w+1){
        dp[0][i]=0;
    }
    rep(i,n+1){
        dp[i][0]=0;
    }
    for(int i=1; i<=n; i++){
        for(int j=1; j<=w; j++){
            //cout << "i:" << i << " j:" << j << endl;
            if(j<v[i-1].first) dp[i][j]=dp[i-1][j];
            else{
                dp[i][j]=max(dp[i-1][j], dp[i-1][j-v[i-1].first] + v[i-1].second);
            }
        }
    }
    cout << dp[n][w] << endl;

}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 80384
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

pair<string, int> a[N];
int id[N],p[N];
string c[N];
bool kk(pair<string, int> x, pair<string, int> y)
{
	if(x.F == y.F)
		return (x.S < y.S);
	return (x.F > y.F);
}
int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++)
	{
		cin >> c[i] >> p[i];
		id[p[i]] = i;
		a[i] = M(c[i], p[i]);
	}
	sort(a + 1, a + n + 1, kk);
	reverse (a + 1, a + n +1);
	for(int i = 1; i <= n; i ++)
		cout << id[a[i].S] << '\n';






	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 6912
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        
        List<String> strs = new ArrayList<>(Arrays.asList("a","b","c"));

        boolean flag = false;
        for(String str : strs){
            if(!S.contains(str)) flag = true;
        }
        String kotae = flag ? "No" : "Yes";
        System.out.println(kotae);
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
long long a[200005];
long long f(long long k){
    if(k==1)return 1;
    return 2*f(k/2)+1;
}
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    long long n;
    cin>>n;
    cout<<f(n);
    return 0;
}


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

using namespace std;

int main()
{
    int n;cin>>n;
    int arr[n];
    
    for(int i=0;i<n;i++)
    cin>>arr[i];
    
    int dp[n]={0};
    
    dp[n-2]=abs(arr[n-1]-arr[n-2]);
     dp[n-3]=min(abs(arr[n-1]-arr[n-3]),dp[n-2]+abs(arr[n-3]-arr[n-2]));
    
    for(int i=n-4;i>=0;i--)
    {
        dp[i]=min( abs(arr[i]-arr[i+1])+dp[i+1] , abs(arr[i]-arr[i+2])+dp[i+2] );
    }
    
    cout<<dp[0]<<endl;

    return 0;
}


Measured memory_bytes: 4424
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>



using namespace std;

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

int r;

int main(){
    cin >> r;
    cout << r*r << endl;



    return 0;
}

Measured memory_bytes: 3624
/*
Program		: echo.c
Description	: Checking echo of a string
Author		: Rey Rizki
Date		: 16 November 2019
Time        : 7:58 P.M. to 
Compiler	: gcc Ubuntu 7.4.0
*/

#include <stdio.h>
#include <string.h>
#include <stdbool.h>

int main() {
    // DECLARATION
    int length;                     // The length of the string
    char string[101];               // The string itself
    int i;                          // for iteration, as usual
    bool echo;                      // for the state

    // INPUT
    scanf("%d\n", &length);
    fgets(string, 101, stdin);

    // PROCESS
    echo = true;
    if (length % 2 == 0) {
        while (echo && i < length/2) {
            if (string[i] != string[i+(length/2)]) {
                echo = false;
            } else {
                i++;
            }
        }
    } else {
        echo = false;
    }

    // OUTPUT
    if (echo) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <queue>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;

ifstream in("ap.in");

const int maxn = 2e5;

int n, m, x, y;
vector <int> g[maxn];
int t, h[maxn], father[maxn];
bool viz[maxn], ans[maxn];

void dfs(int current){
	viz[current] = true;

	father[current] = h[current];

	for(int i = 0; i < g[current].size(); ++i){

		int next = g[current][i];

		if(!viz[next]){

			h[next] = h[current] + 1;
			dfs(next);

			if(current == 0) 
				t++;

			if(current != 0 && father[next] >= h[current]) 
				ans[current] = true;

			father[current] = min(father[current], father[next]);
		}

		else if(h[next] < h[current] - 1){

			father[current] = min(father[current], h[next]);

		}
	}
}


int main(){
	cin >> n >> m;
	for(int i = 0; i < m; ++i){
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(0);
	if(t > 1) ans[0] = true;
  for(int i = 0; i < n; i++) 
  	if(ans[i]) 
  		cout << i << '\n';
  return 0;
}


Measured memory_bytes: 9108