akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <set>

using namespace std;

int check(vector<int> &v) {
	int n = v.size();
	vector<int> cumuls(n + 1, 0);

	for (int i = 0; i < n; i++) {
		cumuls[i+1] = cumuls[i] ^ v[i];
	}

	vector<int> pos(n / 2, -1);
	set<int> vals;
	for (int i = 0; i < n; i++) {
		int x = v[i];
		if (pos[x] == -1) {
			pos[x] = i;
		} else {
			auto val = cumuls[i+1] ^ cumuls[pos[x]];
			vals.insert(val);
		}
	}

	if (vals.size() > 1) {
		return -1;
	} else {
		return *vals.begin();
	}
}

void check_for_small_case() {
	int m = 2;
	int limit = 1 << m;

	vector<int> v(limit * 2);
	for (int i = 0; i < limit; i++) {
		v[2*i] = i;
		v[2*i + 1] = i;
	}

	do {
		auto val = check(v);
		if (val == 3) {
			// if (v[0] != 0 || v[2] != 0) {
			// 	continue;
			// }
			printf("%3d: ", val);
			for (auto x: v) {
				printf(" %2d", x);
			}
			printf("\n");
		}
	} while (next_permutation(v.begin(), v.end()));
}

int main() {
	// check_for_small_case();
	// exit(0);

	int m, k;
	cin >> m >> k;

	if (k >= (1 << m)) {
		cout << -1 << endl;
		return 0;
	}

	if (m == 1) {
		if (k == 0) {
			cout << "0 0 1 1" << endl;
		} else {
			cout << -1 << endl;
		}
		return 0;
	}

	int x = 1 << m;
	vector<int> ret;

	for (int i = 0; i < x; i++) {
		if (i != k) {
			ret.emplace_back(i);
		}
	}
	ret.emplace_back(k);
	for (int i = x - 1; i >= 0; i--) {
		if (i != k) {
			ret.emplace_back(i);
		}
	}
	ret.emplace_back(k);

	for (int i = 0; i < ret.size(); i++) {
		if (i != 0) {
			cout << " ";
		}
		cout << ret[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 2932
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

int main()
{
	int x;
	cin >> x;
	if (30 <= x) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3588
#include <stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    
    int a[n];
    int i;
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int max=0;
    int min=1145141919;
    for(i=0;i<n;i++){
        if(a[i]>max){
            max=a[i];
        }
        if(a[i]<min){
            min=a[i];
        }
    }
    
    printf("%d",max-min);
    return 0;
}

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

typedef struct
{
	int parent;
	int depth;
	int size;
	int *children;
} node;

void set_depth(node *data, int x, int d)
{
	data[x].depth = d;
	for(int i = 0; i < data[x].size; ++i)
	{
		set_depth(data, data[x].children[i], d+1);
	}
}

int main()
{
	int n;
	node data[100000];
	
	scanf("%d", &n);
	for(int i = 0; i < n; ++i)
	{
		data[i].parent = -1;
		data[i].depth  = -1;
	}
	
	for(int i = 0; i < n; ++i)
	{
		int x, k, c;
		scanf("%d %d", &x, &k);
		
		data[x].size = k;
		data[x].children = malloc(sizeof(int) * k);
		for(int j = 0; j < k; ++j)
		{
			scanf("%d", &c);
			data[x].children[j] = c;
			data[c].parent = x;
		}
	}
	
	for(int i = 0; i < n; ++i)
	{
		if(data[i].parent == -1)
		{
			set_depth(data, i, 0);
			break;
		}
	}
	
	for(int i = 0; i < n; ++i)
	{
		printf("node %d: parent = %d, depth = %d, ", i, data[i].parent, data[i].depth);
		
		if(data[i].parent == -1)
		{
			printf("root");
		}
		else if(data[i].size == 0)
		{
			printf("leaf");
		}
		else
		{
			printf("internal node");
		}
		
		printf(", [");
		for(int j = 0; j < data[i].size; ++j)
		{
			if(j != 0) { printf(", "); }
			printf("%d", data[i].children[j]);
		}
		printf("]\n");

		free(data[i].children);
	}
}



Measured memory_bytes: 7492
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main() {
    int N; cin>>N;
    int H[N];
    REP(i,N){
        cin>>H[i];
    }
    int ans=1;
    int tmp=H[0];
    for(int i=1;i<N;i++){
        if(H[i]>=tmp){
            ans++;
            tmp=H[i];
        }
    }
    cout<<ans<<endl;
}

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

int n,k;
vector<int> pos, neg;

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {int x;
        scanf("%d",&x); if(x<0) neg.push_back(-x); else pos.push_back(x);
    }
    sort(neg.begin(),neg.end());
    int ans = 1e9;
if(pos.size()>=k) ans=min(ans,pos[k-1]);
if(neg.size()>=k) ans=min(ans,neg[k-1]);
for(int i=1;i<k;i++)
{
if(pos.size()<i) break;
int tmp = k-i;
if(neg.size()<tmp) continue;
int co = pos[i-1] + neg[tmp-1] + min(pos[i-1],neg[tmp-1]);
ans = min(ans,co);
}
printf("%d\n",ans);
    return 0;
}

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

int main(){
    LL n;
    cin >> n;
    LL ans1 = 1;
    LL ans2 = 1;
    for(int i = 0; i < n; i++){
        int b;
        cin >> b;
        ans1 *= 3;
        if(b % 2 == 0){
            ans2 *= 2;
        }
    }
    cout << ans1 - ans2 << endl;
}


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

#define N  1050
int max(int a, int b);
int lcs();

char a[N], b[N];

int main()
{
  int n, i;
  scanf("%d\n", &n);
  for ( i = 0; i < n; i++ ){
    fgets(a, N, stdin);
    fgets(b, N, stdin);
    printf("%d\n", lcs());
  }
  return 0;
}

int lcs()
{
 int c[N+1][N+1];
   int aasize, bbsize;
  int i, j, mx;

  memset(c, 0, sizeof(c));

    aasize = strlen(a) - 1;
    bbsize = strlen(b) - 1;


  for (i = 1; i < aasize + 1; i++) {
    for (j = 1; j < bbsize + 1; j++) {
       mx = max(c[i][j - 1], c[i - 1][j]);
      if (a[i - 1] == b[j - 1]) {
        mx = max(mx, c[i - 1][j - 1] + 1);
      }
      c[i][j] = mx;
    }
  }

  return c[aasize][bbsize];
}

int max(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}



Measured memory_bytes: 6100
n, k = map(int, input().split())
lst = list(map(int, input().split()))

ans = 0
MOD = 10**9 + 7
dp = [[0] * (k+1) for _ in range(n+1)]
dp[0][0] = 1

for i in range(n):
    sums = [0] * (k+2)
    for j in range(k+1): #|累積和
        sums[j+1] = sums[j] + dp[i][j]
        sums[j+1] %= MOD
    for j in range(k+1):
        dp[i+1][j] = sums[j+1] - sums[max(0, j-lst[i])]
        dp[i+1][j] %= MOD #累積和を利用した区間和
print(dp[n][k])

Measured memory_bytes: 219272
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

int n;

int main()
{
	cin >> n;
	if (n / 10 == 9 || n % 10 == 9)
		printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int u[2],v[2],n,m,i,j,gr[3][100005],a[100005],ty[100005],tr[3][100005],up;
int lowbit(int p){return p&-p;}
void ins(int t,int p)
{
	while(p<=n)
	{
		tr[t][p]++;
		p+=lowbit(p);
	}
}
int ask(int t,int p)
{
	int ans=0;
	while(p)
	{
		ans+=tr[t][p];
		p-=lowbit(p);
	}
	return ans;
}
void ed()
{
	printf("No\n");
	exit(0);
}
int main()
{
	scanf("%d",&n);
	for(i=0;i<3;i++)for(j=1;j<=n;j++)scanf("%d",&gr[i][j]);
	for(i=1;i<=n;i++)
	{
		if(gr[0][i]%3!=1&&gr[2][i]%3!=1)ed();
		if(gr[0][i]%3==1)
		{
			if(gr[1][i]==gr[0][i]+1&&gr[2][i]==gr[1][i]+1)
			{
				ty[i]=0;
				a[i]=gr[0][i]/3+1;
			}
			else ed();
		}
		else
		{
			if(gr[1][i]==gr[2][i]+1&&gr[0][i]==gr[1][i]+1)
			{
				ty[i]=1;
				a[i]=gr[2][i]/3+1;
			}
			else ed();
		}
		if(i%2!=a[i]%2)ed();
	}
	u[0]=u[1]=v[1]=v[0]=0;up=0;
	for(i=1;i<=n;i++)
	{
		v[i%2]+=ty[i];
		u[i%2]=(u[i%2]+ask(i%2,n-a[i]+1))%2;
		up=(up+ask(2,n-a[i]+1))%2;
		ins(i%2,n-a[i]+1);
		ins(2,n-a[i]+1); 
	}
	if((v[0]+v[1])%2==up&&(u[0]+v[0])%2==up&&(u[1]+v[1])%2==up)printf("Yes\n");
	else printf("No\n");
	return 0;	
} 

Measured memory_bytes: 3328
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var N int
	fmt.Scan(&N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	as := make([]int, N)
	for i := range as {
		sc.Scan()
		as[i], _ = strconv.Atoi(sc.Text())
		as[i]--
	}

	target := 0
	count := 0
	for _, a := range as {
		if target != a {
			count++
			continue
		}
		target++
	}
	if target == 0 {
		fmt.Println(-1)
		return
	}
	fmt.Println(count)
}


Measured memory_bytes: 5064
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<28;
void solve(int a){cout<<( a?"Yes":"No")<<endl;}
int main(){
	int n;
	cin >>n;
	int ans=0;
	int c=0;
	for(int i=1;i<=n;i++){
		c=0;
		if(i%2==1){
			
			for(int j=1;j<=n;j++){
				if(i%j==0){
					c++;
				}
			}
			if(c==8){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N int
	fmt.Scanf("%d", &N)
	d := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &d[i])
	}
	sum := 0
	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			sum += d[i] * d[j]
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void){
	char words[128];
	int i,j,zure,end;

	for(i=0;i < 128;i++){
		words[i] = '\0';
	}
	while(scanf("%[^\n]",words) != EOF){// 文字列を配列に読み込む
	//scanf("%[^\n]",words);
		getchar();
		zure=0,end=0;
		for(j=0;words[j] != '\0';j++){
			for(i=1;i <= 26;i++){// 1つずつずらしていく
				if((j > 0 && words[j-1] == ' ' || j == 0) && (words[j]+i-26 == 't' || words[j]+i == 't') && (words[j+1]+i-26 == 'h' || words[j+1]+i == 'h')){//1文字目t、2文字目h
						if((words[j+2]+i-26 == 'e' || words[j+2]+i == 'e')/* && (words[j+3] == ' ' || words[j+3] == '\0' || words[j+3] == '.')*/){// the
								zure = i;
								end = 1;
								break;
						}else if((words[j+2]+i-26 == 'a' || words[j+2]+i == 'a') && (words[j+3]+i-26 == 't' || words[j+3]+i == 't')/* && (words[j+4] == ' ' || words[j+4] == '\0' || words[j+4] == '.')*/){// that
								zure = i;
								end = 1;
								break;
						}else if((words[j+2]+i-26 == 'i' || words[j+2]+i == 'i') && (words[j+3]+i-26 == 's' || words[j+3]+i == 's')/* && (words[j+4] == ' ' || words[j+4] == '\0' || words[j+4] == '.')*/){// this
								zure = i;
								end = 1;
								break;
						}
				}
			}
			if(end == 1) break;
		}

		for(i=0;words[i] != '\0';i++){
			if(words[i] >= 'a' && words[i] <= 'z'){
				if(words[i]+zure > 'z'){
					printf("%c",words[i]+zure-26);
				}else{
					printf("%c",words[i]+zure);
				}
			}else{
				printf("%c",words[i]);
			}
		}
		printf("\n");
		for(i=0;i < 128;i++){
			words[i] = '\0';
		}
	}
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007



ll n, s[110000], a, b, nm = INF;

int main() {
	cin >> n;
	REP(i, n)cin >> s[i];
	sort(s, s + n, greater<ll>());
	a = s[0];
	REPO(i, n - 1) {
		if (nm > min(abs(a / 2 - s[i]), abs((a + 1) / 2 - s[i]))) {
			nm = min(abs(a / 2 - s[i]), abs((a + 1) / 2 - s[i]));
			b = s[i];
		}
	}
	cout << a << " " << b << endl;
}




Measured memory_bytes: 1024
package main

import ("fmt")

func main(){
	var N, M, count int
	var K [30]int
	var A [100][100]int
	var ans [100]int

	fmt.Scan(&N, &M)

	for i := 0 ; i < 100 ; i++{
		ans[i] = 0
	}
	for i := 0 ; i < N ; i++{
		fmt.Scan(&K[i])

		for j := 0 ; j < K[i] ; j++ {
			fmt.Scan(&A[i][j])
		}	
	}


	for i := 0 ; i < N ; i++ {
		for j := 0 ; j < K[i] ; j++ {
			ans[A[i][j]]++
		}
	}
	count = 0
	for i := 1 ; i <= 30 ; i++ {
	//	fmt.Print(ans[i])
			if ans[i] == N {
			//	fmt.Printf("%d ", i)
				count++;
		}
	}
	fmt.Println()
	fmt.Println(count)

}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;

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

	int a = N / 4;
	int b = N / 7;

	for (int i = 0; i <= a; i++)
	{
		for (int j = 0; j <= b; j++)
		{
			int ans = 4 * i + 7 * j;
			if (ans == N)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<cstdio>
using namespace std;
int n;
int main(){
    cin>>n;
    int mn=1e6+5,mx=-1e6-5,pos1,pos2;
    for (int i=1;i<=n;i++){
        int x;cin>>x;
        if (mn>x){
            mn=x;
            pos1=i;
        }
        if (mx<x){
            mx=x;
            pos2=i;
        }
    }
    printf("%d\n",2*n-1);
    if (abs(mn)<abs(mx)){
        for (int i=1;i<=n;i++){
            printf("%d %d\n",pos2,i);
        }
        for (int i=2;i<=n;i++){
            printf("%d %d\n",i-1,i);
        }
    }
    else{
        for (int i=1;i<=n;i++){
            printf("%d %d\n",pos1,i);
        }
        for (int i=n;i>=2;i--){
            printf("%d %d\n",i,i-1);
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <cctype>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

string rotate(string s) {
  return s.substr(1) + string(1,s[0]);
}

bool equal(char a, char b) {
  if (isupper(a)) {
    return (islower(b) && toupper(b) == a);
  } else {
    return (isupper(b) && tolower(b) == a);
  }
}

string a[9];
vector<string> v;
int solve(int S, int nest) {
  if (nest == 9) {
//    cout << S << endl;
    return 1;
  }
//  cout << nest << endl;
  
  int res = 0;
  int sz = v.size();
  REP(j,9) {
    if (!((S>>j) & 1)) {
      string s = a[j];
      REP(i,4) {
        if (nest == 0) {
          v.push_back(s);
          res += solve(S|(1<<j),nest+1);
          v.pop_back();
        } else if (nest == 1 || nest == 2) {
          if (equal(v[sz-1][1], s[3])) {
            v.push_back(s);
            res += solve(S|(1<<j),nest+1);
            v.pop_back();
          }
        } else if (nest % 3 == 0) {
          if (equal(v[sz-3][2], s[0])) {
            v.push_back(s);
            res += solve(S|(1<<j),nest+1);
            v.pop_back();
          }
        } else {
          if (equal(v[sz-1][1], s[3]) && equal(v[sz-3][2], s[0])) {
            v.push_back(s);
            res += solve(S|(1<<j),nest+1);
            v.pop_back();
          }
        }

        s = rotate(s);
      }
    }
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  while(n--) {
    REP(i,9)
      cin >> a[i];
    int res = solve(0, 0);
    cout << res << endl;;
  }
}

Measured memory_bytes: 936
import java.util.*;
 
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if((b - a) % 2 == 0){
        	System.out.println("Alice");
        }else{
        	System.out.println("Borys");
        }
	}
}

Measured memory_bytes: 35760
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n; cin >> n;
  vector<int> p(n), q(n), a(n);

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

  int cnt = 0, pi = 0, qi = 0;
  do {
    bool is_same_p = true;
    bool is_same_q = true;
    for (int i = 0; i < n; i++) {
      if (a[i] != p[i]) { is_same_p = false; }
      if (a[i] != q[i]) { is_same_q = false; }
    }
    if (is_same_p) { pi = cnt; }
    if (is_same_q) { qi = cnt; }
    cnt++;
  } while (next_permutation(a.begin(), a.end()));

  cout << abs(pi - qi) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define str string
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, N = 1e5 + 10;
const ll LINF = LLONG_MAX;
int main() {
    fast();
   
 	ll a[3];
 	cin >> a[0] >> a[1] >> a[2];
 	sort(a,a+3);
 	cout<<(a[0]*a[1])/2;


    cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}

int main() {
  ll n;
  cin >> n;
  set <ll> s;
  rep(i, n) {
    ll a;
    cin >> a;
    s.insert(a);
  }
  for (auto value : s) {
    if (value == *begin(s)) {
      cout << value;
    } else {
      cout << ' ' << value;
    }
  }
  cout << endl;
}


Measured memory_bytes: 7784
a,b,c =map(int,input().split())

s = a + int(str(b)+str(c))
t = c + int(str(b)+str(a))
u = b + int(str(c)+str(a))
v = a + int(str(c)+str(b))
w = c + int(str(a)+str(b))
x = b + int(str(a)+str(c))

print(max(s,t,u,v,w,x))

Measured memory_bytes: 3064
#include <algorithm>
#include <cstdlib>
#include <complex>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, d;
  scanf("%d %d", &n, &d);
  
  vector<vector<int> > X(n);
  for (int i = 0; i < n; i++) {
    X[i] = vector<int>(d);

    for (int j = 0; j < d; j++) {
      int Xid;
      scanf("%d", &Xid);
      X[i][j] = Xid;
    }
  }

  int result = 0;
  
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int r = 0;
      for (int k = 0; k < d; k++) {
        r += pow(X[i][k] - X[j][k], 2);
      }
      double distance = sqrt(r);
      if (distance == floor(distance)) {
        result++;
      }
    }
  }

  cout << result << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner in = new Scanner(System.in);
    int a = in.nextInt();
    int b = in.nextInt();
    int d = a / b;
    int r = a % b;
    double f = 1.0 * a / b;
    
    System.out.printf("%d %d %.5f",d,r,f);
  }
}

Measured memory_bytes: 26456
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// input scanner
var sc = bufio.NewScanner(os.Stdin)

const (
	initialBufSize = 10e4
	maxBufSize     = 10e6
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// util
func max(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n > ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

func min(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n < ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

// main
func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	x := nextInt()
	ans := (x/500)*1000 + ((x%500)/5)*5
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  int N;
  cin>>N;
  if(N%10==0||N%10==1||N%10==6||N%10==8){
    cout<<"pon"<<endl;
  }
  else if(N%10==3){
    cout<<"bon"<<endl;
  }
  else cout<<"hon"<<endl;
  
  return 0;
}

Measured memory_bytes: 3596
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 08/22/20 18:13:52
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  int pre = 0;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    int a; cin>>a;
    if (pre > a) {
      ans += pre-a;
    } else {
      pre = a;
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int a, b;
	cin >> a >> b;
	cout << abs(a - b) << endl;
	return 0;
}


Measured memory_bytes: 3100
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  while (n--) {
    int k, p;
    cin >> k >> p;
    k %= p;
    if (!k) k += p;
    cout << k << endl;
  }
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;

#define pb push_back
#define fst first
#define snd second
#define ALL(cont) cont.begin(), cont.end()
#define mset(a,b) memset(a,b,sizeof(a));
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i, a, b) for (int i = a, almo5t = b; i < almo5t; ++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
struct pt {  // for 3D add z coordinate
	double x,y;
	pt(double x, double y):x(x),y(y){}
	pt(){}
	double norm2(){return *this**this;}
	double norm(){return sqrt(norm2());}
	bool operator==(pt p){return abs(x-p.x)<=EPS&&abs(y-p.y)<=EPS;}
	pt operator+(pt p){return pt(x+p.x,y+p.y);}
	pt operator-(pt p){return pt(x-p.x,y-p.y);}
	pt operator*(double t){return pt(x*t,y*t);}
	pt operator/(double t){return pt(x/t,y/t);}
	double operator*(pt p){return x*p.x+y*p.y;}
//	pt operator^(pt p){ // only for 3D
//		return pt(y*p.z-z*p.y,z*p.x-x*p.z,x*p.y-y*p.x);}
	double angle(pt p){ // redefine acos for values out of range
		return acos(*this*p/(norm()*p.norm()));}
	pt unit(){return *this/norm();}
	double operator%(pt p){return x*p.y-y*p.x;}
	// 2D from now on
	bool operator<(pt p)const{ // for convex hull
		return x<p.x-EPS||(abs(x-p.x)<=EPS&&y<p.y-EPS);}
	bool left(pt p, pt q){ // is it to the left of directed line pq?
		return (q-p)%(*this-p)>EPS;}
	pt rot(pt r){return pt(*this%r,*this*r);}
	pt rot(double a){return rot(pt(sin(a),cos(a)));}
};
pt ccw90(1,0);
pt cw90(-1,0);
int sgn2(double x){return x<0?-1:1;}
struct ln {
	pt p,pq;
	ln(pt p, pt q):p(p),pq(q-p){}
	ln(){}
	bool has(pt r){return dist(r)<=EPS;}
	bool seghas(pt r){return has(r)&&(r-p)*(r-(p+pq))<=EPS;}
//	bool operator /(ln l){return (pq.unit()^l.pq.unit()).norm()<=EPS;} // 3D
	bool operator/(ln l){return abs(pq.unit()%l.pq.unit())<=EPS;} // 2D
	bool operator==(ln l){return *this/l&&has(l.p);}

	double angle(ln l){return pq.angle(l.pq);}
	int side(pt r){return has(r)?0:sgn2(pq%(r-p));} // 2D
	pt proj(pt r){return p+pq*((r-p)*pq/pq.norm2());}
	pt ref(pt r){return proj(r)*2-r;}
	double dist(pt r){return (r-proj(r)).norm();}

};
int main()
{
    FIN;
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
#define endl '\n'
#endif
    double x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;
    ln l = ln(pt(x1,y1),pt(x2,y2));
    int q;cin>>q;
    while(q--){
        double x,y;cin>>x>>y;
        pt pr = l.proj(pt(x,y));
        cout<<fixed<<setprecision(12)<<pr.x<<' '<<pr.y<<endl;
    }
    return 0;
}



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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main(){
    char a,b;
    cin >> a >> b;
    if(a == 'H') cout << b << '\n';
    else if(b == 'H') cout << 'D' << '\n';
    else cout << 'H' << '\n';
    return 0;
}

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


void solve(long long A, long long B, long long C, long long D){
    long long start = min(B,D);
    long long end = max(A,C);
    long long ans = 0;
    ans = max(ans,start-end);
    cout << ans << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}


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

int main() {
	int n, m;
	cin >> n >> m;

	vector<int> a(m);
	int odd = 0;
	for (int i = 0; i < m; i++) {
		cin >> a[i];
		if (a[i] % 2 == 1) odd++;
	}

	if (m == 1) {
		if (a[0] == 1) {
			cout << a[0] << endl;
			cout << 1 << endl;
			cout << 1 << endl;
		} else {
			cout << a[0] << endl;
			cout << 2 << endl;
			cout << a[0] - 1 << " " << 1 << endl;
		}
		return 0;
	}

	if (odd >= 3) {
		cout << "Impossible" << endl;
		return 0;
	}

	for (int i = 0; i < m; i++) {
		if (a[i] % 2 == 1) {
			swap(a[i], a[0]);
			break;
		}
	}

	for (int i = m - 1; i >= 0; i--) {
		if (a[i] % 2 == 1) {
			swap(a[i], a[m - 1]);
			break;
		}
	}

	vector<int> b;
	for (int i = 0; i < m; i++) {
		if (i == 0) {
			b.push_back(a[i] + 1);
		} else if (i == m - 1) {
			if (a[i] >= 2) {
				b.push_back(a[i] - 1);
			}
		} else {
			b.push_back(a[i]);
		}
	}

	for (int x : a) cout << x << " ";
	cout << endl;
	cout << b.size() << endl;
	for (int x : b) cout << x << " ";
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


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

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}

void solve(){
	int n, k;
	cin>>n>>k;
	map <int, int>m;
	vii v;
	rep(i,0,n){
		int t;
		cin>>t;
		m[t]++;
	}
	for(auto it = m.begin(); it!= m.end(); it++)
		v.pb(mp(it->y, it->x));	
	sort(all(v));
	int ans = 0, i = 0;
	int size = sz(v);
	while(size>k){
		size--;
		ans += v[i++].x;
	}
	cout<<ans<<endl;
}
	
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
  t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 11764
A,B,C,K = map(int,input().split())
S = 0
if K - A >= 0:
    S += A
    K = K - A
    if K - B >= 0:
        K = K - B
        if  K - C >= 0:
            S -= C
        else:
            S -= K
else:
    S += K
print(S)


Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
}

Measured memory_bytes: 256
/// author: Mr.Hakimov

#include <bits/stdc++.h>
#include <chrono>

#define fi first
#define se second
#define pb push_back
#define pf push_front
#define Pb pop_back
#define Pf pop_front
#define all(x) (x).begin(), (x).end()
#define fin(s) freopen(s, "r", stdin);
#define fout(s) freopen(s, "w", stdout);

using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll;
typedef long double ld;

int TN = 1;

void dfs2(int u, int color, vector<bool> &used, vector<vector<int>> &g, vector<int> &col) {
	used[u] = true;
	col[u] = color;
	
	for (int v : g[u]) {
		if (!used[v]) {
			dfs2(v, color, used, g, col);
		}
	}
}

void dfs(int u, int &cnt, vector<bool> &used, vector<vector<int>> &g, vector<int> &stack) {
	used[u] = true;
	stack.pb(u);
	++cnt;
	
	for (int v : g[u]) {
		if (!used[v]) {
			dfs(v, cnt, used, g, stack);
		}
	}
}

void solve() {
	int n;
	int m;
	int k;
	cin >> n >> m >> k;
	
	vector<vector<int>> g(n + 1);
	for (int i = 0; i < m; ++i) {
		int a;
		int b;
		cin >> a >> b;
		
		g[a].pb(b);
		g[b].pb(a);
	}
	
	vector<set<int>> block_old(n + 1);
	for (int i = 0; i < k; ++i) {
		int a;
		int b;
		cin >> a >> b;
		
		block_old[a].insert(b);
		block_old[b].insert(a);
	}
	
	int color = 0;
	vector<bool> vis(n + 1, false);
	vector<int> col(n + 1);
	for (int i = 1; i <= n; ++i) {
		if (!vis[i]) {
			dfs2(i, ++color, vis, g, col);
		}
	}
	
	vector<vector<int>> block(n + 1);
	for (int i = 1; i <= n; ++i) {
		for (int j : block_old[i]) {
			if (col[i] == col[j]) {
				block[i].pb(j);
			}
		}
	}
	
	vector<bool> used(n + 1, false);
	vector<int> answer(n + 1);
	for (int i = 1; i <= n; ++i) {
		vector<int> stack;
		int cnt = 0;
		if (!used[i]) {
			dfs(i, cnt, used, g, stack);
		}
		
		// cout << i << " " << cnt << " " << g[i].size() << " " << block[i].size() << endl;
		for (int j : stack) {
			answer[j] = cnt - 1 - (int) g[j].size() - (int) block[j].size();
		}
	}

	for (int i = 1; i <= n; ++i) {
		cout << answer[i] << " ";
	}
}

int main() {
    auto start = chrono::steady_clock::now();
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    /// =========================================
    /// fin("input.txt"); fout("output.txt");
    /// fin("file.in"); fout("file.out");
    /// cin >> TN;
    /// =========================================

    while (TN--) {
        solve();
    }

    auto finish = chrono::steady_clock::now();
    auto elapsed_ms = chrono::duration_cast<chrono::milliseconds>(finish - start);
    cerr << endl << "Time: " << elapsed_ms.count() << " ms\n";

    return 0;
}


Measured memory_bytes: 28228
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int n = scan.nextInt();
	    int[] r = new int[n];
	    for (int i = 0; i < n; i++) {
			r[i] = scan.nextInt();
		}
	  
	    int min = r[0];
		int margin = r[1] - r[0];
		for (int i = 1; i < r.length; i++) {
			margin = Math.max(margin, r[i] - min);
			min = Math.min(min, r[i]);
		}
		
		System.out.println(margin);
	}
}

Measured memory_bytes: 101300
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}
static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}

i32 nth (i32 *a, i32 n, i32 k) {
  i32 p = rand() % n;
  i32 pivot = a[p];
  a[p] = a[0];
  i32 assign = 0;
  i32 l = 1;
  i32 r = n;
  while (l < r) {
    if (a[l] == pivot) {
      l++;
    } else if (a[l] < pivot) {
      a[assign++] = a[l++];
    } else {
      i32 swap = a[--r];
      a[r] = a[l];
      a[l] = swap;
    }
  }
  for (i32 i = assign; i < l; ++i) a[i] = pivot;
  if (assign <= k && k < r) return pivot;
  return k < assign ? nth (a, assign, k) : nth (a + l, n - l, k - l);
}

void run (void) {
  i32 n = read_int();
  i32 *a = (i32 *) calloc (2 * n, sizeof (i32));
  i32 *b = a + n;
  for (i32 i = 0; i < n; ++i) {
    a[i] = b[i] = read_int();
  }
  i32 l = nth (b, n, n / 2 - 1);
  i32 r = 1000000000;
  for (i32 i = n / 2; i < n; ++i) r = r > b[i] ? b[i] : r;
  for (i32 i = 0; i < n; ++i) {
    print_int (a[i] <= l ? r : l);
    putchar ('\n');
  }
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    if(s==s1)
    cout<<a-1<<" "<<b;
    else
    cout<<a<<" "<<b-1;
    
    
    
    return 0;
}


    
    
    
    
    
    
    
    

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

using namespace std;

void Solution()
{
    int r;
    int degree;
    
    double sum = 0;
    double x = 0;
    double y = 0;
    
    char comma;
    
    while (true)
    {
        cin >> r >> comma >> degree;
        
        if (r==0 && degree==0)
        {
            break;
        }
        
        x += (double)r * sin(M_PI / 180.0 * sum); // when calculate sin, should use radian
        y += (double)r * cos(M_PI / 180.0 * sum); // when calculate cos, should use radian
        
        sum += (double)degree;
    }
    
    cout << (int)x << "\n" << (int)y << endl;
}

int main()
{
    Solution();
    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 1000000;
const int MOD = 1000000007;

signed main() {
int n,t;
cin>>n>>t;
int a[n],b[n];
int a0,b0;
pair<int,int> p[n];
for(int i=0;i<n;i++){
  cin>>a0>>b0;
  p[i]=make_pair(a0,b0);
}
sort(p,p+n);
for(int i=0;i<n;i++){
 a[i]=p[i].first;
 b[i]=p[i].second;
}
int dp[n][t+1];
for(int i=0;i<n;i++)fill(dp[i],dp[i]+t+1,0);
dp[0][min(t,a[0])]=b[0];
for(int i=1;i<n;i++){
  for(int j=0;j<=t;j++)dp[i][j]=dp[i-1][j];
  for(int j=0;j<t;j++){
    dp[i][min(t,j+a[i])]=max(dp[i-1][j]+b[i],dp[i][min(t,j+a[i])]);
  }
}
int ans=0;
for(int i=0;i<=t;i++)ans=max(ans,dp[n-1][i]);
cout<<ans;
return 0;



}


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

#solve
def solve():
    x = II()
    for i in range(50000):
        if int(i * 1.08) == x:
            print(i)
            return
    print(":(")


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


Measured memory_bytes: 39920
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n;
  cin >> n;
  vector<ll> v(n);
  rep(i, n){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  ll a[100000] = {0,0};
  ll k = 0;
  for(int i = 0; i < n-1; i++){
    if(v[i] == v[i+1]){
      a[k++] = v[i];
      i++;
    }
  }
  cout << a[0]*a[1] << endl;
  system("pause");
}


Measured memory_bytes: 2040
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  int k = 1;
  int l[31];

  for(int i = 0;i <= 31;i++){
    l[i] = 0;
  }

  for(int i = 0;i < n;i++){
    cin >> k;
    for(int j = 0;j < k;j++){
      int a = 0;
      cin >> a;
      l[a-1]++;
    }
  }

  int res = 0;
  for(int i = 0;i <= 31;i++){
    if(l[i] == n){
      res++;
    }
  }
  cout << res << endl;




}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define ull  unsigned long long
typedef string str;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int INF = 1e9 + 5;
const int N = 2e5 + 123;
int main(){
    speed;
    int n;
    cin >> n;
    vi a, b;
    for(int i = 0; i < n; ++i){
        int x;
        cin >> x;
        if(i & 1){
            a.pb(x);
        }
        else{
            b.pb(x);
        }
    }
    if(n & 1){
        reverse(all(b));
        for(int i = 0; i < b.size(); ++i){
            cout << b[i] << " ";
        }
        for(int i = 0; i < a.size(); ++i){
            cout << a[i] << " ";
        }
    }
    else{
        reverse(all(a));
        for(int i = 0; i < a.size(); ++i){
            cout << a[i] << " ";
        }
        for(int i = 0; i < b.size(); ++i){
            cout << b[i] << " ";
        }
    }
}

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

int main(){
  string s;
  cin>>s;
  int t=0;
  if(s.at(0)==s.at(1)){
    t++;
  }
  if(s.at(0)==s.at(2)){
    t++;
  }
  if(s.at(0)==s.at(3)){
    t++;
  }
  if(s.at(1)==s.at(2)){
    t++;
  }
  if(s.at(1)==s.at(3)){
    t++;
  }
  if(s.at(2)==s.at(3)){
    t++;
  }
  if(t==2){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}



Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::max;

fn main() {
    input!{
        h: usize,
        w: usize,
        v: [chars; h]
    }
    let mut tabh: Vec<Vec<usize>> = vec![vec![0; w]; h];
    for i in 0..h {
        if v[i][0] == '.' {
            tabh[i][0] = 1;
        }
        for j in 1..w {
            if v[i][j] == '.' {
                tabh[i][j] = tabh[i][j - 1] + 1;
            }
        }
        for j in (0..w - 1).rev() {
            if v[i][j] == '.' && v[i][j + 1] == '.' {
                tabh[i][j] = tabh[i][j + 1];
            }
        }
    }
    let mut tabw: Vec<Vec<usize>> = vec![vec![0; w]; h];
    for j in 0..w {
        if v[0][j] == '.' {
            tabw[0][j] = 1;
        }
        for i in 1..h {
            if v[i][j] == '.' {
                tabw[i][j] = tabw[i - 1][j] + 1;
            }
        }
        for i in (0..h - 1).rev() {
            if v[i][j] == '.' && v[i + 1][j] == '.' {
                tabw[i][j] = tabw[i + 1][j];
            }
        }
    }
    let mut ans = 0;
    for i in 0..h {
        for j in 0..w {
            if v[i][j] == '#' {
                continue;
            }
            ans = max(ans, tabh[i][j] + tabw[i][j] - 1);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 102652
A = int(input())
B = int(input())

if A == 2 and B == 3:
  print(1)
if A == 3 and B == 2:
  print(1)

if A == 1 and B == 3:
  print(2)
if A == 3 and B == 1:
  print(2)

if A == 2 and B == 1:
  print(3)
if A == 1 and B == 2:
  print(3)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N,A,B;
int main(){
    cin>>N>>A>>B;
    if((B-A)%2==0){
        cout<<(B-A)/2<<endl;
    }
    else{
        ll w=A+(B-A-1)/2;
        ll q=N-B+1+(B-A-1)/2;
        cout<<min(w,q)<<endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int h,w;
  // char s;
  // s ='#';
  while (1)
  {
    scanf("%d",&h);
    scanf("%d",&w);
    if(w == 0 && h == 0 )break;
    for (int i = 0; i < h; i++)
    {
      for (int j = 0; j < w; j++)
      {
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  ///////////////////////////////////////////////////////////
  //   while (1)
  // {
  //   scanf("%d",&h);
  //   scanf("%d",&w);
  //   if(w == 0 && h == 0 )break;
  //   for (int i = 0; i < h; i++)
  //   {
  //     for (int j = 0; j < w; j++)
  //     {
  //       if(j == 0 || j == w-1 || i == 0 || i == h-1 ) s = '#';
  //       else
  //       {
  //         s = ' ';
  //       }
        
  //       printf("%c",s);
  //     }
  //     printf("\n");
  //   }
  //   printf("\n");
  // }
  return 0;
}


Measured memory_bytes: 2096