akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

int n, w, h;

template<typename T> 
void print(vector<T> &x) {
    int n = x.size();
    REP(i,n) {
        if (i != n-1) cout << x[i] << " ";
        else cout << x[i] << endl;
    }
}

int main(int argc, char const *argv[]) {
    cin >> n >> w >> h;
    vector<int> vx(w+2, 0), vy(h+2, 0);
    REP(i,n) {
        int x, y, z;
        cin >> x >> y >> z;
        int lx = max(0, x-z); int rx = min(w, x+z);
        ++vx[lx]; --vx[rx];
        int dy = max(0, y-z); int uy = min(h, y+z);
        ++vy[dy]; --vy[uy];
    }
    REP(i,w+1) vx[i+1] += vx[i];
    REP(i,h+1) vy[i+1] += vy[i];
    bool tate = true; bool yoko = true;
    REP(i,w) {
        if (vx[i] == 0) yoko = false;
    }
    REP(i,h) {
        if (vy[i] == 0) tate = false;
    }

    if (tate || yoko) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  ll i,j;
  int n;
  cin>>n;
  rep(i,n+1)
    if(i*(i+1)/2>=n){
      ll ans=i*(i+1)/2-n;
      for(j=1;j<=i;j++)
        if(j!=ans)
          cout<<j<<endl;
      return 0;
    }
}


Measured memory_bytes: 256
s = input()
t = input()
ans = 1000

for idx in range(len(t), len(s)+1):
    tmp = 0
    for s_s, t_s in zip(list(s[idx-len(t):idx]), list(t)):
        if not s_s == t_s:
            tmp += 1
    if ans > tmp:
        ans = tmp

print(ans)

Measured memory_bytes: 9140
<?php

function input(&$h, &$w) {
	$input = rtrim(fgets(STDIN));
	$inputs = explode(' ', $input);
	$h = $inputs[0];
	$w = $inputs[1];
	return !(($h == 0) && ($w == 0));
}

function sharp($w) {
	if ($w > 0) {
		echo '#';
		sharp($w - 1);
	}
}

function line($h, $w) {
	if ($h > 0) {
		sharp($w);
		echo "\n";
		line($h - 1, $w);
	} else {
		echo "\n";
	}
}


while (input($h, $w)) {
	line($h, $w);
}

Measured memory_bytes: 6596
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

typedef long long ll;
const ll INF = 1e17;



int main() {
	int N, K, Q;
	cin >> N >> K >> Q;
	int seikai[200000] = {};

	int a;

	for (int i = 1; i <= Q; i++) {
		cin >> a;
		seikai[a]++;

	}

	for (int i = 1; i <= N; i++) {
		if (K + seikai[i] - Q > 0) { cout << "Yes" << endl; }
		else { cout << "No" << endl; }
	}

	system("PAUSE");
}


Measured memory_bytes: 1656
S = input()

items = ['A', 'G', 'C', 'T']
ans = 0
length = 0
for i in range(len(S)):
    if S[i] in items:
        length += 1
    else:
        ans = max(ans, length)
        length = 0
else:
    ans = max(ans, length)

print(ans)


Measured memory_bytes: 2940
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

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

int main() {

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

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

	struct edge { 
		int from, to; 
		edge(int from = 0, int to = 0) : from(from), to(to) {}
	};
	vector<edge> memo(M);
	for (int i = 0; i < M; i++) {
		int l, r;
		cin >> l >> r;
		memo[i] = { l,r };
	}
	sort(memo.begin(), memo.end(), [](edge l, edge r) {
		return (l.from < r.from) || (l.from == r.from) && (l.to < r.to); 
	});

	int ans = 1, tmp = INF;
	for (int i = 0; i < M; i++) {
		if (tmp <= memo[i].from) {
			ans++;
			tmp = memo[i].to;
		}
		else chmin(tmp, memo[i].to);
		DMP(tmp);
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;

int num[201];

int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=1,now=1;
    long long int a,a1,a2,a3,a4;
    //float f,g,h;
    //char now,pre;
    string s,s1;
    cin>>a1>>a2>>a3>>n;
    for(i=0;i<=a1;i++)
    {
        for(j=0;j<=a2;j++)
        {
            for(k=0;k<=a3;k++)
            {
                if(i*500+j*100+k*50==n) sum++;
            }
        }
    }
    cout<<sum;
    return 0;
}



Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 02.01.2020 23:58:36       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, tt;
  cin >> h >> w >> tt;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }
  vector<vector<int>> a(h + 1, vector<int>(w + 1));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      a[i + 1][j + 1] = a[i + 1][j] + a[i][j + 1] - a[i][j] + (s[i][j] == '1');
    }
  }
  vector<vector<int>> b(h + 1, vector<int>(w + 1));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      b[i + 1][j + 1] = b[i + 1][j] + b[i][j + 1] - b[i][j] + (j < w - 1 && s[i][j] == '1' && s[i][j + 1] == '1');
    }
  }
  vector<vector<int>> c(h + 1, vector<int>(w + 1));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      c[i + 1][j + 1] = c[i + 1][j] + c[i][j + 1] - c[i][j] + (i < h - 1 && s[i][j] == '1' && s[i + 1][j] == '1');
    }
  }
  while (tt--) {
    int i1, j1, i2, j2;
    cin >> i1 >> j1 >> i2 >> j2;
    --i1; --j1;
    int ans = a[i2][j2] - a[i1][j2] - a[i2][j1] + a[i1][j1];
    ans -= b[i2][j2 - 1] - b[i1][j2 - 1] - b[i2][j1] + b[i1][j1];
    ans -= c[i2 - 1][j2] - c[i1][j2] - c[i2 - 1][j1] + c[i1][j1];
    cout << ans << '\n';
  }
  return 0;
}


Measured memory_bytes: 53248
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }

    auto P = minmax_element(A.begin(), A.end());

    int res = *P.second - *P.first;
    cout << res << '\n';

    return 0;
}

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

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if(C - (A - B) >= 0){
		cout << C - (A - B) << endl;
	}
	else{
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

const int maxn = 100000;
const int maxd = 10;

int n, m, q, col[maxn];
vector<int> g[maxn];
int id[maxn][maxd + 1];
bool in[maxn];

int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u; --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  memset(id, -1, sizeof id);
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int v, d;
    scanf("%d%d%d", &v, &d, col + i);
    --v;
    id[v][d] = i;
  }
  queue<int> q;
  for (int i = 0; i < n; ++i) {
    for (int j = maxd; j; --j) {
      id[i][j - 1] = max(id[i][j - 1], id[i][j]);
    }
    q.push(i);
    in[i] = true;
  }
  while (!q.empty()) {
    int u = q.front(); q.pop(); in[u] = false;
    for (int i = 0; i < (int)g[u].size(); ++i) {
      int v = g[u][i];
      bool update = false;
      for (int j = maxd; j; --j) {
        id[v][j - 1] = max(id[v][j - 1], id[v][j]);
        if (id[v][j - 1] < id[u][j]) {
          id[v][j - 1] = id[u][j];
          update = true;
        }
      }
      if (update && !in[v]) {
        q.push(v);
        in[v] = true;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    printf("%d\n", id[i][0] < 0 ? 0 : col[id[i][0]]);
  }
  return 0;
}


Measured memory_bytes: 12664
#include<bits/stdc++.h>
using namespace std;
#define ck cout<<" xxx  "<<endl
typedef long long ll;
const int maxn=1e3+100;
const int maxc=26;
const int inf=0x3f3f3f3f;
ll n,m;
ll a[maxn];
bool cmp(ll x,ll y){
    return x>y;
}
int main()
{
    ll x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z;
    return 0;
}
/*

*/


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define EPS 1E-8

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

const int MAX_N = 51;
const int MAX_K = 51;
ll dp[MAX_N][MAX_K];

ll comb(int n, int k) {
    if(k < 0 || k > n) return 0;
    if(n == 0) return 1;
    if(dp[n][k] > 0) return dp[n][k];

    return dp[n][k] = comb(n-1, k-1) + comb(n-1, k);
}


int main() {

	ll n, a, b;
	cin >> n >> a >> b;
	vector<ll> v(n);
	rep(i, n) cin >> v[i];

	SORT(v);
	reverse(v.begin(), v.end());
	map<ll, int> mp;
	rep(i, v.size()) mp[v[i]]++;
	memset(dp, 0, sizeof(dp));

	ll ans = 0;
	ll ans_sum = 0;
	ll ans_num = 1;

	REP(i, a, b+1){
		ll sum = 0;
		rep(j, i) sum += v[j];

		if(sum * ans_num > ans_sum * i) ans = 0;
		if(sum * ans_num >= ans_sum * i){
			int cnt = 1;
			for(int j = i-2; j >= 0; j--){
				if(v[i-1] == v[j]) cnt++;
			}
			ans_sum = sum;
			ans_num = i;
			ans += comb(mp[v[i-1]], cnt);
		}
	}

	printf("%.8lf\n%lld\n", (double)(1.0 * ans_sum / ans_num), ans);

	return 0;
}


Measured memory_bytes: 256
import queue
def dist(graph, start):
    q = queue.Queue()
    rtn = [None]*len(graph)
    q.put(start)
    rtn[start] = 0
    while not q.empty():
        target = q.get()
        for index in graph[target]:
            if rtn[index] is None:
                q.put(index)
                rtn[index] = rtn[target] + 1
    return rtn

def solve(dist_t, dist_a):
    ans = 0
    for i in range(len(dist_t)):
        if dist_t[i] < dist_a[i]:
            if ans < dist_a[i] - 1:
                ans = dist_a[i] - 1
    return ans

def main():
    n, u, v = map(int, input().split())
    u -= 1
    v -= 1
    graph = [[] for _ in range(n)]
    for _ in range(n-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append(b)
        graph[b].append(a)
    dist_t = dist(graph, u)
    dist_a = dist(graph, v)
    print(solve(dist_t, dist_a))

if __name__ == "__main__":
    main()

Measured memory_bytes: 29936
#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
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  sort(A.rbegin(),A.rend());
  ll sum = A[0];
  int cnt = N-2;
  for(int i=1; i<N; i++){
    if(cnt >= 2){
      sum += (ll)A[i]*2;
    }else if(cnt == 1){
      sum += A[i];
    }else{
      break;
    }
    cnt -= 2;
  }
  cout << sum << "\n";
  return 0;
}

Measured memory_bytes: 3988
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

# Wrong Answer
# WA


N, K = map(int, input().split())
MOD = 10 ** 9 + 7

# 階乗、Combinationコンビネーション(numpyを使う)


def cumprod(arr, MOD):
    L = len(arr)
    Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]
        arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]
        arr[n] %= MOD
    return arr.ravel()[:L]


def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64)
    x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64)
    x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv


U = 10**6
fact, fact_inv = make_fact(U, MOD)


def mod_comb_k(n, k, mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod


ans = 0
for i in range(N):
    if K < i:
        continue

    if N - 1 <= K:
        ans = mod_comb_k(N + N - 1, N - 1, MOD)
        break

    if i == 0:
        ans += 1
        continue

    '''
    a = mod_comb_k(N - 1, i, MOD)
    b = mod_comb_k(N, i, MOD)
    c = a * b
    c %= MOD
    '''
    a = mod_comb_k(N - 1, i, MOD)
    b = mod_comb_k(N, i, MOD)
    c = a * b % MOD
    ans += c
    ans %= MOD

print(ans)


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

int main() {
  
  	string S;
  	cin >> S;
	
  	vector<char> N(4);
 	for ( int i = 0 ; i < 4 ; i++ ){
    	N.at(i)=S.at(i);
    } 	
  	
	sort(N.begin(),N.end());
  	if(N.at(0)==N.at(1) && N.at(2)==N.at(3) && N.at(1)!=N.at(2))
      cout << "Yes" << endl;
  	else
      cout << "No" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  vector<long> P(N);
  rep (i, N) cin >> P[i];
  map<long, long> pos;
  rep (i, N) pos[P[i]] = i;
  set<long> largest;
  long ans = 0;
  for (long current = N; current >= 1; current--) {
    long p = pos[current];
    auto next_itr = largest.upper_bound(p);
    // right
    if (next_itr != largest.end()) {
      long before = 0;
      if (next_itr != largest.begin()) {
        auto before_itr = next_itr;
        before_itr--;
        before = (*before_itr) + 1;
      }
      auto next_next_itr = next_itr;
      next_next_itr++;
      long end = N-1;
      if (next_next_itr != largest.end()) {
        end = (*next_next_itr) - 1;
      }
      //cout << "right: ans += " << current << " * " << (p-before+1) << " * " << (end-(*next_itr)+1) << endl;
      //cout << "end: " << end << ", *next_itr: " << *next_itr << endl;
      ans += current * (p-before+1) * (end-(*next_itr)+1);
    }
    // left
    if (next_itr != largest.begin()) {
      auto before_itr = next_itr;
      before_itr--;
      long start = 0;
      if (before_itr != largest.begin()) {
        auto before_before_itr = before_itr;
        before_before_itr--;
        start = (*before_before_itr) + 1;
      }
      long end = N - 1;
      if (next_itr != largest.end()) end = (*next_itr) - 1;
      ans += current * ((*before_itr)-start+1) * (end-p+1);
      //cout << "left: ans += " << current << " * " << ((*before_itr)-start+1) << " * " << (end-p+1) << endl;;
    }
    largest.insert(pos[current]);
  }
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int dfs(int now, vii &G, vi &par, vi &num) {
  if (G[now].size() == 0) {
    return num[now] / 2 + 1;
  }
  vi temp;
  rep (i, G[now].size()) {
    temp.push_back(dfs(G[now][i], G, par, num));
  }
  sort(all(temp));
  int res = 0;
  rep (i, temp.size() / 2 + 1) {
    res += temp[i];
  }
  return res;
}

int main() {
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    vii G(10010);
    vi par(10010, -1);
    vi num(10010);
    int now = 0, n = 1;
    string temp;
    rep (i, s.size()) {
      if (s[i] == '[') {
        par[n] = now;
        G[now].push_back(n);
        now = n;
        n++;
      }
      else if (s[i] >= '0' && s[i] <= '9') {
        temp += s[i];
      }
      else {
        if (temp.size() > 0) {
          num[now] = stoi(temp);
          temp.clear();
        }
        now = par[now];
      }
    }
    cout << dfs(0, G, par, num) << endl;
  }
}



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

int main() {
	string S;
	while (cin >> S) {
		int w;
		scanf("%d", &w);
		string ans;
		for (int i = 0; i < (int)S.size(); i += w)
			ans += S[i];
		puts(ans.c_str());
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,b[110];
  cin>>n;
  string s;
  vector<string> a(110);
  for(int i=0;i<n;i++){
    cin>>s>>b[i];
    a[i]=s;
  }
 vector<pair<string,pair<int,int>>> p(110);
  for(int i=0;i<n;i++){
    p[i]=make_pair(a[i],make_pair(-b[i],i+1));
                   }
   sort(p.begin(),p.begin()+n);
  
    for(int i=0;i<n;i++){
     cout<<p[i].second.second<<endl;
    }
                   }

Measured memory_bytes: 256
import java.util.*;
public class Main  {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int n = sc.nextInt();
      
      int k = sc.nextInt();
      
      int a[] = new int[n];
      
      for (int i = 0; i < n; i++) {
         a[i] = sc.nextInt();
      }
      
      Arrays.sort(a);
      
      int ans = 0;
      
      for (int j = 0; j < k; j++) {
         int x = a[j];
         ans += x;
      }
      
      System.out.println(ans);
   }
}

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

int main() {
    string s;
    int ans = 700;
    cin >> s;
    for (int i = 0; i < 3; i++) {
        if (s.at(i) == 'o') {
            ans += 100;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
l_ans = [0,abs(l[1]-l[0])]
for i in range(2,n):
    a = l_ans[i-1]+abs(l[i]-l[i-1])
    b = l_ans[i-2]+abs(l[i]-l[i-2])
    l_ans.append(min(a,b))
print(l_ans[::-1][0])

Measured memory_bytes: 13928
"use strict";

// 21:39
function I(s,f){this._s=s.split("\n");this._c=0;this._l=0;this._f=f||Number}I.prototype.a=function(){var l=this._s[this._l];if(!l)return;var t=l.trim().split(" ");var a=t[this._c];this._c++;if(t.length===this._c){this._c=0;this._l++}return this._f(a)};I.prototype.l=function(){var l=this._s[this._l];if(!l)return;this._c=0;this._l++;return l.split(" ").map(this._f)};
function buildArray(r,t){let l=t||0;for(let t=r.length;t>0;t--){const n=r[t-1];l=Array(n).fill().map(()=>JSON.parse(JSON.stringify(l)))}return l}

const mod = 1000000007;

function main(input) {
  var o = new I(input);

  var h = o.a();
  var w = o.a();
  var k = o.a();

  var wc = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
  var dp = buildArray([h, w], 0);

  dp[0][0] = wc[w - 1];
  dp[0][1] = wc[w - 2];

  for (var i = 1; i < h; i++) {
    for (var j = 0; j < w; j++) {
      dp[i][j] += dp[i-1][j] * (wc[w - j - 1] * wc[j]);
      if (j - 1 >= 0) {
        dp[i][j] += dp[i-1][j-1] * (wc[w - j - 1] * wc[j - 1]);
      }
      if ( j + 1 <= w - 1) {
        dp[i][j] += dp[i-1][j+1] * (wc[w - j - 2] * wc[j]);
      }

      dp[i][j] %= mod;
    }
  }

  console.log(dp[h-1][k-1]);
}


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


Measured memory_bytes: 7372
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

int cnt[100005];

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

    int N;
    cin >> N;
    LL sum = 0;
    rep(i, N) {
        int A;
        cin >> A;
        ++cnt[A];
        sum += (LL) A;
    }

    int Q;
    cin >> Q;
    rep(i, Q) {
        int B, C;
        cin >> B >> C;
        int mv = cnt[B];
        sum += (C-B) * mv;
        cout << sum << endl;;
        cnt[B] = 0;
        cnt[C] += mv;
    }

    return 0;
}


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

using namespace std;

int main(){
  int n;
  while(true){
    cin >> n;
    if(!n) break;
    int min_diff = 1000000;
    int a[n];
    for(int i = 0; i < n; i++){
      cin >> a[i];
    }

    for(int i = 0; i < n; i++){
      for(int j = i + 1; j < n; j++){
        int diff = abs(a[i] - a[j]);
        if(min_diff > diff) min_diff = diff;
      }
    }

    cout << min_diff << endl;
  }
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int triple_max(int x, int y, int z);

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a+b+c) - triple_max(a, b, c) << endl;

    return 0;
}

int triple_max(int x, int y, int z){
    int ans = x;
    if (y > x && y > z) ans = y;
    else if (z > x && z > y) ans = z;

    return ans;
}


Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
from math import gcd
def hurui(n):
    """n以下の素数のリストを返す
    """
    l = list(range(2,n+1))
    p = 2
    i = 0
    while True:
        l = [item for item in l if item==p or item%p!=0]
        i += 1
        p = l[i]
        if p*p>n:
            break
    return l
b = [0]*(max(a)+1)
done = False
if max(a)>=10:
    l = hurui(max(a)+1)
else:
    l = [2,3,5,7]
for num in a:
    b[num] += 1
for num in l:
    val = sum(b[i] for i in range(num, len(b), num))
    if val>=2:
        g = a[0]
        for i in range(1,n):
            g = gcd(g, a[i])
            if g==1:
                print("setwise coprime")
                done = True
                break
        else:
            print("not coprime")
            done = True
    if done:
        break
else:
    print("pairwise coprime")

Measured memory_bytes: 251768
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(){
    char ch[300],ptn[11],end[]="END_OF_TEXT";
    int i,x=0;
    
    scanf("%s",ptn);
    for (i=0; i< strlen(ptn); i++) {
        ptn[i] = tolower(ptn[i]);
    }
    while(1){
        scanf("%s",ch);
        if(strcmp(ch,end)==0) break;
        for (i=0; i< strlen(ch); i++) {
            if (isupper(ch[i])) {
                ch[i]=tolower(ch[i]);
            }
        }
    if (strcmp(ch, ptn)==0) {
        x++;
    }
    }
    printf("%d\n",x);
    return(0);
}

Measured memory_bytes: 552
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
void yes(){
  cout << "YES" << endl;
  exit(0);
}

void no(){
  cout << "NO" << endl;
  exit(0);
}
int main() {
  string s; cin >> s;
  ll n = s.size();
  if(n==1) yes();
  if(n==2){
    if(s[0]==s[1]) no();
    else yes();
  }

  vector<ll> cnt(3,0);
  REP(i,n) cnt[s[i]-'a']++;
  ll mini = 1e18;
  REP(i,3) mini = min(cnt[i],mini);
  REP(i,3) if(cnt[i]-mini>1) no();
  yes();
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;

	int arr[n], brr[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> arr[i] >> brr[i];
	}

	sort(arr, arr+n);
	sort(brr, brr+n);

	long long x, y;
	if (n%2==1)
	{
		x = arr[n/2]; y = brr[n/2];
	}
	else
	{
		x = arr[n/2 - 1] + arr[n/2];
		y = brr[n/2 - 1] + brr[n/2];
	}

	cout << y - x + 1;
	return 0;
}

Measured memory_bytes: 5208
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define int long long
#define rep(x, a, b) for(int x = (a); x <= (b); ++x)
#define rop(x, a, b) for(int x = (a); x < (b); ++x)
#define per(x, a, b) for(int x = (a); x >= (b); --x)
using namespace std;
typedef long long LL;
typedef double DB;
const long double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679;
struct node {
	int x, y;
}a[200005];
bool operator < (const node & a, const node & b) {
	if(a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator == (const node & a, const node & b) {
	return a.x == b.x && a.y == b.y;
}
const int INF = 2000000000;
int x_1, x_2, y_1, y_2;
int n;
int f[200005];
main() {
	scanf("%lld%lld%lld%lld", &x_1, &y_1, &x_2, &y_2);
	int bj = 1;
	if(x_1 > x_2) swap(x_1, x_2), bj *= -1;
	if(y_1 > y_2) swap(y_1, y_2), bj *= -1;
	scanf("%lld", &n);
	rep(i, 1, n) {
		scanf("%lld%lld", &a[i].x, &a[i].y);
		if(a[i].x < x_1) a[i].x = INF, a[i].y = INF;
		else if(a[i].x > x_2) a[i].x = INF, a[i].y = INF;
		else if(a[i].y < y_1) a[i].x = INF, a[i].y = INF;
		else if(a[i].y > y_2) a[i].x = INF, a[i].y = INF;
		else a[i].x *= bj;
	}
	sort(a + 1, a + 1 + n);
	n = unique(a + 1, a + 1 + n) - a - 1;
	if(a[n].x == INF) --n;
	int as = 0;
	rep(i, 1, n) {
		if(as == 0) f[++as] = a[i].y;
		else {
			int k = upper_bound(f + 1, f + 1 + as, a[i].y) - f;
			while(k <= as && f[k] < a[i].y) ++k;
			f[k] = a[i].y;
			as = max(as, k);
		}
	}
	printf("%0.15f", (DB) (((LL) x_2 - x_1 + y_2 - y_1) * 100.0 - (20 - 5 * pi) * as + ((as == min(x_2 - x_1 + 1, y_2 - y_1 + 1)) ? 5.0 * pi : 0)));
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
#include<map>
#include<cmath>
#include<complex>
using namespace std;

typedef complex<double> P;

#define X real()
#define Y imag()
typedef int kz;

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

int main(){
    int mod=1000000007;
    double tmp=7.814814814814;
    double n;
    while (scanf("%lf",&n)!=EOF) {
        printf("%.10lf\n",n*tmp);
    }
    return 0;
}

Measured memory_bytes: 3092
# 2019/07/24

s=list(input())

a=['1','0']
b=['0','1']

cnta=0
cntb=0

for i in range(len(s)):
    r=i%2
    if s[i]!=a[r]:cnta+=1
    elif s[i]!=b[r]:cntb+=1

print(min(cnta,cntb))

Measured memory_bytes: 3956
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long

int x[6];
int d,t,s;

int main(){
  scanf("%d%d%d",&d,&t,&s);
  
  if(d<=t*s) puts("Yes");
  else puts("No");
  
  return 0;
}


Measured memory_bytes: 1664
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#a, b = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
mod = (10 ** 9) + 7


def lcm(a):
  from fractions import gcd
  x = a[0]
  for i in range(1, len(a)):
      x = (x * a[i]) // gcd(x, a[i])
  return x

p = lcm(A)
#print (p)

sum = 0
for i in range(N) :
  sum += p//A[i]

print (int(sum%mod))



Measured memory_bytes: 5588
#include <set>
#include <cstdio>
#include <algorithm>

using namespace std;

int n, a[100010];
set < pair <int, int> > s;

bool ok(int p) {
    s.clear();
    for (int i = 0; i < n; i++) {
        if (i != p) {
            s.insert(make_pair(a[i], i));
        }
    }
    int v = a[p];
    for (int i = 1; i < n; i++) {
        set < pair <int, int> >::iterator it = s.lower_bound(make_pair(2 * v + 1, -1));
        if (it == s.begin()) {
            return false;
        }
        it--;
        v = min(1000000000, v + (*it).first);
        s.erase(it);
    }
    return true;
}

int main() {

    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }

    sort(a, a + n);
    reverse(a, a + n);

    int l = 0;
    int r = n - 1;

    while (l <= r) {
        int m = (l + r) / 2;
        if (ok(m)) {
            l = m + 1;
        } else {
            r = m - 1;
        }
    }

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

    return 0;

}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 200001
#define ll long long
#define int ll 
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
int* getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
	  lps[i] = j+1;
   i++;
   j++;
  }
  else{
		if(j != 0){
		 j = lps[j-1];
		}
		else{
		 lps[i] = 0;
		 i++;
		}
  }
 }
 return lps;
}
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return ans.x;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int arr[n];
for(int i=  0 ; i < n ;i++){
 cin>>arr[i];
}
int mini = INT_MAX;
for(int i = 1 ; i <= 101 ; i++){
	int sum = 0;
   for(int j = 0 ; j < n ; j++){
        sum += (abs(arr[j] - i) * abs(arr[j] - i));
   }
   mini = min(mini , sum);
}
cout<<mini<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll c[3][3];

int main(){
	ll sum = 0;
	ll isum[3]; memset(isum, 0, sizeof(isum));
	for(int i = 0; i <3; i++){
		for(int j = 0; j < 3; j++){
			cin >> c[i][j];
			sum += c[i][j];
			//isum[i] += c[i][j];
		}
	}
	string ans = "Yes";
	
	for(int i = 0; i < 3; i++){
		if(!(c[i][0]-c[(i+1)%3][0] == c[i][1]-c[(i+1)%3][1] && c[i][0]-c[(i+1)%3][0] == c[i][2]-c[(i+1)%3][2])){
			ans = "No";
		}
	}
	
	cout << ans << endl;
	return 0;
}

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

int main() {
  int a;
  cin >> a;
  if(a % 111 == a / 1000 | a % 111 == a % 10) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << 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));
		String[] str = br.readLine().split(" ");

		double x1 = Double.parseDouble(str[0]);
		double y1 = Double.parseDouble(str[1]);
		double x2 = Double.parseDouble(str[2]);
		double y2 = Double.parseDouble(str[3]);

		double d = Math.sqrt((x1 - x2) * (x1 - x2) + (y1-y2)*(y1-y2));
		System.out.println(d);

	}
}

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

int main()
{
	int pay;
	int change;
	int coin;
	while (cin >> pay)
	{
		if(pay == 0) break;
		coin = 0;
		change = 1000 - pay;
		while (change >= 500)
		{
			coin++;
			change -= 500;
		}
		while (change >= 100)
		{
			coin++;
			change -= 100;
		}
		while (change >= 50)
		{
			coin++;
			change -= 50;
		}
		while (change >= 10)
		{
			coin++;
			change -= 10;
		}
		while (change >= 5)
		{
			coin++;
			change -= 5;
		}
		while (change >= 1)
		{
			coin++;
			change -= 1;
		}
		cout << coin << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define scd(t)              scanf("%d",&t)
#define scld(t)             scanf("%ld",&t)
#define sclld(t)            scanf("%lld",&t)
#define scc(t)              scanf("%c",&t)
#define scs(t)              scanf("%s",t)
#define scf(t)              scanf("%f",&t)
#define sclf(t)             scanf("%lf",&t)
#define mem(a, b)           memset(a, (b), sizeof(a))
#define for(i, j, k, in)    for (int i=j ; i<k ; i+=in)
#define rfor(i, j, k, in)   for (int i=j ; i>=k ; i-=in)
#define rep(i, j)           FOR(i, 0, j, 1)
#define rrep(i, j)          RFOR(i, j, 0, 1)
#define all(cont)           cont.begin(), cont.end()
#define rall(cont)          cont.end(), cont.begin()
#define foreach(it, l)      for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C)         assert( B <= A && A <= C)
#define mk(arr,n,type)      type *arr=new type[n];
#define w(x)                int x; cin>>x; while(x--)
#define ff                  first
#define ss                  second
#define mp                  make_pair
#define pb                  push_back
#define INF                 (int)1e9
#define EPS                 1e-9
#define PI                  3.1415926535897932384626433832795
#define MOD                 1000000007

const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int,int> mpii;
typedef set<int> seti;
typedef multiset<int> msei;
typedef priority_queue<int> pqb;
typedef priority_queue<int,vi,greater<int>> pqs;
typedef long long ll;
typedef long double ld;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

/****** Template of some basic operations *****/
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
/**********************************************/

/******** User-defined Function *******/
void c_p_c(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}

/**************************************/

/********** Main()  function **********/
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //c_p_c();
    double n;
    cin>>n;
    double res = n/2;
    cout<<(int)ceil(res);
	return 0;
}
/********  Main() Ends Here *************/

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CsharpSpiral {
    partial class Program {
        static void Main(string[] args) {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }
        public void Solve(ConsoleInput cin) {
            while(true) {
                var H = cin.ReadInt;
                var W = cin.ReadInt;
                if(W == 0 && H == 0) break;
                for(int i = 0; i < H; i++) {
                    for(int j = 0; j < W; j++) {
                        Console.Write((i + j) % 2 == 0 ? '#' : '.');
                    }
                    Console.Write("\n");
                }
                Console.WriteLine("");
            }
        }
    }

    static class ExtendClass {
        public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
    }

    class ConsoleInput {
        private readonly TextReader _stream;
        private readonly char _separator = ' ';
        private readonly Queue<string> inputStream;
        public ConsoleInput(TextReader stream, char separator = ' ') {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read {
            get {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) {
            var ret = new string[N];
            for(long i = 0; i < N; ++i)
                ret[i] = Read;
            return ret;
        }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
    }

}



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

int main(void){
	const int INF = INT_MAX/4;
	int machi, miti;
	int time[10][10];

	while(true){
		// init
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				if( i==j )
					time[i][j] = 0;
				else
					time[i][j] = INF;
			}
		}

		cin >> miti;
		if( miti==0 )
			break;
		machi = 0;
		for(int i=0; i<miti; i++){
			int from, to, t;
			cin >> from >> to >> t;
		
			machi = max(from, machi);
			machi = max(to, machi);
		
			time[from][to] = t;
			time[to][from] = t;
		}
		machi++;


		for(int k=0; k<machi; k++){
			for(int i=0; i<machi; i++){
				for(int j=0; j<machi; j++){
					time[i][j] = min(time[i][j], time[i][k]+time[k][j]);
				}
			}
		}

		int maxTime = INF, maxMachi = -1;
		for(int i=0; i<machi; i++){
			int temp = 0;
			for(int j=0; j<machi; j++)
				temp += time[i][j];
			if( temp < maxTime ){	
				maxTime = temp;
				maxMachi = i;
			}
		}

		cout << maxMachi << " " << maxTime << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
bool comp(int a,int b){
return a>b;
}
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main()
{
	fast;
	int n;
	cin>>n;
	ll sum=0;
	int a[n+1];
	     unordered_map<int,int>mp;

	rep(i,1,n+1){
	cin>>a[i];
	mp[a[i]]++;
	sum+=a[i];
}
     int Q;
     cin>>Q;
     while(Q--)
	{
		int x,k;
		cin>>x>>k;
		int p=mp[x];
		sum+=p*k-p*x;
	//	a[x]=k;
	mp[x]=0;
	mp[k]+=p;
		cout<<sum<<endl;
		
	}

}



Measured memory_bytes: 7472
// AGC5-A
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    string s;
    cin>>s;
    vector<char> stack;
    rep(i,s.size()){
        if(s[i]=='S'){
            stack.e_b(s[i]);
        }else{
            if(!stack.empty() && stack.back()=='S'){
                stack.pop_back();
            }else{
                stack.e_b(s[i]);
            }
        }
    }
    cout<<stack.size()<<endl;
    return 0;
}

Measured memory_bytes: 3716
#include <cstdio>
#include <cmath>
int main(){int n,i,r,m;while(scanf("%d",&n)&&n){r=-n;m=sqrt(n);for(i=1;i<=m;i++)if(n%i==0){r+=i+n/i;if(i==n/i)r-=i;}printf("%s\n",n>r?"deficient number":n<r?"abundant number":"perfect number");}}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);

		int n = scanner.nextInt();
		for (int i = 0; i < n; i++) {
			int x = scanner.nextInt();
			int y = scanner.nextInt();
			int b = scanner.nextInt();
			int p = scanner.nextInt();
			int an1 = x * b + y * p;
			int an2 = (int) ((x * Math.max(5, b) + y * Math.max(2, p)) * 0.8);
			System.out.println(Math.min(an1, an2));
		}
	}
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main()
{
    int32 n,k;
    cin >> n >> k;
    ANS(n-k+1);
    return 0;
}

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

int main() {
	int month, day, date = 0;

	while (cin >> month >> day, month != 0) {
		while (month) {
			switch (month - 1)
			{
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
				date += 31;
				break;
			case 2:
				date += 29;
				break;
			case 4:
			case 6:
			case 9:
			case 11:
				date += 30;
				break;
			default:
				break;
			}
			month--;
		}

		date += day;

		switch (date % 7)
		{
		case 1:
			cout << "Thursday" << endl;
			break;
		case 2:
			cout << "Friday" << endl;
			break;
		case 3:
			cout << "Saturday" << endl;
			break;
		case 4:
			cout << "Sunday" << endl;
			break;
		case 5:
			cout << "Monday" << endl;
			break;
		case 6:
			cout << "Tuesday" << endl;
			break;
		case 0:
			cout << "Wednesday" << endl;
			break;
		default:
			break;
		}
		date = 0;
	}
	return 0;
}

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

int main()
{
	string S;
	cin >> S;

	int32_t N = S.size();
	int32_t cntZero = 0;
	for (int32_t i = 0; i < N; i++) {
		if (S[i] == '0')
			cntZero++;
	}
	int32_t cntOne = N - cntZero;
	cout << (cntZero == cntOne ? N : min(cntZero, cntOne) * 2) << endl;

	return 0;
}


Measured memory_bytes: 512