akhauriyash/Code-Regression huggingface dataset:
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,-1,1,0 }, dy[4] = { 1,0,0,-1 };


int main()
{
	int w, h;
	while (cin >> w >> h&&w)
	{
		int a[60][60] = {};
		queue<pii> bb,ww;
		for (int i = 1; i <= h; i++)
		{
			for (int j = 1; j <= w; j++)
			{
				char c; cin >> c;
				if (c == 'B')
				{
					a[i][j] = 1;
					bb.push(pii(i, j));
				}
				else if (c == 'W')
				{
					a[i][j] = -1;
					ww.push(pii(i, j));
				}
				else a[i][j] = 2;
			}
		}
		int B[60][60] = {}, W[60][60] = {};

		while (!bb.empty())
		{
			pii now = bb.front(); bb.pop();
			if (a[now.first][now.second] == -1||a[now.first][now.second]==0||B[now.first][now.second])
				continue;
			B[now.first][now.second] = 1;

			for (int i = 0; i < 4; i++)
			{
				pii next = now;
				next.first += dx[i];
				next.second += dy[i];
				bb.push(next);
			}
		}

		while (!ww.empty())
		{
			pii now = ww.front(); ww.pop();
			if (a[now.first][now.second] == 1 || a[now.first][now.second] == 0 || W[now.first][now.second])
				continue;
			W[now.first][now.second] = 1;

			for (int i = 0; i < 4; i++)
			{
				pii next = now;
				next.first += dx[i];
				next.second += dy[i];
				ww.push(next);
			}
		}
		int ansb=0, answ=0;
		for (int i = 1; i <= h; i++)
		{
			for (int j = 1; j <= w; j++)
			{
				if (B[i][j] == 1 && W[i][j] == 0&&a[i][j]==2)ansb++;
				if (B[i][j] == 0 && W[i][j] == 1&&a[i][j]==2)answ++;
			}
		}
		cout << ansb<<" "<<answ << endl;

	}
}

Measured memory_bytes: 3176
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string N; cin >> N;
    ll ans = 0;
    rep(i, N.length()) {
        ans += N[i] - '0';
    }
    if(ans % 9 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3740
import collections

N = int(input())

S = list()
for i in range(N): S.append(input())

c = collections.Counter(S)
max_value = c.most_common()[0][1]

ans = list()
for s in c.most_common():
	if s[1] == max_value:
		ans.append(s[0])
	else:
		break

ans.sort()
for a in ans:
	print(a)

Measured memory_bytes: 45120
/**
 * Title:
 * Url:
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    int n, k; cin >> n >> k;
    vector<int> d(n+1,0);
    for(int i=0; i<k; i++) {
        int di; cin >> di;
        for(int j=0; j<di; j++) {
            int aii; cin >> aii;
            d[aii]++;
        }
    }
    int ans = 0;
    for(int i=1; i<=n; i++) {
        if(d[i]==0) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

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

signed main(){
	ll a;
	string s;
	cin >> a >> s;
	
	if(a >= 3200) cout << s << endl;
	else cout << "red" << endl;
    return 0;
}

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

#define INF 10000000000


#define MAX_NUM 100000 //maxinum of input

// prototype declaration
void quickSort(int array[], int left, int right);
int threeElementMedian(int num1, int num2, int num3);

int main(void) {
    // declarations and inputs
    int n, k, ans=0, p[MAX_NUM];
    cin >> n >> k;
    for (int i=0; i<n; i++){
        cin >> p[i];
    }
    
    // sorting on array (N pipes)
    quickSort(p, 0, n-1);

    // output the sorted array
    for (int i=0; i<k; i++){
        ans += p[i];
    }
    cout << ans << endl;

    return 0;
}

// separating array into elements less than pivot and greater than pivot
int partition(int array[], int left, int right){
    int mid, pivot, swap; 
    mid = (left+right)/2;
    pivot = threeElementMedian(array[left], array[mid], array[right]); // pivot is the median of any three values
    left = left-1;
    right = right+1;
    // gathering values less than the pivot to the left of the pivot and greater than the pivot to the right of the pivot
    while (1){
        while (array[++left] < pivot); // finding element to the left of the pivot that are larger than the pivot
        while (array[--right] > pivot); // finding element to the right of the pivot that are smaller than the pivot
        if (left < right){
            // swapping "array[left]" and "array[right]"
            swap=array[left]; array[left]=array[right]; array[right]=swap;
        }else{
            // returning 
            return (right);
        }
    }
}

// running a sort recursively
void quickSort(int array[], int left, int right){
    int pivot;
    if (left < right){
        pivot = partition(array, left, right);
        quickSort(array, left, pivot); // sorting the part of the array to the left of the pivot, including the pivot
        quickSort(array, pivot+1, right); // sorting the part of the array to the right of the pivot
    }
}

// sesrching the median of any three values
int threeElementMedian(int num1, int num2, int num3){
    int median;
    if (num1 <= num2){
        if(num3 <= num1){
            median = num1;
        }else if (num2 <= num3){
            median = num2;
        }else{
            median = num3;
        }
    }else{
        if(num3 <= num2){
            median = num2;
        }else if (num1 <= num3){
            median = num1;
        }else{
            median = num3;
        }
    }
    return median;
}

Measured memory_bytes: 3636
#include<stdio.h>
#define N 100
int main(){
  int kosuu,i,j,A[N],count = 0,a,b,minj;
  
  scanf("%d",&kosuu);
  for(i = 0;i < kosuu ; i++){
    scanf("%d",&A[i]);
  }

  for(i=0;i<kosuu-1;i++)
    {
      minj = i;
      for(j = i;j<kosuu;j++)
      {
      if(A[j] < A[minj])
	{
	  minj = j ;
	 
	}
      }
      a = A[i];
      b = A[minj];
      A[i] = b;
      A[minj] = a;
      if(A[minj]==A[i])count--;
       count++;
      
    }
  for(i=0;i<kosuu-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n%d\n",A[i],count);
	
  return 0;
}



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

#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int;  // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9) + 7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector<pair<ll, ll> > prime_factorize(ll n) {
  vector<pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
  ll b = MOD, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0) {
    u += MOD;
  }
  return u;
}
// 順列
ll permutation(const ll n, const ll m) {
  ll result = 1;
  for (ll i = n; i > n - m; i--) {
    result = (result * i) % MOD;
  }
  return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
  if (x == 0) return 1;
  ll res = repeat_square(n, x / 2);
  res = res * res % MOD;
  if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ
ll combination(const ll n, const ll a) {
  ll x = 1, y = 1;
  for (ll i = 0; i < a; i++) {
    x = x * (n - i) % MOD;
    y = y * (i + 1) % MOD;
  }
  return x * repeat_square(y, MOD - 2) % MOD;
}

int main() {
  ll X, K, D;
  cin >> X >> K >> D;

  X = abs(X);

  ll ans = X;
  if (K < (X/D)) {
    ans = X - K * D;
  } else {
    ll a = X / D;
    ans = X - a * D;
    K -= a;
    K %= 2;
    ans -= K * D;
  }

  cout << abs(ans) << endl;
  return 0;
}


Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;

public class Main {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] line = br.readLine().split(" ", 0);
        int min = Integer.MAX_VALUE, max = -Integer.MAX_VALUE, num = 0;
        for (int i = 0; i < 3; i++) {
            num = Integer.parseInt(line[i]);
            if (num < min) {
                min = num;
            }
            if (num > max) {
                max = num;
            }
        }
        System.out.println(min + " " + max);
    }
}



Measured memory_bytes: 24332
#include <bits/stdc++.h>
using namespace std;
int r,C,sx,sy,gx,gy,kyori[100][100],hn;
pair<int,int> movemy[4]={{0,1},{1,0},{-1,0},{0,-1}};
queue<pair<int,int>> q;
char c[100][100];
bool went[100][100];

/*void bfs(int y,int x){
	if(y>c-1||y<0||x<0||x>r-1||c[y][x]=='#')return;
	for(int i=0;i<4;i++)
}*/
int main(){
	cin>>r>>C;
	
	for(int i=0;i<r;i++){
		for(int j=0;j<C;j++){
			cin>>c[i][j];
			if(c[i][j]=='#')hn++;
		}
	}
	q.push({0,0});
	while(!q.empty()){
		int y=q.front().first;
		int x=q.front().second;
		
		q.pop();
		
		//cout<<"original"<<y<<' '<<x<<endl;
		for(int i=0;i<4;i++){
			int kariy=y+movemy[i].first, karix=x+movemy[i].second;
			if(kariy>r-1||kariy<0||karix<0||karix>C-1||c[kariy][karix]=='#'||went[kariy][karix]);//cout<<"bad"<<endl;
			else{
				q.push({kariy,karix});
				kyori[kariy][karix]=kyori[y][x]+1;
				went[kariy][karix]=true;
				//cout<<kariy<<' '<<karix<<endl;
			}
		}
		
		//cout<<endl;
	}
	int ans=r*C-hn-kyori[r-1][C-1]-1;
	if(kyori[r-1][C-1]==0){cout<<-1<<endl;return 0;}
	cout<<ans<<endl;
	/*for(int i=0;i<r;i++){
		for(int j=0;j<C;j++){
			cout<<kyori[i][j]<<' ';
		}
		cout<<endl;
	}*/
}


Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    ll m=1;
    rep(i,n) m*=(i+1);
    vector<vector<int>> a(m,vector<int> (n));
    vector<int> q(n);
    vector<int> x(n);
    vector<int> y(n);
    rep(i,n) cin >> x[i];
    rep(i,n) cin >> y[i];
    rep(i,n) q[i] = i+1;
    ll j=0;
    // rep(i,n) cout << q[i] << " ";
    // cout << endl;
    do{
        rep(i,n){
            a[j][i] = q[i]; 
            // cout << q[i] << " ";
        }
        j++;
        // cout << endl;
    }while(next_permutation(q.begin(),q.end()));
    ll ans1;
    rep(j,m){
        bool o = false;
        rep(i,n){
            if(a[j][i]!=x[i]){
                o = false;
                break;
            }
            else{
                o = true;
            }
        }
        if(o){
            ans1 = j+1; 
        }
    }
    ll ans2;
    rep(j,m){
        bool o = false;
        rep(i,n){
            if(a[j][i]!=y[i]){
                o = false;
                break;
            }
            else{
                o = true;
            }
        }
        if(o){
            ans2 = j+1; 
        }
    }
    // cout << ans1 << endl;
    // cout << ans2 << endl;
    cout << abs(ans1-ans2) << endl;
    return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n;
vector<int> v;

signed main() {
    v.pb(2);
    for(int i = 3;i<=100003;i+=2) {
        int b = sqrt(i);
        bool f = true;
        for(auto j : v) {
            if (i%j == 0) {
                f = false;
                break;
            }
            if (j > b) break;
        }
        if (f) v.pb(i);
    }
    cin >> n;
    cout << *lower_bound(all(v), n) << endl;
}



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

signed main(){
    int N, M, Q; cin >> N >> M >> Q;
    vector<vector<int> > num(N + 1, vector<int> (N + 1, 0));
    for(int i = 0; i < M; i++){
        int l, r; cin >> l >> r;
        num[l][r]++;
    }
    vector<vector<int> > sum(N + 1, vector<int> (N + 1, 0));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + num[i + 1][j + 1]; 
       }
    }

    for(int i = 0; i < Q; i++){
        int p, q; cin >> p >> q;
        int ans = sum[q][q] - sum[p -1][q] - sum[q][p - 1] + sum[p - 1][p - 1];
        cout << ans << '\n';
    }
}

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

namespace ABC140_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = nk[0];
            var k = nk[1];
            var s = Console.ReadLine().ToArray();

            var ans = 0;
            var dir = '0';
            var cnt = 1;
            for (int i = 0; i < n; i++)
            {
                if (dir != s[i])
                {
                    ans += cnt - 1;
                    cnt = 0;
                    dir = s[i];
                }
                cnt++;
            }

            ans += cnt - 1;

            Console.WriteLine(Math.Min(ans + 2 * k, n - 1));
        }
    }
}


Measured memory_bytes: 14176
#include <iostream>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

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

	if (A + B > C + D) {
		cout << "Left";
	}
	else if (A + B < C + D) {
		cout << "Right";
	}
	else {
		cout << "Balanced";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define sec second
#define fir first
#define mo  998244353
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)
#define adiii\                               
  ios_base::sync_with_stdio(false);\                                      
  cin.tie(NULL);\
  cout.tie(NULL);									
 
ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}
ll gcd(ll a,ll b) {if (b == 0) return a;return gcd(b, a % b);}

int main(){
	adiii
	ll n;cin>>n;
	map<string,ll> m;
	string s;
	rep(i,0,n) {cin>>s;m[s]++;}
	cout<<m.size();

	
}


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

#define INF 1000000000000
#define MOD 1000000007

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);

    ll h,w;
    cin>>h>>w;
    if(h==1 || w==1){
        cout<<1<<endl;
    }else{
        cout<<(h*w+1)/2<<endl;
    }
    return 0;
}

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

typedef long long ll;
const int maxn = 2e5 + 10;

int main(){
//    freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin>>s;
    int n = s.size();
    vector<int>v;
    v.clear();
    int r1 = 0, r2 = 0;
    for(int i = 0; i < n; ++i){
        if(i&1){
            if(s[i] == '1')continue;
            else r1++;
        }
        else {
            if(s[i] == '0')continue;
            else r1++;
        }
    }
    for(int i = 0; i < n; ++i){
        if(i&1){
            if(s[i] == '0')continue;
            else r2++;
        }
        else {
            if(s[i] == '1')continue;
            else r2++;
        }
    }
    cout << min(r1, r2) << '\n';
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
typedef long long ll;


int main()
{
	int x, y;
	cin >> x >> y;
	if (!(y & 1) && (y >= 2*x && y <= 4*x)) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	
}


Measured memory_bytes: 3628
#include <iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;

int main() {
	int N;
	string w;
	cin >> w;
	N = w.size();
	vector<int> ans(26);
	for (int i = 0; i < N; i++) {
		ans[w[i] - 'a']++;
	}

	for (int i = 0; i < 26; i++) {
		if (ans[i] % 2 != 0) {
			cout << "No" << endl;

			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Salary for a Plumber
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0260

"""
import sys


def solve(n):
    pipes = [int(p) for p in input().split()]
    joints = sorted([int(j) for j in input().split()])
    total_length = sum(pipes)
    record = total_length * n

    while joints:
        total_length += joints.pop()
        n -= 1
        if total_length * n > record:
            record = total_length * n
        else:
            break
    return record


def main(args):
    while True:
        n = int(input())
        if n == 0:
            break
        ans = solve(n)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])



Measured memory_bytes: 7736
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	int d[55];
	for(int i=0;i<n;i++){
		cin >> d[i];
	}
	int ans = 0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			ans += d[i]*d[j];
		}
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long int ll;
using namespace std;

int main(){
    ll a, b, c, k;
    cin>>a>>b>>c>>k;
    if(k <= a+ b){
        if(k>=a)cout<<a<<endl;
        else cout<<k<<endl;
    }
    else{
        cout<<a - (k-(a+b))<<endl;
    }
    return 0;

}

Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define pii pair<int,int> 
signed main(){
    fast;
   	int n;
   	cin>>n;
   	int x[n+1];
   	for(int i=1;i<=n;i++){
   		cin>>x[i];
   	}
   	int ans = 1e18;
   	for(int i=1;i<=100;i++){
   		int cnt = 0;
   		for(int j=1;j<=n;j++){
   			cnt+=(abs(i-x[j])*abs(i-x[j]));
   		}
   		ans = min(ans,cnt);
   	}
   	cout<<ans;
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int H = input[0];
            int W = input[1];

            int[,] dp = new int[H, W];

            int maxWidth = 0;

            for (int i = 0; i < H; i++)
            {
                input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

                for (int j = 0; j < W; j++)
                {
                    if (input[j] == 0)
                    {
                        dp[i, j] = 1;
                        maxWidth = 1;
                    }
                }
            }

            for (int i = 1; i < H; i++)
            {
                for (int j = 1; j < W; j++)
                {
                    if (dp[i, j] != 0)
                    {
                        int temp = Math.Min(dp[i - 1, j], dp[i, j - 1]);
                        dp[i, j] = Math.Min(dp[i - 1, j - 1], temp) + 1;
                        maxWidth = Math.Max(maxWidth, dp[i, j]);
                    }
                }
            }

            Console.WriteLine(maxWidth * maxWidth);
        }
    }
}

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

using namespace std;

const int MAX = 1000100;
bool prime[MAX];

void sieve(){
	fill(prime, prime+MAX, true);
	prime[0] = prime[1] = false;

	for(int i=2; i*i < MAX; i++){
		if(!prime[i]) continue;
		for(int j=i*i; j < MAX; j += i) prime[j] = false;
	}
}


int main(){
	sieve();
	int n;
	while(cin >> n, n){
		int ret = 0;
		for(int i=0; i<= n/2; i++) if(prime[i] && prime[n-i]){ret++;}
		cout << ret << endl;
	}
}

Measured memory_bytes: 2136
# -*- coding: utf-8 -*-
 
num_member, life, num_question = [int(s) for s in input().split()]

win_num_list = [0]*num_member
for i in range(num_question):
  winner_no = int(input())
  win_num_list[winner_no-1] += 1
  
for win_num in win_num_list:
  if life > num_question - win_num:
    print('Yes')
  else:
    print('No')





Measured memory_bytes: 4700
use std::io;

fn main(){
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let (a, b) = {
        let mut ws = buf.split_whitespace();
        let a: i32 = ws.next().unwrap().parse().unwrap();
        let b: i32 = ws.next().unwrap().parse().unwrap();
        (a, b)
    };

    let area = a*b;
    let phi = 2*(a+b);

    println!("{} {}", area, phi);
}


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

using namespace std;

int n; 
bool g[205][205]={};

int h=0,isb=1;

void bfs(int s){
	int vis[n]={}, d[n], col[n];
	queue<int> q;
	q.push(s); d[s]=0; vis[s]=1;
	col[s]=0;
	
	while(!q.empty()){
		int u = q.front();
		q.pop();
		for(int v=0;v<n;v++){
			if(g[u][v]){
				if(!vis[v]){
					vis[v]=1;
					d[v]=d[u]+1;
					h=max(h,d[v]);
					col[v]=1-col[u];
					q.push(v);
				}
				else{
					if(col[v]==col[u]){
						isb=0;
					}
				}
			}
		}
	}
	
}

int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		string s; cin >> s;
		for(int j=0;j<n;j++){
			g[i][j]=(s[j]=='1');
		}
	}
	for(int i=0;i<n;i++){
		bfs(i);
	}
	if(isb){
		cout << h+1 << endl;
	}
	else{
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

int main(){
    int D,T,S;
    cin>>D>>T>>S;
    if(D>S*T){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }

    return 0;
}

Measured memory_bytes: 3632
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 62;
const int inf = 1<<30;
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; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << P.first;
    os << ",";
    os << P.second;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
//fixed<<setprecision(10)<<ans<<endl;

bool is_ok(int x, vi& A, ll V, ll P, ll M){
    int N=A.size();
    if (V==N) return A[x]>=A[N-P];
    int nokori = V-(x+1);
    // debug(N-P-1)
    nokori -= P-1;
    // if (nokori<=0) debug(nokori)
    if (nokori<=0) return A[x]+M>=A[N-P];
    // debug(nokori)
    ll dif_sum = 0;
    for(int i=x+1;i<=N-P;i++){
        dif_sum+=A[i]-A[x];
    }
    // debug(dif_sum)
    // debug((N-P)-nokori)
    ll sub = ((N-P)-x-nokori)*M; //毎ターン埋められる差
    // debug(sub)

    if(A[x]+M<A[N-P]) return false;

    return dif_sum <= sub;




}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,V,P;
    cin >> N>>M>>V>>P;
    vi A(N);
    REP(i,N) cin >> A[i];
    sort(ALL(A));

    // debug(A)
    // is_ok(2,A,V,P,M);
    // return 0;
    int ok = N-1;
    int ng = -1;
    if (!is_ok(0,A,V,P,M)) ng=0;
    while (abs(ok-ng)>1){
        int mid = (ok+ng)/2;
        // debug(mid)
        // cout << ok << " " << ng << "ok,mid,A[mid]" << A[mid]<<endl;
        if(is_ok(mid,A,V,P,M)) ok = mid;
        else ng = mid;
    }
    // debug(ok)

    int ans=N-ok;
    cout << ans << endl;
}

Measured memory_bytes: 640
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val s = sc.next()
  val x, y = sc.nextInt()

  val d = s.split("T", -1).map(_.length)
  val h = d(0)
  var dx = List[Int]()
  for (i <- 2 until d.length by 2) {
    dx ::= d(i)
  }

  var dy = List[Int]()
  for (i <- 1 until d.length by 2) {
    dy ::= d(i)
  }

  println(if (check(dx.toArray, (x - h).abs) && check(dy.toArray, y.abs)) "Yes" else "No")
  
  def check(a: Array[Int], t: Int): Boolean = {
    def subsetSum(a: Array[Int], n: Int, s: Int): Boolean = {
      val dp = Array.fill(n+1, s+1)(false)
      dp(0)(0) = true
      for {
        i <- 1 to n
        j <- 0 to s
      } {
        if (a(i-1) <= j) {
          dp(i)(j) = dp(i-1)(j) || dp(i-1)(j - a(i-1))
        } else {
          dp(i)(j) = dp(i-1)(j)
        }
      }
      dp(n)(s)
    }

    val sum = a.sum
    !(sum < t || (sum - t) % 2 == 1) && subsetSum(a, a.length, (sum - t) / 2)
  }
}


Measured memory_bytes: 59624
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

// vector<int> d[60]; // segmentation fault
int d[60][212345]; 

int main() {
  int n; ll k;
  cin >> n >> k;
  rep(i, n) {
    int a;
    cin >> a;
    a--;
    d[0][i] = a;
  }

  rep(i, 60) {
    if (i==0) continue;
    rep(j, n) {
      d[i][j] = d[i-1][d[i-1][j]];
      // d[i+1][j] = d[i][d[i][j]];
    }
  }

  int v =0;
  for(int i=60; i>=0; i--) {
    ll l = 1ll << i;
    if(l<=k) {
      v = d[i][v];
      k-=l;
    }
  }
  cout << v+1 << endl;

  return 0;
}

Measured memory_bytes: 50720
#include <bits/stdc++.h>
using namespace std;
int v,e;
vector<int> print;
vector<int> edge[10000];
int indeg[10000];
bool alrdy[10000];

void bfs(int start){
	queue<int> next;	next.push(start);
	while(!next.empty()){
		int ne=next.front();	next.pop();
		print.push_back(ne);
		alrdy[ne]=false;
		for(int i=0;i<(int)edge[ne].size();i++){
			int tem=edge[ne][i];
			if(alrdy[tem]&&indeg[tem]>0){
				indeg[tem]--;
				if(indeg[tem]==0){
					next.push(tem);
				}
			}
		}
	}
}

int main(){
	cin>>v>>e;
	for(int i=0;i<10000;i++){
		indeg[i]=0;	alrdy[i]=true;
	}
	int s,t;
	for(int i=0;i<e;i++){
		cin>>s>>t;
		edge[s].push_back(t);
		indeg[t]++;
	}
	for(int i=0;i<v;i++){
		if(alrdy[i]&&indeg[i]==0)	bfs(i);
	}
	for(vector<int>::iterator it=print.begin();it!=print.end();it++){
		cout<<*it<<endl;
	}
	return 0;
}

Measured memory_bytes: 1800
#include <iostream>
using namespace std;
int main(){
    string a[7]={"SUN", "MON", "TUE", "WED", "THU", "FRI",  "SAT"};
    string s;
    cin>>s;
    for(int i=0;i<7;i++){
        if(a[i]==s){
            cout<<7-i<<"\n";
        }
    }
}

Measured memory_bytes: 3416
#include <bits/stdc++.h>
using namespace std;
vector<int> G1[605];
vector<int> G2[605];
double dp1[605];
double dp2[605];
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    for(int i = 0; i < m; i++) {
        int s, t;
        scanf("%d %d", &s, &t);
        G1[s].push_back(t);
        G2[t].push_back(s);
    }
    dp1[1] = 1.0;
    for(int i = 1; i < n; i++) {
        int size = G1[i].size();
        for(int nxt : G1[i]) {
            dp1[nxt] += dp1[i] / size;
        }
    }
    for(int i = n; i > 0; i--) {
        int size = G2[i].size();
        for(int nxt : G2[i]) {
            dp2[nxt] += (dp2[i] + 1.0) / G1[nxt].size();
        }
    }
    double ans = dp2[1];
    for(int i = 1; i < n; i++) {
        if(G1[i].size() <= 1) continue;
        int size = G1[i].size();
        double ma = 0, sum = 0;
        double rate = dp1[i] / size;
        for(int nxt : G1[i]) {
            sum += dp2[nxt];
            ma = max(dp2[nxt], ma);
        }
        ans = min(ans, dp2[1] - sum * rate + (sum - ma) * dp1[i] / (size - 1));
    }
    printf("%.10f\n", ans);
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e9;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n; cin >> n;
    vector<ll> vec(n);
    rep(i, n) cin >> vec[i];

    rep(k, n){
        if(k != n - 1){
            cout << vec[k] << " ";
        }else{
            cout << vec[k];
        }
    }
    cout << endl;

    for(ll i = 1; i < n; i++){
        ll v = vec[i];
        ll j = i - 1;
        while(j >= 0 && vec[j] > v){
            vec[j+1] = vec[j];
            j--;
        }
        vec[j+1] = v;
        rep(k, n){
            if(k != n - 1){
                cout << vec[k] << " ";
            }else{
                cout << vec[k];
            }
        }
        cout << endl;
    }

}


Measured memory_bytes: 3096
#include <iostream>
#include <cmath>
#include <cstdio>
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main(){
    ll n;
    cin>>n;
    ll w[n];
    for(int i=0;i<n;++i){
        cin>>w[i];
    }
    ll sum=0;
    for(int i=0;i<n;++i){
        sum+=w[i];
    }
    ll flag=0;
    ll minT=10000;
    for(int i=0;i<n;++i){
        flag+=w[i];
        sum-=w[i];
        minT=min(minT,abs(sum-flag));
    }
    cout<<minT<<endl;
}

Measured memory_bytes: 256
import java.util.*;
 
class Main {
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt();
//        int b = sc.nextInt();
//        String s = sc.next();
//        if ((a * b) % 2 == 0)
//            System.out.println("Even");
//        else
//            System.out.println("Odd");
        System.out.println(2 * Math.PI * R);
        
	}
}

Measured memory_bytes: 36016
#include <iostream>
#include <vector>
#include <limits>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>
#include <unordered_set>
#include <deque>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

struct Edge{
    uint node_to;
    int weight;
    explicit Edge(uint _node_to, int _weight): node_to(_node_to), weight(_weight){};
};


struct Node{
    bool visited{false};
    uint id{numeric_limits<uint>::max()};
    uint position{numeric_limits<uint>::max()};
    vector<Edge> adjacent_node{};
    explicit Node() = default;;
};



int main() {
    uint N, M;
    cin >> N >> M;
    vector<uint> lefts(M, 0);
    vector<uint> rights(M, 0);
    vector<uint> distances(M, 0);
    for (auto &&i: irange((unsigned int) 0, M)){
        uint l, r;
        cin >> l >> r;
        lefts.at(i) = l - 1;
        rights.at(i) = r - 1;
        cin  >> distances.at(i);
    }

    vector<Node> nodes(N, Node());
    for (auto &&i: irange((unsigned int) 0, N)){
        nodes.at(i).id = i;
    }

    for (auto &&i: irange((unsigned int) 0, M)){
        nodes.at(lefts.at(i)).adjacent_node.emplace_back(Edge(rights.at(i), distances.at(i)));
        nodes.at(rights.at(i)).adjacent_node.emplace_back(Edge(lefts.at(i), -distances.at(i)));
    }

    unordered_set<uint> unsettled;
    for (auto &&i: irange((unsigned int) 0, N)){
        unsettled.insert(i);
    }

    while (!unsettled.empty()){
        uint first_index = *unsettled.begin();

        nodes.at(first_index).visited = true;
        nodes.at(first_index).position = 0;

        deque<uint> stack{first_index};
        while (!stack.empty()){
            uint visiting = stack.back();
            stack.pop_back();
            unsettled.erase(visiting);
            for (auto &&edge: nodes.at(visiting).adjacent_node){
                if (!nodes.at(edge.node_to).visited){
                    nodes.at(edge.node_to).visited = true;
                    nodes.at(edge.node_to).position = nodes.at(visiting).position + edge.weight;
                    stack.push_back(edge.node_to);
                }
            }
        }
    }

    for (auto &&i: irange((unsigned int) 0, M)){
        if (nodes.at(rights.at(i)).position - nodes.at(lefts.at(i)).position != distances.at(i)){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 16444
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++)
    {
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    int chk=a.at(n-1);
    int ans=0;
    for(int i=0; i<n-1; i++)
    {
        if(abs(chk-a.at(i)>=ans))
        {
            ans=a.at(i);
        }
    }
    cout << chk <<" "<< ans << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll h,w,k;


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

  cin>>h>>w>>k;
  vector<string> s(h);
  REP(i,h)cin>>s[i];

  ll check=0;
  REP(i,h){
    REP(j,w){
      if(s[i][j]=='1')
        check++;
    }
  }

  if(check<=k){
    cout<<0<<endl;
    return 0;
  }


  vector<vll> remind(h+1,vll(w+1));
  REP(i,h){
    REP(j,w){
      remind[i][j+1] = remind[i][j];
      if(s[i][j]=='1')
        remind[i][j+1]++;
    }
  }

  ll ans=LLINF;
  REP(bit, (1<<(h-1))){
    ll lw=0;
    ll rw=0;
    ll cnt=0;
    bool canflag=true;
    REP(i,w){
      rw = i+1;
      ll sum=0;
      ll maxsum=0;
      REP(j,h){
        sum+=remind[j][rw]-remind[j][lw];
        maxsum = max(maxsum,sum);
        if((bit>>j)&1)
          sum=0;
      }

      if(maxsum>k){
        if(lw==rw-1){
          canflag=false;
          break;
        }
        else
          lw=rw-1;
        cnt++;
      }
    }

    REP(j,h){
      if((bit>>j)&1)
        cnt++;
    }

    if(canflag)
      ans = min(ans,cnt);
  }

  cout<<ans<<endl;

}



Measured memory_bytes: 384
#include <cstdio>
typedef long long lld;
const int LOGN = 60;
const int MOD = 1e9+7;
int cnt[LOGN]{ };
lld A;
int N;

int main() {
  scanf("%d", &N);
  int ret = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%lld", &A);
    for (int j = 0; j < LOGN; ++j) {
      int two = (1LL << j) % MOD;
      int val;
      if ((A >> j) & 1) {
        val = 1LL * two * (i - cnt[j]) % MOD;
        ++cnt[j];
      } else {
        val = 1LL * two * cnt[j] % MOD;
      }
      ret = (1LL * ret + val) % MOD;
    }
  }
  printf("%d\n", ret);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#define Limit 100
#define Size 16
int swap_upper(int*, int*, int);
int swap_lower(int*, int*, int);
int swap_left(int*, int*, int);
int swap_right(int*, int*, int);
int fair_evaluator(int*, int*);
int Dfs(int*, int*, int, int, int);
int main(void)
{
  int i, e = sqrt(Size), dis, init[Size], goal[Size] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0};
  for (i = 0; i < Size; i++) scanf("%d", &init[i]);
  dis = fair_evaluator(init, goal);
  for (i = dis; i < Limit; i++) {
    if (Dfs(init, goal, 0, -1, i)) {
      printf("%d\n", i);
      break;
    }
  }
}
int swap_upper(int *board, int *next, int prev)
{
  int i, pos, e = sqrt(Size);
  for (i = 0; i < Size; i++) {
    if (!board[i]) pos = i;
  }
  if (!(pos / e) || prev == 1) return 0;
  else {
    memcpy(next, board, sizeof(int) * Size);
    next[pos] = board[pos - e];
    next[pos - e] = board[pos];
  }
  return 1;
}
int swap_lower(int *board, int *next, int prev)
{
  int i, pos, e = sqrt(Size);
  for (i = 0; i < Size; i++) {
    if (!board[i]) pos = i;
  }
  if ((pos / e) == e - 1 || prev == 0) return 0;
  else {
    memcpy(next, board, sizeof(int) * Size);
    next[pos] = board[pos + e];
    next[pos + e] = board[pos];
  }
  return 1;
}
int swap_left(int *board, int *next, int prev)
{
  int i, pos, e = sqrt(Size);
  for (i = 0; i < Size; i++) {
    if (!board[i]) pos = i;
  }
  if (!(pos % e) || prev == 3) return 0;
  else {
    memcpy(next, board, sizeof(int) * Size);
    next[pos] = board[pos - 1];
    next[pos - 1] = board[pos];
  }
  return 1;
}
int swap_right(int *board, int *next, int prev)
{
  int i, pos, e = sqrt(Size);
  for (i = 0; i < Size; i++) {
    if (!board[i]) pos = i;
  }
  if ((pos % e) == e - 1 || prev == 2) return 0;
  else {
    memcpy(next, board, sizeof(int) * Size);
    next[pos] = board[pos + 1];
    next[pos + 1] = board[pos];
  }
  return 1;
}
int fair_evaluator(int *board, int *goal)
{
  int i, j, e = sqrt(Size), score = 0;
  for (i = 1; i < Size; i++) {
    int x1, y1, x2, y2;
    for (j = 0; j < Size; j++) {
      if (board[j] == i) {
        x1 = j % e;
        y1 = j / e;
      }
      if (goal[j] == i) {
        x2 = j % e;
        y2 = j / e;
      }
    }
    score += fabs(x1 - x2) + fabs(y1 - y2);
  }
  return score;
}
 int Dfs(int *board, int *goal, int depth, int prev, int limit)
{
  int dis = fair_evaluator(board, goal), next[Size];
  if (!dis) return 1;
  else if (depth + dis > limit) return 0;
  if (swap_upper(board, next, prev)) {
    if (Dfs(next, goal, depth + 1, 0, limit)) return 1;
  }
  if (swap_lower(board, next, prev)) {
    if (Dfs(next, goal, depth + 1, 1, limit)) return 1;
  }
  if (swap_left(board, next, prev)) {
    if (Dfs(next, goal, depth + 1, 2, limit)) return 1;
  }
  if (swap_right(board, next, prev)) {
    if (Dfs(next, goal, depth + 1, 3, limit)) return 1;
  }
  return 0;
}


Measured memory_bytes: 2096
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

int dp[3001];
void solve() {
	int n, t; cin >> n >> t;
	vector<int> a(n), b(n);
	vector<P> v;
	rep(i, n) {
		cin >> a[i] >> b[i];
		v.push_back({ a[i],b[i] });
	}
	sort(v.begin(), v.end());
	rep(i, n) {
		a[i] = v[i].first, b[i] = v[i].second;
	}
	rep(i, n) {
		per(j, t) {
			int x = j + a[i];
			x = min(x, t);
			dp[x] = max(dp[x], dp[j] + b[i]);
		}
	}
	int ans = 0;
	rep(i, t + 1) {
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 384
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstring>
#include <math.h>
#include <set>
#include <vector>
#include <algorithm>
#include <map>


using namespace std;

typedef long long ll;
#define INF 0x3f3f3f3f
#define ESP 1e-8
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
const double PI = acos(-1.0);

int main(){
    int n, T, a, b, ans;
    while(scanf("%d%d", &n, &T)!=EOF){
        ans = INF;
        for(int i = 1; i <= n; i++){
            scanf("%d%d", &a, &b);
            if(b <= T)
                ans = MIN(ans, a);
        }
        if(ans == INF)
            printf("TLE\n");
        else
            printf("%d\n", ans);
    }

    return 0;
}

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


int main(){
  int n;
  int u,k;
  int v;
  int map[100][100]={0};
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> u >> k;
    for(int j=0;j<k;j++){
      cin >> v;
      map[u-1][v-1]=1;
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cout << map[i][j];
      if(j<n-1){
        cout << " ";
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3132
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <queue>
#include <tuple>

using namespace std;

int64_t x[100'000];
int64_t y[100'000];

int xOrdered[100'000];
int yOrdered[100'000];

int64_t parent[100'000];
int depth[100'000];

int64_t findRoot(int node)
{
    int curr = node;
    while (parent[curr] != curr)
        curr = curr[parent];
    return curr;
}

void mergeSet(int r0, int r1)
{
    if (depth[r0] < depth[r1])
    {
        parent[r0] = r1;
    }
    else if (depth[r0] > depth[r1])
    {
        parent[r1] = r0;
    }
    else
    {
        parent[r0] = r1;
        depth[r1]++;
    }
}

int64_t dist(int n0, int n1)
{
    return min(abs(x[n0] - x[n1]), abs(y[n0] - y[n1]));
}

int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }

    for (int i = 0; i < N; i++)
    {
        xOrdered[i] = yOrdered[i] = i;
    }
    sort(xOrdered, xOrdered + N, [](const int &lh, const int &rh) {
        return x[lh] < x[rh];
    });
    sort(yOrdered, yOrdered + N, [](const int &lh, const int &rh) {
        return y[lh] < y[rh];
    });

    auto cmp = [](const tuple<int, int, int64_t> &lh, const tuple<int, int, int64_t> &rh) {
        return get<2>(lh) > get<2>(rh);
    };
    priority_queue<tuple<int, int, int64_t>, vector<tuple<int, int, int64_t>>, decltype(cmp)> edges(cmp);
    for (int i = 0; i < N - 1; i++)
    {
        edges.push(make_tuple(xOrdered[i], xOrdered[i + 1], dist(xOrdered[i], xOrdered[i + 1])));
        edges.push(make_tuple(yOrdered[i], yOrdered[i + 1], dist(yOrdered[i], yOrdered[i + 1])));
    }

    int64_t cost = 0;
    for (int i = 0; i < N; i++)
    {
        parent[i] = i;
        depth[i] = 0;
    }

    for (int i = 0; i < N - 1; i++)
    {
        while (findRoot(get<0>(edges.top())) == findRoot(get<1>(edges.top())))
        {
            edges.pop();
        }
        auto &e = edges.top();
        cost += get<2>(e);
        mergeSet(findRoot(get<0>(e)), findRoot(get<1>(e)));
    }

    cout << cost << endl;

    return 0;
}

Measured memory_bytes: 8688
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    var x = 0;
    var maximam = 0;
	var n = parseInt(input[0],10);
    var s = input[1];
    for(var i=0;i<s.length;i++) {
      if(s[i] === "I") {
        x++;
        maximam=Math.max(x,maximam);
      } else {
        x--;
      }
    }
    console.log(maximam);
    
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372