akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <vector>
#include <functional>
#include <cmath>
#include <cstdio>

using namespace std;

typedef pair<int, int> P;
typedef pair<P, int> Q;

double limit(int x, int y, int r) {
	if (x*x>r*r) {
		return 100.0;
	} else if (x*x==r*r && y == 0) {
		return 100.0;
	}
	return (double)y - (-(double)r+sqrt(r*r-x*x));
}

int main() {
	int r, n;
	while (cin >> r >> n) {
		if (r == 0 && n == 0) {
			break;
		}
		priority_queue< Q, vector<Q>, greater<Q> > pq;
		Q q;
		for (int i = 0; i < n; i++) {
			cin >> (q.first).first >> (q.first).second >> q.second;
			pq.push(q);
		}
		vector<Q> data;
		while (!pq.empty()) {
			Q q1 = pq.top();
			pq.pop();
			if (!pq.empty()) {
				Q q2 = pq.top();
				pq.pop();
				if ((q2.first).first < (q1.first).second) {
					if (((q2.first).second <= (q1.first).second) && (q2.second <= q1.second)) {
						pq.push(q1);
					} else if ((q1.first).first != (q2.first).first){
						Q q3;
						q3.second = q1.second;
						(q3.first).first = (q1.first).first;
						(q3.first).second = (q2.first).first;
						data.push_back(q3);
						(q1.first).first = (q2.first).first;
						pq.push(q1);
						pq.push(q2);
					} else {
						if (q1.second <= q2.second) {
							pq.push(q2);
						} else {
							pq.push(q1);
							(q2.first).first = (q1.first).second;
							pq.push(q2);
						}
					}
				} else {
					data.push_back(q1);
					pq.push(q2);
				}
			} else {
				data.push_back(q1);
			}
		}
		double MIN = 100.0;
		bool hantei = true;
		for (int i = 0; i< data.size(); i++) {
			int xl = (data[i].first).first;
			int xr = (data[i].first).second;
			int h = data[i].second;
			if (xl <= 0 && xr >= 0) {
				hantei = false;
				MIN = min(MIN, limit(0, h, r));
			}
			if (i == 0){
				MIN = min(MIN, min(limit(xl, 0, r), min(limit(xl, h, r), limit(xr, h, r))));
				if (xr != (data[i+1].first).first) {
					MIN = min(MIN, limit(xr, 0, r));
				}
			} else if (i+1 == data.size()) {
				MIN = min(MIN, min(limit(xr, 0, r), min(limit(xl, h, r), limit(xr, h, r))));
				if (xl != (data[i-1].first).second) {
					MIN = min(MIN, limit(xl, 0, r));
				}
			} else {
				MIN = min(MIN, min(limit(xl, h, r), limit(xr, h, r)));
				if (xr != (data[i+1].first).first) {
					MIN = min(MIN, limit(xr, 0, r));
				}
				if (xl != (data[i-1].first).second) {
					MIN = min(MIN, limit(xl, 0, r));
				}
			}
		}
		if (hantei) {
			MIN = min(MIN, limit(0, 0, r));
		}
		printf("%.4f\n", MIN);
	}
	return 0;
}

Measured memory_bytes: 1232
#include<stdio.h>
int main(){
	int a,b,c,i,x;
	scanf("%d%d%d",&a,&b,&c);
	
	x=0;
	for(i=a;i<=b;i++){
		if(c%i==0){
			x++;
		}
	}
	
	printf("%d\n",x);
	
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int var[11];
bool flag;

bool formula(string &s, int &i){
    if(s[i] == 'T'){
        ++i;
        return 1;
    }
    else if(s[i] == 'F'){
        ++i;
        return 0;
    }
    else if('a' <= s[i] && s[i] <= 'k'){
        return var[s[i++]-'a'];
    }
    else if(s[i] == '-'){
        ++i;
        return !formula(s, i);
    }
    ++i;
    int x = formula(s, i);
    if(s[i] == '*'){
        ++i;
        int y = formula(s, i);
        ++i;
        return x & y;
    }
    else if(s[i] == '+'){
        ++i;
        int y = formula(s, i);
        ++i;
        return x | y;
    }
    else{
        i += 2;
        int y = formula(s, i);
        ++i;
        return !x | y;
    }
}

void solve(int cur, string &s, string &t){
    if(cur == 11){
        int idx = 0;
        int x = formula(s, idx);
        idx = 0;
        int y = formula(t, idx);
        flag &= (x == y);
        return;
    }
    var[cur] = 0;
    solve(cur+1, s, t);
    var[cur] = 1;
    solve(cur+1, s, t);
}

int main(){
    string s, t;
    while(cin >> s && s != "#"){
        rep(i, s.size())if(s[i] == '='){
            t = s.substr(i+1, s.size()-i-1);
            s = s.substr(0, i);
            break;
        }
        flag = true;
        solve(0, s, t);
        puts(flag ? "YES" : "NO");
    }
}


Measured memory_bytes: 3192
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main() {
  ll n,k;
  cin >> n>>k;

  ll ans = k;
  rep(i,n-1){
    ans*=k-1;
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxN = 1005;
string s;
int x[maxN], y[maxN];
int n;
vector < pair < int, int > > all;
int stx = 0;
int sty = 0;
string ans[maxN];
vector < int > d;
void solve(vector < pair < int, int > > all) {
    bool ok = true;
    for (int i = 0; i < all.size(); i++) {
        if (abs(all[i].first) > 1 || abs(all[i].second) > 1) {
            ok = false;
            break;
        }
    }
    if (ok) {
        d.push_back(1);
        for (int j = 0; j < n; j++) {
            if (all[j].first == 1) {
                ans[j] += 'R';
            }
            if (all[j].first == -1) {
                ans[j] += 'L';
            }
            if (all[j].second == 1) {
                ans[j] += 'U';
            }
            if (all[j].second == -1) {
                ans[j] += 'D';
            }
        }
        return ;
    }
    vector < pair < int, int > > nall;
    for (int i = 0; i < n; i++) {
        int mn = 2 * (int)1e9;
        pair < int, int > opt;
        for (int t1 = -2; t1 <= 2; t1++) {
            for (int t2 = -2; t2 <= 2; t2++) {
                int p1 = (all[i].first + t1) / 2;
                int p2 = (all[i].second + t2) / 2;
                if (abs(p1 + p2) % 2 == 0) continue;
                if (abs(2 * p1 - all[i].first) > 1) continue;
                if (abs(2 * p2 - all[i].second) > 1) continue;
                if (mn > abs(p1) + abs(p2)) {
                    mn = abs(p1) + abs(p2);
                    opt = make_pair(p1, p2);
                }
            }
        }
        nall.push_back(opt);
    }
    solve(nall);
    for (int i = 0; i < d.size(); i++) d[i] *= 2;
    d.push_back(1);
    for (int i = 0; i < all.size(); i++) {
        pair < int, int > prv = nall[i];
        pair < int, int > cur = all[i];
        int dif1 = cur.first - 2 * prv.first;
        int dif2 = cur.second - 2 * prv.second;
        if (dif1 == 1) {
            ans[i] += 'R';
        }
        if (dif1 == -1) {
            ans[i] += 'L';
        }
        if (dif2 == 1) {
            ans[i] += 'U';
        }
        if (dif2 == -1) {
            ans[i] += 'D';
        }
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i];
    }
    for (int i = 1; i <= n; i++) {
        int p1 = abs(x[1] + y[1]) % 2;
        int p2 = abs(x[i] + y[i]) % 2;
        if (p1 != p2) {
            cout << -1;
            return 0;
        }
    }
    if ((abs(x[1] + y[1]) % 2) == 0) {
        stx = 0;
        sty = 1;
        for (int i = 1; i <= n; i++) {
            y[i] -= 1;
        }
    }
    for (int i = 1; i <= n; i++) {
        all.emplace_back(make_pair(x[i], y[i]));
    }
    solve(all);
    if (sty == 1) {
        d.push_back(1);
        for (int i = 0; i < n; i++) {
            ans[i] += 'U';
        }
    }
    cout << d.size() << '\n';
    for (int v : d) cout << v << " ";
    cout << '\n';
    for (int i = 0; i < n; i++) {
        cout << ans[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 896
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


string sorted(string s){
    sort(all(s));
    return s;
}


int main() {
    string s;
    string ans="";
    string aizu="AIZUNYAN";
    string nyan="AIDUNYAN";
    sort(all(nyan));
    
    while(cin>>s){
        rep(i,s.size()){
            if(i<s.size()-7 && sorted(s.substr(i,8))==nyan){
                ans+=aizu;
                i+=7;
            }
            else ans+=s[i];
        }
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;


int main(){

	int dp[100][200],row = 0,tmp,index,width[100],max_width = 0, max_width_row;
	char buf[200];

	while(scanf("%s",buf)!=EOF){
		index = tmp = 0;
		for(int i=0;buf[i] != '\0'; i++){
			if(buf[i] >= '0' && buf[i] <= '9'){
				tmp = tmp*10 + (buf[i] - '0');
				if(buf[i+1] == '\0'){
					dp[row][index++] = tmp;
				}
			}else{
				dp[row][index++] = tmp;
				tmp = 0;
			}
		}
		if(max_width < index){
			max_width = index;
			max_width_row = row;
		}

		width[row] = index;
		row++;
	}

	for(int i=1; i <= max_width_row; i++){
		for(int k=0; k < width[i]; k++){
			if(k == 0){
				dp[i][0] += dp[i-1][0];
			}else if(k == width[i]-1){
				dp[i][k] += dp[i-1][width[i-1]-1];
			}else{
				dp[i][k] += max(dp[i-1][k-1],dp[i-1][k]);
			}
		}
	}

	for(int i = max_width_row+1;i < row; i++){
		for(int k=0; k < width[i]; k++){
			dp[i][k] += max(dp[i-1][k],dp[i-1][k+1]);
		}
	}

	printf("%d\n",dp[row-1][0]);

    return 0;
}

Measured memory_bytes: 2668
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cstdlib>
using namespace std;

int main(){
	int x;
	cin >> x;
	int s = 0;
	for(int i = 1;;i++){
		s += i;
		if(s >= x){
			cout << i << endl;
			break;
		}
	}
}


Measured memory_bytes: 384
x, y = map(int, input().split())

if x*y < 0:
    print(abs(abs(x)-abs(y))+1)
elif x*y == 0:
    if x < y:
        print(y-x)
    else:
        print(x-y+1)
else:
    if x < y:
        print(y-x)
    else:
        print(x-y+2)


Measured memory_bytes: 9176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;
 
int main(){
  ll N,K;
  cin >> N >> K;
  ll c1 = N/K;
  if(K % 2 == 0){
    int c2 = (N + (K/2)) / K;
    cout << (ll)powl(c1, 3) + (ll)powl(c2, 3) << endl;
  }else{
    cout << (ll)powl(c1, 3)<< endl;
  }
}

Measured memory_bytes: 384
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {
	if (a > b) a = b;
}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {
	if (a < b) a = b;
}
typedef pair<int, int> pii;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 200020;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;


void solve() {
	int N, K;
	cin >> N >> K;

	vector<int>h(N);
	REP(i, N)cin >> h[i];
	VSORT(h);
	int ans = 1e9;
	REP(i, N - K + 1) {
		ans = min(ans, h[i + K - 1] - h[i]);
	}
	cout << ans << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// int q; cin >> q;
	// while (q--)
	solve();
}


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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for(int i = 0; i < n; i++){
    cin >> h.at(i);
  }

  bool judge = true;
  for(int i = n-1; i > 0; i--){
    if (h.at(i-1) - h.at(i) > 1){
      judge = false;
      break;
    } else if (h.at(i-1) - h.at(i) == 1){
      h.at(i-1)--;
    }
  }
  cout << (judge ? "Yes" : "No") << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
ll cnt = 0;

int main(){
    int a,p;    cin >> a >> p;
    a *= 3;
    cout << (a+p)/2 << endl;
}

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

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値



// 深さ優先探索
using Graph = vector<vector<int>>;
vector<bool> seen;
ll N, K; 
ll dist1,dist2;
void dfs(const Graph &G,vector<ll> &dist, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]){
            dist1=dist[next_v];
            dist2=dist[v]+1;
            continue;
        } // next_v が探索済だったらスルー
        dist[next_v]=dist[v]+1;
        dfs(G,dist, next_v); // 再帰的に探索
    }
}







int main(){
    // メイン
    // 頂点数と辺数
    cin >> N >> K;
    Graph G(N);
    vector<ll> dist(N,-1);
    // グラフ入力受取 (無向グラフ)
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        a--;
        G[i].push_back(a);
    }
    

    // 頂点0スタート
    seen.assign(N, false); // 全頂点を「未訪問」に初期化
    dist[0]=0;
    dfs(G,dist, 0);
    if(K<=dist1){
        REP(i,N){
            if(dist[i]==K){
                cout << i+1 <<endl;
                return 0;
            }
        }
    }else{
        REP(i,N){
            if((dist[i]!=-1)&&(dist[i]==dist1+(K-dist1)%(dist2-dist1))){
                cout << i+1 <<endl;
                return 0;
            }
        }
    }
    
}

Measured memory_bytes: 27912
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
time, x, y = 0, 0, 0
for i in range(N):
    timei, xi, yi = A[i][0], A[i][1], A[i][2]
    time = timei - time
    x = xi - x
    y = yi - y
    move = x + y
    if time >= move:
        if(move*time)%2==1 or (move*time)%4==0:
            ans = "Yes"
        else:
            ans = "No"
            break
    else:
        ans = "No"
        break
    time, x, y = timei, xi, yi
print(ans)

Measured memory_bytes: 60760
# できなかった
# a1,...,anがdivisorで割り切れる、すなわちdivisorはMの約数である
n,m=map(int,input().split())

divisors=[]
for i in range(1,int(m**0.5)+1):
    if m%i==0:
        divisors.append(i)
        if i!=m//i:
            divisors.append(m//i)

divisors.sort(key=lambda x:-x)
# print(divisors)
for d in divisors:
    if d<=m//n:
        print(d)
        break


Measured memory_bytes: 3060
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) {
        try {
            InputReader in;
            PrintWriter out;
            boolean useOutput = false;
            // if (System.getProperty("ONLINE_JUDGE") == null) useOutput = true;
            if (useOutput) {
                FileInputStream fin = new FileInputStream(new File("src/testdata.in"));
                in = new InputReader(fin);
                FileOutputStream fout = new FileOutputStream(new File("src/testData.out"));
                out = new PrintWriter(fout);
            } else {
                InputStream inputStream = System.in;
                in = new InputReader(inputStream);
                OutputStream outputStream = System.out;
                out = new PrintWriter(outputStream);
            }
            Solver solver = new Solver();
            solver.solve(in, out);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static class Solver {

        public void solve(InputReader cin, PrintWriter cout) {
            try {
                int n = cin.nextInt();
                int cost[] = new int[n], dp[] = new int[n];
                for (int i = 0; i < n; ++i) {
                    cost[i] = cin.nextInt();
                }
                dp[0] = 0;
                if (n > 1) dp[1] = Math.abs(cost[1] - cost[0]);
                for (int i = 2; i < n; ++i) {
                    dp[i] = Math.min(Math.abs(cost[i] - cost[i - 1]) + dp[i - 1],
                                    Math.abs(cost[i] - cost[i - 2]) + dp[i - 2]);
                }
                cout.println(dp[n - 1]);
            } catch (RuntimeException e) {
                e.printStackTrace();
                return;
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }

        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }

}

Measured memory_bytes: 32332
using System;
using System.Collections.Generic;
using System.Linq;
namespace c
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			var inp = Array.ConvertAll(Console.ReadLine().Split(),double.Parse);
			Console.WriteLine (Math.Ceiling (inp [0] / (2 * inp [1] + 1)));
		}
	}
}

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

using namespace std;


int main()
{
    long long A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
    C *= 2;

    long long ans = 0;

    ans = max(X, Y) * C;

    ans = min(ans, A * X + B * Y);

    ans = min(ans, (X < Y ? X * C + (Y - X) * B : Y * C + (X - Y) * A));

    cout << ans << endl;
}

Measured memory_bytes: 3628
n,x = map(int,input().split())
a = [int(x.strip()) for x in input().split()]
a_sorted = sorted(a)
ch,ans = 0,0
for i in range(n):
  ch = sum(a_sorted[:i+1])
  if ch < x:
    ans += 1
  elif ch == x:
    ans += 1
    break
  else:
    break
if n == ans and sum(a) < x:
  ans -= 1
print(ans)

Measured memory_bytes: 9184
#include <iostream>
using namespace std;
struct pos { int td,kd; };
int dm[50][50],tc[2500][2500],pn[2],g;
pos p[2][3000000];

int main() {
	int ax,ay,i,j,t,x,y,tx,ty,kx,ky,tx2,ty2,kx2,ky2,dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
	while(cin >> x >> y && x>0) {
		pn[0]=1; g=0;
		for (i=0;i<x*y;i++) for (j=0;j<x*y;j++) tc[i][j]=0;
		cin >> tx >> ty >> kx >> ky;
		ax=(ty-1)*x+tx-1; ay=(ky-1)*x+kx-1; tc[ax][ay]=1; p[g][0].td=ax; p[g][0].kd=ay;
		for (i=0;i<y;i++) for (j=0;j<x;j++) cin >> dm[i][j];
		for (t=1;t<100;t++) {
			pn[1-g]=0;
			for (i=0;i<pn[g];i++) {
				tx=p[g][i].td % x; ty=p[g][i].td/x;
				kx=p[g][i].kd % x; ky=p[g][i].kd/x;
				for (j=0;j<4;j++) {
					ax=tx+dx[j]; ay=ty+dy[j]; tx2=tx; ty2=ty; kx2=kx; ky2=ky;
					if (ax>=0 && ax<x && ay>=0 && ay<y) if (dm[ay][ax]==0) { tx2=ax; ty2=ay;}
					ax=kx-dx[j]; ay=ky-dy[j];
					if (ax>=0 && ax<x && ay>=0 && ay<y) if (dm[ay][ax]==0) { kx2=ax; ky2=ay;}
					if (tx2==kx2 && ty2==ky2) break;
					ax=ty2*x+tx2; ay=ky2*x+kx2;
					if (tc[ax][ay]==0) { tc[ax][ay]=1; p[1-g][pn[1-g]].td=ax; p[1-g][pn[1-g]].kd=ay; pn[1-g]++;}
				}
				if (j<4) break;
			}
			if (j<4) break;
			g=1-g;
		}
		if (j<4 && t<100) cout << t << endl; else cout << "NA" << endl;
	} 
	return 0;
}  

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

typedef long long ll;
typedef pair<int, int> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

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

Measured memory_bytes: 19124
import java.util.*;

public class Main{
  public static void main(String[] args){
    
    Scanner scan = new Scanner(System.in);
    int val1 = scan.nextInt();
    String val2 = scan.next();
    int val3 = scan.nextInt();
    
    if (val2.equals("+")){
      System.out.print(val1 + val3);
    }else{
      System.out.print(val1 - val3);
    }
    
    
  }
}

Measured memory_bytes: 35656
#include <stdio.h>

int main(void)
{
  int N,M,i,A,s;

  scanf("%d%d",&N,&M);

  s=0;
  for(i=0;i<M;i++){
  scanf("%d",&A);
  s+=A;
  }

  if(s>N)
   printf("-1\n");
  else
   printf("%d\n",N-s);

  return 0;
}


Measured memory_bytes: 1704
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)

#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

using namespace std;
using ll = long long;
using vel = vector<ll>;
using ves = vector<string>;
using veb = vector<bool>;
using qul = queue<ll>;

void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

int binary_search(ll x, vel a){
    auto ite = lower_bound(ALL(a), x);
    if(ite != a.end() && *ite == x) {
        return ite - a.begin() ;
    } else {
        return -1;
    }

}

ll modpow(ll a, ll n, ll mod) {
    if(n == 0)
        return 1;
    if(n == 1)
        return a % mod;
    if(n % 2 == 1)
        return (a * modpow(a, n - 1, mod)) % mod;
    ll t = modpow(a, n / 2, mod);
    return (t * t) % mod;
}



int main() {
    ll N,count=0;
    cin >> N;
    vel L(N);
    REP(i,N) cin >> L[i];
    sort(ALL(L));
    FOR(i,0,N-2){
        FOR(j,i+1,N-1){
            FOR(k,j+1,N){
                if(L[i] != L[j] && L[j] != L[k] && L[i] != L[k] && L[i] + L[j] > L[k]) count ++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3600
# coding: utf-8

n, k = map(int, input().split())
z = 10**9 + 7

ans = 0
for i in range(k, n+2):
    mini = (0+(i-1))*i/2
    maxi = ((n)+(n-i+1))*i/2
    ans += maxi-mini+1
    
print(int(ans%z))

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

typedef long long lnt;

std::map<lnt,lnt>mp;

int main(){
    int n;
    lnt tmp=0;
    scanf("%d",&n);
    mp[0]++;
    lnt ans=0;
    for(int k=1;k<=n;k++){
        lnt x;
        scanf("%lld",&x);
        tmp+=x;
        ans+=mp[tmp];
        mp[tmp]++;
    }
    printf("%lld\n",ans);
}
        

Measured memory_bytes: 12800
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);
	      	  
	      	  string x;
	      	  cin >> x;
	      	  
	      	  if((x[0]==x[1] && x[1]==x[2]) || (x[1]==x[2] && x[2]==x[3])){
	      		  cout << "Yes" << endl;
	      	  }else{
	      		cout << "No" << endl;
	      	  }

	          return 0;
}


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

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	while (true) {
		C -= B;
		A -= D;
		if (C <= 0) {
			cout << "Yes" << endl;
			break;
		} else if (A <= 0) {
			cout << "No" << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>

int gcd(int,int);

int main()
{
  int x,y;

  /* 入力 */
  scanf("%d%d",&x,&y);
  /* 出力 */
  printf("%d\n",gcd(x,y));
  return 0;
}

/* 関数gcd 最大公約数を求める */
int gcd(int x,int y)
{
  int d;
  int temp;
  if(x<y){
    temp = x;
    x=y;
    y=temp;
  }
  while(y>0){
    d = x % y;
    x = y;
    y = d;
  }
  return x;
}



Measured memory_bytes: 2144
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
#include <cmath>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define mp make_pair
#define pb push_back
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

int x[10], y[10];

double dist(int i, int j) {
	double dx = x[i] - x[j];
	double dy = y[i] - y[j];
	return pow(dx*dx + dy*dy, 0.5);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];

	vector<int> v;
	int factorial = 1;
	for (int i = 1; i <= n; i++) {
		v.pb(i);
		factorial *= i;
	}

	double ans = 0;
	do {
		for (int i = 0; i < n-1; i++) {
			ans += dist(v[i], v[i+1]) / factorial;
		}
	} while (next_permutation(ALL(v)));

	printf("%8lf\n", ans);
    return 0;
}


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

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

const ll INF = 1e18;
const ll MOD = 1e9+7;

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


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    while(true)
    {
        int n; cin >> n;
        if(n == 0) break;
        vi imos(250000);
        REP(i, n)
        {
            string s, t; cin >> s >> t;
            s.erase(5, 1); s.erase(2, 1);
            t.erase(5, 1); t.erase(2, 1);
            int x = stoi(s), y = stoi(t);
            imos[x]++; imos[y]--;
        }
        REP(i, imos.size()-1) imos[i+1] += imos[i];
        cout << *max_element(ALL(imos)) << endl;
    }
}


Measured memory_bytes: 4208
N, M, X = gets.split.map{|i|i.to_i}
books = []
N.times{
    books << gets.split.map{|i|i.to_i}
}
min = 10 ** 7
(1 .. 2 ** N - 1).each{|n|
    skills = Array.new(M){0}
    cost = 0
    N.times{|b|
        if n[b] == 1
            cost += books[b][0]
            M.times{|m|
                skills[m] += books[b][m + 1]
            }
        end
    }
    #warn skills.inspect
    if skills.all?{|i|i >= X}
        if min > cost
            min = cost
        end
    end
}
if min == 10 ** 7
    min = -1
end
puts min


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

using namespace std;
long long gcd(long long a,long long b);

int main()
{
    long long x=0;
    long long y=0;
    cin >> x >> y ;
    int ans=gcd(x,y);
    cout << ans << endl;
    return 0;
}

long long gcd(long long a,long long b)
{
    while(b!=0)
    {
        long long r=a%b;
        a=b;
        b=r;
    }
    return(a);
}


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

using namespace std;

const int Maxn = 4000 + 100;
int Begin[Maxn], To[Maxn], Next[Maxn], e;
int sum[Maxn], dis[Maxn];
int n, K, maxi;
vector<int> graph[Maxn];

void add_edge(int x, int y)
{
    To[++e] = y;
    Next[e] = Begin[x];
    Begin[x] = e;
}
void dfs (int x, int fa)
{
    maxi = max(maxi, dis[x]);
    sum[dis[x]] ++;
    for (int i = 0; i < graph[x].size(); i++)
    {
        int y = graph[x][i];
        if (y == fa) 
        	continue;
        dis[y] = dis[x] + 1;
        dfs(y, x);
    }
}

int main()
{
    cin >> n >> K;
    for (int i = 1; i < n; ++i)
    {
        int x, y;
        cin >> x >> y;
        graph[x].push_back(y);
        graph[y].push_back(x);
        add_edge(x, y);
        add_edge(y, x);
    }
    int ans = 1000 * 1000 * 1000;
    for (int i = 1; i <= n; ++i)
    {
        memset(sum, 0, sizeof(sum));
        memset(dis, 0, sizeof(dis));
        maxi = 0;
        dfs(i, 0);
        int cnt = 0;
        for (int j = K / 2 + 1; j <= maxi; ++j)
            cnt += sum[j];
        if (!(K & 1))
        {
        	ans = min(ans, cnt);
        }
        else 
        {
            for (int j = Begin[i]; j; j = Next[j])
            {
                int y = To[j];
                int tmp = 0;
                memset(sum, 0, sizeof(sum));
                memset(dis, 0, sizeof(dis));
                maxi = 0;
                dfs(i, y);
                for (int k = K / 2 + 1; k <= maxi; ++k)
                {
                    tmp += sum[k];
                }
                memset(sum, 0, sizeof(sum));
                memset(dis, 0, sizeof(dis));
                maxi = 0;
                dfs(y, i);
                for (int k = K / 2 + 1; k <= maxi; k++)
                {
                    tmp += sum[k];
                }
                ans = min(ans, tmp);
            }
        }
    }
    cout << ans << endl;
}
 

   


Measured memory_bytes: 640
#include <bits/stdc++.h>
     
    using namespace std;
     
    #define MOD 1000000007
    #define PI 3.1415926535897932384626433832795
    #define INF (int)1e9
    typedef long long int int64;
     
    void print() {
        cout << endl;
    }
     
    void print(string s, bool endline = true) {
        cout << s;
        if (endline) print();
    }
     
    void print(int64 s, bool endline = true) {
        cout << s;
        if (endline) print();
    }
     
    template <typename T, typename T2>
    void print(pair<T, T2>& p, bool endline = true) {
        print("(", false);
        print(p.first, false);
        print(", ", false);
        print(p.second, false);
        print(")", false);
     
        if (endline) print();
    }
     
    template <typename T, typename T2>
    void print(map<T, T2>& m, bool endline = true) {
        print("{");
        for (auto& p : m) {
            print("  ", false);
            print(p);
        }
        print("}");
     
        if (endline) {}
    }
     
    template<typename T>
    void print(vector<T>& v, bool endline = true) {
        print("[", false);
        for (size_t i = 0; i < v.size(); ++i) {
            print(v[i], false);
            if(i != v.size() - 1) print(",", false);
        }
        print("]", false);
     
        if(endline) print();
    }
     
    template <typename T>
    vector<T> operator+(const vector<T> &a, const vector<T> &b)
    {
        vector<T> ret;
        ret.reserve( a.size() + b.size() );                // preallocate memory
        ret.insert( ret.end(), a.begin(), a.end() );        // add A;
        ret.insert( ret.end(), b.begin(), b.end() );        // add B;
     
        return ret;
    }
     
    template <typename T>
    vector<T> &operator+=(vector<T> &a, const vector<T> &b)
    {
        a.reserve( a.size() + b.size() );                // preallocate memory without erase original data
        a.insert( a.end(), b.begin(), b.end() );         // add B;
        return a;
    }

    int main() {
        // g++ -Wall -Wextra -O2 -std=c++17 helloworld.cpp
        int64 a1, a2, a3;

        cin >> a1 >> a2 >> a3;

        if (a1 + a2 + a3 > 21) {
            print("bust");
        } else {
            print("win");
        }

        return 0;
    }

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  // TODO 自動生成されたメソッド・スタブ
    public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int i = scan.nextInt();
    String s = String.valueOf(i);
    String[] ss = s.split("");
    int count = 0;
    for(String masu : ss){
      if(masu.equals("1")) {
        count = count + 1;
      }
    }
    System.out.println(count);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;

int main()
{
  ll a, b, x;
  cin >> a >> b;

  x = a * b;
  if (a < b){
    ll tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  ll ans;
  if (r == 0) ans = a;
  else{
    while(r > 0){
      a = b;
      b = r;
      r = a % b;
    }
    ans = x/b;
  }

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


Measured memory_bytes: 256
$\=$/;$L=0,$|=$R=10,$_=${print("? ",($_*10+($M=$L+$R>>1))*1e9),<>=~Y?$R:$L=$M while$R-$L>1;_}*10+$L while$i++<9;
$_++;s/0*$//;
print"? ",$_+1;
print("? ",($_.=0)+1)while<>=~(/^9*$/?Y:N);
print"! ",$_

Measured memory_bytes: 852
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};


llong pow(int x, int n){
    llong ans = x;
    if (n == 0) return 1;

    for(int i = 0; i < n - 1; i++) {
        ans *= x;
    }

    return ans;
}


void swap(int *X, int *Y){
    int t = *X; *X = *Y; *Y = t;
}


string toUpper(string s) {
    string t = s;
    REP(i, s.size()) {
        t[i] = toupper(s[i]);
    }
    return t;
}

string toLower(string s) {
    string t = s;
    REP(i, s.size()) {
        t[i] = tolower(s[i]);
    }
    return t;
}


int main() {
    string s;
    cin >> s;
    cout << s.replace(0, 4, "2018") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P2;
const ll inf=0xfffffffffffffff;
vector<P> vec;
vector<P> st;
P2 mk_P(ll a,ll b,ll c){
  return P2(a,P(b,c));
}
int main(){
  int n;
  ll ans=0;
  cin>>n;
  for(int i=0;i<n;i++){
    ll a,b;
    cin>>a>>b;
    st.push_back(P(a+b,i));
    vec.push_back(P(a,b));
  }
  sort(st.begin(),st.end(),greater<P>());
  for(int i=0;i<n;i+=2){
    int lk=st[i].second;
    ans+=vec[lk].first;
  }
  for(int i=1;i<n;i+=2){
    int lk=st[i].second;
    ans-=vec[lk].second;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
const int N=101;
ll n,f[N][10],p[N][11],mmax,ans;
int ttable[10],j;


ll rieki(){
	ll a=0,c=0;
	FOR(j,1,n+1){
		c=0;
		FOR(i,0,10){
			if(ttable[i])
				if (f[j][i])
					c++;
		}
		a += p[j][c];
	}
	return a;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	mmax = -1ll*pow(10,7);
	ans = 0ll;
	cin >> n;
	FOR(i,1,n+1){
		FOR(j,0,10){
			cin >> f[i][j];
		}
	}
	FOR(i,1,n+1){
		FOR(j,0,11){
			cin >> p[i][j];
		}
	}

	FOR(i,1,1024){
		j=i;
		FOR(k,0,10){
			ttable[k]=j&1;j/=2;
		}
		if(i==1)ans = rieki();
		else ans = max(ans,rieki());
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define dd double

using namespace std;


int main(){
    string S,T;
    cin >> S;
    cin >> T;
    int ans = 0;
    for(int i = 0; i < 3; i++){
        if(S[i] == T[i]) ans++;
    }
    cout << ans << endl;
}

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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define si(d)  scanf("%d",&d)
#define sll(d) scanf("%lld",&d)
#define pin(d) printf("%d\n",d)
#define pln(d) printf("%lld\n",d)
#define nl 	   printf("\n")

#define ll  long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi      vector<int>
#define pii     pair<int,int>
#define piii    pair<pair<int,int>,int>
#define all(v)  v.begin(), v.end()

#define chalne_de continue
int mod = 1000000007;
const int N = 1000005;

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    int x = n % 10;
     n /= 100;
     if (x == n)
        cout << "Yes";
     else
        cout << "No";
	return 0;
}


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

void Main() {
  string s;
  cin >> s;

  int red = 0, blue = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') red++;
    else blue++;
  }
  cout << min(red, blue) * 2 << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

//---------------------------------------------------------------
//---------------------------------------------------------------
int D;

signed main(){
	cin >> D;
	
	if(D == 25)	cout << "Christmas";
	if(D == 24)	cout << "Christmas Eve";
	if(D == 23)	cout << "Christmas Eve Eve";
	if(D == 22)	cout << "Christmas Eve Eve Eve";
	
	return 0;
}


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

using namespace std;

int main() {
    set<long long> As;
    int N;
    cin >> N;
    for(auto i = 0; i < N; i++){
        long long t;
        cin >> t;
        if(As.find(t) != As.end()){
            cout << "NO" << endl;
            return 0;
        }
        As.insert(t);
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
int dp[1005][20005];
tuple<int,int,int> arr[1005];
bool cmp(tuple<int,int,int>a,tuple<int,int,int>b)
{
	return get<0>(a)+get<1>(a)<get<0>(b)+get<1>(b);
}
signed main()
{
	int n,i,j;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		int w,s,v;
		cin>>w>>s>>v;
		arr[i]=make_tuple(w,s,v);
	}
	sort(arr+1,arr+n+1,cmp);
	for(i=1;i<=n;i++)
	{
		int w,s,v;
		tie(w,s,v)=arr[i];
		for(j=1;j<=20000;j++)
		{
			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			if(s>=j-w&&j>=w)
			{
			dp[i][j]=max(dp[i-1][j-w]+v,dp[i][j]);
		}
		}
	}
	
	cout<<dp[n][20000]<<"\n";
}

Measured memory_bytes: 159952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
using Tree = vector<pair<int, int>>;

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (to_string(i).length() % 2 == 1)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
a = list()
for i in range(n):
    a.append(list(map(int, input().split())))
b = list()
for i in range(m):
    b.append(int(input()))
for i in range(n):
    ans = 0
    for j in range(m):
        ans += a[i][j] * b[j]
    print(ans)
        



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

int main(){
 long int a,b,v,w,t;
  scanf("%ld %ld",&a,&v);
  scanf("%ld %ld",&b,&w);
  scanf("%ld",&t);

  int flag=0;
  if(v>w){
    if(abs(a-b)<=(v-w)*t){
    flag=1;
    }
  }

  if(flag==0){
  printf("NO\n");
  }else{
  printf("YES\n");
  }
  return 0;
}

Measured memory_bytes: 2068
N=int(input())
B=sorted([list(map(int,input().split())) for i in range(N)])
d={}
for i in range(N):
    for j in range(i+1,N):
        x=(B[j][0]-B[i][0],B[j][1]-B[i][1])
        if x in d:
            d[x]+=1
        else:
            d[x]=1
if N==1:
    print(1)
else:
    print(N-max(d.values()))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define fix(n) cout<<fixed<<setprecision(n);
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int a,b=360,r; cin>>a;
  rep(i,1,180){
    if(360*i%a==0){
      co(360*i/a);
      break;
    }
  }
  
  return 0;
}

Measured memory_bytes: 3600
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        char[] chars = s.toCharArray();
        int numChanges = 0;

        for (int i = 0; i < chars.length - 1; i++) {
            if (chars[i] == chars[i + 1]) {
                chars[i + 1] = (char)(1 - (chars[i + 1] - '0') + '0');
                numChanges++;
            }
        }

        System.out.println(numChanges);

    }
}


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

int main() { 
    int n, a, ans = 0;
    cin >> n;
    map<int, int> mp;
    for(int i = 0; i < n; ++i) {
        cin >> a;
        mp[a]++;
    }
    auto begin = mp.begin(), end = mp.end();
    for(auto iter = begin; iter != end; iter++) {
        //cerr << iter->first << " " << iter->second << endl;
        if(iter->first <= iter->second) ans += iter->second - iter->first;
        else ans += iter->second;
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll h,w,k;
bool cut[12];
ll ch[12][1002];
ll ans=INF;
void cal(ll cnt){
	ll left=0;
	bool out=false;
	for(ll j=1;j<=w;j++){
		ll sum=0;
		for(ll i=1;i<=h;i++){
			sum+=ch[i][j]-ch[i][left];
			if(sum>k){
				if(left+1==j){
					out =true;
				}
				cnt++;
				left=j-1;
				break;
			}
			if(cut[i]){
				sum=0;
			}
		}
	}
	if(out==false){
	ans=min(ans,cnt);
	}
}
void dep(ll now,ll cnt){
	if(now==h){
		cal(cnt);
		return;
	}
	cut[now]=1;dep(now+1,cnt+1);
	cut[now]=0;dep(now+1,cnt);
}
int main() {
	cin>>h>>w>>k;
	for(ll i=0;i<h;i++){
		string s;
		cin>>s;
		for(ll j=0;j<w;j++){
			if(s[j]=='1'){
				ch[i+1][j+1]=1;
			}
		}
	}
	for(ll i=1;i<=h;i++){
		for(ll j=1;j<=w;j++){
			ch[i][j]=ch[i][j-1]+ch[i][j];
		}
	}
	dep(1,0);
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 384
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            int n = sc.nextInt();
            if(n==0) break;
            
            boolean[][] alpha = new boolean[26][26];
            boolean[] used = new boolean[26];
            int[] deg = new int[26];
            for(int i=0; i<n; i++){
                char[] in = sc.next().toCharArray();
                int first = (int)(in[0] - 'a');
                int last = (int)(in[in.length-1] - 'a');
                alpha[first][last] = true;
                used[first] = used[last] = true;
                deg[first]--;
                deg[last]++;
            }
            
            boolean boo = true;
            for(int i=0; i<26; i++){
                if(deg[i]!=0) boo = false;
            }
            if(!boo){
                System.out.println("NG");
                continue;
            }
            
            for(int k=0; k<26; k++)
                for(int i=0; i<26; i++)
                    for(int j=0; j<26; j++)
                        alpha[i][j] |= alpha[i][k] & alpha[k][j];
            
            for(int i=0; i<26; i++){
                for(int j=0; j<26; j++){
                    if(used[i] && used[j]){
                        if(!alpha[i][j]) boo = false;
                    }
                }
            }
            if(!boo) System.out.println("NG");
            else System.out.println("OK");
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 53432
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define rep1(i,n) for(int i=1; i<(int)n; i++)
#define repa(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
#define COUT(x) cout<<(x)<<endl
#define YES(x) cout<<(x?"YES":"NO")<<endl
#define Yes(x) cout<<(x?"Yes":"No")<<endl
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a / gcd(a, b)*b;}

int N, M, K, H, W, L, R, X;
//string S, T;

signed main(){
  cin >> N;
  int ans = 1e15;
  for(int i=1; i*i<=N; i++){
    if(N%i == 0) ans = min(ans, i+N/i-2); 
  }
  COUT(ans);
  return 0;
}


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

const int MOD = (int) 1e9 + 7;

int C[2002][2002];

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

    int N, K;
    cin >> N >> K;

    for(int i=0; i<=N; i++)
        C[i][0] = 1;
    
    for(int i=1; i<=N; i++)
        for(int j=1; j<=N; j++)
            C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
    
    for(int i=1; i<=K; i++)
        cout << 1LL * C[N-K+1][i] * C[K-1][i-1] % MOD << "\n";

    return 0;
}


Measured memory_bytes: 15872