akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
  int s,a[4];
  scanf("%d",&s);
  for(int i=0;i<4;i++){
    a[i] = s%10;
    s /= 10;
  }
  if(a[0] == a[1] || a[1] == a[2] || a[2] == a[3] )printf("Bad\n");
  else printf("Good\n");
  return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import static java.lang.System.in;

public class Main {
    static ArrayList<Integer>[] rec;
    static int[] size, id;
    public static void main(String[] args)throws IOException {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String[] buf = s.split("/");
        int mon = Integer.parseInt(buf[1]);
        int day = Integer.parseInt(buf[2]);
        String ans = mon<=4?"Heisei":"TBD";
        System.out.println(ans);
    }
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    if(4*a*b < (c-a-b)*(c-a-b) && c-a-b>0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int N, M;
  while (cin >> N >> M) {
    if (N == 0 && M == 0) break;
    int pc[1004][800] = {};
    //memset(pc, 0, sizeof(pc));
    int r;
    cin >> r;
    int t, n, m, s;
    while (r--) {
      cin >> t >> n >> m >> s;
      //  m--;
      n--;
      t -= 540;

      if (s == 1) { // login
        pc[n][t] = m;
      } else { // logout
        pc[n][t] = -m;
      }
    }
    rep(i, N) rep(j, 799) pc[i][j + 1] += pc[i][j];
    
    //rep(i, N) {
    //  rep(j, 799) { cout << pc[i][j] << ' '; }
    //  cout << endl;
    //}
    int q;
    cin >> q;
    int ts, te;
    while (q--) {
      cin >> ts >> te >> m;
      // m--;
      ts -= 540;
      te -= 540;
      int cnt = 0;

      loop(j, ts, te) {
        bool f = false;
        rep(i, N) {
          f = f or pc[i][j] == m;
        }
        cnt += f;
      }
      cout << cnt << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 9352
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(){

	char str[21];
	int i,j;
	char output[21]={'\0'};
	int s,t;
	s=0;
	t=0;
	scanf("%s",str);
	i = strlen(str);
	if(i==1){
		printf("-1\n");
		return 0;
	}
	
	for(j=0;j<i;j++){
		if(str[j]=='A'){
			s=1;
		
		}
		if(str[j]=='Z' && s==1){
			s=0;
			output[t]='A';
			output[t+1]='Z';
			t=t+2;
		}
	}
	if(t>0)printf("%s\n",output);
	else printf("-1\n");
	return 0;
}

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

#define ___ ios::sync_with_stdio(0),  cin.tie(0);
#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'
#define MAX 50
typedef long long ll;

void printString(ll n) 
{ 
    char str[MAX]; // To store result (Excel column name) 
    int i = 0; // To store current index in str which is result 
    while (n > 0) { 
        int rem = n % 26; 
        if (rem == 0) { 
            str[i++] = 'z'; 
            n = (n / 26) - 1; 
        } 
        else // If remainder is non-zero 
        { 
            str[i++] = (rem - 1) + 'a'; 
            n = n / 26; 
        } 
    } 
    str[i] = '\0'; 
    reverse(str, str + strlen(str)); 
    cout << str << endl; 
  
    return; 
} 

int main(){___
  ll n; cin >> n;
  printString(n);
  return 0;
}

Measured memory_bytes: 3684
package main

import "fmt"

func main() {
	var a, b, k int
	fmt.Scan(&a, &b, &k)
	dic := map[int]struct{}{}

	for _, i := range []int{a, b - k + 1} {
		for j := range make([]struct{}, k) {
			k := i + j
			if _, in := dic[k]; !in && a <= k && k <= b {
				fmt.Println(k)
				dic[k] = struct{}{}
			}
		}
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int N;
int a[310];
int cnt[3];
int used[310][310][310];
double memo[310][310][310];

double dfs(int x, int y, int z) {
  if (x < 0 || y < 0 || z < 0) return 0.0;
  if (x == 0 && y == 0 && z == 0) return 0.0;
  if (used[x][y][z]) return memo[x][y][z];
  used[x][y][z] = 1;
  return memo[x][y][z] = (N+x*dfs(x-1,y,z)+y*dfs(x+1,y-1,z)+z*dfs(x,y+1,z-1))/(x+y+z);
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  
  cin >> N;
  REP(i, N) {
    cin >> a[i];
    cnt[a[i]-1]++;
  }
  cout << dfs(cnt[0], cnt[1], cnt[2]) << endl;

  return 0;
}

Measured memory_bytes: 452864
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define lop(i, n) for(i=0; i<n; i++)

/* 0126 */

int cmpnum(const void * n1, const void * n2)
{
	if (*(long *)n1 > *(long *)n2)
	{
		return -1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}


int main()
{
	int n, k, i, ini, c=1;
	long int h[200000], cnt=0;
	
	scanf("%d %d", &n, &k);
	lop(i, n){
		scanf("%ld", &h[i]);
	}
	
	qsort(h, n, sizeof(long int), cmpnum);
	
	for(i=k; i<n; i++){
		if(h[i]==h[i+1]){
			c++;
		}
		else if(h[i]!=h[i+1]){
			cnt+=h[i]*c;
			c=1;
		}
	}
	
	printf("%ld", cnt);
	
return 0;
}

Measured memory_bytes: 3324
#include <stdio.h>
#include <memory.h>
int main(void){
  char str[101];
  int i,l,s,a[101]={0};
  while(scanf("%s",str)!=EOF){
    s=0;
    memset(a,0,sizeof(a));
    for(i=0;str[i]!='\0';i++){
      if(str[i]=='I')
	a[i]=1;
      else if(str[i]=='V')
	a[i]=5;
      else if(str[i]=='X')
	a[i]=10;
      else if(str[i]=='L')
	a[i]=50;
      else if(str[i]=='C')
	a[i]=100;
      else if(str[i]=='D')
	a[i]=500;
      else
	a[i]=1000;
    }
    l=i;
    for(i=0;i<l;i++){
      if(a[i]<a[i+1]){
	s+=a[i+1]-a[i];
	i++;
      }
      else
	s+=a[i];
    }
    printf("%d\n",s);
  }
  return 0;
}

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

int main(){
	long long n;
	cin >> n;
	string s;
	cin >> s;
	long long all_W=0,all_E=0;
	
	for(long long i=0;i<s.size();i++){
		if(s[i]=='W')all_W++;
		else all_E++;
	}
	
	vector<long long> d(n,0);
	long long now_W=0,now_E=0;
	
	for(long long i=0;i<s.size();i++){
		if(s[i]=='W'){
			now_W++;
			d[i]+=now_W-1;
			d[i]+=all_E-now_E;
		}
		if(s[i]=='E'){
			now_E++;
			d[i]+=now_W;
			d[i]+=all_E-now_E;
		}
	}
	
	sort(d.begin(),d.end());
	
	cout << d[0] << endl;
	return 0;
}


Measured memory_bytes: 3076
#include<stdio.h>
int main(){
    int n, x, i, r, z, num, tmp = 0;
    for(;;){
        scanf("%d%d", &n, &x);
        tmp = 0;
        if( n == 0 && x == 0 ){
            break;
        }
        for( i = 1; i <= n; i++ ){
            for( r = i+1 ; r <= n; r++ ){
                for( z = r+1; z <= n; z++ ){
                    num = i + r + z;
                    if( num == x ){
                        tmp += 1;
                    }
                }
            }
        }
        printf("%d\n",tmp);
    }
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>

int main() {
	int n,m;
	cin >> n >> m;
	vector<P>p(m);
	rep(i, m) {
		cin >>p[i].first>>p[i].second;
	}
	rep(i, 1000) {
		vector<int>x;
		int nn;
		x.push_back(i % 10);
		x.push_back((i/10) % 10);
		x.push_back((i/100) %10);
		if (x[2] != 0) {
			nn = 3;
		}
		else if (x[1] != 0) {
			nn = 2;
			x.pop_back();
		}
		else {
			nn = 1;
			x.pop_back();
			x.pop_back();
		}
		if (nn != n) {
			continue;
		}
		bool ok = true;
		reverse(x.begin(), x.end());
		rep(j, m) {
			if (x[p[j].first - 1] != p[j].second) {
				ok = false;
			}
		}
		//cout << i << endl;
		if (ok) {
			
			cout << i;
			return 0;
		}
	}
	cout << -1;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef long long 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;
}

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  set<string>se;
  REP(i,N){
    string tmp;
    cin>>tmp;
    se.insert(tmp);
  }
  cout<<se.size()<<endl;
}


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

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

int main() {
  int N, K;
  cin >> N >> K;
  // N 人のすぬけ君
  // snuke[i] = i 番目のすぬけ君はお菓子を持っているか
  vector<bool> snuke(N);
  
  rep(i, K) {
    // d = i 番目のお菓子を持っているすぬけ君の数
    int d;
    cin >> d;
    rep(j, d) {
      // すぬけ君 a がお菓子を持っているので、snuke[a] = true
      // 1 <= a <= N なので、 0-indexed にするために 1 を引く
      int a;
      cin >> a;
      snuke.at(a - 1) = true;
    }
  }
  
  int ans = 0;
  rep(i, N) {
    // お菓子を持っていなかったら、答えをインクリメント
    if (!snuke[i]) ++ans;
  }
  
  cout << ans << endl;
}


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

int W, H;
char c;

signed main()
{
    cin >> W >> H >> c;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(i == 0 || i == H - 1){
                if(j == 0 || j == W - 1){
                    printf("+");
                }
                else{
                    printf("-");
                }
            }
            else if(j == 0 || j == W - 1){
                printf("|");
            }
            else if(i == H / 2 && j == W / 2){
                printf("%c", c);
            }
            else{
                printf(".");
            }
        }
        printf("\n");
    }

    return 0;
}



Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define FILEIN freopen("input.txt", "r", stdin)

#define ll long long
#define endl "\n"

int main(){
	// FILEIN;
	int x, n;cin>>x>>n;
	if(ceil((double)n/500) != floor((double)n/500)) x--;
	if(n/500 <= x){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
 
int main(void)
{
    int n, t[100001], x[100001], y[100001];
    int i, dt, dist;
    bool flag = false;
    scanf("%d", &n);
    t[0] = x[0] = y[0] = 0;
    for (i=1; i<n+1; i++)
    {
        scanf("%d %d %d", &t[i], &x[i], &y[i]);
    }
 
    for (i=1; i<n+1; i++)
    {
        dt =  t[i] - t[i-1];
        dist = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]);
        if (dt < dist) {
            printf("No");
            return 0;
        }
        if (dt%2 != dist%2) {
            printf("No");
            return 0;
        }
    }
 
    if (flag == true) {
        printf("No\n");
    } else {
        printf("Yes\n");
    }
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  int ans=0;
  if (s.at(0) == '1') {ans++;}
  if (s.at(1) == '1') {ans++;}
  if (s.at(2) == '1') {ans++;}
  cout << ans << endl;
}


Measured memory_bytes: 3520
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


int main(){
    LL n, m;
    cin >> n >> m;
    vector<LL> a(n+1);
    for(LL i = 0; i < m; ++i){
        LL l, r;
        cin >> l >> r;
        a[l-1] += 1;
        a[r] -= 1;
    }

    LL ans = 0;
    LL cur = 0;
    for(LL i = 0; i < n+1; ++i){
        cur += a[i];
        if(cur == m) ++ans;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6,inf=1e9;
int dp[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);

  int n;cin>>n;
  vector<pair<int,int> >pp(n);
  for(int i=1;i<=n;i++)
  {
    int x,l;cin>>x>>l;
    pp[i-1]={x-l,x+l};
  }
  sort(pp.begin(),pp.end());

  dp[n-1]=1;
  for(int i=n-2;i>=0;i--)
  {
    dp[i]=dp[i+1];
    int id=lower_bound(pp.begin(),pp.end(),make_pair(pp[i].second,-1))-pp.begin();
    dp[i]=max(dp[i],dp[id]+1);
  }
  cout<<dp[0]<<endl;
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

vector<vector<ll>> cost(400, vector<ll>(400, INF));
vector<vector<ll>> hok(400, vector<ll>(400, INF));

int main() {
	ll n, m, l;
	cin >> n >> m >> l;
	ll a, b, c;
	REP(i, m) {
		cin >> a >> b >> c;
		if (c <= l) {
			cost[a][b] = c;
			cost[b][a] = c;
		}
	}
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (cost[i][j] <= l) hok[i][j] = 1;
		}
	}
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				hok[i][j] = min(hok[i][j], hok[i][k] + hok[k][j]);
			}
		}
	}
	int q;
	cin >> q;
	int s, t;
	REP(i, q) {
		cin >> s >> t;
		if (hok[s][t] < INF)
			cout << hok[s][t] - 1 << '\n';
		else
			cout << -1 << '\n';
	}
}

Measured memory_bytes: 3072
N,Y = map(int,input().split())
for i in range(N + 1):
	a = i
	for j in range(N - a + 1):
		b = j
		c = N - a - b
		if a*10000 + b*5000 + c*1000 == Y:
			break
	if a*10000 + b*5000 + c*1000 == Y:
			print(str(a)+" "+str(b)+" "+str(c))
			break
if a*10000 + b*5000 + c*1000 != Y:
	print(str(-1)+" "+str(-1)+" "+str(-1))

Measured memory_bytes: 8860
#include <stdio.h>

const int INF = 1e9;

int main() {
  long long sum = 0;
  int min = INF, max = -INF;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    sum += x;
    min = x < min ? x : min;
    max = max < x ? x : max;
  }
  printf("%d %d %lld\n", min, max, sum);
  return 0;
}



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

//　けんちょんブログ見ながら

int N; 
const int MAX_bit = 1 << 20;
const int inf = 1e9;

int dp[MAX_bit][60];

void chmin(int &a, int b){ if( a > b ){ swap(a,b);} return ;}




int main(){ 
  
  cin >> N;
  vector<int> A(N),B(N);
  
  for(int i = 0; i < N; i++){ cin >> A[i];}
  for(int i = 0; i < N; i++){ cin >> B[i];} 
  
  for(int i = 0; i < MAX_bit; i++){ 
    for(int j = 0; j < 60; j++){ 
      dp[i][j] = inf;
    }
  }
  
  dp[0][0] = 0;
  
  for(int bit = 0; bit < (1<<N); bit++){ 
    //　現在bitまで揃っているものとする
    
     int res = 0;
    
      for(int i = 0; i < N; i++){ 
        if( ( bit>> i) & 1){ res++;}
      } //現在これだけのbitが立っている
    
    
      vector<pair<int,int>> vec;
      int u = res;
      
      for(int i = 0; i < N; i++){ 
        if(!( (bit>>i) & 1)){ //この順番のカードはまだ揃っていない
          vec.push_back({i,u++});
        }
      }
    
    for(int s = 0; s <= 50; s++){ 
      
      if( dp[bit][s] >= inf ){ continue;}
      
      for(auto p : vec ){
        
        // p.first　は　元のindex, p.second　は　移動後のindex
        // 移動した後のindexがソート済みの右側から小さい順に並んでいると貪欲に示せる
       
        int a;
        
        if( abs(p.first-res) % 2 == 0 ){ 
          a = A[p.first];
        }
        else{
          a = B[p.first];
        }
        
        if( a < s ){ continue;}
        
        
        chmin( dp[bit|(1<<p.first)][a], dp[bit][s]+abs(p.second-res) );
        
      }//p
      
    }//s
    
  }//bit
  
  int ans = inf;
  
  for(int i = 0; i <= 50; i++){
    chmin(ans, dp[(1<<N)-1][i]);
  }
  
  if( ans == inf){ ans = -1;}
  
  cout << ans << endl;
  
  return 0;
}
  
      
      
        
        
          
      
      

Measured memory_bytes: 246144
n = gets.chomp.to_i
k = gets.chomp.to_i

@memo = {}

def solve(n, k)
    return @memo[[n, k]] if @memo[[n, k]]
    return 1 if k == 0
    return 0 if n < 1
    return 0 if n.to_s.size < k

    head = n.to_s.chars[0].to_i
    c = n.to_s.chars
    c.shift
    right = c.join.to_i
    v = 10**c.size - 1

    v1 = solve(right, k - 1)
    v2 = (head - 1) * solve(v, k - 1)
    v3 = solve(v, k)

    @memo[[n, k]] = v1 + v2 + v3
end

puts solve(n, k)

Measured memory_bytes: 2172
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>

#define maxn 205
#define maxm 10000005

using namespace std;

inline int getint()
{
	int num=0,flag=1;char c;
	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
	while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();
	return num*flag;
}

int n,N;
int a[maxn],w[maxn][maxn],link[maxn];
int pri[maxm],cnt;
bool np[maxm],col[maxm],vis[maxn];
int X[maxn],Y[maxn],ans;

inline void init()
{
	np[1]=1;
	for(int i=2;i<=N;i++)
	{
		if(!np[i])pri[++cnt]=i;
		for(int j=1;j<=cnt&&i*pri[j]<=N;j++)np[i*pri[j]]=1;
	}
}

inline bool match(int x)
{
	for(int i=1;i<=Y[0];i++)if(w[x][i]&&!vis[i])
	{
		vis[i]=1;
		if(!link[i]||match(link[i])){link[i]=x;return 1;}
	}
	return 0;
}

int main()
{
	n=getint();
	for(int i=1;i<=n;i++)N=max(N,a[i]=getint()),col[a[i]]=1;
	N++;init();
	for(int i=1;i<=N;i++)if(col[i]^col[i-1])i&1?X[++X[0]]=i:Y[++Y[0]]=i;
	for(int j=1;j<=Y[0];j++)for(int i=1;i<=X[0];i++)w[i][j]=!np[abs(X[i]-Y[j])];
	for(int i=1;i<=X[0];i++)
	{
		memset(vis,0,sizeof vis);
		ans+=match(i);
	}
	ans+=2*((X[0]-ans)/2)+2*((Y[0]-ans)/2)+3*((X[0]-ans)&1);
	printf("%d\n",ans);
}

Measured memory_bytes: 20864
#include<stdio.h>
int main(){
        int i,j,a,max,min;
        max=-1000000;min=1000000;
        long sum; sum=0;
        scanf("%d\n",&j);
        for(i=0;i<j;i++){
                scanf("%d",&a);
                if(a<=min)min=a;
                if(a>=max)max=a;
                sum+=a;}
                printf("%d %d %ld\n",min,max,sum);
                return 0;}

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

int N,W;
int v[110],w[110];
int dp[110][10010];

int main(){
    
    cin >> N >> W;
    for(int i = 0; i<N;++i){
        cin >> v[i] >> w[i];
    }
    for(int j=0;j <= W;j++){
        dp[0][j] = 0;
    }
    for(int i = 0;i < N;++i){
        for(int j = 0;j <= W;++j){
            if(w[i] <= j){
                dp[i+1][j] = max(dp[i][j-w[i]] + v[i],dp[i][j]);
            }
            else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }

    cout << dp[N][W] << endl;
    int k;
    cin >> k;

}


Measured memory_bytes: 7044
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <functional>
#include <cmath>
#include <cstdint>
#include <mutex>
#include <thread>
#include <bitset>
#include <utility>

using namespace std;

int main()
{
	unsigned int n;
	vector<string> s;
	string s_;

	vector<pair<string, int>> ans;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> s_;
		s.push_back(s_);
	}
	sort(s.begin(), s.end());

	int cnt = 0;
	int max = 0;
	ans.push_back(make_pair(s[0], 1));
	for (int i = 1; i < n; i++)
	{
		if (ans[cnt].first.compare(s[i]) == 0)
		{
			ans[cnt].second++;
			if (i == n - 1)
			{
				if (max < ans[cnt].second)
					max = ans[cnt].second;
			}
		}
		else
		{
			if (max < ans[cnt].second)
				max = ans[cnt].second;
			cnt++;
			ans.push_back(make_pair(s[i], 1));
		}
	}

	for (auto i : ans)
	{
		if (i.second == max)
			cout << i.first << endl;
	}

	return 0;
}


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

int main() {
	string s, k, t;
	int n, a, b;
	cin >> s >> n;
	for (int i = 0; i < n; i++){
		cin >> k >> a >> b;
		if (k == "print"){
			for (int i = a; i <= b; i++){
				cout << s[i];
			}
			cout << '\n';
		}else if (k == "replace"){
			cin >> t;
			for (int i = 0; i < (b - a + 1) ; i++){
				s[i + a] = t[i];
			}		
		 }else if (k == "reverse"){
			char temp;
			for (int i = 0; i < (b - a + 1) / 2; i++){
				temp = s[a + i];
				s[a + i] = s[b - i];
				s[b - i] = temp;
			}
		  }
	}
	return 0;
}


Measured memory_bytes: 3208
#include<stdio.h>
int main(void){
 	int a;
  	scanf("%d",&a);
  	a %= 10;  //a%=10;
  	if(a==3){
    	printf("bon");
    }
  	else if(a==0 || a==1 || a==6 || a==8){
     	printf("pon");
    }
  	else{
     	printf("hon") ;
    }
  return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}


void solve(){
    int n ;
    ll d;
    cin >> n >> d;
    d = d * d;
    vector<pair<ll, ll>> x;
    REP(i, n){
        ll a, b;
        cin >> a >> b;
        x.push_back(make_pair(a,b));
    }
    int count = 0;
    for(int i = 0 ; i < n ; i++){
        ll dist = x[i].first * x[i].first + x[i].second * x[i].second; 
        if( dist <= d) count++;
    }
    cout << count << "\n";

} 

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    solve();

    return 0;
}


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

int main() {
	int n; cin >> n;
	vector<int>a(n); 
	int cntMin = (int)1e9;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 2 != 0) {
			cout << 0 << endl;
			return 0;
		}
		int tmp = a[i];
		int cnt = 0;
		while (tmp % 2 == 0) {
			cnt++; tmp /= 2;
		}
		cntMin = min(cnt, cntMin);
	}
	cout << cntMin << endl;

	return 0;
}

Measured memory_bytes: 256
program sample
	implicit none
    integer ::a,b
    
    read(*,*) a,b
    if (a /=1 .and. b/=1) then
    	if (a<b) then
        	write(*,*) 'Bob'
        else if (b<a) then
        	write(*,*) 'Alice'
        else
        	write(*,*) 'Draw'
        end if
    else
    	if(a==1 .and. b==1) then
        	write(*,*) 'Draw'
        else if(a==1 .and. b/=1) then
    		write(*,*) 'Alice'
        else
        	write(*,*) 'Bob'
        end if
    end if
    stop
end program sample

Measured memory_bytes: 2764
n = int(input())

c = [[0] * 10 for i in range(10)]

for i in range(1, n+1):
    start = int(str(i)[0])
    stop = int(str(i)[-1])

    c[start][stop] += 1

r = 0
for i in range(10):
    for j in range(10):
        r += c[i][j] * c[j][i]

#iとjがどちらも0の場合は問題設定と合致しないので引く
print(r)

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

int main(){
    string s;
    vector<char> ans;
    cin >> s;
    for(auto& c : s){
        if(c!='B') ans.push_back(c);
        else if(!ans.empty()) ans.pop_back();
    }

    for(auto& c : ans) cout << c;
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
N, M, K = map(int, input().split())
ans = [0] * (N + 1)
child = {i:[] for i in range(1, N+1)}
isChecked = [0] * (N + 1)
isBlocked = [set() for _ in range(N+1)]

for _ in range(M):
    a, b = map(int, input().split())
    child[a].append(b)
    child[b].append(a)
for _ in range(K):
    c, d = map(int, input().split())
    isBlocked[c].add(d)
    isBlocked[d].add(c)
for i in range(1, N+1):
    if isChecked[i]:
        continue
    isChecked[i] = 1
    x = set([i])
    ch = child[i].copy()
    while ch:
        c = ch.pop()
        if isChecked[c]:
            continue
        isChecked[c] = 1
        x.add(c)
        ch.extend(child[c])
    for j in x:
        ans[j] = len(x) - 1 - len(child[j]) - len(x & isBlocked[j])
print(*ans[1:])

Measured memory_bytes: 73012
# -*- coding: utf-8 -*-
n,x=map(int,input().split())
L=input().split()
L=[int(i) for i in L]
count=0
l=0
while l<=x:
    if count>n-1:
        count=count+1
        break
    else:
        l=l+L[count]
        count=count+1
print(count)

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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

struct ft {
  int l;
  int r;
  int val;
  ft(int _l, int _r, int _val) : l(_l), r(_r), val(_val){};
};

template <typename T>
void debug_out(T t) {
  cerr << t;
}

template <typename A, typename B>
void debug_out(pair<A, B> u) {
  cerr << "(" << u.first << " " << u.second << ")";
}

template <typename T>
void debug_out(vector<T> t) {
  int sz = t.size();
  for(int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if(i != sz - 1) cerr << ", ";
  }
}

template <typename T>
void debug_out(vector<vector<T>> t) {
  int sz = t.size();
  for(int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if(i != sz - 1) cerr << endl;
  }
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" << endl, debug_out(__VA_ARGS__), cerr << endl;

void debug_out(ft a) {
  cerr << a.l << " " << a.r << " " << a.val;
}

int n;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  vector<int> a(n + 1);
  range(i, 0, n) cin >> a[i];
  int cur = 0;
  vector<ft> dp;
  dp.emplace_back(0, 0, 0);
  for(int st : a) {
    // x cur st y
    // + 1 y <= x - 1
    // + 1 y <= st - cur + x - 1
    // x -> x - 1, st - cur + x - 1
    vector<ft> new_dp;
    for(ft res : dp) {
      int x = res.l;
      int val = res.val;
      int l = x - 1, r = st - cur + x - 1;
      l = max(-1, l); r = max(-1, r);
      if(l > r) swap(l, r);
      if(l >= 0) new_dp.emplace_back(0, l, val + 2);
      if(r > l) new_dp.emplace_back(l + 1, r, val + 1);
      if(st > r) new_dp.emplace_back(r + 1, st, val);
    }
    //debug(new_dp);
    vector<int> pos;
    for(ft res : new_dp) {
      pos.push_back(res.l);
      pos.push_back(res.r);
    }
    sort(pos.begin(), pos.end());
    pos.resize(unique(pos.begin(), pos.end()) - pos.begin());
    vector<int> val(pos.size(), INT_MAX);
    for(ft res : new_dp) {
      range(i, 0, (int) pos.size()) {
        if(pos[i] < res.l || pos[i] > res.r) continue;
        val[i] = min(val[i], res.val);
      }
    }
    dp.clear();
    range(i, 0, (int) pos.size()) {
      if(!dp.empty() && dp.back().val == val[i]) dp.pop_back();
      dp.emplace_back((dp.empty() ? 0 : dp.back().r + 1), pos[i], val[i]);
    }
    cur = st;
    assert(dp.size() <= 3);
  }
  cout << dp.back().val;
  return 0;
}


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

const int M1 = 2e5 + 5;

int N;
int freq[M1];

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

  cin >> N;

  for(int i = 0; i < N - 1; i++) {
    int A;
    cin >> A;
    freq[A]++;
  }

  for(int i = 1; i <= N; i++) cout << freq[i] << "\n";

  return 0;
}

Measured memory_bytes: 4400
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

const int N = 1e6 + 10;

ll cnt;
int l, a[N], n;
vector<int> g;

void insertionsort(int a[], int n, int g)
{
    for(int i = g; i < n; i++)
    {
        int v = a[i];
        int j = i - g;
        while(j >= 0 && a[j] > v)
        {
            a[j + g] = a[j];
            j -= g;
            cnt++;
        }
        a[j + g] = v;
    }
}

void shellsort(int a[], int n)
{
    for(int h = 1;;)
    {
        if(h > n) break;
        g.push_back(h);
        h = 3 * h + 1;
    }

    for(int i = g.size() - 1; i >= 0; i--) insertionsort(a, n, g[i]);
}

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

    cin >> n;

    for(int i = 0; i < n; i++) cin >> a[i];

    cnt=0;

    shellsort(a, n);

    cout << g.size() << endl;

    for(int i = g.size() - 1; i >= 0; i--)
    {
        cout << g[i];
        if(i) cout << ' ';
    }
    cout << endl;

    cout << cnt << endl;

    for(int i = 0; i < n; i++) cout << a[i] << endl;

    return 0;
}



Measured memory_bytes: 7048
#include <bits/stdc++.h>
using namespace std;
int n,a[110];
int b[2];
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cin >> n;
        for(int i=0;i<n;i++) cin >> a[i];
        int cur = 0;
        sort(a,a+n);
        for(int i=n-1;i>=0;i--){
            b[cur] += a[i];
            cur = 1-cur;
        }
        cout << (b[0]-b[1]) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

#include <map>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;

int main()
{
    ios::sync_with_stdio(false);

    string a, b, c;
    cin >> a >> b >> c;

    cout << a[0] << b[1] << c[2] << '\n';

    return 0;
}


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

#define int long long
typedef pair<int, int> P;
typedef pair<long long, P> P2;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int X[100000], Y[100000];
int U[100000], R[100000];

int find(int x) {
  if (U[x] == x) return x;
  return U[x] = find(U[x]);
}

void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  if (R[x] < R[y]) swap(x, y);
  U[y] = x;
  R[x] += R[y];
  R[y] = 0;
}

bool same(int x, int y) {
  return find(x) == find(y);
}

vector<P2> edges;

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  vector<P> xy, yx;
  cin >> N;
  for (int i=0; i<N; i++) U[i] = i, R[i] = 1;
  rep(i, N) {
    cin >> X[i] >> Y[i];
    xy.pb(P(X[i], i));
    yx.pb(P(Y[i], i));
  }
  sort(all(xy));
  sort(all(yx));
  for (int i=1; i<xy.size(); i++) {
    int a = xy[i-1]._2, b = xy[i]._2;
    edges.pb(P2(abs(X[a]-X[b]), P(a, b)));
  }
  for (int i=1; i<yx.size(); i++) {
    int a = yx[i-1]._2, b = yx[i]._2;
    edges.pb(P2(abs(Y[a]-Y[b]), P(a, b)));
  }
  long long sum = 0;
  sort(all(edges));
  for (P2 p : edges) {
    long long cost = p._1;
    int a = p._2._1, b = p._2._2;
    if (!same(a, b)) {
      sum += cost;
      unite(a, b);
    }
  }
  cout << sum << "\n";
  return 0;
}


Measured memory_bytes: 16224
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void run(){
		LinkedList<Integer> st = new LinkedList<Integer>();
		for(;;){
			if(!sc.hasNext()){
				break;
			}
			int n= sc.nextInt();
			if(n ==0){
				System.out.println(st.pop());
			}else{
				st.push(n);
			}
		}
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
	}
}

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

const long long INF = 1e18L + 5;

long long solve(int n, int W, vector<int> &w, vector<int> &v) {
	long long max_val = 0;
	for (auto val : v) {
		max_val += val;
	}
	vector<long long> dp(max_val+1, INF);
	dp[0] = 0;
	for (int i = 0; i < n; ++i)
	{
		for (int val_already = max_val - v[i]; val_already >= 0 ; --val_already)
		{
			dp[val_already+v[i]] = min(dp[val_already+v[i]], dp[val_already] + w[i]);
		}
	}
	long long ans = 0;
	for (int i = max_val; i >= 0; --i)
	{
		if (dp[i] <= W) {
			ans = i;
			break;
		}
	}
	return ans;
}

int main(int argc, char const *argv[])
{
	int n, m;
	cin >> n >> m;
	vector<int> w(n), v(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> w[i] >> v[i];
	}

	cout << solve(n,m,w,v) << "\n";
	return 0;
}

Measured memory_bytes: 4036
#include <stdio.h>
int main(){
    
  int a[4][3][10],i,j,k,n,b,f,v,r;
  
  for ( i = 0; i < 4; i++){
    for ( j = 0; j < 3; j++){
      for( k = 0; k < 10; k++){
        a[i][j][k]=0;
      }
    }
  }
  scanf("%d\n",&n);
  for ( i = 0; i < n; i++){
    scanf("%d %d %d %d\n", &b, &f, &r, &v);
    a[b-1][f-1][r-1] += v;
  }
  
  for ( i = 0; i < 4;  i++){
    for ( j = 0; j < 3; j++){
      for( k = 0; k < 10; k++){
          
        printf (" %d",a[i][j][k]);
        
        if ( k == 9) printf("\n");
        
    if( k == 9 && j == 2 && i < 3) printf("####################\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int a,b,n,c=0;
  cin>>a>>b>>n;
  vector<int> d;
  for(int i=1;i<=1000;i++){
    if(a%i==0&&b%i==0)d.push_back(i);
  }
  reverse(d.begin(),d.end());
  cout<<d[n-1];
}

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

namespace ABC061A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a,b,c;

            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);

            if (c >= a && c <= b)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n;
int cnt[1000];
bool fix[1000];
int seq[100];
int tempseq[100];
set<vector<int> > ans;

void calc(int depth, int maxd);

void next(int depth, int d, int maxd) {
  bool can = true;
  REP(i, depth) {
    int dist = abs(seq[i] - d);
    cnt[dist]--;
    if (cnt[dist] < 0) { can = false; }
  }
  if (can) {
    seq[depth] = d;
    fix[d] = true;
    calc(depth + 1, maxd);
    fix[d] = false;
    seq[depth] = 0;
  }
  REP(i, depth) {
    int dist = abs(seq[i] - d);
    cnt[dist]++;
  }
}

void calc(int depth, int maxd) {
  if (depth == n) {
    memcpy(tempseq, seq, sizeof(seq));
    sort(tempseq, tempseq + n);
    int prev = 0;
    vector<int> dist(n - 1);
    FOR(i, 1, n) {
      dist[i - 1] = tempseq[i] - prev;
      prev = tempseq[i];
    }
    ans.insert(dist);
    return;
  }
  int nd = maxd;
  for (; nd >= 0; nd--) { if (cnt[nd] > 0) { break; } }
  if (!fix[nd]) { next(depth, nd, nd); }
  if (!fix[seq[1] - nd]) { next(depth, seq[1] - nd, nd); }
}

int main() {
  while (scanf("%d", &n), n) {
    ans.clear();
    MEMSET(fix, false);
    MEMSET(cnt, 0);
    MEMSET(seq, 0);
    REP(i, n * (n - 1) / 2) {
      int d ;
      scanf("%d", &d);
      if (i == 0) { seq[1] = d; continue; }
      cnt[d]++;
    }
    calc(2, seq[1]);
    FORIT(it, ans) {
      REP(i, it->size()) {
        if (i != 0) { putchar(' '); }
        printf("%d", (*it)[i]);
      }
      puts("");
    }
    puts("-----");
  }
}

Measured memory_bytes: 0
#include<stdio.h>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  char S[n];
  scanf("%s", S);
  
  int dp[n];
  dp[0] = (S[0] == 'W') ? 1 : 0;
  for (int i=0 ; i<n-1 ; i++) {
    if (S[i+1] == 'W') dp[i+1] = dp[i] + 1;
    else dp[i+1] = dp[i];
  }
  
  int res = n - 1 - dp[n-1] + dp[0];
  
  for (int i=1 ; i<n; i++) {
    res = min(dp[i-1] + n - i - 1 - dp[n-1] + dp[i], res);
  }
  printf("%d\n", res);
}

Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <map>

using namespace std;

typedef long long ll;

ll M = 998244353;
ll n;
string s;
ll R, G, B, RB, RG, GB;
ll ans = 1;

int main()
{
    cin>>n>>s;
    for(ll i = 0; i < s.size(); i++)
    {
        if(s[i] == 'R')
        {
            if(GB) ans *= GB, GB--;
            else if(B) ans *= B, B--, RB++;
            else if(G) ans *= G, G--, RG++;
            else R++;
        }
        else if(s[i] == 'B')
        {
            if(RG) ans *= RG, RG--;
            else if(R) ans *= R, R--, RB++;
            else if(G) ans *= G, G--, GB++;
            else B++;
        }
        else
        {
            if(RB) ans *= RB, RB--;
            else if(R) ans *= R, R--, RG++;
            else if(B) ans *= B, B--, GB++;
            else G++;
        }
        ans %= M;
    }
    for(ll i = 1; i <= n; i++) ans *= i, ans %= M;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 900
def f(N, D, b=False):
    if len(N)==0: return 0 if b else 1

    n0 = int(N[0])
    m = 0
    for d in D:
        if d==n0:
            m += f(N[1:], D)
        if d<n0:
            m += len(D)**len(N[1:])
    return m + f('9'*len(N[1:]), D, True) if b else m

N = input()
print(( f(N,[3,5,7],True)
       -f(N,[3,5  ],True)
       -f(N,[  5,7],True)
       -f(N,[3,  7],True)
       +f(N,[3    ],True)
       +f(N,[  5  ],True)
       +f(N,[    7],True)))


Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <string>
using namespace std;

#define PI 3.14159265358979

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

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

int n,x;
int d[31];
const int MAX_C = 1000001;
bool primes[MAX_C];
bool dp[MAX_C];

void eratosthenes() {
	fill(primes, primes+MAX_C, true);
	primes[0] = primes[1] = false;
	repa(i,2,MAX_C-1) {
		if(primes[i]) {
			int j = i<<1;
			while(j < MAX_C) {
				primes[j] = false;
				j += i;
			}
		}
	}
}

void solve() {
	memset(dp, 0, sizeof(dp));
	dp[0] = true;
	repa(i,1,x) {
		if(!dp[i]) {
			rep(j,n) {
				if(i-d[j] >= 0 && dp[i-d[j]]) {
					dp[i] = true;
					break;
				}
			}
		}
	}

	repd(i,x,0) {
		if(dp[i] && primes[i]) {
			cout << i << endl;
			return;
		}
	}
	cout << "NA" << endl;
}

int main() {
	eratosthenes();
	while(cin>>n>>x, n|x) {
		rep(i,n) cin>>d[i];
		solve();
	}
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
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; }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) do{}while(0)
#endif





int main(){
	ll n, k;
	cin >> n >> k;
	
	vector<ll> v(n);
	ll h = 0;
	rep(i,n){
		cin >> v[i];
		chmax(h,v[i]);
	}
	
	ll l = 0;
	
	while ( h-l > 1 ){
		ll m = l + (h-l)/2;
		
		// 長さmにするには、何回切ればいいか？
		// 長さlではk回より多くかかる。長さhならk回以下に収まる
		ll cut = 0;
		rep(i,n){
			if ( v[i] > m ){
				ll num_frag = v[i] / m;
				ll remain = v[i] % m;
				
				if ( remain == 0 )
					cut += num_frag-1;
				else
					cut +=num_frag;
			}
			
		}
		if ( cut <= k )
			h = m;
		else
			l = m;
	}
	
	
	
	
	cout << h << endl;

	return 0;
}




Measured memory_bytes: 4788
#include <iostream>
#include <cstdio>
using namespace std;
int n,a,b,t,res;

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin >> n >> a >> b;
	int res=0;
	for (int i=1; i<=n; i++)
	{
		cin >> t;
		if (t<a or t>=b) res++;
	}
	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{
	cin>>n;int a1=0,a2=0,a4=0;
	for(int i=1;i<=n;i++)
	{
		int x;cin>>x;
		if(x%4==0)a4++;
		else if(x%2==0)a2++;
		else a1++;
	}
	if(a2==0&&a4>=a1-1)puts("Yes");
		else
		{
			if(a4>=a1)puts("Yes");
			else puts("No");
		}
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
using namespace std;
//5
//2 1 5 4 3
typedef long long ll;
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int before = A[0];
    long sum = 0;
    for (int i = 1; i < N; i++) {
        if (before > A[i]) {
            sum += before - A[i];
        } else {
            before = A[i];
        }

    }

    // for (int i = 0; i < N; i++) cout << A[i] << endl;
    std::cout << sum << std::endl;
    return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long long> v(n);
  for (int i=0; i<n; i++) {
    int t, cnt=0;
    cin >> t;
    while (t%2==0) {
      t/=2;
      cnt++;
    }
    v[i]=cnt;
  }

  printf("%d\n", *min_element(v.begin(), v.end()));
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int n,a,b,x;
  scanf("%d%d%d",&n,&a,&b);
  if(a*n>b)
  {
    x=b;
  }
  else
  {
    x=a*n;
  }
  printf("%d\n",x);
  return 0;
}


Measured memory_bytes: 128
use strict;
my $N = <STDIN>;
my $line = <STDIN>;
my @a=split ' ',$line;

my $mean=0;
for(my $i=0;$i<$N;$i++){ $mean += $a[$i]; }

$mean = int($mean/$N);

my $upper=$mean+1;
my $lower=$mean-1;

my @aaa;
my $k=0;
my $cost =0;
my $costU =0;
my $costL =0;
for($k=0;$k<$N;$k++){
  $cost += ($a[$k]-$mean)*($a[$k]-$mean);
}
push @aaa,$cost;
for($k=0;$k<$N;$k++){
  $costU += ($a[$k]-$upper)*($a[$k]-$upper);
}
push @aaa,$costU;
for($k=0;$k<$N;$k++){
  $costL += ($a[$k]-$lower)*($a[$k]-$lower);
}
push @aaa,$costL;

@aaa = sort{$a<=>$b}@aaa;

print $aaa[0]


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int main()
{
    int N, L;
    cin >> N >> L;
    int min_v = INF;
    int ans = 0;
    rep(i, N)
    {
        if (min_v > abs(L + i))
        {
            min_v = abs(L + i);
            ans = i;
        }
    }
    int v = 0;
    rep(i, N)
    {
        if (i != ans)
        {
            v += L + i;
        }
    }
    cout << v << endl;
    return 0;
}


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

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

int l;
pi dist[305][305];
vector<pi> g[305];

bool lss(pi a, pi b){
	if(a.fi != b.fi) return a.fi < b.fi;
	return a.se > b.se;
}

struct cmp{
	bool operator() (pair<pi, int> a, pair<pi, int> b){
		if(a.fi.fi != b.fi.fi) return a.fi.fi < b.fi.fi;
		else if(a.fi.se != b.fi.se) return a.fi.se > b.fi.se;
		return a.se > b.se;
	}
};

void dijkstra(int source){
	dist[source][source] = {0, l};
	set<pair<pi, int>, cmp> q;
	q.insert(mp(dist[source][source], source));
	while(!q.empty()){
		pair<pi, int> cur = *q.begin();
		q.erase(q.begin());
		for(pi x : g[cur.se]) if(x.se <= l){
			pi nw = cur.fi;
			if(x.se <= nw.se) nw.se -= x.se;
			else{
				nw.fi++;
				nw.se = l - x.se;
			}
			if(lss(nw, dist[source][x.fi])){
				q.erase(mp(dist[source][x.fi], x.fi));
				dist[source][x.fi] = nw;
				q.insert(mp(dist[source][x.fi], x.fi));
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m >> l;
	rep(i, 305) rep(j, 305) dist[i][j] = {1e9, 0};
	rep(i, m){
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
        	g[a].pb(mp(b, c));
        	g[b].pb(mp(a, c));
	}
	rep(i, n) dijkstra(i);
	int q;
	cin >> q;
	rep(i, q){
		int s, t;
        	cin >> s >> t;
        	if(dist[s - 1][t - 1].fi == 1e9) cout << -1 << endl;
        	else cout << dist[s - 1][t - 1].fi << endl;
	}
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 2432
import itertools

n, m = map(int, input().split())
xyz = []
for i in range(n):
    x, y, z = map(int, input().split())
    xyz.append((x, y, z))

bit = [-1, 1]
ret = 0
for i in itertools.product(bit, repeat=3):
    tmp = []
    for item in xyz:
        tmp.append(item[0] * i[0] + item[1] * i[1] + item[2] * i[2])
    tmp.sort()
    tmp.reverse()
    val = sum(tmp[:m])
    ret = max(ret, val)

print(ret)


Measured memory_bytes: 40048