akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = -1;
vl flag, color, D; vll path;
//***********//
int main() {
	cin >> N;
	string S;
	cin >> S;
	//N,1タイ目の組み合わせで決める
	vl Ans(N);
	vl T(N);
	for (i = 0; i < N; i++) {
		if (S[i] == 'o') T[i] = 0;
		else T[i] = 1;
	}
	for (l = 0; l < 4; l++) {
		ll k = l;
		Ans[0] = k % 2; k /= 2; Ans[1] = k % 2;
		for (i = 0; i <= N - 3; i++) {
			if (Ans[i] == 0) Ans[i + 2] = Ans[i + 1] ^ T[i + 1];
			else Ans[i + 2] = !(Ans[i + 1] ^ T[i + 1]);
		}
		ll pre0 = 0; ll pre1 = 0;
		if (Ans[N - 2] == 0) pre0 = Ans[N - 1] ^ T[N - 1];
		else pre0 = !(Ans[N - 1] ^ T[N - 1]);
		if (Ans[N - 1] == 0) pre1 = pre0 ^ T[0];
		else pre1 = !(pre0 ^ T[0]);
		//for (j = 0; j < N; j++) {
			//cout << Ans[j];
		//}
		//cout << endl << pre0 << pre1 << endl;
		if (Ans[0] == pre0 && Ans[1] == pre1) {
			for (i = 0; i < N; i++) {
				if (Ans[i])cout << "W";
				else cout << "S";
			}
			exit(0);
		}
	}
	cout << -1;
}

Measured memory_bytes: 2176
#include <iostream>
#include <stdio.h>
#include <numeric>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    sort(a,a+n);
    long long sum=accumulate(a,a+n,0LL);
    cout<<a[0]<<" "<<a[n-1]<<" "<<sum<<endl;
    return 0;
}



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

int main() {
  int n, m;
  int a[100100];
  int s = 0;
  
  cin >> n >> m;
  
  for(int i = 0; i < m; i++){
    cin >> a[i];
    s += a[i];
  }
  if(s > n){
    cout << -1 << endl;
  }else{
    cout << n - s << endl;
  }
}

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

int main() {
  string s,t;
  cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s<t) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

int main()
{
    long long N;
    long long t, x, y, dt, dx, dy, d;
    long long pre_t, pre_x, pre_y;
    bool flag = true;
    // read N
    cin >> N;

    pre_t = pre_x = pre_y = 0;

    while (cin >> t >> x >> y)
    {
        dt = t - pre_t;
        dx = x - pre_x;
        dy = y - pre_y;
        d = abs(dx) + abs(dy);
        if (((d % 2) == (dt % 2)) && dt >= d)
        {
            flag *= 1;
        }
        else
        {
            flag *= 0;
            break;
        }
    }
    if (flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int n,m;
  while(cin>>n>>m,n+m){
    bool frend[500]={0};
    bool f[500][500]={{0}};
    for(int i=0; i<m; i++){
      int a,b;
      cin>>a>>b;a--;b--;
      f[a][b]=true;
      f[b][a]=true;
    }
    for(int i=0; i<n; i++){
      if(f[0][i]){
	frend[i]=true;
	for(int j=0; j<n; j++)
	  if(f[i][j]) frend[j]=true;
      }
    }
    int ans = 0;
    for(int i=1; i<n; i++){
      if(frend[i]) ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

#define cc (100.0*E)/(100.0+E)

int A, B, C, D, E, F, ans_a, ans_b;
double m;

bool v[3000][3000];

void solve(int a,int b){
  if(a+b>F || v[a][b] || (100.0*b)/(a+b)>(100.0*E)/(E+100.0)) return;
  v[a][b]=true;
  double tmp=(100.0*b)/(a+b);
  if(tmp>=m){
    m=tmp;
    ans_a=a;
    ans_b=b;
  }
  solve(a + A * 100, b);
  solve(a + B * 100, b);
  solve(a, b + C);
  solve(a, b + D);
}

int main(){
  cin >> A >> B >> C >> D >> E >> F;
  solve(0,0);
  cout << ans_a + ans_b << " " << ans_b << endl;
  return 0;
}

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



int main() {
  int n ; cin >> n;
  vector<double> vec(n);
  for(int i = 0; i < n; i++) cin >> vec[i];
  sort(vec.begin(), vec.end());
  for(int i = 1; i < n; i++) {
    vec[i] = (vec[i-1]+vec[i])/2;
  }
  cout << vec[n-1] << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void)
{
    ll n,l[2100];
    ll i,j,k;
    ll ab;
    ll cnt = 0;
    cin >> n;
    for(i = 0; i < n; i++) {
        cin >> l[i];
    }
    sort(l,l+n);
    for(i = 0; i < n-2; i++) {
        for(j = i+1; j < n - 1; j++) {
          ab = l[i]+l[j];
          for(k = j+1; k < n; k++) {
              if(ab>l[k]) {
//                  cout << l[i] << " " << l[j] << " " << l[k] << endl;
                  cnt ++;
              }
          }
        }
    }
    cout << cnt << endl;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,d;
  cin>>n>>d;
  vector<vector<int>>v(n,vector<int>(d));
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin>>v[i][j];
    }
  }
  int ans = 0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int b=0;
      for(int k=0;k<d;k++){
        int a=abs(v[i][k]-v[j][k]);
        b+=a*a;
      }
      bool flag = false;
     for(int x=0;x<=b;x++) {
       if(b==x*x){
         flag=true; 
       }
     }
     if(flag)ans++;
    }
    
  }
  cout<<ans<<endl;
}
    
    

Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    s = list(input())
    n = len(s)
    for i in range(n//2):
        if s[i] != s[-1-i]:
            print('No')
            return
    for i in range(((n-1)//2)//2):
        if s[i] != s[(n-1)//2-1-i]:
            print('No')
            return
    s.reverse()
    for i in range(((n-1)//2)//2):
        if s[i] != s[(n-1)//2-1-i]:
            print('No')
            return
    print('Yes')    
    
if __name__ == "__main__":
    main()

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

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int k = 0; k <= c; k++) {
        if (x == 500 * i + 100 * j + 50 * k)
          ans++;
      }
    }
  }
  cout << ans << endl;
}


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

int main(){
    int N;
    long long ans = 0, sum =0;
    int mod = 1000000000+7;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
        sum += a.at(i);
        
    }
 	 sum %= mod;
    for (int i = 0; i < N-1; i++) {
        sum -= a.at(i);
        if(sum<0) sum += mod;
        ans += sum * a.at(i);
        ans %= mod;
    }
    cout << ans << endl;
}
/*

*/


Measured memory_bytes: 4008
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }

int main() {
   int N, X;
   cin >> N >> X;
   int L[N];
   for (int i = 0; i < N; i++) cin >> L[i];
   int ans = 0;

   int D = 0;
   if (D <= X) ans++;
   for (int i = 1; i <= N; i++) {
      D += L[i - 1];
      if (D <= X) ans++;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline

n,m=map(int,input().split())
if n>=m:
    print(0)
    exit()

lst=sorted(map(int,input().split()))
sa=[]
for i in range(m-1):
    sa.append(lst[i+1]-lst[i])
sa=sorted(sa)
print(sum(sa[:m-n]))

Measured memory_bytes: 91704
#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)
using namespace std;
typedef long long ll;
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;
}

ll modpow(ll a, ll p) {
    if(p == 0)
        return 1;
    if(p % 2 == 0) {
        ll halfp = p / 2;
        ll half = modpow(a, halfp);
        return half * half % MOD;
    } else {
        return a * modpow(a, p - 1) % MOD;
    }
}

ll calcComb(ll a, ll b) {
    if(b < 0) {
        return 0;
    }
    if(a < 0) {
        return 0;
    }
    if(a < b) {
        return 0;
    }
    if(b > a - b) {
        return calcComb(a, a - b);
    }
    ll ansMul = 1;
    ll ansDiv = 1;
    REP(i, b) {
        ansMul *= (a - i);
        ansDiv *= (i + 1);
        ansMul %= MOD;
        ansDiv %= MOD;
    }
    ll ans = ansMul * modpow(ansDiv, MOD - 2);
    ans %= MOD;
    return ans;
}

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

    if(abs(N - M) > 1) {
        cout << "0" << endl;
        return 0;
    }
    long long ans = 1;
    if(N == M) {
        ans *= 2;
    }
    for(int i = 1; i <= N; i++) {
        ans *= i;
        ans %= MOD;
    }
    for(int i = 1; i <= M; i++) {
        ans *= i;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// AOJ 2382: King Slime
// 2018.1.22 bal4u@uu

#include <stdio.h>

#define MAX 40002

/* UNION-FIND library */
int id[MAX], size[MAX];

void init(int n)
{
	int i;
	for (i = 1; i <= n; i++) id[i] = i, size[i] = 1;
}

int root(int i)
{
	while (i != id[i]) id[i] = id[id[i]], i = id[i];
	return i;
}

int connected(int p, int q) { return root(p) == root(q); }

void unite(int p, int q)
{
    int i = root(p), j = root(q);
	if (i == j) return;
    if (size[i] < size[j]) id[i] = j, size[j] += size[i];
    else                   id[j] = i, size[i] += size[j];
}
/* UNION-FIND library */


int xx[100002], yy[100002];
char tbl[40002];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, w, h, i, x, y, f, ans;

	n = in(), w = in(), h = in();
	init(n);

	f = 0;
	for (i = 1; i <= n; i++) {
		x = in(), y = in();
		if (x == 1 || x == w || y == 1 || y == h) f = 1;
		if (!xx[x]) xx[x] = i; else unite(xx[x], i);
		if (!yy[y]) yy[y] = i; else unite(yy[y], i);
	}

	ans = 0;
	for (i = 1; i <= n; i++) {
		x = root(i);
		if (!tbl[x]) ans++, tbl[x] = 1;
	}
	if (ans == 1) f = 1;
	ans += n - (f + 1);
	printf("%d\n", ans);
	return 0;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
// #define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int k, x; cin >> k >> x;
    Rep(i, x-k+1, x+k){
        if(i - (x-k+1)) cout << " ";
        cout << i;
    }
    cout << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7748
#include <stdio.h>
int main(){
  int n, a[100], i, j, count=0, minj, b;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d", &a[i]);
  }

  for(i=0; i<n-1; i++){
    minj=i;
    for(j=i; j<n; j++){
      if(a[j]<a[minj]){
	minj=j;
      }
    }
    if(i!=minj){
      count++;
    }
    b=a[i];
    a[i]=a[minj];
    a[minj] = b;
    
  }

  for(i=0; i<n-1; i++){
    printf("%d ", a[i]);
  }
  printf("%d\n%d\n", a[n-1], count);
  
  return 0;
}



Measured memory_bytes: 2136
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
 
using namespace std;

struct tree{
    int node;
    tree *left;
    tree *right;
    tree *parent;
};

typedef struct tree T;

void insert(T *t)
{
    T *insert_node, *nownode;
    insert_node = (T *)malloc(sizeof(T));
    cin >> insert_node->node;
    insert_node->parent = NULL;
    insert_node->left = NULL;
    insert_node->right = NULL;
    if(t->left == NULL && t->right == NULL){
        t->left = insert_node;
    }
    else {
        insert_node->parent = t;
        nownode = t->left;
        bool isleft = true;
        while(nownode != NULL){
            insert_node->parent = nownode;
            if(nownode->node > insert_node->node) {
                nownode = nownode->left;
                isleft = true;
            }else {
                nownode = nownode->right;
                isleft = false;
            }
        }
        if(isleft) (insert_node->parent)->left = insert_node;
        else (insert_node->parent)->right = insert_node;}
    return;
}

void inorder(T *t)
{
    if(t == NULL) return;
    inorder(t->left);
    if(t->node != -1) cout << " " << t->node;
    inorder(t->right);
}

void preorder(T *t)
{
    if(t == NULL) return;
    if(t->node != -1) cout << " " << t->node;
    preorder(t->left);
    preorder(t->right);
}

void print(T *t)
{
    inorder(t);
    cout << endl;
    preorder(t);
    cout << endl;
}

int main()
{
    T *root_p;
    root_p = (T *)malloc(sizeof(T));
    root_p->node = -1;
    root_p->left = NULL;
    root_p->right = NULL;
    root_p->parent = NULL;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        string meirei;
        cin >> meirei;
        if(meirei == "insert") insert(root_p);
        else if(meirei == "print") print(root_p);
    }
    return 0;
}

Measured memory_bytes: 24652
x, y, a, b, c = gets.split.map(&:to_i)
_p = p
p = gets.split.map(&:to_i).sort.reverse
q = gets.split.map(&:to_i).sort.reverse
r = gets.split.map(&:to_i).sort.reverse

mix = (p[0...x] + q[0...y] + r).sort.reverse

result = 0
(x+y).times do |i|
  result += mix[i]
end
puts result

Measured memory_bytes: 33104
package main

import "fmt"

func main() {
	var k, s int
	fmt.Scanf("%d %d\n", &k, &s)
	cnt := 0
	for x := 0; x <= k; x++ {
		for y := 0; y <= k; y++ {
			r := s - x - y
			if 0 <= r && r <= k {
				cnt++
			}
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let n = get!(usize);
    let mut aa = get!(u64; n);

    let mut ans = 0;


    for i in 0..n - 1 {
        if aa[i] % 2 == 1 && aa[i + 1] > 0 {
            aa[i] -= 1;
            aa[i + 1] -= 1;
            ans += 1;
        }
    }

    for &x in &aa {
        ans += x / 2;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<functional>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef queue<P> Q;

#define _CRT_SECURE_NO_WARNINGS

int N,H,W;
int main() {
	cin >> N >> H >> W;
    int c=0;
	for(int i=0;i<N;i++){
        int a,b;
        cin >>a >>b;
        if(a>=H && b>=W)c++;
    }
    cout<<c;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int):
    able = A - B
    result = C - able
    if result >= 0:
        print(result)
    else:
        print(0)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
n, m, q = [int(i) for i in input().split()]
L = [[int(i) for i in input().split()] for j in range(m)]
Q = [[int(i) for i in input().split()] for j in range(q)]

A = [[0] * (n+1) for i in range (n+1)]

for l, r in L:
    A[l][r] += 1

for l in range(n, 0, -1):
    for r in range(1, n+1):
        A[l][r] += A[l][r-1]

for l in range(n-1, 0, -1):
    for r in range(1, n+1):
        A[l][r] += A[l+1][r]

for p, q in Q:
    print(A[p][q])

Measured memory_bytes: 54532
program main
    implicit none
    integer n, m
    integer, allocatable, dimension(:) :: s, c
    integer i,j,k,l, flag
    integer, dimension(3) :: x
    read(*,*) n, m
    allocate(s(m))
    allocate(c(m))

    do i = 1, m
        read(*,*) s(i), c(i)
    end do

    x = 0
    flag = 0

    do i = 1,m
        if(x(s(i)) /= 0) then
            if(x(s(i)) /= c(i)) then
                flag = -1
                exit
            end if
        else
            x(s(i)) = c(i)
        end if

!--------------
        if(n == 3) then
            if(s(i) == 1) then
                if(c(i) == 0) then
                    flag = -1
                end if
            end if
        end if

!---------------
        if(n == 2) then
            if(s(i) == 1) then
                if(c(i) == 0) then
                    flag = -1
                end if
            end if
        end if

    end do

    
    if (flag == -1) then
        write(*,*) -1
    else
        if (n == 3) then
            if (x(1) == 0) then
                x(1) = 1
            end if
            write(*,*) 100*x(1)+10*x(2)+x(3)
        else if (n == 2) then
            if (x(1) == 0) then
                x(1) = 1
            end if
            write(*,*) 10*x(1)+x(2)
        else
            write(*,*) x(1)
        end if
        
    end if

end program

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef vector<vi> vii;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
  fio();
  int x; cin>>x;
  cout<<(x^1)<<endl;
  return 0;
}

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

const int MAX_N = 210;
int GCD[MAX_N][MAX_N];

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

int main() {
    int K;
    cin >> K;
    for(int i = 1; i <= K; ++i) {
        for(int j = 1; j <= i; ++j) {
            GCD[i][j] = GCD[j][i] = gcd(i,j);
        }
    }
    long long res = 0LL;
    for(int a = 1; a <= K; ++a) {
        for(int b = 1; b <= K; ++b) {
            for(int c = 1; c <= K; ++c) {
                res += GCD[a][GCD[b][c]];
            }
        }
    }
    cout << res << endl;
    return 0;
}

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

int main(){
  long long int x;
  cin >> x;
  
  long long int money = 100;
  long long int year = 0;
  bool over = true;
  while(over){
    year++;
    money *= 1.01;
    if(money>=x) over = false;
  }
  printf("%d\n",year);
}


Measured memory_bytes: 3748
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;

const int N=305;

int n,m;
int dp[N][N][N];
char s[N];

int main(){
	int l,r,k,d,i;
	scanf("%s",s+1); n=strlen(s+1);
	scanf("%d",&m);
	for (i=1;i<=n;i++)
		for (k=0;k<=m;k++) dp[i][i][k]=1;
	for (d=2;d<=n;d++){
		for (l=1;l+d-1<=n;l++){
			r=l+d-1;
			for (k=0;k<=m;k++){
				if (k) dp[l][r][k]=max(dp[l][r][k],dp[l][r][k-1]);
				dp[l][r][k]=max(dp[l][r][k],dp[l+1][r][k]);
				dp[l][r][k]=max(dp[l][r][k],dp[l][r-1][k]);
				if (s[l]==s[r]) dp[l][r][k]=max(dp[l][r][k],dp[l+1][r-1][k]+2);
				if (k) dp[l][r][k]=max(dp[l][r][k],dp[l+1][r-1][k-1]+2);
			}
		}
	}
	printf("%d\n",dp[1][n][m]);
	return 0;
}

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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;



typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9+7;
/**********showtime************/

            const int maxn =  109;
            int a[maxn];
int main(){
            int n;  scanf("%d", &n);
            int ans = 0;
            for(int i=1; i<=n; i++) scanf("%d", &a[i]);
            for(int i=2; i<n; i++) {
                int q = a[i-1], w = a[i+1];
                if(q > w) swap(q, w);
                if(q < a[i] && a[i] < w)ans ++;
            }
            printf("%d\n", ans);
            return 0;
}


Measured memory_bytes: 256
from collections import deque

n, m = map(int, input().split())

route = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    route[a-1].append(b-1)
    route[b-1].append(a-1)

d = deque()
d.append(0)
ans = [-1] * n
ans[0] = 0
cnt = 0
while d:
    idx = d.popleft()
    for i in route[idx]:
        if ans[i] < 0:
            ans[i] = idx
            d.append(i)
            cnt += 1

if cnt == n - 1:
    print("Yes")
    for i in ans[1:]:
        print(i + 1)
else:
    print("No")

Measured memory_bytes: 94864
#include<bits/stdc++.h>
 
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;

ll arr[10000002];

int run_test(){
      int n;
      cin >> n;
      cout << arr[n] << "\n";
      return 0; 
}
 
int main(){
    FAST;
    ll t;
    t = 1;

    for(int i = 1; i<=10000000; i++){
            for(int j = i; j <= 10000000; j+=i){
                  arr[j]++;
            } 
    }
    ll sum = 0, count = 1;
    for(int i=1; i<=10000000; i++){
            sum += arr[i]*(count++);
            arr[i] = sum;  
    }
 
    while(t--){
        run_test();
    }
}

Measured memory_bytes: 81764
# AOJ 0185 Goldbach's Conjecture II
# Python3 2018.6.20 bal4u

MAX = 1000000
SQRT = 1000     # sqrt(MAX)

prime = [True for i in range(MAX)]
prime[1] = False

def sieve():
	for i in range(3, SQRT, 2):
		if prime[i] is True:
			for j in range(i*i, MAX, i):
				prime[j] = False
sieve()

while True:
	n = int(input())
	if n == 0: break
	i = j = n >> 1
	if (i & 1) == 0:
		i -= 1
		j += 1
	ans = 0
	while i > 0:
		if prime[i] and prime[j]: ans += 1
		i -= 2
		j += 2
	print(ans)



Measured memory_bytes: 13512
na = lambda: list(map(int, input().split()))
n = int(input())
a = na()
ans = set()
pro = 0
for i in a:
    if i >= 3200:
        pro += 1
        continue
    ans.add(i // 400)
print(len(ans) if len(ans) > 0 else 1,  len(ans)+pro)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n);(i)>=0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
  int main(){
    lint N,count2=0,count4=0,counto=0;
    cin>>N;
    vector<lint> x;
    rep(i,N){
      lint v;
      cin>>v;
    x.push_back(v);
    if(x[i]%4==0)count4++;
    else if(x[i]%2==0)count2++;
    else counto++;
    }
    if(count2!=N&&count2!=0)counto++;
  if(counto>count4+1)cout<<"No";
  else cout<<"Yes";
  }

Measured memory_bytes: 1400
/***
 **   A S M Atikur Rahman
 **   Update: 17-12-2019
***/

//#include <bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<cstring>
#include<time.h>
#include<limits.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<utility>
#include<iterator>
#include<algorithm>
#include<cassert>
#include<iomanip> ///setprecision


#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sci(x) scanf("%d%*c", &(x))
#define scll(x) scanf("%lld%*c", &(x))
#define scd(x) scanf("%lf%*c", &(x))
#define scstr(x) scanf("%s", x)
#define pfi(x) printf("%d", (x))
#define pfll(x) printf("%lld", (x))
#define pfd(x) printf("%f", (x))
#define pfstr(x) printf("%s", (x))
#define ps printf(" ")
#define pn printf("\n")
#define pfdot printf("..")

#define For(i,a,n) for(int i=(a); i<(n); i++)
#define rFor(i,n,a) for(int i=n-1; i>=0; i--)
#define trav(a,x) for (auto& a : x)
#define Mset(ara, val) memset(ara, val, sizeof(ara))

#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound

#define pi  (2*acos(0))


using namespace std;

using ll=long long;
using pii= pair<int,int>;
using pll= pair<long long, long long>;
using pcc= pair<char, char>;
using pdd= pair<double, double>;

#define V(a) vector<a>
using vi= vector<int>;
using vs= vector<string>;
using vll= vector<ll>;
using vpii= vector<pii>;
using vc= vector<char>;
using vd= vector<double>;

//ll POW(ll a,ll b){if(b==0)return 1;ll x=POW(a,b/2);x=(x*x);if(b&1)x=(x*a);return x;}

int ck[100100],pntt[100100];


int main( int argc, char *argv[] )
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stout);
    int n,k,m,pnt=0,ans=0;
    sci(n);sci(m);
    for(int i=0; i<m; i++)
    {
        sci(k);
        string s;
        cin>>s;
        if(s[0]=='A')
        {
            if(ck[k]==0)
            {
                ans++;
                ck[k]=1;
                pnt+=pntt[k];
            }
        }
        else
        {
            pntt[k]++;
        }
    }
    pfi(ans);ps;pfi(pnt);pn;


    return 0;
}




















Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String sSplit[] = s.split("");
        for(int i = 0;i < s.length();i++){
            if(i % 2 == 0){
                System.out.print(sSplit[i]);
            }
        }
        System.out.println();
    }
}

Measured memory_bytes: 35436
#include <bits/stdc++.h>
#include <iostream>
#include <cstdlib>

using namespace std;

int main(){
	string S;
	cin >> S;
	
	if(stoi(S.substr(0, 4)) < 2019){
		cout << "Heisei" << endl;
		return 0;
	}else if(stoi(S.substr(0, 4)) == 2019){
		if(stoi(S.substr(5, 7)) < 4){
			cout << "Heisei" << endl;
			return 0;
		}else if(stoi(S.substr(5, 7)) == 4){
			if(stoi(S.substr(8, 10)) <= 30){
				cout << "Heisei" << endl;
				return 0;
			}else{
				cout << "TBD" << endl;
				return 0;
			}
		}else{
			cout << "TBD" << endl;
			return 0;
		}
	}else{
		cout << "TBD" << endl;
		return 0;
	}
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

S_ba = []
S_ab = []
for i in range(N):
    if A[i] < B[i]: S_ba.append(B[i] - A[i])
    # elif A[i] > B[i]: S_ab.append(A[i] - B[i])
    else: S_ab.append(A[i] - B[i])

ans = len(S_ba)
now = 0
rem = sum(S_ba)

S_ab.sort(reverse=True)

if rem > sum(S_ab):
    print(-1)
    exit()
for i in range(len(S_ab)):
    if rem <= now: break
    now += S_ab[i]
    ans += 1
print(ans)


Measured memory_bytes: 24084
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <map>
#include <set>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

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

typedef pair<P, P> state; // cargo man
typedef pair<int, state> data;
bool can[10][10];
int memo[10][10][10][10];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

int main(){
	int w, h;
	int num;
	bool ok;
	while(cin >> w >> h && (w || h)){
		int sx = 0, sy = 0;
		int cx = 0, cy = 0;
		int gx = 0, gy = 0;
		fill(&memo[0][0][0][0], &memo[0][0][0][0] + 10000, INF);
		memset(can, false, sizeof(can));
		rep(i, h)rep(j, w){
			cin >> num;
			if(num == 0) can[i+1][j+1] = true;
			else if(num == 1) can[i+1][j+1] = false;
			else if(num == 2) can[i+1][j+1] = true, cx = j + 1, cy = i + 1;
			else if(num == 3) can[i+1][j+1] = true, gx = j + 1, gy = i + 1;
			else can[i+1][j+1] = true, sx = j + 1, sy = i + 1;
		}
		priority_queue<data, vector<data>, greater<data> > que;
		memo[cy][cx][sy][sx] = 0;
		que.push(data(0, state(P(cy, cx), P(sy, sx))));
		ok = false;
		while(!que.empty()){
			data d = que.top();
			que.pop();
			int cost = d.first;
			state s = d.second;
			// cargo
			int x1 = s.first.second;
			int y1 = s.first.first;
			// man
			int x2 = s.second.second;
			int y2 = s.second.first;

			if(x1 == gx && y1 == gy){
				ok = true;
				cout << cost << endl;
				break;
			}

			if(cost > memo[y1][x1][y2][x2]) continue;

			rep(i, 4){
				int nx = x2 + dx[i];
				int ny = y2 + dy[i];
				int nx2 = x2 + dx[i] * 2;
				int ny2 = y2 + dy[i] * 2;
				if(!can[ny][nx]) continue;
				if(nx == x1 && ny == y1){
					if(can[ny2][nx2] && memo[ny2][nx2][ny][nx] > cost + 1){
						memo[ny2][nx2][ny][nx] = cost + 1;
						que.push(data(cost + 1, state(P(ny2, nx2), P(ny, nx))));
					}
				}else{
					if(memo[y1][x1][ny][nx] > cost){
						memo[y1][x1][ny][nx] = cost;
						que.push(data(cost, state(P(y1, x1), P(ny, nx))));
					}
				}
			}
		}
		if(!ok) cout << -1 << endl;
	}
	return 0;
}

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

int main(){
  double a,b,h,m,x,y;
  scanf("%lf",&a);
  scanf("%lf",&b);
  scanf("%lf",&h);
  scanf("%lf",&m);
  h=(h*60+m)*M_PI/360;
  m*=M_PI/30;
  y=a*cos(h)-b*cos(m);
  x=a*sin(h)-b*sin(m);
  printf("%.10lf",sqrt(pow(x,2)+pow(y,2)));
  return(0);
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), ord(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ord[i] = i;
  }
  sort(ord.begin(), ord.end(), [&](int i, int j) { return a[i] < a[j]; });
  int x = a[ord[n / 2 - 1]];
  int y = a[ord[n / 2]];
  for (int i = 0; i < n; i++) {
    if (a[i] <= x) cout << y << '\n';
    else cout << x << '\n';
  }
  return 0;
}

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

#define rep(i,N) for(int i=0; i<(N); i++)
#define pb push_back

typedef long long ll;
typedef pair<int,int> P;
const ll mod=1e9+7;

int N;
P a[200005];


int main(){ 

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

cin>>N;

rep(i,N){
	int A;
	cin>>A;
	a[i].first=A;
	a[i].second=i;
}

sort(a,a+N);

rep(i,N){
	if(i!=a[N-1].second){
		cout<<a[N-1].first<<endl;
	}
	else{
		cout<<a[N-2].first<<endl;
	}
}


}


Measured memory_bytes: 3200
import java.util.*;
import java.lang.*;
import java.io.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        if(n%2==0){
            System.out.println(n/2);    
        }else{
            System.out.println((n/2)+1);    
        }
    }
}

Measured memory_bytes: 35748
#include <iostream>

using namespace std;

//#define int long long

using ll = long long;
using pii =  pair<int, int>;

const int IINF =  0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9+7;

#define for_(i, a, b) for(int i = (a);i < (b);++i)
#define rfor_(i, a, b) for(int i = (b)-1;i >= (a);--i)

#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 100007;

int N;
char s[10004][12];
int l[10004];

signed main() {
  //cin.tie(0);cout.tie(0);
  //ios_base::sync_with_stdio(false);

  cin >> N;
  rep(i, N) cin >> s[i];

  ll ans = 0, a = 0, b = 0, c = 0;

  rep(i, N) {
    for(int j=0;s[i][j]!='\0';++j) {
      if(s[i][j] == 'A' && s[i][j+1] == 'B') ++ans;
      ++l[i];
    }
    --l[i];
    if(s[i][0] == 'B') ++b;
    if(s[i][l[i]] == 'A') ++a;
    if(s[i][0] == 'B' && s[i][l[i]] == 'A') ++c;
  }

  if(c>0) { // B...AB...AB...A の1つの文字列に
    ans += c-1;
    a -= c;
    b -= c;
    if(b > 0 || a > 0) ++ans;
  }

  if(b>a) {
    ans += a;
  } else {
    ans += b;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use text_io::*;

fn main() {
    const U_INF: usize = 1 << 60;
    const I_INF: isize = 1 << 60;
    const MOD: i128 = 1000000007;

    let n: usize = read!();
    let k: usize = read!();
    let mut a = Vec::new();
    for _ in 0..n {
        let ai: usize = read!();
        a.push(ai);
    }

    let mut dp = vec![vec![ModUsize::new(0); k * 3 + 10]; n + 10];
    dp[0][0] = ModUsize::new(1);
    for i in 0..n {
        for j in 0..=k {
            let dij = dp[i][j];
            let ai = a[i];
            let ai = ai.min(k - j);
            dp[i + 1][j] += dij;
            dp[i + 1][j + ai + 1] -= dij;
        }

        for j in 0..k {
            let m = dp[i + 1][j];
            dp[i + 1][j + 1] += m;
        }
    }
    println!("{}", dp[n][k].value);
}

use num_integer::Integer;
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};

#[derive(Copy, Clone)]
pub struct ModUsize {
    pub mod_value: usize,
    pub value: usize,
}

impl ModUsize {
    pub fn new(n: usize) -> Self {
        Self {
            mod_value: Self::mod1(),
            value: n % Self::mod1(),
        }
    }

    pub fn pow(self, n: usize) -> Self {
        if n == 0 {
            Self::new(1)
        } else if n % 2 == 0 {
            let t = self.pow(n / 2);
            t * t
        } else {
            self * self.pow(n - 1)
        }
    }

    pub fn inv(self) -> Self {
        self.pow(self.mod_value - 2)
    }

    pub fn mod1() -> usize {
        1000000007
    }

    pub fn mod2() -> usize {
        998244353
    }
}

impl Add for ModUsize {
    type Output = ModUsize;

    fn add(self, rhs: Self) -> Self::Output {
        let mut tmp = self;
        tmp.value += rhs.value;
        if tmp.value >= self.mod_value {
            tmp.value -= self.mod_value;
        }
        tmp
    }
}

impl AddAssign for ModUsize {
    fn add_assign(&mut self, rhs: Self) {
        *self = *self + rhs;
    }
}

impl Sub for ModUsize {
    type Output = ModUsize;
    
    fn sub(self, rhs: Self) -> Self::Output {
        let mut tmp = self;
        if tmp.value < rhs.value {
            tmp.value += self.mod_value;
        }
        tmp.value -= rhs.value;
        tmp
    }
}

impl SubAssign for ModUsize {
    fn sub_assign(&mut self, rhs: Self) {
        *self = *self - rhs;
    }
}

impl Mul for ModUsize {
    type Output = ModUsize;

    fn mul(self, rhs: Self) -> Self::Output {
        let mut tmp = self;
        tmp.value *= rhs.value;
        tmp.value %= self.mod_value;
        tmp
    }
}

impl MulAssign for ModUsize {
    fn mul_assign(&mut self, rhs: Self) {
        *self = *self * rhs;
    }
}

impl Div for ModUsize {
    type Output = ModUsize;

    fn div(self, rhs: Self) -> Self::Output {
        let mut tmp = self;
        tmp.value /= rhs.value;
        tmp.value %= self.mod_value;
        tmp
    }
}

impl DivAssign for ModUsize {
    fn div_assign(&mut self, rhs: Self) {
        *self = *self / rhs;
    }
}


Measured memory_bytes: 517468
class MF_Graph
    def initialize(n = 0)
        @n = n
        @pos = []
        @g = Array.new(n) {[]}
    end

    def add_edge(from, to, cap)
        m = @pos.size
        @pos << [from, @g[from].size]
        @g[from] << [to, @g[to].size, cap]
        @g[to] << [from, @g[from].size - 1, 0]
        return m
    end

    def flow(s, t, flow_limit = 1 << 64)
        level = Array.new(@n)
        iter = Array.new(@n)
        que = []

        bfs =->() {
            level.fill(-1)
            level[s] = 0
            que.clear
            que << s

            while v = que.shift
                @g[v].each do |e|
                    next if e[2] == 0 || level[e[0]] >= 0
                    level[e[0]] = level[v] + 1
                    return if e[0] == t
                    que << e[0]
                end
            end
        }

        dfs =-> (v, up) {
            return up if v == s
            res = 0
            level_v = level[v]

            iter[v].upto(@g[v].size - 1) do |i|
                e = @g[v][i]
                next if level_v <= level[e[0]] || @g[e[0]][e[1]][2] == 0
                d = dfs.(e[0], [ up - res, @g[e[0]][e[1]][2] ].min)
                next if d <= 0
                @g[v][i][2] += d
                @g[e[0]][e[1]][2] -= d
                res += d
                break if res == up
            end

            return res
        }
  
        flow = 0
        while flow < flow_limit
            bfs.()
            break if level[t] == -1
            iter.fill(0)

            while flow < flow_limit
                f = dfs.(t, flow_limit - flow)
                break if f == 0
                flow += f
            end
        end

        return flow
    end

    def calc(s, ans, m)
        @g[s].each do |e|
            next if e[2] > 0
            i, j = e[0].divmod(m)
            @g[e[0]].each do |f|
                next if f[2] > 0
                    x, y = f[0].divmod(m)

                    if i == x
                        j, y = y, j if y < j
                        ans[i][j], ans[i][y] = ?>, ?<
                    else
                        i, x = x, i if x < i
                        ans[i][j], ans[x][j] = ?v, ?^
                    end
                break
            end
        end
    end
end

n, m = gets.split.map(&:to_i)
l = n * m
mf = MF_Graph.new(l+2)

s = n.times.map {gets.chars} << Array.new(m+1, ?#)
move = [[1,0], [0,1]]

n.times do |i|
    m.times do |j|
        next if s[i][j] != ?.
        f = !(i.odd? ^ j.odd?)
        f ? mf.add_edge(l, i * m + j, 1) : mf.add_edge(i * m + j, l + 1, 1)

        move.each do |x, y|
            x = i + x
            y = j + y
            next if s[x][y] != ?.
            f ? mf.add_edge(i * m + j, x * m + y, 1) : mf.add_edge(x * m + y, i * m + j, 1)
        end
    end
end

puts mf.flow(l, l+1)
mf.calc(l, s, m)
puts s[0..-2].map{|e| e.join.chomp}

Measured memory_bytes: 23256
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  for (;;) {
    auto rd = readln.split.map!(to!int), h = rd[0], w = rd[1];
    if (h == 0 && w == 0) break;
    foreach (i; 0..h)
      if (i == 0 || i == h - 1)
        writeln('#'.repeat(w));
      else
        writeln("#" ~ '.'.repeat(w - 2).to!string ~ "#");
    writeln;
  }
}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int n;
double x[11], y[11], l[11];

double sq(double a) {
  return a*a;
}

double f(double _x, double _y) {
  double res = 1e9;
  rep(i, n) {
    double h = sq(l[i]) - sq(_x-x[i]) - sq(_y-y[i]);
    chmin(res, h);
  }
  return res;
}

double tsY(double _x) {
  double l = -100.0, r = 100.0;
  rep(i, 200) {
    double c = (r - l) / 3;
    double a = l + c, b = r - c;
    if(f(_x, a) <= f(_x, b)) l = a;
    else r = b;
  }
  return f(_x, l);
}

double tsX() {
  double l = -100.0, r = 100.0;
  rep(i, 200) {
    double c = (r - l) / 3;
    double a = l + c, b = r - c;
    if(tsY(a) <= tsY(b)) l = a;
    else r = b;
  }
  return tsY(l);
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> n, n) {
    rep(i, n) cin >> x[i] >> y[i] >> l[i];
    cout << sqrt(tsX()) << endl;
  }

  return 0;
}

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

int main(void){
  int w;
  int x,k;   //x:???????????????
  int a[10];
  int i,maxx;
  while((scanf("%d",&w))!=EOF){
    for(i=0;i<10;i++){
      a[i]=0;
    }

    x=512;
    for(i=9;i>=0;i--){
      if(w>=x){
	k=i;
	maxx=x;
	break;
      }else{
	x=x/2;
      }
    }

    a[k]=1;  w-=maxx; x=maxx/2;
    for(i=k-1;i>=0;i--){
      if(w>=x){
	w-=x;
	a[i]=1;
      }
      x=x/2;
    }

    x=1;
    for(i=0;i<k;i++){
      if(a[i]==1){
	printf("%d ",x);
      }
      x=x*2;
    }
    printf("%d\n",maxx);
  }
  return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
 
int main(void)
{
    int n;
    int i, j, k;
    int ans, tmp;
    int a[5000];
     
    while (scanf("%d", &n), n){
        for (i = 0; i < n; i++) scanf("%d", a + i);         
        
        ans = -200000;
        for (i = 0; i < n; i++){
            tmp = 0;
            for (j = i; j < n; j++){
                tmp += a[j];
                ans = fmax(tmp, ans);
            }
        }
        printf("%d\n", ans);
    } 
    return (0);
}

Measured memory_bytes: 620