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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

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

vector<string> parse(string &s, char dec) {
    int pos = 0;
    vector<string> res;
    s += dec;
    REP(i, 0, s.size()) {
        if (s[i] == dec) {
            res.push_back(s.substr(pos, i - pos));
            pos = i + 1;
        }
    }
    return res;
}

bool check(vector<int> &var) {
    set<int> s;
    for (auto &n : var) {
        if(s.count(-n)) {
            return false;
        }
        s.insert(n);
    }
    return true;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    while (cin >> s, s != "#") {
        vector<string> clauses = parse(s, '|');
        bool ans = false;
        for (auto clause : clauses) {
            clause = clause.substr(1, clause.size() - 2);
            vector<string> literals = parse(clause, '&');
            vector<int> var;
            for (auto literal : literals) {
                int sign = 2 * (literal[0] != '~') - 1;
                int num = literal[literal.size() - 1];
                var.push_back(sign * num);
            }
            ans |= check(var);
        }
        cout << (ans ? "yes" : "no") << endl;
    }
    return 0;
}



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

using namespace std;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<bool>> a(n, vector<bool>(m));
  for (int i = 0; i < n; i++) {
    string foo;
    cin >> foo;
    for (int j = 0; j < m; j++) {
      a[i][j] = foo[j] == '#';
    }
  }
  queue<pair<int, int>> que;
  vector<vector<int>> dist(n, vector<int>(m, -1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j]) {
        que.push({i, j});
        dist[i][j] = 0;
      }
    }
  }
  while (!que.empty()) {
    auto u = que.front();
    que.pop();
    int x = u.first, y = u.second;
    for (int i = 0; i < 4; i++) {
      int tx = x + dx[i], ty = y + dy[i];
      if (0 <= tx && tx < n && 0 <= ty && ty < m && dist[tx][ty] == -1) {
        dist[tx][ty] = dist[x][y] + 1;
        que.push({tx, ty});
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans = max(ans, dist[i][j]);
    }
  }
  cout << ans << '\n';
  return 0; // :)
}


Measured memory_bytes: 15408
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main()
{
  int s, t, a[101];
  bool f;
   
  while(cin>>s>>t){
    fill(a, a+101, 0);
    a[s] = a[t] = 1;
 
    while(cin>>s>>t && s && t){
      a[s]++;
      a[t]++;
    }
 
    f = true;
    if(!(a[1]%2) || !(a[2]%2))
      f = false;
 
    for(int i = 3; i <= 100 && f; i++)
      if(a[i]%2) f = false;
     
    cout << (f? "OK" : "NG") << endl;
  }
   
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <math.h>

int judge(int *L, int idx, int m){
    int i;
    for (i = 0; i < idx; i++)
    {
        if (L[i] == m) return 1;
    }
    return 0;
}

int main(void){
    // Your code here!
    int i, j, n, A[20], q, m, L[1500000], idx;
    long x, temp;
    double xx;
    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &A[i]);
    // x = 2 ^ n;
    xx = pow(2.0, (double)n);
    x = (long)xx;
    idx = 0;
    for (i = 0; i < x; i++)
    {
        temp = 0;
        for (j = 0; j < n; j++)
        {
            if (i & (1 << j)) temp += A[j];
        }
        L[idx] = temp;
        L[idx + 1] = -1;
        idx++;
    }
    /*
    printf("x = %d\n", x);
    for (i = 0; i < idx; i++) printf("%d ", L[i]);
    printf("\n");
    */
    scanf("%d", &q);
    for (i = 0; i < q; i++)
    {
        scanf("%d", &m);
        if (judge(L, idx, m) == 1) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 5900
#![allow(unused)]

use std::io::{Read, StdinLock};
use std::iter::{FromIterator, Iterator};
use std::str::{FromStr};
use std::string::String;
use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};

pub fn read_bytes<T: FromIterator<char>>(s: &mut StdinLock) -> T {
    s.bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<T>()
}

pub fn reads(s: &mut StdinLock) -> String {
    read_bytes::<String>(s)
}

pub fn read<T: FromStr>(s: &mut StdinLock) -> T {
    reads(s).parse().ok().unwrap()
}

fn main() {
    let sin = std::io::stdin();
    let mut sin = sin.lock();

    let n = read::<i64>(&mut sin);
    let avec = (0..n).map(|_| read::<i64>(&mut sin)).collect::<Vec<_>>();

    let mut count = HashMap::new();

    for a in avec.iter() {
        let val = match count.entry(a) {
            Vacant(e) => e.insert(0),
            Occupied(e) => e.into_mut(),
        };
        *val += 1;
    }

    //println!("{:?}", count);

    let tot: i64 = count.iter().map(|(k, v): (&&i64, &i64)| v * (v - 1) / 2).sum();

    for a in avec.iter() {
        let m = count[a];
        let dec = if m <= 1 { 0 } else { m * (m - 1) / 2 - (m - 1) * (m - 2) / 2 };
        println!("{}", tot - dec);
    }
}

Measured memory_bytes: 17176
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main()
{
  vector<int> A1(4);
  vector<int> A2(4);
  vector<int> A3(4);
  rep(i, 3)
  {
    cin >> A1.at(i);
  }
  rep(i, 3)
  {
    cin >> A2.at(i);
  }
  rep(i, 3)
  {
    cin >> A3.at(i);
  }
  int N;
  cin >> N;
  vector<int> B(N + 1);
  int a;
  bool ans = false;
  rep(i, N)
  {
    cin >> B.at(i);
    rep(j, 4)
    {
      if (B.at(i) == A1.at(j))
      {
        A1.at(j) = 101;
      }
      if (B.at(i) == A2.at(j))
      {
        A2.at(j) = 101;
      }
      if (B.at(i) == A3.at(j))
      {
        A3.at(j) = 101;
      }
    }
  }

  // cout << A1.at(0) << " " << A1.at(1) << " " << A1.at(2) << endl;
  // cout << A2.at(0) << " " << A2.at(1) << " " << A2.at(2) << endl;
  // cout << A3.at(0) << " " << A3.at(1) << " " << A3.at(2) << endl;

  //hoko
  if (A1.at(0) == 101 && A1.at(1) == 101 && A1.at(2) == 101)
  {
    ans = true;
  }
  if (A2.at(0) == 101 && A2.at(1) == 101 && A2.at(2) == 101)
  {
    ans = true;
  }
  if (A3.at(0) == 101 && A3.at(1) == 101 && A3.at(2) == 101)
  {
    ans = true;
  }
  //tate
  if (A1.at(0) == 101 && A2.at(0) == 101 && A3.at(0) == 101)
  {
    ans = true;
  }
  if (A1.at(1) == 101 && A2.at(1) == 101 && A3.at(1) == 101)
  {
    ans = true;
  }
  if (A1.at(2) == 101 && A2.at(2) == 101 && A3.at(2) == 101)
  {
    ans = true;
  }
  //naname
  if (A1.at(0) == 101 && A2.at(1) == 101 && A3.at(2) == 101)
  {
    ans = true;
  }
  if (A1.at(2) == 101 && A2.at(1) == 101 && A3.at(0) == 101)
  {
    ans = true;
  }

  if (ans)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
int a[105][2],b[105][2];
vector<int> vec[225];
int vis[225];
int link[225];
int dfs(int u){
	for(int i=0;i<vec[u].size();i++){
		int v=vec[u][i];
		//cout<<u<<" "<<v<<endl;
		if(vis[v]==0){
			vis[v]=1;
			if(link[v]==0 || dfs(link[v])){
				link[v]=u;
				return 1;
			}
		}
	} 
	return 0;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i][0]>>a[i][1];	
	}
	for(int i=1;i<=n;i++){
		cin>>b[i][0]>>b[i][1];
		for(int j=1;j<=n;j++){
			if(b[i][0]>a[j][0] && b[i][1]>a[j][1]){
				vec[i].push_back(j+105);
				vec[j+105].push_back(i);
			//	cout<<i<<" -- "<<j+105<<endl;
			}
		}
	}
	int ans=0;
	for(int i=1;i<=221;i++){
		memset(vis,0,sizeof(vis));
		if(dfs(i))ans++;
	}
	cout<<ans/2;
	return 0;
}
/*
*/

Measured memory_bytes: 256
/**
*    author:  souzai32
*    created: 01.08.2020 19:02:17
**/

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

int main() {

    string s;
    cin >> s;
    int n=s.size();
    int ans=n;
    rep(i,n-1){
        if(s.at(i)==s.at(i+1)){
            ans--;
            i+=2;
        }
    }
    cout << ans << endl;

    return 0;
}

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

/*
code credits : ਜ਼ੈਲਦਾਰ
dashan jot singh
*/
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define inf LLONG_MAX
#define pl pair<ll,ll>
int n,m,x;
int c[100010];
int arr[20][20];
// int dp[20][]
int ans=INT_MAX;
void solve(int i,vector<int> &temp){
	if(i>=n){
		int xx=0;
		for(auto x:temp){
			xx+=c[x];
		}
		bool flag=true;
		int wer[m];
		memset(wer,0,sizeof(wer));
		for(auto x:temp){
			for(int j=0;j<m;j++){
				wer[j]+=arr[x][j];
			}
		}
		for(int i=0;i<m;i++){
			if(wer[i]<x){
				flag=false;
				break;
			}
		}
		if(xx==0 or flag==false){
			return;
		}
		ans=min(ans,xx);
		return;
	}
	solve(i+1,temp);
	temp.pb(i);
	solve(i+1,temp);
	temp.pop_back();
}
void solve(){
    cin>>n>>m>>x;
    for(int i=0;i<n;i++){
    	cin>>c[i];
    	for(int j=0;j<m;j++){
    		cin>>arr[i][j];
    	}
    }
    vector<int> temp;
    ans=INT_MAX;
    solve(0,temp);
    if(ans==INT_MAX){
    	ans=-1;
    }
    cout<<ans<<"\n";
}
int main(){
	fast;
	int t=1;
	// cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3664
// 全然わからないので、解説を読んで実装
// 兎と亀の例はそこから

#include <iostream>
#include <unordered_map>
#include <vector>

using namespace std;

void limit_add(long long& target, long long add) {
  target = (target + add) % 1000000007;
}

void dump(vector<vector<unordered_map<int, long long>>>& dp) {
  int n = dp.size();
  for (int i = 0; i < n; i++) {
    int j_size = dp[i].size();
    for (long long j = 0; j < j_size; j++) {
      for (auto ks : dp[i][j]) {
        int current_k = ks.first;
        long long count = ks.second;

        cout << i << " " << j << " " << current_k << " " << count << endl;
      }
    }
  }
}

int main() {
  int n,k;
  cin >> n;
  cin >> k;
  
  vector<vector<unordered_map<int, long long>>> dp;
  dp.assign(2, vector<unordered_map<int, long long>>());
  //TODO kは偶数しかとらない(奇数だと結果0) k/2をインデックスにすれば、mapではなくvectorにできる
  int dp_size = dp.size();
  dp[0].assign(1, unordered_map<int, long long>());
  dp[0][0][0] = 1;
  
  for (int i = 0; i < n; i++) {
    dp[(i+1)%2].clear();
    dp[(i+1)%2].assign(i+2, unordered_map<int, long long>());
    int j_size = dp[i%2].size();

    for (long long j = 0; j < j_size; j++) {
      for (auto ks : dp[i%2][j]) {
        int current_k = ks.first;
        long long count = ks.second;
        // 1追加されて、i+1,j+1の状態になった時
        //TODO: 結果に不要な場合は枝切りしたい
        
        // 追加された兎、亀はこれまでとマッチしない場合
        // kはj+1個残るので、その2倍(交換すると2増えるため、以下同じ)
        // 増えるcountは、これが起こる場合の数なので、1通り
        limit_add(dp[(i+1)%2][j+1][current_k + 2 * (j+1)], count);
        
        // 追加された兎、亀とこれまでが1組のみマッチした場合 (j+1同士も含む)
        // 起こる場合は 兎がj+1,亀がjまでのどれかでj通り
        // その反対でj通り
        // 兎、亀ともj+1を選んで1通り
        limit_add(dp[(i+1)%2][j]  [current_k + 2 * j], count * (j+j+1));
        
        // 追加された兎、亀とこれまでが2組ともマッチした場合
        // 起こる場合は、兎がj+1,亀がjまでのどれかでj通り
        // その反対でj通り
        // 同時に発生するので、j*j
        if (j>0) {
          limit_add(dp[(i+1)%2][j-1][current_k + 2 * (j-1)], count * (j*j));
        }
      }
    }
  }
  
  cout << dp[n%2][0][k] << endl;;
  //TODO: debug dump(dp);
  
  return 0;
}


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

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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int d, t, s;
  cin >> d >> t >> s;
  if (d <= t * s) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  ll sum = 0;
  ll way1 = 0;
  ll way2 = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    if (i % 2 == 0 && sum <= 0) {
      way1 += 1 - sum;
      sum = 1;
    } else if (i % 2 == 1 && sum >= 0) {
      way1 += sum + 1;
      sum = -1;
    }
  }
  sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    if (i % 2 == 1 && sum <= 0) {
      way2 += 1 - sum;
      sum = 1;
    } else if (i % 2 == 0 && sum >= 0) {
      way2 += sum + 1;
      sum = -1;
    }
  }

  cout << min(way1,way2) << endl;
  return 0;
}

Measured memory_bytes: 4332
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> g(100005);

int kaijo(int n) {
	int ans = 1;
	rrep (i, n) ans *= i;
	return ans;
}

int main(void) {
	int n;
	cin >> n;
	ll x[n], y[n];
	rep (i, n) cin >> x[i] >> y[i];

	vector<int> num(n);
	rep (i, n) num[i] = i;

	double ans = 0;
	do {

		rep (i, n - 1) ans += sqrt(pow(x[num[i]] - x[num[i + 1]], 2) + pow(y[num[i]] - y[num[i + 1]], 2));
	} while (next_permutation(rng(num)));

	ans /= (double)kaijo(n);

	printd(ans);
	return 0;
}

Measured memory_bytes: 2560
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  int n, q;
  cin >> n >> q;
  string s = "kogakubu10gokan";
  while (n--) {
    int y;
    string t;
    cin >> y >> t;
    if (y <= q) s = move(t);
  }
  cout << s << endl;
}

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

int main(){
	int mon, day, total;
	string s;

	while ( 1 ){
		cin >> mon >> day;
		if ( !mon ) break;

		total = day;
		for ( int i = 1; i < mon; ++i ){
			switch ( i ){
				case 1 : case 3 : case 5 : case 7 :
				case 8 : case 10 : case 12:
					total += 31;
					break;
				case 2 :
					total += 29;
					break;
				case 4 : case 6 : case 9 : case 11 :
					total += 30;
					break;
			}
		}

		switch ( total % 7 ) {
			case 0 : s = "Wednesday"; break;
			case 1 : s = "Thursday"; break;
			case 2 : s = "Friday"; break;
			case 3 : s = "Saturday"; break;
			case 4 : s = "Sunday"; break;
			case 5 : s = "Monday"; break;
			case 6 : s = "Tuesday"; break;
		}

		cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;

int count_bit(int b) {
  int ret = 0;
  while(b) {
    ret += b&1;
    b >>=1;
  }
  return ret;
}

int check(int b, vector<vector<int>>& x, vector<vector<int>>& y, int N) {
  for (int i = 0; i < N; i++) {
    if (((b>>i)&1) == 1) {
      for (int j = 0; j < x[i].size(); j++) {
        if (((b>>x[i][j])&1) != (y[i][j]&1)) {
          return 0;
        }
      }
    }
  }
  return count_bit(b);
}

int main(){
  int N;
  std::cin >> N;
  vector<vector<int>> X;
  vector<vector<int>> Y;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
    vector<int> x(A[i]);
    vector<int> y(A[i]);
    for (int j = 0; j < A[i]; j++) {
      std::cin >> x[j] >> y[j];
      x[j] -= 1;
    }
    X.push_back(x);
    Y.push_back(y);
  }

  int ret = 0;
  int a;
  for (int b = 0; b < 1<<N; b++) {
    a = check(b, X, Y, N);
    ret = max(a, ret);
  }
  std::cout << ret << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int flag,temp,sumn,summ,i,j,n,m,ren,rem,nc[101],mc[101];
  while(1){
    sumn=0;
    summ=0;
    ren=100;
    rem=100;
    flag=0;
    scanf("%d%d",&n,&m);
    if(n==0&&m==0) break;
 
    for(i=1;i<=n;i++){
      scanf("%d",&nc[i]);
      sumn+=nc[i];
    }
    for(i=1;i<=m;i++){
      scanf("%d",&mc[i]);
      summ+=mc[i];
    }
     
    for(i=1;i<=n;i++){
      for(j=1;j<=m;j++){
    if(sumn-nc[i]+mc[j]==summ-mc[j]+nc[i]&&nc[i]+mc[j]<ren+rem){    
          ren=nc[i];
          rem=mc[j];
      temp=nc[i];
      nc[i]=mc[j];
      mc[j]=temp;
      flag=1;
    }
      }
    }
 
    if(flag==1) printf("%d %d\n",ren,rem);
    else printf("-1\n");
 
  }
 
  return 0;
}

Measured memory_bytes: 1040
N = int(input())
P = []
for i in range(N):
    x,y,h = map(int,input().split())
    P.append((x,y,h))
def f(x,y,h,i,j):
    H = h + max(x-i,i-x) + max(y-j,j-y)
    return H
for i in range(101):
    for j in range(101):
        Hi = []
        t = 1
        M = 10**100
        for k in range(N):
            x,y,h = P[k]
            if h == 0:
                H = f(x,y,h,i,j)
                M = min(M,H)
                continue
            H = f(x,y,h,i,j)
            if H > M:
                t = 0
            if H not in Hi:
                Hi.append(H)
        if len(Hi) != 1:
            t = 0
        else:
            if Hi[0] > M:
                t = 0
        if t == 1:
            print(i,j,Hi[0])
            quit()

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

int main(void){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int s,w;

    cin >> s >> w;

    if(s<=w){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }


    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>

using namespace std;
double x[8], y[8];

int main() {
	int N;
	int ar[8] = {};
	cin >> N;
	for (int i = 0; i < N; i++) cin >> x[i] >> y[i], ar[i] = i;
	
	double ans = 0;
	int cnt = 0;
	do {
		for (int i = 1; i < N; i++) {
			ans += sqrt((x[ar[i - 1]] - x[ar[i]])*(x[ar[i - 1]] - x[ar[i]]) + 
				(y[ar[i - 1]] - y[ar[i]]) * (y[ar[i - 1]] - y[ar[i]]));
		}
		cnt++;
	} while (next_permutation(ar, ar + N));

	cout << setprecision(12) << ans / (double)cnt << endl;

	return 0;
}

Measured memory_bytes: 256
import itertools
import math

def main():
    n = int(input())
    A = [list(map(int, input().split())) for i in range(n)]
    total = 0
    L = list(itertools.permutations(range(n), n))
    for l in L:
        l1, *la = l
        for i in la:
            total += ((A[l1][0]-A[i][0])**2 + (A[l1][1]-A[i][1])**2)**0.5
            l1 = i
    print(total/math.factorial(n))


if __name__ == '__main__':
    main()

Measured memory_bytes: 8100
import java.util.*;
public class Main {	
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new AOJ0034();
	}
	
	
	
	class  AOJ0155{
		int d[];
		int n;
		int x[];
		int y[];
		int ban[];
		int[][] cost;
		public AOJ0155(){
			Scanner in = new Scanner(System.in);
			while(true){
				n = in.nextInt();
				if(n==0)break;
				cost = new int[n+1][n+1];
				ban = new int[n+1];
				x = new int[n+1];
				y = new int[n+1];
				for(int i=1;i<n+1;i++){
					ban[i] = in.nextInt();
					x[i] = in.nextInt();
					y[i] = in.nextInt();
				}
				for(int i=1;i<n+1;i++){
					for(int s=i+1;s<n+1;s++){
						int x1 = x[i],y1= y[i],x2=x[s],y2=y[s];
						int costs = (int)Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));		
						cost[i][s] = costs > 50 ? 1000000:costs;
						cost[s][i] = cost[i][s];
					}
				}
				int kai = in.nextInt();
				for(int i=0;i<kai;i++){
					int s = in.nextInt();
					int g = in.nextInt();
					//ArrayList<Integer> list = dijkstra(s, g);
				}
			}
		}
	}
	
	class AOJ0034{
		int[] kyori = new int[11];
		double speed1,speed2;
		public AOJ0034() {
			Scanner in = new Scanner(System.in);
			while(in.hasNext()){
				speed1 = 0.000000;
				speed2 = 0.000000;
				String input[] = in.next().split(",");
				int sum=0;
				for(int i=1;i<=10;i++){
					kyori[i] = Integer.parseInt(input[i-1]);
					sum+=kyori[i];
				}
				speed1 = Integer.parseInt(input[10]);
				speed2 = Integer.parseInt(input[11]);
				speed1/=3600;
				speed2/=3600;
				double speed = speed1+speed2;//km/秒速を合計
				double time = sum/speed;
				int came = 0;
//				System.out.println(time+" "+speed+" "+speed*time);
				for(int i=1;i<=10;i++){
					came+=kyori[i];
					if(came>=speed1*time){
						System.out.println(i);
						break;
					}
				}
			}
		}
		
		
	}
}

Measured memory_bytes: 17132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int n, k;
int main(){
  cin >> n >> k;
  int ans = 1;
  while(n){
    ans = min(ans * 2, ans + k);
    n--;
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] res = new int[n+1];
        String[] str = br.readLine().split(" ");
        for(int i=0; i<n-1; ++i){
            res[Integer.parseInt(str[i])]++;
        }
        for(int i=1; i<=n; ++i){
            System.out.println(res[i]);
        }
    }
}


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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000001)
#define MOD (1000000007)
#define PI (acos(-1))

int H,W,N,sy,sx;
string S,T;
bool solve(){
  int left=0,up=0,right=W-1,down=H-1;
  if(S[N-1]=='L')left++;
  if(S[N-1]=='R')right--;
  if(S[N-1]=='U')up++;
  if(S[N-1]=='D')down--;
  if(left==right || up==down)return false;
  for(int i=N-2; i>=0; i--){
    if(T[i]=='L')right=min(W-1,right+1);
    if(T[i]=='R')left=max(0,left-1);
    if(T[i]=='U')down=min(H-1,down+1);
    if(T[i]=='D')up=max(0,up-1);
    if(S[i]=='L')left++;
    if(S[i]=='R')right--;
    if(S[i]=='U')up++;
    if(S[i]=='D')down--;
    //cout << left << " " << right << " " << up << " " << down << endl;
    if(left>right || up>down)return false;
  }
  if(left<=sx&&sx<=right && up<=sy&&sy<=down)return true;
  else return false;
}

int main(){
  cin >> H >> W >> N >> sy >> sx >> S >> T;
  sy--;sx--;
  if(solve())cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 776
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashMap<String,Long> namelist = new HashMap<>();
        String s = "MARCH";
        for(int i = 0;i<s.length();i++){
            namelist.put(String.valueOf(s.charAt(i)), Long.valueOf(0));
        }
        for (int i = 0; i < n; i++) {
            String name = String.valueOf(sc.next().charAt(0));
            if(namelist.containsKey(name)){
                namelist.put(name,namelist.get(name)+1);
            }
        }
        
        long ans=0;
        
        for(int i =0;i<s.length()-2;i++){
            long a = namelist.get(String.valueOf(s.charAt(i)));
            for(int j=i+1;j<s.length()-1;j++){
                long b = namelist.get(String.valueOf(s.charAt(j)));
                for(int k = j+1;k<s.length();k++){
                    long c = namelist.get(String.valueOf(s.charAt(k)));
                    ans += a*b*c;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 46708
#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(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    string s;
    cin >> s;
    int l = 0;
    int r = s.length() - 1;
    int cnt = 0;
    while(r - l >= 1) {
        // cout << s[l] << " " << s[r] << endl;
        if(s[l] == s[r]) {
            l++;
            r--;
        } else if(s[l] == 'x') {
            l++;
            cnt++;
        } else if(s[r] == 'x') {
            r--;
            cnt++;
        } else {
            // cout << s[l] << " " << s[r] << endl;
            cout << -1 << endl;
            return 0;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main()
{
  int n,k,s,i,j,l,m,o,p,q,r,t,u,sum,ans;

  for(;;){
    cin>>n>>k>>s;
    if(!(n|k|s)) break;

    ans=0;
    if(k>0){
      for(i=1;i<=n-k+1;i++){
	sum=i;
	if(sum>s) break;
	if(sum==s&&k==1){
	  ans++; break;
	}
	if(k>1){
	  for(j=i+1;j<=n-k+2;j++){
	    sum=i+j;
	    if(sum>s) break;
	    if(sum==s&&k==2){
	      ans++; break;
	    }
	    if(k>2){
	      for(l=j+1;l<=n-k+3;l++){
		sum=i+j+l;
		if(sum>s) break;
		if(sum==s&&k==3){
		  ans++; break;
		}
		if(k>3){
		  for(m=l+1;m<=n-k+4;m++){
		    sum=i+j+l+m;
		    if(sum>s) break;
		    if(sum==s&&k==4){
		      ans++; break;
		    }
		    if(k>4){
		      for(o=m+1;o<=n-k+5;o++){
			sum=i+j+l+m+o;
			if(sum>s) break;
			if(sum==s&&k==5){
			  ans++; break;
			}
			if(k>5){
			  for(p=o+1;p<=n-k+6;p++){
			    sum=i+j+l+m+o+p;
			    if(sum>s) break;
			    if(sum==s&&k==6){
			      ans++; break;
			    }
			    if(k>6){
			      for(q=p+1;q<=n-k+7;q++){
				sum=i+j+l+m+o+p+q;
				if(sum>s) break;
				if(sum==s&&k==7){
				  ans++; break;
				}
				if(k>7){
				  for(r=q+1;r<=n-k+8;r++){
				    sum=i+j+l+m+o+p+q+r;
				    if(sum>s) break;
				    if(sum==s&&k==8){
				      ans++; break;
				    }
				    if(k>8){
				      for(t=r+1;t<=n-k+9;t++){
					sum=i+j+l+m+o+p+q+r+t;
					if(sum>s) break;
					if(sum==s&&k==9){
					  ans++; break;
					}
					if(k>9){
					  for(u=t+1;u<=n;u++){
					    sum=i+j+l+m+o+p+q+r+t+u;
					    if(sum>s) break;
					    if(sum==s){
					      ans++; break;
					    }
					  }
					}
				      }
				    }
				  }
				}
			      }
			    }
			  }
			}
		      }
		    }
		  }
		}
	      }	  
	    }
	  }
	}
      }
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
int n,m;
ll w[N],v[N],dp[N];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>w[i]>>v[i];
    for(int i=1;i<=n;i++){
        for(int j=m;j>=w[i];j--){
            dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
        //cout<<j<<i<<" "<<dp[j]<<endl;
        }
    }
    cout<<dp[m];
}


Measured memory_bytes: 4348
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			long a = stdIn.nextLong();
			long b = stdIn.nextLong();
			if(a < b)
			{
				long temp = a;
				a = b;
				b = temp;
			}
			long g = gcd(a, b);
			System.out.println(g + " " + (a * b / g));
		}
	}
	
	static long gcd(long a, long b)
	{
		if(b == 0)
		{
			return(a);
		}
		return(gcd(b, a % b));
	}
}

Measured memory_bytes: 17216
S = input()
mod = 10**9+7
dp = [[0]*13 for _ in range(len(S)+1)]
dp[0][0] = 1

for i, s in enumerate(S[::-1], start=1):
    m = pow(10, i-1, 13)
    if s=="?":
        for j in range(10):
            for k in range(13):
                dp[i][(j*m+k)%13] += dp[i-1][k]
    else:
        j = int(s)
        for k in range(13):
            dp[i][(j*m+k)%13] += dp[i-1][k]
    
    for j in range(13):
        dp[i][j] %= mod

print(dp[-1][5])

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

int main() {
  string s, t;
  cin >> s >> t;

  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());

  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3612
from collections import defaultdict
N, = map(int, input().split())

def normal(xs):
    mnx = min(xs)
    xi = xs.index(mnx)
    if xs[(xi+3)%4] == mnx:
        if xs[(xi+2)%4] == mnx:
            xi = (xi+2)%4
        else:
            xi = (xi+3)%4
    if xs[(xi+1)%4] > xs[(xi+3)%4]:
        xi = (xi+2)%4
    return (xs[xi%4], xs[(xi+1)%4], xs[(xi+2)%4], xs[(xi+3)%4])
#x = (0,2,2,0)
#print(normal(x))

dd = defaultdict(int)
ss = []
for _ in range(N):
    a, b, c, d = map(int, input().split())
    x = normal([a,b,c,d])
    n=1
    if x[0] == x[2] and x[1] == x[3]:
        n *= 2
        if x[0] == x[1]:
            n *= 2
    dd[x] += n
    ss.append(x)

def icr(x):
    n = 1
    if x[0] == x[2] and x[1] == x[3]:
        n *= 2
        if x[0] == x[1]:
            n *= 2
    dd[x] += n

def dcr(x):
    n = 1
    if x[0] == x[2] and x[1] == x[3]:
        n *= 2
        if x[0] == x[1]:
            n *= 2
    dd[x] -= n

def f(ff, gg):
    #print(dd)
    a,b,c,d=ff
    e,h,g,f=gg
    tl = list(map(normal, [(a,e,f,b), (b,f,g,c), (c,g,h,d), (d,h,e,a)]))
    r = 1
    for cp in tl:
        if cp not in dd:
            r = 0
            break
        r *= dd[cp]
        dcr(cp)
    for cp in tl:
        if cp not in dd:
            break
        icr(cp)
    return r

r = 0
for i in range(N):
    ff = ss[i]
    dcr(ff)
    for j in range(i+1, N):
        sl = ss[j]
        dcr(sl)
        x, y, z, w = sl
        sls = [(x,y,z,w), (y,z,w,x), (z,w,x,y), (w,x,y,z)]
        for s in sls:
            r += f(ff, s)
        icr(sl)
    icr(ff)
print(r//3)


Measured memory_bytes: 75908
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    string s;
    cin >> s;
    cout << s;
    if (s[s.size()-1] == 's') cout << "es";
    else cout << "s";
    cout << endl;
}

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

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5+5;
int a[maxn], dp[maxn];

int main(){
	int n; cin >> n;
	memset(dp, 0x3f, sizeof dp);
	for(int i = 1; i <= n; i++) cin >> a[i];
	dp[1] = 0;
	for(int i = 2; i <= n; i++){
		dp[i] = min(dp[i], dp[i-1] + abs(a[i] - a[i-1]));
		if(i > 2) dp[i] = min(dp[i], dp[i-2] + abs(a[i] - a[i-2]));
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll N;
ll A[105000];
ll num[3];
ll ans = 1;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> A[i];
    for(int i = 1; i <= N; i++) {
        ll newans = 0;
        for(int j = 0; j <= 2; j++) {
            if(A[i] == num[j]) newans += ans;
        }
        ans = newans % mod;
        for(int j = 0; j <= 2; j++) {
            if(A[i] == num[j]) {
                num[j]++;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int H, W;
	int i = 1;
	while (1){
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		if (i)i = 0;
		else cout << endl;
		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				if ((i+j) % 2 == 0){
					cout << '#';
				}
				else{
					cout << '.';
				}
			}
			cout << endl;
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,string> P;

int main(){
  int n;
  while(cin>>n,n){
    map<string,int> M;

    P ans=P(-1,"#");
    for(int i=0;i<n;i++){
      string name;
      cin>>name;
      M[name]++;
      
      map<string,int>::iterator it=M.begin();
      vector<P> v;
      v.push_back(P(0,"$"));
      for(;it!=M.end();it++)v.push_back(P(it->second,it->first));
      sort(v.begin(),v.end(),greater<P>());
      if(v[0].first==v[1].first)continue;
      if(ans!=P(-1,"#"))continue;
      if(v[0].first>v[1].first+n-i-1)ans=P(i+1,v[0].second);
    }

    if(ans==P(-1,"#"))cout<<"TIE"<<endl;
    else cout<<ans.second<<" "<<ans.first<<endl;
  }

  return 0;
}

Measured memory_bytes: 3104
program main
  implicit none
  integer :: y, m, d
  character(1) :: tmp1, tmp2

  read '(i4, a1, i2, a1, i2)', y, tmp1, m, tmp2, d
  if (m .le. 4) then
    print '(6a)', 'Heisei'
  else
    print '(3a)', 'TBD'
  end if
end

Measured memory_bytes: 384
s = int(input())

a = []

a.append(s)
cont = True

i = 0
while cont:
    if a[i]%2 == 0:
        t = a[i]/2
    else:
        t = 3*a[i] + 1
    if t in a:
        cont = False
    else:
        i += 1
        a.append(t)

print(i+2)

Measured memory_bytes: 3060
N = int(input())
A = [[int(i) for i in input().split()] for _ in range(2)]

# dpj[i]: (i,j)でアメの最大値
dp1 = [0] * N
dp2 = [0] * N

# 初期条件
dp1[0] = A[0][0]
dp2[0] = A[0][0] + A[1][0]

# 貰うdp
for i in range(1,N):
    dp1[i] = dp1[i-1] + A[0][i]

for i in range(1,N):
    dp2[i] = max(dp1[i], dp2[i-1]) + A[1][i]

print(dp2[-1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
 
int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    p.push_back(0);
    int ans = 0;
    for(int i = 1; i < n+1; i++){
        if(p[i-1] > p[i]){
            ans += p[i-1] - p[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

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


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  std::string S; std::cin >> S;
  std::unordered_map<char, int> m;
  for(auto&& s : S) {
    if ( m.count(s) == 1 ) {
      std::cout << "no" << std::endl;
      return 0;
    }
    else m[s] = 1;
  }
  std::cout << "yes" << std::endl;
  return 0;
}


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

int main()
{
    int a, b;
    cin >> a >> b;
    queue<int> q;
    int c = 0;
    for (int i = a; i <= b; i++) {
        int n = i;
        while (n > 0) {
            q.push(n % 10);
            n /= 10;
        }
        int nn = 0;
        while (!q.empty()) {
            nn = nn * 10 + q.front();
            q.pop();
        }
        if (i == nn) {
            c++;
        }
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
s=int(input())
k=[]
k.append(s)
cnt=0
while(True):
    cnt+=1
    if k.count(s)==2:
        print(cnt)
        break
        
    if s%2==0:
        s=int(s/2)
        k.append(s)
    else:
        s=s*3+1
        k.append(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
#define pb push_back
#define mp make_pair
#define pf push_front
#define FOR(i,a,b)           for(int i = a;   i <  (int)(b); ++i)
#define for_rev(i,a,b)       for(int i = b-1; i >= (int)(a); --i)
#define for_it(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define all(v) v.begin(), v.end()
#define sortv sort(all(v))
#define print(v)     \
    for (auto i : v) \
        cout << i << " ";
#define FAST                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL);
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef unordered_set<int> ust;
typedef set<int> st;
typedef unordered_map<int, int> ump;
typedef map<int, int> mi;
#define F first
#define S second
/*****************************************************************************/
long long dp[100001];
int main()
{
	FAST
	int N , wt ; cin >> N >> wt ;
	int wi [N], val [N];
	for (int i = 0 ; i < N ; i++) cin >> wi[i] >> val[i] ;
	// cout << dp[0] <<endl;
	for ( int i = 0 ; i < N ; i++)
	{
		for (int j = wt - wi[i] ; j >= 0 ; j--)
		{
			// cout << j << "   " << j + wi[i] << "  " << dp[j] + val[i] << endl; 
			dp[j + wi[i]] = max(dp[j] + val[i], dp[j + wi[i]]);
		}
	}
	cout << dp[wt] ;
	return 0 ;
}

Measured memory_bytes: 4356
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int H,W;
  	char a[100][100],b[102][102];
 	cin >> H >> W;
  	for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        cin >> a[i][j];
      }
    }
    for(int i=0;i<H+2;i++){
      for(int j=0;j<W+2;j++){
        b[i][j] = '#';
      }
    }
  	for(int i=1;i<H+1;i++){
      for(int j=1;j<W+1;j++){
        b[i][j] = a[i-1][j-1];
      }
    }
  for(int i=0;i<H+2;i++){
    for(int j=0;j<W+2;j++){
      cout << b[i][j];
    }
    cout << endl;
  }
}
  

Measured memory_bytes: 256
N,M = map(int,input().split())
listM = list(range(1,M+1))
for i in range(N):
    K = list(map(int,input().split()))
    K.pop(0)
    a = []
    for j in range(len(listM)):
        if listM[j] not in K:
          	a.append(listM[j])
    for j in range(len(a)):
      	listM.remove(a[j])
print(len(listM))
            

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
Int INF = 1e18;
double EPS = 0.00000001;
//Int mod = 1e6+3;

int main() {
    Int n, k;
    cin >> n >> k;
    Int x = (n - 1) * (n - 2) / 2;
    if (k > x) {
        dump(-1);
    }
    else {
        vector<pair<Int, Int>> res;
        for (Int i = 1; i < n; i++) res.emplace_back(i, n);
        Int cnt = x;
        for (Int i = 1; i <= n - 2; i++) {
            for (Int j = i + 1; j <= n - 1; j++) {
                if (cnt == k) {
                    i = j = n;
                    break;
                }
                res.emplace_back(i, j);
                cnt--;
            }
        }
        dump(res.size());
        for (Int i = 0; i < (Int)res.size(); i++) cout << res[i].fi << " " << res[i].se << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

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

void solve(istream& cin, ostream& cout) {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n + 1), b(m + 1);
  a[0] = 0;
  b[0] = 0;
  FOR(i, 1, n) cin >> a[i];
  FOR(i, 1, m) cin >> b[i];
  FOR(i, 1, n) a[i] += a[i - 1];
  FOR(i, 1, m) b[i] += b[i - 1];
  int ans = 0;
  REP(i, n + 1) {
    if (a[i] > k) break;
    if (k - a[i] < 0) continue;
    int l = 0, r = m + 1;
    while (r - l > 1) {
      int mid = (l + r) / 2;
      ll sum = a[i] + b[mid];
      if (sum > k) {
        r = mid;
      } else {
        l = mid;
      }
    }
    ans = max(ans, i + l);
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


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

int main(void){
  int n;
  cin >> n;
  int ans = 0;
  int i = 1;
  while(n > ans){
    i++;
    ans = pow(i,2);
    if(ans > n){
      i--;
      ans = pow(i,2);
      break;
    }
  }
  cout << ans << endl;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        String[] S = new String[N];
        for(int n=0;n<N;n++) S[n]=sc.next();
        Arrays.sort(S);
        for(int n=0;n<N;n++) System.out.print(S[n]);
        System.out.println();
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define int long long
//#define _GLIBCXX_DEBUG


signed main() {
  int N; cin >> N;
  vector<int> A(N, 0);
  rep(i, N) {
    int a; cin >> a;
    A[a]++;
  }
  
  if(N%2 == 0) {
    rep(i, N) {
      if(i%2 == 0 && A[i] != 0) {
        cout << 0 << endl;
        return 0;
      } else if(i%2 == 1 && A[i] != 2) {
        cout << 0 << endl;
        return 0;
      }
    }
    int ans = 1;
    rep(i, N/2) {
      ans *= 2;
      ans %= 1000000007;
    }
    cout << ans << endl;
    return 0;
  }
  if(N%2 == 1) {
    rep(i, N) {
      if(i%2 == 1 && A[i] != 0) {
        cout << 0 << endl;
        return 0;
      } else if(i == 0 && A[i] != 1) {
        cout << 0 << endl;
        return 0;
      } else if(i > 0 && i%2 == 0 && A[i] != 2) {
        cout << 3 << endl;
        return 0;
      }
    }
    int ans = 1;
    rep(i, N/2) {
      ans *= 2;
      ans %= 1000000007;
    }
    cout << ans << endl;
    return 0;
  }
}


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

#define N_MAX 3000
class Point{
public:
  int x, y;
  Point(int x = 0, int y = 0):x(x), y(y){

  }
};

int N, K;
Point P[N_MAX];
Point T[N_MAX];

bool compX(const Point &p1, const Point &p2){
  if ( p1.x == p2.x ) return p1.y < p2.y;
  return p1.x < p2.x;
}

bool compA(const Point &p1, const Point &p2){
  return p2.x*p1.y < p1.x*p2.y;
}

bool eq(const Point &p1, const Point &p2){
  return p2.x*p1.y == p1.x*p2.y;
}

int check(int p, int M){
  sort(T, T + M, compA);
  int maxl = 1;
  int l = 1;
  Point pre = T[0];
  for ( int i = 1; i < M; i++ ){
    if ( eq(pre, T[i]) ){
      l++;
      maxl = max(maxl, l);
    } else {
      l = 1;
    }
    pre = T[i];
  }
  return maxl;
}


bool solve(){
  for ( int i = 0; i < N; i++ ){ // origin
    int k = 0;
    int v = 0;
    for ( int j = i+1; j < N; j++ ){
      if ( P[i].x == P[j].x ){
	v++;
      } else {
	T[k] = P[j];
	T[k].x -= P[i].x;
	T[k].y -= P[i].y;
	k++;
      }
    }
    if ( 1 + v >= K ) return true;
    if ( 1 + check(i, k) >= K ) return true;
  }

  return false;
}

main(){
  cin >> N >> K;
  for ( int i = 0; i < N; i++ ) cin >> P[i].x >> P[i].y;
  sort(P, P + N, compX);

  cout << solve() << endl;

  return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <functional>
using namespace std;

int main() {
	int n; cin >> n;
	string S = to_string(n);
	int ret = 0; for (int i = 0; i < S.size(); i++)ret += (S[i] - '0');
	if (n%ret == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 100005

int N;
char buf[NUM];

int main(){

	scanf("%d",&N);
	scanf("%s",buf);


	int ans = 0;

	for(int i = 0; i+1 < N;){

		if(buf[i] == 'O' && buf[i+1] == 'X'){
			ans++;
			i += 2;
		}else if(buf[i] == 'X' && buf[i+1] == 'O'){
			ans++;
			i += 2;
		}else{
			i++;
		}
	}

	printf("%d\n",ans);

	return 0;
}



Measured memory_bytes: 3312