akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll MOD = 1000000007;
ll bpow(ll b, ll p, ll m = MOD) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
ll fac[500005], invfac[500005];
ll npr(ll n, ll r) { return fac[n] * invfac[n - r] % MOD; }
ll ncr(ll n, ll r) { return fac[n] * invfac[n - r] % MOD * invfac[r] % MOD; }
int main() {
  IOS;
  fac[0] = invfac[0] = 1;
  for (int i = 1; i <= 500000; i++)
    fac[i] = fac[i - 1] * i % MOD;
  for (int i = 1; i <= 500000; i++)
    invfac[i] = bpow(fac[i], MOD - 2, MOD);
  ll n, m;
  cin >> n >> m;
  ll tmp = 0;
  for (int i = 1; i <= n; i++) {
    if (i & 1)
      tmp = (tmp + (ncr(n, i) * npr(m - i, n - i) % MOD)) % MOD;
    else
      tmp = (tmp - (ncr(n, i) * npr(m - i, n - i) % MOD) + MOD) % MOD;
  }
  cout << (npr(m, n) * npr(m, n) % MOD - (npr(m, n) * tmp) % MOD + MOD) % MOD
       << endl;
}

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

int main(){
  int a;
  cin >> a;
  if(a < 10){
    cout << a << endl;
  }else if(10 <= a && a < 100){
    cout << 9 << endl;
  }else if(100 <= a && 999 >= a){
    cout << 9 + (a - 100 + 1) << endl;
  }else if(1000 <= a && a <= 9999){
    cout << 909 << endl;
  }else if(10000 <= a && a <= 99999){
    cout << 909 + (a - 10000 + 1) << endl;
  }else{
    cout << 90909 << endl;
  }
}

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

int main(){
  string s;
  cin >> s;
  int index_a=0,index_z=0;
  for(int i=0;i<s.size();i++) {
    if(s.at(i) == 'A'){ index_a = i;break;}
  }
  for(int i=index_a+1;i<s.size();i++){
    if(s.at(i) == 'Z'){ index_z=i;}
  }
  cout << index_z - index_a + 1 << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
int main() 
{
	int a;
	scanf("%d",&a);
	int i;
	int judge = 0;
	for(i=1;i<=a;i++)
	{
		if(a%i==0)
		{
			if((a/i)<10 && i<10)
			{
				judge = 1;
				printf("Yes");
				i=a+1;
				break;
			}
		}
	}
	if(judge == 0)
		printf("No");
	return 0;
}

Measured memory_bytes: 128
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}


fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let a= line[0];
    let b= line[1];

    let mut mat = vec![vec!['.'; 100]; 100];

    for i in 0..50 {
        for j in 0..100 {
            mat[i][j] = '#';
        }
    }

    let mut count = 0;
    let mut x = 0; let mut y = 0;
    while count < a-1 {
        mat[x][y] = '.';
        count += 1;
        y += 2;
        if y >= 100 {
            x += 2;
            y = 0;
        }
    }
    let mut x = 51; let mut y = 0;
    let mut count = 0;
    while count < b-1 {
        mat[x][y] = '#';
        count += 1;
        y += 2;
        if y>= 100 {
            x += 2;
            y = 0;
        }
    }
    println!("100 100");
    for i in 0..100 {
        let s = mat[i].clone().into_iter().collect::<String>();
        println!("{}", s);
    }
}


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

int main(){
  string N;
  int n=0,m=0;
  cin >> N;
  
  if(N[0]==N[1]){
    n++;
    if(N[2]==N[1])
      n++;
  }
  if(N[2]==N[1]){
    m++;
    if(N[2]==N[3])
      m++;
  }
  if(n==2||m==2)
    cout << "Yes";
  else
    cout << "No";
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#define int ll
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
const int MOD = 998244353;
// const int MOD = 1000000007;

ll bitpow(ll x,ll n){
	ll ans = 1;
	while(n > 0){
		if(n%2 == 1) ans = ans * x % MOD;
		x = x * x %MOD;
		n = n >> 1;
	}
	return ans;
}
int fac[11];
int inv[11];


int dp[3010][3010] = {};
/*----------------------------------------------------------------*/
signed main(){

	int n;
	cin >> n;
	int s;
	cin >> s;
	vll a(n);
	rep(i,n)cin >> a[i];

	fac[0] = 1;
    inv[0] = 1;
    for(int i = 1;i <= 2;i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = bitpow(fac[i],MOD-2)%MOD;
    }

	dp[0][0] = bitpow(2,n);
	for(int i = 1;i <= n;i++){
		for(int j = 0;j <= s;j++){
			dp[i][j] += dp[i-1][j];
			if(j-a[i-1] >= 0)dp[i][j] += inv[2]*dp[i-1][j-a[i-1]];
			dp[i][j] %= MOD;
		}
	}
	cout << dp[n][s]%MOD << endl;

	rep(i,n){
		cerr << dp[i+1][s] << endl;
	}




	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://pakencamp-2019-day3.contest.atcoder.jp/tasks/pakencamp_2019_day3_c
// rm -r -f test;oj dl https://atcoder.jp/contests/abc169/tasks/abc169_b


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


int main(){
    string S;
    cin>>S;
    if(S=="SUN")cout<<7<<endl;
    else if(S=="MON")cout<<6<<endl;
    else if(S=="TUE")cout<<5<<endl;
    else if(S=="WED")cout<<4<<endl;
    else if(S=="THU")cout<<3<<endl;
    else if(S=="FRI")cout<<2<<endl;
    else             cout<<1<<endl;
    return 0;
}


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

int main() {
     int n;
     double d;
     cin >> n >> d;
     int ok = 0;
     for(int i = 0; i < n; i++){
       double x,y;
       cin >> x >> y;
       double s = sqrt(x*x + y*y);
       if(s  <= d) ok++;
     }
  cout << ok << endl;
}


Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;

	int p[20000];
	rep(i, N) cin >> p[i];

	int a[20001], b[20001];
	rep1(i, N) {
		a[i] = i * 30000;
		b[i] = (N - i + 1) * 30000;
	}
	rep(i, N) {
		a[p[i]] += i;
	}

	rep1(i, N) cout << a[i] << (i == N ? '\n' : ' ');
	rep1(i, N) cout << b[i] << (i == N ? '\n' : ' ');

	Would you please return 0;
}

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

typedef long long ll;


void solve(long long K, std::string S){
  if(S.size() > K){
    cout << S.substr(0,K) << "..." << endl;
  }else{
    cout << S << endl;
  }

}

int main(){
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(K, S);
    return 0;
}


Measured memory_bytes: 3628
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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

vector<bool> is_prime(maxn, true);
void sieve() {
	for (long long i = 2; i * i < maxn; i++) {
		if (is_prime[i] == true) {
			for (long long j = i * i; j < maxn; j += i) is_prime[j] = false;
		}
	}
	is_prime[0] = false;
	is_prime[1] = false;
	return;
}

int main() {

	sieve();
	long long n; cin >> n;
	long long ans = 0;
	for (long long i = 2; i * i <= n; i++) {
		if (is_prime[i] == true and ((n % i) == 0)) {
			long long e = 0;
			while (n % i == 0) n /= i, e++;

			double curr = (sqrt(8 * e + 1) - 1.0) / 2.0;
			ans += floor(curr);
		}
	}
	if (n > 1) ans++;

	cout << ans;


	return 0;
}

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

int  main()
{
	ll x,y; cin >> x >> y;
	vector<ll> a;
	int p = 0;
	while (x * (ll)pow(2 , p) <= y)
	{
		a.push_back(x * (ll)pow(2,p));
		p++;
	}
	cout << a.size() << endl;
	return 0;
}

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

int main() {
  string S,T;
  cin >> S >> T;
  int ans=10000;
  int N = S.size()-T.size()+1;
  for(int i=0; i<N; i++){
    int A=0;
    for(int j=0; j<T.size(); j++){
      if(S[i+j] != T[j]){
        A++;
      }
    }
    ans = min(ans,A);
  }
  cout << ans << endl;
}


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


int main() {
    Int N, M, X, Y;
    cin >> N >> M >> X >> Y;

    vector<Int> x(N), y(M);
    rep(i,N) cin >> x[i];
    rep(j,M) cin >> y[j];
  
    sort(x.begin(),x.end(),greater<Int>());
    sort(y.begin(),y.end());
  
    bool flag = true;
    if (X >= Y) flag = false;
    if (x[0] >= y[0]) flag = false;
    if (x[0] >= Y) flag = false;
    if (X >= y[0]) flag = false;
  
    if (flag) cout << "No War" << endl;
    else cout << "War" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main() {
	
	while(true){
	int n,k;
	cin >> n >> k;
	if(n==0&&k==0)break;

	vector<int> s;
	s.reserve(n+1);
	bool sp=false;
	for(int i=0;i<k;i++){
		int t;
		cin >> t;
		if(t==0) sp=true;
		else s.push_back(t);
	}
	s.push_back(n+100);
	sort(s.begin(),s.end());

	vector<pair<int,int>> pairs;	
	int prev=-10;
	pair<int,int> pair_;

	int ans =0;
	for( int i=0;i<s.size();i++){
		if( s[i]==prev+1){
			pair_.second=s[i];
		}else{
			if(i!=0){
//				cout << pair_.first << "-" << pair_.second << endl;
				pairs.push_back(pair_);
				ans = max(ans, pair_.second-pair_.first+1);
			}
			pair_.first=pair_.second=s[i];
		}
		prev = s[i];
	}
	if( sp&& k<n){
		ans+1;
	}

	if( sp ){
		for(int i=0;i<pairs.size()-1;i++){
			auto &p0=pairs[i];
			auto &p1=pairs[i+1];
			if( p0.second + 2 == p1.first){
				ans = max(ans, p0.second-p0.first+p1.second-p1.first+3);
			}
		}
	}
	cout << ans << endl;
	}

	return 0;
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main(){
    int a, b;
    cin >> a >> b;
    
    string A = {(char)('0' + a)};
    string AA = "";
    rep(i,b)
        AA = AA + A;
    
    string B = {(char)('0'+b)};
    string BB = "";
    rep(i,a)
        BB = BB + B;

    if(AA<BB) cout << AA << endl;
    else cout << BB << endl;
}


Measured memory_bytes: 256
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n, k = map(int, input().split())
    mod = 10 ** 9+ 7
    table = [0]*(k+1)
    ans= 0
    for i in range(k, 0, -1):
        table[i] = pow(k//i, n, mod)
        j = 2
        while i*j <= k:
            table[i] -= table[i*j]
            table[i] %= mod
            j += 1
        ans += i*table[i]
        ans %= mod
    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 11144
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

typedef pair<ll,ll> p;

int main(){
  ll n,m;
  cin >> n >> m;
  vector<p> stores;
  REP(i,n){
    ll a,b; cin >> a >> b;
    stores.push_back(p(a,b));
  }
  sort(stores.begin(),stores.end());
  ll ans = 0;
  ll left = m;
  REP(i,n){
    ll bottles = min(stores[i].second,left);
    ans += bottles * stores[i].first;
    left -= bottles;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2420
#include<iostream>
#include<numeric>

int main() {
  int ans = 0, K; std::cin >> K;
  for(int a = 1; a <= K; ++a) for(int b = 1; b <= K; ++b) {
    int g = std::gcd(a, b);
    for(int c = 1; c <= K; ++c) ans += std::gcd(g, c);
  }
  std::cout << ans << std::endl;
  return 0;
}


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

using namespace std;

int main(){

    int N, M;
    cin >> N >> M;

    vector<int> vec(N, 0);

    for(int i = 0; i < M; i++){
	int a, b;
	cin >> a >> b;
	vec.at(a-1) += 1;
	vec.at(b-1) += 1;
    }

    for(int i = 0; i < N; i++){
	cout << vec.at(i) << endl;
    }
    
    return 0;
}


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

int main() {
  string S, T;
  cin >> S >> T;
  
  int len = S.size()-T.size()+1;
  int Tlen = T.size();
  int mini = 2000;
  rep(i, len){
    int cnt = 0;
    rep(j, Tlen){
      if(S.at(i+j) != T.at(j)){
       cnt++;
      }
    }
    mini = min(mini, cnt);
  }
  cout << mini << endl;
  return 0;
}




Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    p = S.count('p')
    return len(S)//2 - p


def main():
    S = read_str()
    print(slv(''.join(S)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6844
#include<bits/stdc++.h>
#define ll long long
using namespace std;
signed main(){
  ll n,m,a[1000000],sum=0;
  cin>>n>>m;
  for(ll i=0;i<m;i++){
	cin>>a[i];
    sum += a[i];
  }
  if(n-sum>=0){
  cout<<n-sum<<"\n";
  }else{
    cout<<"-1\n";
  }
  return 0;
}


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

struct Node {
  int key;
  Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;
  z = (Node*)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x!=NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if (y==NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void preorder(Node *v) {
  if (v==NIL) {
    return;
  }
  cout << " " << v->key;
  preorder(v->left);
  preorder(v->right);
}

void inorder(Node *v) {
  if (v==NIL) {
    return;
  }
  inorder(v->left);
  cout << " " << v->key;
  inorder(v->right);
}

void find(Node *v, int x) {
  if (v==NIL) {
    cout << "no" << endl;
    return;
  } else if (v->key==x) {
    cout << "yes" << endl;
    return;
  }
  if (v->key < x) {
    find(v->right, x);
  } else{
    find(v->left, x);
  }
}

int main() {
  int n;
  cin >> n;
  int x;
  string com;
  for (int i=0; i<n; i++) {
    cin >> com;
    if (com=="insert") {
      cin >> x;
      insert(x);
    } else if (com=="print") {
      inorder(root);
      cout << endl;
      preorder(root);
      cout << endl;
    } else if (com=="find") {
      cin >> x;
      find(root, x);
    }
  }
  return 0;
}



Measured memory_bytes: 21808
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <tuple>
#include <numeric>
#include <utility>
#include <climits>
#include <float.h>
#include <cmath>
#define _USE_MATH_DEFINES
#include <math.h>
#pragma GCC target ("avx2")

using namespace std;

typedef long long ll;
typedef long double ld;
constexpr ll INF = LLONG_MAX;
constexpr double DINF = DBL_MAX;
constexpr ll mod = 1e9+7;
constexpr double PI = M_PI;

template<typename T>
vector<T> make_v(size_t a){
  	return vector<T>(a);
}
 
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts){
  	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

int main(){
  	cin.tie(0);
  	cout.tie(0);
  	ios::sync_with_stdio(false);
	
	int a, b;
	cin >> a >> b;
	cout << 6 - a - b << endl;
	return 0;
}


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

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> A(N), B(M);
    for (int i = 0; i < N; ++i) cin >> A[i];
    for (int i = 0; i < M; ++i) cin >> B[i];
    ll sumA = 0;
    int ia = 0;
    ll sumB = 0;
    int ib = 0;
    while (ia < N && sumA + A[ia] <= K) sumA += A[ia++];
    int ans = ia;
    for (int i = ia; i >= 0; --i) {
        ll rt = K - sumA;
        while (ib < M && sumB + B[ib] <= rt) sumB += B[ib++];
        ans = max(ans, i + ib);
        if (i > 0) sumA -= A[i - 1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  int x;
  cin >> x;

  for (int i = 1; i < 99999; i++) {
    if (i * x % 360 == 0) {
      cout << i << endl;
      return 0;
    }
  }
}

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

int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size()-1;i++){
		if(s[i]==s[i+1]){
			cout<<i+1<<" "<<i+2<<endl;
			return 0;
		}
	}
	for(int i=0;i<s.size()-2;i++){
		if(s[i]==s[i+2]){
			cout<<i+1<<" "<<i+3<<endl;
			return 0;
		}
	}
	cout<<-1<<" "<<-1<<endl;
	return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			var inputs = new List<int>();
			inputs.Add(int.Parse(Console.ReadLine()));
			inputs.Add(int.Parse(Console.ReadLine()));
			inputs.Add(int.Parse(Console.ReadLine()));
			inputs.Add(int.Parse(Console.ReadLine()));
			inputs.Add(int.Parse(Console.ReadLine()));

			var sum = inputs.Select(input => input % 10 == 0 ? input : ((input / 10) + 1) * 10).Sum();
			var min = inputs.Min(input => (input - 1) % 10);
			Console.WriteLine(sum - (9 - min));
		}
	}
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

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

  vector<int> P(N);
  REP(i, N){
    int tmp;
    cin >> tmp;
    P[tmp - 1] = i;  
  }

  multiset<int> se;
  se.insert(-1);
  se.insert(-1);
  se.insert(N);
  se.insert(N);

  ll ans = 0;
  for(int i = N - 1; i >= 0; i--){
    auto itr = se.lower_bound(P[i]);
    ll idx1 = *itr;
    ++itr;
    ll idx2 = *itr;
    --itr;
    --itr;
    ll idx3 = *itr;
    --itr;
    ll idx4 = *itr;
    ans += (i + 1) * (idx2 - idx1) * (P[i] - idx3);
    ans += (i + 1) * (idx3 - idx4) * (idx1 - P[i]);
    se.insert(P[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
typedef long long ll;
const ll modul = 1e9 + 7;
ll fact[N];
ll mod(ll x) { x %= modul; if (x < 0) x += modul; return x; }
ll add(ll a, ll b) { return mod(a + b); }
ll sub(ll a, ll b) { return mod(a - b); }
ll mul(ll a, ll b) { return mod(mod(a)*mod(b)); }
ll pow(ll a, ll b) {
	if (b == 0) return 1LL;
	if (b == 1) return mod(a);
	ll tmp = pow(a, b / 2);
	return (b % 2 == 0 ? mul(tmp,tmp) : mul(mul(tmp, tmp), a));
}
ll inv(ll x) { return pow(x, modul-2); }
ll c(ll n, ll k) {
	if (n < k) return 0LL;
	if (n == k) return 1LL;
	ll ans = fact[n];
	ans = mul(ans, inv(fact[k]));
	ans = mul(ans, inv(fact[n-k]));
	return ans;
}
int n, k;
ll a[N];
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i];
	fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = mul(fact[i - 1], i);
	sort(a + 1, a + n + 1);
	ll ans = 0LL;
	for (int i = k; i <= n; ++i) {
		ll waymax = c(i - 1, k - 1);
		ans = add(ans, mul(waymax, a[i]));
	}
	for (int i = 1; i+k-1<=n; ++i) {
		ll waymin = c(n - i, k - 1);
		ans = sub(ans, mul(waymin, a[i]));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a,b,c,d;
int main(void){
	cin>>a>>b>>c>>d;
	if(c-a==1||(c==1&&a==12)){
		cout<<"1"<<endl;
	}
	else cout<<"0"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
char in[110];
int main(){
	scanf("%s",in);
	if(in[5]=='0'&&in[6]<='4')printf("Heisei\n");else printf("TBD\n");
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
  float	a,b,c,d,e,f;
  float	det;
  float x,y;

  while(scanf("%f %f %f %f %f %f",&a,&b,&c,&d,&e,&f) !=	EOF){
    det=(e*a)-(b*d);
    x=(e*c-b*f)/det;
    y=(-d*c+a*f)/det;

    if(x==0){
      x=0;
    }else if (y==0){
      y=0;
    }

    printf("%.3f %.3f\n",x,y);
  }

  return 0;
}

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

using namespace std;

int main() {
  int a,b; cin >> a >> b;
  if(a%3==0 || b%3==0 || (a+b)%3==0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<vector>
int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
struct S{int x,y,a;S(int x,int y,int a):x(x),y(y),a(a){}};
int F(char c){return c=='.'||c=='X';}
int main()
{
	char*p,a[32][32];
	int W,H,x,y,t,i,j;
	while(scanf("%d%d",&W,&H),W)
	{
		std::vector<S>v,u[4],g,b;
		for(y=0;y<H;++y)
		{
			scanf("%s",a[y]);
			for(p=a[y];p=strpbrk(p,"NEWS");++p)
				v.push_back(S(p-a[y],y,*p=='W'?0:*p=='S'?1:*p=='E'?2:3));
		}
		for(t=0;t<181&&v.size();++t)
		{
			for(i=0;i<4;++i)u[i].clear();
			b.clear();
			for(i=0;i<v.size();++i)
			{
				S s=v[i];
				for(j=0;j<4;++j)
				{
					x=s.x+dx[(s.a+3+j)%4];
					y=s.y+dy[(s.a+3+j)%4];
					if(F(a[y][x]))
					{
						s.a=(s.a+3+j)%4;
						u[s.a].push_back(s);
						goto N;
					}
				}
				b.push_back(s);
				N:;
			}
			v=b;
			g.clear();
			for(i=0;i<4;++i)
			{
				for(j=0;j<u[i].size();++j)
				{
					S s=u[i][j];
					x=s.x+dx[i];
					y=s.y+dy[i];
					if(F(a[y][x]))
					{
						a[s.y][s.x]='.';
						s.x=x;
						s.y=y;
						if(a[y][x]=='X')
						{
							g.push_back(s);
							a[y][x]='@';
							continue;
						}
						a[y][x]='@';
					}
					v.push_back(s);
				}
			}
			for(i=0;i<g.size();++i)a[g[i].y][g[i].x]='X';
		}
		if(t<181)printf("%d\n",t);
		else puts("NA");
	}
	return 0;
}

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

int main() {
    ll n,d;
    cin >> n >> d;
    vector<pair<ll,ll>>p;
    rep(i,n) {
        ll x,y;
        cin >> x >> y;
        p.push_back(make_pair(x,y));
    }
    int sum = 0;
    rep(i,n) {
        ll dist = p[i].first*p[i].first + p[i].second * p[i].second;
        if(dist <= d*d) sum++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 7396
#include<bits/stdc++.h>
using namespace std;
const int c[]={0,2,5,5,4,5,6,3,7,6};
string stmax(string a, string b)
{
  if(a.size() > b.size())
  {
    return a;
  }
  else if(a.size() < b.size())
  {
      return b;
  }
  else{
  	if(a>=b)return a;
    else return b;
  }
}
    
int main(){
  int n,m;
  cin>>n>>m;
  vector<int>a(m);
  for(int i=0; i<m; i++){
    cin>>a[i];
  }
  vector<string>dp(10101,"");
  for(int i=0; i<=n; i++){
    for(int j=0; j<a.size(); j++){
      if(i==0||dp[i]!=""){			//
        dp[i+c[a[j]]]=stmax(dp[i]+to_string(a[j]),dp[i+c[a[j]]]);
      }
    }
  }
  cout<<dp[n]<<endl;
}
    
  
   


Measured memory_bytes: 33024
fun main(args: Array<String>) {
    val (n,k,q) = readLine()!!.split(" ").map(String::toInt)
    var ml : MutableList<Int> = mutableListOf()
    for (i in 1..n) { ml.add(0)}
    for (i in 1..q) {
        val x = readLine()!!.toInt()
        ml[x-1]++
    }

    var sb = StringBuilder()
    ml.forEach { 
        if (k - q + it > 0) { sb.append("Yes\n")}
        else {sb.append("No\n")}
    }
    print(sb)
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<string> A(N), B(M);
    rep(i, N) cin >> A.at(i);
    rep(i, M) cin >> B.at(i);

    bool exist = false;
    rep(i, N - M + 1) {      // 縦方向の正方形の移動
        rep(j, N - M + 1) {  // 横方向の正方形の移動
            bool isSame = true;
            rep(k, M) {      // 縦方向の正方形の要素
                rep(l, M) {  // 横方向の正方形の要素
                    if (A.at(i + k).at(j + l) != B.at(k).at(l)) isSame = false;
                }
            }
            if (isSame) exist = true;
        }
    }

    string ans = exist ? "Yes" : "No";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    for (int i = 0; i < n; i++) cin >> s[i];

    sort(s.begin(), s.end());
    for (int i = 0; i < n; i++) cout << s[i];
    cout << endl;
}

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

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> s;
	if(s[5] >= '1' || s[6]>= '5') cout << "TBD";
	else cout << "Heisei";
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		String s = scan.next();
		
		if(!s.equals(s.toLowerCase()))
			System.out.println("A");
		else
			System.out.println("a");
				
		

	}

}


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

int main()
{
  int X, Y;
  cin >> X >> Y;
  int crane = 4*X - Y;
  if (crane >= 0)
  {
    if (2*X - crane < 0) cout << "No" << endl;
    else if (crane % 2 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else cout << "No" << endl;
}


Measured memory_bytes: 3624
import java.util.*

fun main() {
    val (n, m, q) = readLine()!!.split(" ").map(String::toInt)
    val array = Array(q) {
        readLine()!!.split(" ").map(String::toInt).toIntArray()
    }
    val seq = (1..m).toList().toIntArray()
    val list = LinkedList<Int>()

    var result = 0
    fun calc(list: IntArray) {
        var sum = 0
        array.forEach { (a, b, c, d) ->
//            println("${list[b-1]} - ${list[a-1]} == $c")
            if (list[b - 1] - list[a - 1] == c) {
                sum += d
            }
        }
        result = Math.max(result, sum)
    }

    fun combination(i: Int) {

        if (list.size == n) {
//            println(list.joinToString(","))
            calc(list.toIntArray())
            return
        }

        if (i >= m) {
            return
        }

        list.add(seq[i])
        combination(i)
        combination(i + 1)
        list.removeLast()
        combination(i + 1)
    }

    combination(0)

    println(result)
}





Measured memory_bytes: 61136
const { parse } = require("path");

function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    var N = input[0][0];
    var l = N.length;
    var vec_N = N.split('').map(e => parseInt(e, 10));
    var vec_tf = Array.from({length: l}, () => false);
    var num, j;
    whole_loop:
    for (var i = 0; i < l; i++){
        num = vec_N[i];
        if (num === 5){
            j = 1
            while (true) {
                if (vec_N[i + j] === 4) j++;
                else break;
                if (vec_N[i + j] === 5) j++;
                else break;
            }
            if (i + j >= l || vec_N[i + j] <= 4) {
                i += j;
                continue whole_loop;
            } else {
                for (var k = i; k <= i + j; k++){
                    vec_tf[k] = true;
                }
            } 
        }
    }

    var ans = 0;
    var tmpKuriage = false;
    for (var i = 0; i < l; i++){
        num = vec_N[i];
        if (num >= 6){
            if (tmpKuriage) ans -= 2;
            vec_tf[i] = tmpKuriage = true;
            ans += (11 - num);
        } else if (num <= 3){
            tmpKuriage = false;
            ans += num;
        } else if (num === 5){
            if (tmpKuriage) {
                ans -= 2;
                vec_tf[i] = true;
                ans += (11 - num);
            } else {
                if (vec_N[i + 1] >= 5) {
                    vec_tf[i] = tmpKuriage = true;
                    ans += (11 - num);
                } else if (vec_N[i + 1] <= 3) {
                    ans += num;
                } else if (vec_tf[i]) { //vec_N[i + 1] === 4 から分岐
                    tmpKuriage = true;
                    ans += (11 - num);
                } else {
                    ans += num;
                }
            }
        } else { //num === 4
            if (tmpKuriage) {
                if (vec_N[i + 1] >= 5){
                    ans -= 2;
                    vec_tf[i] = true;
                    ans += (11 - num);
                } else {
                    tmpKuriage = false;
                    ans += num;
                }
            } else {
                ans += num;
            }
        }
    }

    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 

Measured memory_bytes: 57140
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define prique priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int int_fast64_t
using Graph = vector<vector<int> >;
typedef pair<int, int> P;

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

vector<int> tsort(const Graph &G, vector<int> incnt){
  const int V = G.size();
  vector<bool> visit(V, false);
  vector<int> ret;
  queue<int> que;
  REP(i, V) if(incnt[i] == 0) que.push(i);
  while(!que.empty()){
    int pos = que.front(); que.pop();
    visit[pos] = 1;
    REP(i, G[pos].size()){
      int nx = G[pos][i];
      if(visit[nx]) return vector<int>{-1};
      else {
        incnt[nx]--;
        if(incnt[nx] == 0) que.push(nx);
      }
    }
    ret.eb(pos);
  }
  REP(i, V) if(!visit[i]) return vector<int>{-1};
  return ret;
}

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

  int N, A[1000][1000]; cin >> N;
  map<P, int> nidx;
  int tmp = 0;
  for(int i = 1; i <= N; i++) for(int j = i+1; j <= N; j++){
    nidx[P(i, j)] = tmp;
    tmp++;
  }
  int V = N*(N-1)/2;
  Graph G(V);
  vector<int> incnt(V, 0);
  REP(i, N) REP(j, N-1){
    cin >> A[i][j];
    if(j>0){
      int a = i+1, b = A[i][j-1], c = i+1, d = A[i][j];
      if(a>b) swap(a, b);
      if(c>d) swap(c, d);
      int from = nidx[P(a, b)], to = nidx[P(c, d)];
      G[from].eb(to);
      incnt[to]++;
    }
  }

  vector<int> dag = tsort(G, incnt);
  if(dag[0] == -1){
    cout << -1 << ln;
    return 0;
  }

  vector<int> ans(V, 0);
  int res = 0;
  REP(i, V){
    int pos = dag[i];
    REP(j, G[pos].size()){
      int nx = G[pos][j];
      ans[nx] = max(ans[nx], ans[pos]+1);
    }
    res = max(res, ans[pos]);
  }
  cout << res+1 << ln;
}


Measured memory_bytes: 80496
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include<stack>
#include<string>
#include<algorithm> 
#include <set>
#include<list>
#include <bit>
#include <bitset>
#include <cstdint>
#include <initializer_list>
using namespace std;
int main() {
	long long int N, ans=0; cin >> N;
	long long int count;
	for (long long int i = 1; i <= N; i++) {
		count = N / i;
		ans += i * count * (count + 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

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

ll n,x[15],y[15],p[15],ans[16],xm[1<<15][15],ym[1<<15][15],ti,now[15],xnow,ynow,cnt,nowans;

void pre(){
  for(int j=0;j<15;j++){
    for(int i=0;i<(1<<15);i++){
      xm[i][j]=abs(x[j]);
      ym[i][j]=abs(y[j]);
      ti=i;
      for(int k=0;k<15;k++){
        if((ti&1)==1){
          xm[i][j]=min(abs(x[j]-x[k]),xm[i][j]);
          ym[i][j]=min(abs(y[j]-y[k]),ym[i][j]);
        }
        ti>>=1;
      }
      xm[i][j]*=p[j];
      ym[i][j]*=p[j];
    }
  }
}

void dfs(int a){
  if(a==n){
    xnow=0;
    ynow=0;
    cnt=0;
    nowans=0;
    for(int i=0;i<15;i++){
      if(now[i]==1){xnow+=(1<<i);cnt++;}
      if(now[i]==2){ynow+=(1<<i);cnt++;}
    }
    for(int i=0;i<15;i++){
      nowans+=min(xm[xnow][i],ym[ynow][i]);
    }
    ans[cnt]=min(nowans,ans[cnt]);
  }
  else{
    for(int i=0;i<3;i++){
      now[a]=i;
      dfs(a+1);
    }
  }
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i]>>p[i];
    ans[i]=(ll)1e18;
  }
  pre();
  dfs(0);
  for(int i=0;i<=n;i++) cout<<ans[i]<<endl;
}


Measured memory_bytes: 11320
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    if (n == 0) { cout << "0"; return 0; }
    int b[100] = {};
    int *p = b, s = 1;
    while (n) {
        if (n%2) {
            *p = 1;
            n = (n - s)/2;
        } else {
            *p = 0;
            n /= 2;
        }
        s *= -1; p++;
    }
    for (int *q = p; q != b; ) printf("%d", *--q);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
//#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007ll
#define pb push_back
#define fi first
#define se second
#define mk(a, b) make_pair(a, b)
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int N, K, a[5020], sum, ans;
bool dp[5020];

signed main()
{
    scanf("%lld %lld\n", &N, &K);
    for(int i = 0; i < N; i++){
        scanf("%lld", a + i);
        sum += a[i];
    }
    sort(a, a + N);
    dp[0] = true;
    for(int i = N - 1; i >= 0; i--){
        bool flag = false;
        for(int j = 0; j < K; j++){
            if(dp[j] && j + sum >= K){
                flag = true;
            }
        }
        if(!flag){
            printf("%lld\n", i + 1);
            return 0;
        }
        sum -= a[i];
        for(int j = K - 1; j >= a[i]; j--){
            dp[j] |= dp[j - a[i]];
        }
    }
    printf("0\n");

    return 0;
}
/*


*/


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        int A=sc.nextInt();
        if(A>=N%500) {
        	System.out.println("Yes");
        }else {
        	System.out.println("No");
        }
    }
}

Measured memory_bytes: 35680
// https://beta.atcoder.jp/contests/abc075
// status: [solve]

#define SUBMIT
//#define DEBUG

#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <queue>
#include <numeric>
#include <limits>
#include <set>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    auto program_input = std::string(R"(-100 100 100
)");
    stringstream stream(program_input);
#endif
    int A, B, C;
    stream >> A >> B >> C;
    if (A == B) cout << C << endl;
    else if (B == C) cout << A << endl;
    else cout << B << endl;

    return 0;
}

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

int main() {
  vector<vector<int>> c(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c.at(i).at(j);
    }
  }

  for (int i = 0; i <= c.at(0).at(0); i++) {
    vector<int> a(3);
    vector<int> b(3);

    a.at(0) = i;
    b.at(0) = c.at(0).at(0) - a.at(0);
    b.at(1) = c.at(0).at(1) - a.at(0);
    b.at(2) = c.at(0).at(2) - a.at(0);
    a.at(1) = c.at(1).at(0) - b.at(0);
    a.at(2) = c.at(2).at(0) - b.at(0);

    vector<pair<int, int>> vp;
    vp.push_back(make_pair(1, 1));
    vp.push_back(make_pair(1, 2));
    vp.push_back(make_pair(2, 1));
    vp.push_back(make_pair(2, 2));

    for (auto p : vp) {
      int ii = p.first;
      int jj = p.second;

      if (c.at(ii).at(jj) != (a.at(ii) + b.at(jj))) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()

int main(){
    int n,k;
    string s;
    cin>>n>>k>>s;
    s[k-1]+=32;
    cout<<s<<endl;
}

Measured memory_bytes: 256
using System;

namespace AtCoderBeginnerContest174
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = Console.ReadLine().Split();
			var n = int.Parse(input[0]);
			var d = int.Parse(input[1]);

			var count = 0;
			for(var i = 0; i < n; i++)
			{
				input = Console.ReadLine().Split();
				var x = int.Parse(input[0]);
				var y = int.Parse(input[1]);

				if(Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) <= d)
				{
					count++;
				}
			}

			Console.WriteLine(count);
		}
	}
}


Measured memory_bytes: 40752
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
using ll = long long;
int main(){
    int x[5];
    for(int i=0;i < 5;i++)cin >> x[i];
    for(int i=0;i < 4;i++){
        for(int j=0;j < 4-i;j++){
            int tmp;
            if(x[j+1]%10 < x[j]%10){
                tmp = x[j+1];
                x[j+1] = x[j];
                x[j] = tmp;
            }
        }
    }
    for(int i=0;i< 5;i++){
        if(x[i]%10 != 0){
            int tmp;
            tmp = x[4];
            x[4] = x[i];
            x[i] = tmp;
            break;
        }
        
    }
    int ans = 0;
        for(int i=0;i<4;i++){
            if(x[i]%10 == 0)ans+=x[i];
            else ans+=((x[i]/10) + 1)*10;
        }
        ans+=x[4];
        cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let h: usize = iterator.next().unwrap().parse().unwrap();
    let w: usize = iterator.next().unwrap().parse().unwrap();
    let d: usize = iterator.next().unwrap().parse().unwrap();

    let mut points: Vec<(isize, isize)> = vec![(0, 0); h * w];
    for i in 0..h {
        for j in 0..w {
            let a: usize = iterator.next().unwrap().parse().unwrap();
            points[a - 1] = (i as isize, j as isize);
        }
    }

    let mut costs: Vec<usize> = vec![0; h * w];
    for i in 0..(h * w) {
        if i < d {
            continue;
        }
        costs[i] = costs[i - d] + (points[i].0 - points[i - d].0).abs() as usize + (points[i].1 - points[i - d].1).abs() as usize;
    }

    let mut result = String::new();
    let q: usize = iterator.next().unwrap().parse().unwrap();
    for _ in 0..q {
        let l: usize = iterator.next().unwrap().parse().unwrap();
        let r: usize = iterator.next().unwrap().parse().unwrap();
        let ans = costs[r - 1] - costs[l - 1];
        result.push_str(&format!("{}\n", ans));
    }
    result.trim().to_string()
}


Measured memory_bytes: 7232
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, T, *AB = map(int, read().split())
    D = [(a, b) for a, b in zip(*[iter(AB)] * 2)]

    D.sort()

    dp = [[0] * T for _ in range(N + 1)]
    for i, (a, b) in enumerate(D):
        for t in range(T):
            if 0 <= t - a:
                dp[i + 1][t] = dp[i][t - a] + b
            if dp[i + 1][t] < dp[i][t]:
                dp[i + 1][t] = dp[i][t]

    ans = 0
    for i in range(N - 1):
        if ans < dp[i + 1][T - 1] + D[i + 1][1]:
            ans = dp[i + 1][T - 1] + D[i + 1][1]

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 139492