akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//素数判定
bool is_prime(ll n, vll &prime) {
  if (n == 1) return false;
  if (n == 2) return true;
  if (n % 2 == 0) return false;
  for (ll i = 0; i < prime.size() && prime[i] <= sqrt(n); i++) {
    if (n % prime[i] == 0) return false;
  }
  return true;
}

//モジュラ逆数
ll modinv(ll n, ll p) {
  ll a = p, u = 1, v = 0;
  while (a) {
    ll t = n / a;
    n -= t * a;
    swap(n, a);
    u -= t * v;
    swap(u, v);
  }
  u %= p;
  if (u < 0) u += p;
  return u;
}

int main() {
  ll n, p = 1e9 + 7;
  cin >> n;
  vll a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  sort(all(a));

  vll prime(1, 2);
  for (ll i = 3; i <= a[n - 1]; i += 2) {
    if (is_prime(i, prime)) prime.push_back(i);
  }
  ll m = prime.size();

  vll lcm(a[n - 1] + 1, 0);
  for (ll i = 0; i < n; i++) {
    ll x = a[i];
    if (is_prime(x, prime)) {
      lcm[x] = max(lcm[x], 1ll);
      continue;
    }
    for (ll j = 0; j < m && prime[j] <= x; j++) {
      if (x % prime[j] > 0) continue;
      ll cnt = 0;
      while (x % prime[j] == 0) {
        x /= prime[j];
        cnt++;
      }
      lcm[prime[j]] = max(lcm[prime[j]], cnt);
    }
  }

  ll ans = 1;
  for (ll i = 2; i <= a[n - 1]; i++) {
    while (lcm[i]) {
      ans *= i;
      ans %= p;
      lcm[i]--;
    }
  }
  ll subans = 0;
  for (ll i = 0; i < n; i++) {
    ll x = ans * modinv(a[i], p) % p;
    subans += x;
    subans %= p;
  }
  cout << subans << endl;
}

Measured memory_bytes: 8824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, c, d, e, f, s;
  in(s);
  a = 0;
  b = 0;
  c = 1000000000;
  d = 1;
  f = (s + 999999999) / 1000000000;
  e = 1000000000 * f - s;
  out(a);
  hina;
  out(b);
  hina;
  out(c);
  hina;
  out(d);
  hina;
  out(e);
  hina;
  out(f);
  memi;
}

Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define out(ans) cout << ans << endl;

int main()
{
  int n;cin>>n;
  ll a[n+10];
  rep(i,n)cin>>a[i];

  ll count=0;
  ll r=0;
  ll sum=0;
  rep(l,n){
    while(r<n&&(sum^a[r])==(sum+a[r])){
      sum+=a[r];
      r++;
    }
    count+=r-l;
    if (l == r) ++r;
    else sum-=a[l];
  }
  out(count);

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
using P = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n;
  cin >> n;
  bool flag = false;
  for(int i = -118;i <= 119;i++){
    for(int j = -118;j <= 119;j++){
      if(pow(i,5) - pow(j,5) == n){
        cout << i << " " << j << endl;
        flag = true;
        break;
      }
    }
    if(flag) break;
  }
}

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

typedef int int_;
#define int long long
#define enable_fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)

const int MAX = 1e5+10;
const int MOD = 1e9+7;

//----------------------

int dig(int x){
	if(x==0) return 0;
	else return 1+dig(x/10);
}

int f(int a,int b){
	return max(dig(a),dig(b));
}

int_ main()
{	
	enable_fast;

	int n; cin>>n;

	vector<int> x;
	int ans=11;
	for(int i=1;i*i<=n;i++){
		if(n%i == 0){
			ans = min(ans,f(i,n/i));
		}
	}

	cout << ans;
}

Measured memory_bytes: 256
alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
s = str(input())
for i in range(len(s)):
    if s[i] in alphabet:
        m = alphabet.index(s[i])
        del alphabet[m]
    if alphabet == []:
        print("None")
        exit()
print(alphabet[0])

Measured memory_bytes: 3188
import sys
input = sys.stdin.readline
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
R = []

pre = 0
suff = 0
for i in range(1, N):
	suff ^= A[i]

for i in range(N):
	R.append(pre^suff)
	pre ^= A[i]

	if i != N-1:
		suff ^= A[i+1]
	else:
		suff = 0

print(*R)



Measured memory_bytes: 109220
#include <iostream>
#include <numeric>
#include <iomanip>
#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
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {

	int A,B,C;
	cin >> A>>B>>C;
	


	cout << A+B+C-max(max(A,B),C)<< endl;
}

Measured memory_bytes: 256
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

A = [0]
B = [0]

for i in range(n):
    A.append(A[i]+a[i])

for i in range(m):
    B.append(B[i]+b[i])
    
ans,j = 0,m
for i in range(n+1):
    if A[i] > k:
        break
    while B[j] + A[i] > k:
        j -= 1
    ans = max(ans,i+j)
print(ans)

Measured memory_bytes: 134052
#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) {
  int i,j,k;
  int h,w;
  cin>>h>>w;
  int n=10;
  vector<vi> d(n,vi(n));
  rep(i,n)rep(j,n)cin>>d[i][j];
  rep(k,n)rep(i,n)rep(j,n)
    d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
  vi num(n,0);
  rep(i,h)rep(j,w){
    int a;
    cin>>a;
    if(a>=0)num[a]++;
  }
  int ans=0;
  rep(i,n)if(i!=1)ans+=d[i][1]*num[i];
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int n,V;
vector<vector<int>> G(1e6);
vector<int> match(1e6,-1),used(1e6);

//uとvを結ぶ辺をグラフに追加する
void add_edge(int u,int v){
    G[u].push_back(v);
    G[v].push_back(u);
    return;
}

bool dfs(int v){
    used[v]=true;
    rep(i,G[v].size()){
        int u=G[v][i],w=match[u];
        if(w<0||(!used[w]&&dfs(w))){
            match[v]=u;match[u]=v;
            return true;
        }
    }
    return false;
}

//2部グラフの最大マッチングを求める
int bipartite_matching(){
    int res=0;
    rep(v,n){
        if(match[v]<0){
            rep(i,200)used[i]=false;
            if(dfs(v))res++;
        }
    }
    return res;
}

int main(void){
    cin>>n;V=10000;
    vector<pair<int,int>> ps(n),pt(n);
    rep(i,n)cin>>ps[i].first>>ps[i].second;
    rep(i,n)cin>>pt[i].first>>pt[i].second;
    rep(i,n)rep(j,n){
        if(ps[i].first<pt[j].first&&ps[i].second<pt[j].second) add_edge(i,n+j);
    }
    int res=bipartite_matching();
    cout<<res<<endl;
}

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

#define ll long long

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x;
	cin >> x;
	ll ans = 0;
	ll t = 0;
	while (true){
		t++; 
		if (x>ans){ ans += t; }
		if (x<=ans){ break; }
	}
	cout << t << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}

int main(void) {
    int n,k; cin>>n>>k;
    if(k != 1) {
        cout << n-(k-1)-1 << endl;
    } else {
        pr(0);
    }
    return 0;
}


Measured memory_bytes: 256
def c(n, P):
    return sum([1 for p in P if p + 1 >= n])


N = int(input())
pN = {}
for i in range(N + 1):
    for j in range(2, i + 1):
        while i % j == 0:
            i //= j
            pN[j] = pN.get(j, 0) + 1
V = pN.values()
ans = c(75, V)
ans += c(25, V) * (c(3, V) - 1)
ans += c(15, V) * (c(5, V) - 1)
ans += c(5, V) * (c(5, V) - 1) * (c(3, V) - 2) // 2
print(ans)


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
MOD = 10**9+7
N,K = map(int,readline().split())
fact = [1] * (N+1)
fact_inv = [1] * (N+1)
for i in range(1,N+1):
    fact[i] = fact[i-1] * i % MOD 
fact_inv[N] = pow(fact[N],MOD-2,MOD)
for i in range(N,0,-1):
    fact_inv[i-1] = (i * fact_inv[i]) % MOD
### nCrの計算 
def comb(n,r):
  return fact[n] * fact_inv[r] * fact_inv[n-r] % MOD

A = list(map(int,readline().split()))
A = sorted(A)
n = N-1
k = K-1
i = 0
ans = 0
while n >= k:
    ans += comb(n,k) * (A[N-1-i]-A[i]) % MOD
    n -= 1 
    i += 1
print(ans%MOD)

Measured memory_bytes: 88696
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  vector<int> vec(n);
  vector<int> cal(pow(10, 5)+4, 0);
  ll total = 0;
  rep(i, n) {
    cin >> vec[i];
    total += vec[i];
    cal[vec[i]]++;
  }
  int q;
  cin >> q;
  rep(i, q) {
    int x, y;
    cin >> x >> y;
    total += (y - x) * cal[x];
    cal[y] += cal[x];
    cal[x] = 0;
    cout << total << endl;
  }
  return 0;
}

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("5 5 7");
            //YES
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("7 7 5");
            //NO
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();
        Array.Sort(wkArr);

        bool IsOK = true;
        if (wkArr[0] != 5) IsOK = false;
        if (wkArr[1] != 5) IsOK = false;
        if (wkArr[2] != 7) IsOK = false;
        Console.WriteLine(IsOK ? "YES" : "NO");
    }
}


Measured memory_bytes: 3160
// C - Bugged
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	int sumS = 0;
	int mini = INT_MAX;
	for(int i=1; i<=N; ++i){
		int s; cin>>s;
		sumS += s;
		if(s%10){
			mini = min(mini, s);
		}
	}

	if(sumS%10==0){
		if(mini == INT_MAX) sumS = 0;
		else sumS -= mini;
	}
	cout<< sumS <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
constexpr int MOD = 1e9+7, MX = 500005;
using ll = long long;
int n, m;
ll ans, cum;
ll exp(ll b, ll n){
	ll res = 1;
	for(; n; n/=2,(b*=b)%=MOD) if(n%2) (res *= b) %= MOD;
	return res;
}
ll fact[MX], invf[MX];
void setcomb(int n){
	fact[0] = 1;
	for(int i = 1; i <= n; i++) fact[i] = (fact[i-1] * i) % MOD;
	invf[n] =  exp(fact[n] ,MOD-2);
	for(int i = n; i > 0; i--) invf[i-1] = (invf[i] * i) % MOD;
}
inline ll comb(int a, int b){return fact[a] * invf[a-b] % MOD * invf[b] % MOD;}
int main(){
	scanf("%d%d", &n, &m);
	setcomb(m);
	ans = fact[n] * fact[m] % MOD * invf[m-n] % MOD * invf[m-n] % MOD;
	for(int i=0; i<=n; i++) (cum += invf[n-i] * invf[i] % MOD * fact[m-i] % MOD * (i&1 ? -1 : 1)) %= MOD;
	ans = ans * cum % MOD;
	if(ans < 0) ans += MOD;
	printf("%lld\n", ans);
}

Measured memory_bytes: 11512
import math
a,b,x = [list(map(int, s.split())) for s in open(0)][0]

x /= a
if a*b/2 == x:
    ans = 45
else:
    if a*b/2 > x:
        ans = math.atan(b*b/x/2) * 180 / math.pi
    else:
        ans = math.atan((a*b-x)/a/a*2) * 180 / math.pi
print(ans)

Measured memory_bytes: 3060
MOD = 998244353
n, s = map(int, input().split())
a = list(map(int, input().split()))
dp = [[0] * (s+1) for _ in range(n+1)]
dp[0][0] = 1

for i in range(n):
    for j in range(s+1):
        dp[i+1][j] += dp[i][j]
        nj = j + a[i]
        if nj > s: continue
        dp[i+1][nj] += i+1 if j == 0 else dp[i][j]
        if nj == s: dp[i+1][nj] *= n-i
        dp[i+1][nj] %= MOD

print(dp[n][s] % MOD)


Measured memory_bytes: 112604
#include <stdio.h>
int cnt=0,B[101];
void BubbleSort(int n);
int main(void){
	int i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&B[i]);
	BubbleSort(n);
	for(i=0;i<n;i++){
		if(i) printf(" ");
		printf("%d",B[i]);
	}
	printf("\n%d\n",cnt);
	return 0;
}

void BubbleSort(int n){
	int i,j,tmp;
	for(i=0;i<n-1;i++){
		for(j=n-1;j>i;j--){	
			if(B[j] < B[j-1]){
				tmp = B[j-1];
				B[j-1] = B[j];
				B[j] = tmp;
				cnt++;
			}
		}
	}	
}

Measured memory_bytes: 604
import math

N = int(input())
m = [ int(i) for i in input().strip().split(" ")]

k_tmp = float(sum(m))/len(m)

k1 = int(math.ceil(k_tmp))
k2 = int(math.floor(k_tmp))

res1 = sum([(x-k1) * (x-k1) for x in m])
res2 = sum([(x-k2) * (x-k2) for x in m])
res = 0
if res1 > res2:
    res = res2
else:
    res = res1
print(res)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = 0;
  rep2(i, 1, n + 1) {
    ll now = 0;
    ll m = i;
    while(m > 0) {
      now += m % 10;
      m /= 10;
    }
    if(a <= now && now <= b) ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n,q,i,j,cnt=0;
  int S[10000];
  int T[500];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&T[j]);
  }
  for(j=0;j<q;j++){
    for(i=0;i<n;i++){
      if(T[j]==S[i]){
	cnt++;
	break;
      }
    }
  }
  printf("%d\n",cnt);
  return 0;
}



Measured memory_bytes: 2088
/// However long the night,
///     The dawn will break
/// ICPC next year

#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std ;

typedef unsigned long long ull ;
const int N = 5e3+5 ,base = 29 ;

struct rabinKarp{
    ull val ;
    rabinKarp(){
        val = 0 ;
    }
    void push_back(int x){
        val = (1ll * val * base) ;
        val += x ;
    }
    ull hashVal(){
        return val;
    }
};

int n ;
ull pre[N] ,p[N] ;
string str ;

ull subStr(int i,int j){
    return pre[j] - pre[i] * p[j-i] ;
}
bool ok(int sz){
    for(int i=1;i+sz+sz-1<=n;++i){
        ull x = subStr(i-1,i+sz-1) ;
        for(int j=i+sz;j+sz-1<=n;++j){
            if(subStr(j-1,j+sz-1) != x) continue ;
            return 1;
        }
    }
    return 0;
}
int main(){
    p[0] = 1 ;
    for(int i=1;i<N;++i) p[i] = p[i-1] * base ;

    cin >> n >> str ;
    rabinKarp rbk ;
    for(int i=0;i<n;++i){
        rbk.push_back(str[i]-'a'+1);
        pre[i+1] = rbk.hashVal() ;
    }
    int st=0 ,en = n/2 ;
    while(st<en){
        int mid = (st+en+1)/2;
        if(ok(mid)) st=mid ;
        else en = mid-1 ;
    }
    cout << st;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<set>
#define rep(i,a, n) for (int i = a; i < (int)(n); i++)
#define INF 1000000;

using ll = long long;
using namespace std;



int main(){
    int w, h, n;
    cin >> w >> h >> n;

    int sq[110][110]={0};

    int x[110], y[110], a[110];
    rep(i,0,n){
        cin >> x[i];
        cin >> y[i];
        cin >> a[i];
    }
    for(int k=0; k<n; k++){
        if(a[k] == 1){
            rep(i,0,h){
                rep(j, 0, x[k]){
                    sq[i][j]++;
                }
            }
        }
        else if (a[k] == 2){
             rep(i,0,h){
                for(int j=x[k]; j<w; j++){
                    sq[i][j]++;
                }
            }

        }
        else if (a[k] == 3){
             for(int i=h-y[k]; i<h;i++){
                rep(j, 0, w){
                    sq[i][j]++;
                }
            }
        }
        else if (a[k] == 4){
            for(int i=(h-y[k]-1);i>=0;i--){
                rep(j, 0, w){
                    sq[i][j]++;
                }
            }
        }
    }
    int count=0;
    
    rep(i,0,h){
        rep(j, 0, w){
            // cout << sq[i][j];
            if (sq[i][j]) count++;
                }
            // cout << endl;
            }
        
    cout << (w*h - count) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

//解説参考.
int main(){
	int k;
	cin>>k;
	
	queue<llong> que;
	for(int i=1;i<=9;++i) que.push(i);
	
	llong ans;
	REP(i,k){
		ans=que.front();
		que.pop();
		
		if(ans%10!=0) que.push(10*ans+ans%10-1);
		que.push(10*ans+ans%10);
		if(ans%10!=9) que.push(10*ans+ans%10+1);
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> a(n);
	REP(i,n)cin>>a[i];
	vector<int> mp(n,INF);
	queue<pair<int,int> > que;
	que.push(make_pair(0,0));
	while(!que.empty()){
		int x = que.front().first;
		int t = que.front().second;
		que.pop();
		if(a[x] !=0){
			if(t < mp[x + a[x]]){
				mp[x + a[x] ] = t;
				que.push(make_pair(x+a[x],t));
			}
		}else{
			for(int i = 6;i>0;i--){
				if(x+i <n && t+1 < mp[x + i]){
					mp[x+i] = t+1;
					que.push(make_pair(x+i,t+1));
				}
			}
		}
	}
	cout << mp[n-1] << endl;
  return 0;
}

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

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int                                       long long
#define lop(i,s,e)                                for(int i=s;i<(int)e;i++)
#define rlop(i,e,s)                               for(int i=e;i>=s;i--)
#define prvec(v)                                  lop(R15,0,v.size())cout << v[R15] <<" "; cout << endl;
#define prarr(arr,s1,e1)                          lop(R15,s1,e1)cout << arr[R15] << " "; cout << endl;

#define endl                                      '\n'
#define ff                                        first
#define ss                                        second
#define pii                                       pair<int,int>

#define pb                                        push_back
#define all(v)                                    v.begin(),v.end()         

#define bug(...)                                  __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

inline void INP();
const int N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;

int n, Q;
int arr[N+2];


void solve()
{
      
      int n, m;
      cin >> n >> m;
      cout << (n*(n-1))/2 + (m*(m-1))/2 << endl;
}


int32_t main()
{
      
      ios_base::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);
     // INP(); //
      int t = 1;
      //cin >> t;
      while(t--) solve();

}











inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //






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

int main () {
  double r;
  cin >> r;
//  double PI = 3.141592653589;
  double a = r*r*M_PI;
  double b = r*2*M_PI;
  printf("%f %f\n",a,b);
}


Measured memory_bytes: 3184
import java.util.Scanner;
  
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int r = sc.nextInt();
    int c = sc.nextInt();
    int a[][] = new int[r+1][c+1];

  	for(int x = 0; x <= r; x++){
  	  for(int y = 0; y <= c; y++){
  	  	a[x][y] = 0;
  	  }
    }
    for(int x = 0; x < r; x++){
      for(int y = 0; y < c; y++){
        a[x][y] = sc.nextInt();
        a[x][c] = a[x][c]+a[x][y];
        a[r][y] = a[r][y]+a[x][y];
      	a[r][c] = a[x][y]+a[r][c];
      }
    }
  
    for(int x = 0; x <= r; x++){
      for(int y = 0; y <= c; y++){
        if(y == c){
          System.out.print(a[x][y]);
        }else{
          System.out.print(a[x][y]+" ");
        }
      }
      System.out.println("");
    }
  }
}


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

int main()
{
	int stack[10];
	int stacknum = -1;
	int n;	
	while(scanf("%d",&n) != EOF)
	{
		if(n == 0)
		{
			printf("%d\n",stack[stacknum]);
			stacknum--;
		}
		else
		{
			stacknum++;
			stack[stacknum] = n;
		}
	}
	return 0;
}

Measured memory_bytes: 0
s = input()
t = input()
next_alpha = [[-1] * len(s) for _ in range(30)] # (文字種a, 今いるsのインデックス)=>(次のaが出るsのインデックス)
for i, s_ in enumerate(s):
    j = ord(s_) - 97
    for k in range(i, -1, -1):
        if next_alpha[j][k] != -1:
            break
        next_alpha[j][k] = i

ans = 0
for t_ in t:
    i = ans % len(s)
    tmp = next_alpha[ord(t_) - 97][i]
    if tmp == -1:
        ans += (-1 * ans) % len(s)
        i = ans % len(s)
        tmp = next_alpha[ord(t_) - 97][i]
    if tmp == -1:
        ans = -1
        break
    else:
        ans += tmp - (i - 1)
print(ans)


Measured memory_bytes: 97576
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
using ll = long long;

int gcd(int a,int b){
    if(a<b) swap(a,b);
    int have_mod =true;
    while(have_mod){
        int mod = a % b;
        if(mod == 0 ) have_mod = false;
        a = b;
        b = mod;
    }
    return a;
}

//区間ごとに切り出す処理
int main(){
    int n,x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i=0;i<n;i++){
        cin >> a.at(i);
    }
    vector<int> b(n);
    for (int i=0;i<n;i++){
        b.at(i) = abs(a.at(i)-x);
    }
    if(n==1){
        cout << b.at(0) << endl;
        return 0;
    }
    int ans = gcd(b.at(0),b.at(1));
    if(n==2){
        cout << ans << endl;
        return 0;
    }

    for(int i=2;i<n;i++){
        ans = gcd(ans,b.at(i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
s = input()
n = len(s)
n2 = (n+1)//2
for i in range(n):
  if(s[i] != s[n-i-1]):
    print("No")
    exit()
for i in range((n-1)//2):
  if(s[i] != s[n2-2-i]):
    print("No")
    exit()
  if(s[n2+i] != s[n-i-1]):
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 9076
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;

int t,n,d;

int calc(int x,bool flag){
  int a[7];
  for(int i=0;i<7;i++){
    a[i] = x%2;
    x/=2;
  }
}

int main(){
  scanf("%d",&t);
  for(int turai=0;turai<t;turai++){
    priority_queue<int,vector<int>,greater<int> > q;
    scanf("%d %d",&n,&d);
    int ans = d;
    q.push(d);
    for(int i=0;i<n-1;i++){
      int z = q.top(); q.pop();
      ans-=z;
      q.push(127);
      z = z^127;
      ans+=(z+127);
      q.push(z);
    }
    printf("%d\n",ans);
  }
  return 0;
}


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

int main() {
    long long K;
    string S, S_concat;

    cin >> S;
    cin >> K;

    S_concat = S + S;
    int uni_same_count = 0, concat_same_count = 0, tri_concat_same_count = 0;
    char cache = '\0';
    
    for (int i = 0; i < S_concat.size(); i++) {
        if (S_concat[i] == cache && cache != '\0')
        {
            concat_same_count += 1;
            cache = '\0';
        } else 
        {
            cache = S_concat[i];
        }
        
    }

    cache = '\0';
    S_concat = S + S + S;
    for (int i = 0; i < S_concat.size(); i++) {
        if (S_concat[i] == cache && cache != '\0')
        {
            tri_concat_same_count += 1;
            cache = '\0';
        } else 
        {
            cache = S_concat[i];
        }
        
    }

    cache = '\0';
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == cache && cache != '\0')
        {
            uni_same_count += 1;
            cache = '\0';
        } else 
        {
            cache = S[i];
        }
    }


    int odd_concat = tri_concat_same_count - concat_same_count;
    int even_concat = concat_same_count - uni_same_count;

    long long replace_count = uni_same_count + even_concat * (K / 2) + odd_concat * ((K - 1)/ 2);
    if (K == 1) replace_count = uni_same_count;
    cout << replace_count << endl;
}

Measured memory_bytes: 256
#coding:utf-8
#1_6_D 2015.4.5
n,m = map(int,input().split())
matrix = [list(map(int,input().split())) for i in range(n)]
vector = [int(input()) for i in range(m)]
for j in range(n):
    sum = 0
    for i in range(m):
        sum += matrix[j][i] * vector[i]
    print(sum)

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

isApproved = True
for i in range(N):
    if A[i] % 2 == 0:
        if A[i] % 3 != 0:
            if A[i] % 5 != 0:
                isApproved = False


if isApproved:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if (a==b && a!= c && b!=c ){
    cout<<"2"<<endl;
    
  }
    else if (a==c && a!= b && c!=b ){
    cout<<"2"<<endl;
    
  }   
 else if (b==c && b!= a && c!=a ){
    cout<<"2"<<endl;
    
  }
     else if (a!=b && b!= c && a!=c ){
    cout<<"3"<<endl;
    
  }
     else if (a == b && b == c ){
    cout<<"1"<<endl;
    
  }
}


Measured memory_bytes: 256
s = input()
flg1 = s[0] == "A"
flg2 = s[2:-1].count("C") == 1
s = s.replace("A", "")
s = s.replace("C", "")
flg3 = s.islower()
print(["WA", "AC"][flg1 and flg2 and flg3])

Measured memory_bytes: 9052
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> X >> Y;
    REP(i, X + 1) {
        ans = 2 * i + 4 * (X - i);
        if (ans == Y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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


int main(){
  int h,n;
  cin>>h>>n;
  int a,b;
  b=0;
  rep(i,n){
    cin>>a;
    b+=a;
  }
  if(b>=h)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  }

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

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

int main(){
  ll a, b;
  cin >> a >> b;
  ll c = gcd(a,b);
    
  ll ans = 0; //答えを格納する
  
  ans++; //1は答えに含まれる
  
  for(int i = 2; 1LL*i*i <= c; i++){
    if(c % i == 0){
      ans ++;
    }
    while(c % i == 0){
      c /= i;
    }
  }
  
  if(c > 1){
    ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int n;
int A[10000];

void judge(){
  int i,j;
  int flag,count=0;
  for(i=0;i<n;i++){
    flag=0;
    for(j=2;j*j<=A[i];j++){
      if( A[i] % j ==0){
      	flag = 1;
      	break;
      }
    }
    if(flag == 0) count++;
  }
  printf("%d\n",count);
}

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

Measured memory_bytes: 2712
#include<stdio.h>

void swap(int *a,int *b){
	int  tmp = *a;
	*a = *b;
	*b = tmp;
}

int main(){
	int x,y,r;
	scanf("%d %d",&x,&y);
	if(x<y){
		swap(&x,&y);
	}
	while(y > 0){
		r = x%y;
		x = y;
		y = r;
	}
	printf("%d\n",x);
}

Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let a = get!(usize);
    let s = get!(String);
    if a < 3200 {
        println!("red");
    } else {
        println!("{}", s);
    }
}


Measured memory_bytes: 8572
count_500 = int(input())
count_100 = int(input())
count_50 = int(input())
target = int(input())

ways = 0
for i in range(1+count_500):
    for j in range(1+count_100):
        for k in range(1+count_50):
            if target == 500*i+100*j+50*k:
                ways +=1
print(ways)

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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
typedef struct aaaaa{
  int x,y,t;
}Grid;
using namespace std;

int main(){
  string s;cin>>s;
  vector<ll>hog(s.size());
  for(int i=0;i<s.size();i++){
    if(s[i]=='B')
      hog[i]=1;
    else
      hog[i]=0;
  }
  for(int i=1;i<s.size();i++){
    hog[i]+=hog[i-1];
  }
  ll ans=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='W')
      ans+=hog[i];
  }
  cout<<ans<<endl;
  return 0;
}


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

class meb{
public:
	int num;
	unsigned long long tanka;
	unsigned long long count;
	unsigned long long sum;
};

int main(){
	int n;
	while(1){
		int cc=0;
		cin>>n;
		meb st[n];
		if(n==0)break;
		for(int i=0;i<n;i++){
			cin>>st[i].num>>st[i].tanka>>st[i].count;
		}
		for(int k=0;k<n;k++){
			st[k].sum=st[k].tanka*st[k].count;
		}
		for(int j=0;j<n;j++){
			for(int l=j+1;l<n;l++){
				if(st[j].num==st[l].num){
					(st[j].sum)=(st[j].sum)+(st[l].sum);
					st[l].sum=0;
				}
			}
		}
		for(int a=0;a<n;a++){
			if(st[a].sum>=1000000)cout<<st[a].num<<endl;
			else cc++;
		}
		if(cc==n)cout<<"NA"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, K, Q, A;
	vector<int> con;
	
	cin>>N>>K>>Q;
	
	con.resize(N+1,K-Q);
	
	for(int i = 0; i < Q; i++){
		cin>>A;
		con[A]++;
	}
	
	for(int i = 1; i <= N; i++){
		cout<<yn(con[i] > 0)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1408
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int r = sc.nextInt();
		int g = sc.nextInt();
       
        
		// 出力
		System.out.println(2 * g - r);
	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;



ll a, b, c;

int main() {

	cin >> a >> b;

	if (a > b) {
		swap(a, b);
	}
	c = a;
	REP(i, 1, b) {
		a += c * pow(10, i);
	}

	cout << a << endl;

	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

void buildMaxHeap(int*, int);
void maxHeapify(int*,int,int);

int main(){
  int h,i;
  scanf("%d",&h);

  int a[h+1];

  for(i=1;i<=h;i++){
    scanf("%d",&a[i]);
  }

  buildMaxHeap(a,h);

  for(i=1;i<=h;i++){
    printf(" %d",a[i]);
  }

  printf("\n");

  return 0;
}

void buildMaxHeap(int *A, int H){
  int i;
  
  for(i=H/2; i>=1; i--){
    maxHeapify(A,i,H);
  }
}

void maxHeapify(int *A, int i, int H){
  int left,right,largest,change;
    
  left=i*2;
  right=i*2+1;

  if(left<=H && A[left]>A[i])
    largest=left;
  
  else
    largest=i;

  if(right<=H && A[right]>A[largest])
    largest=right;

  if(largest!=i){
    change=A[i];
    A[i]=A[largest];
    A[largest]=change;
    maxHeapify(A,largest,H);
  }
}



Measured memory_bytes: 3652
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
 
using namespace std;


int main()
{
	int N;
	cin>>N;
	int *cost = new int[N];
	int *value = new int [N];
	for(int i = 0; i < N; i++){
		cin>>value[i];
	}
	for(int i = 0; i < N; i++){
		cin>>cost[i];
	}
	int total = 0;
	int x,y;
	x = 0;
	y = 0;
	for(int i = 0; i < N; i++){
		if(value[i] > cost[i]){
			x += value[i];
			y += cost[i];
		}
	}
	cout<<x-y<<endl;

	return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())

    count = 0
    answer = 'No'
    for i in range(n):
        d = list(map(int, input().split()))
        if d[0] == d[1]:
            count += 1
        else:
            count = 0
        if count >= 3:
            answer = 'Yes'

    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62344
#include<iostream>
#include<cmath>
#include<vector>
#define N 1299709

using namespace std;

vector<int> MakePrimeNumber(void);

int main(){
  int i, n, x;
  vector<int> data;

  data = MakePrimeNumber();

  while(1){
    cin >> n;
    if(n == 0) break;

    for(i=0; i<data.size(); ++i){
      if(n == data[i]){
	x = 0;
	break;
      }else if(n < data[i]){
	x = data[i] - data[i-1];
	break;
      }
    }
    cout << x << endl;
  }
  return 0;
}

vector<int> MakePrimeNumber(void){
  int i, j, k;
  vector<int> data;

  data.push_back(2);
  data.push_back(3);
  for(i=5; i<=N; i+=2){
    for(j=1, k=0; data[j]<=sqrt(i); ++j){
      if(i%data[j] == 0){
	k = 1;
	break;
      }
    }
    if(k == 0) data.push_back(i);
  }
  return data;
}

Measured memory_bytes: 1424
K=int(input())
A,B=map(int,input().split())
E=False
C=B%K
D=(B-C)//K

for i in range(D):
    if A<=K*(i+1) and K*(i+1)<=B:
        E=True
        break
    else:
        pass
if E==False:
    print("NG")
else:
    print("OK")


Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=100;
int n;
bool used[N];
string s;
vector<string>res;
void rec(int ch){
	vector<int>ind;
	for(int i=0;i<n;++i)if(!used[i])ind.push_back(i);
	int m=ind.size();
	if(!m){
		res.push_back(s);
		return;
	}
	for(int i=0;i<(1ll<<m);++i){
		if((i&1)==0)continue;
		for(int j=0;j<m;++j){
			if(i&(1ll<<j)){
				used[ind[j]]=1;
				s[ind[j]]=ch+'a';
			}
		}
		rec(ch+1);
		for(int j=0;j<m;++j){
			if(i&(1ll<<j)){
				used[ind[j]]=0;
			}
		}
	}
}
signed main(){;
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=0;i<n;++i)s+='a';
	rec(0);
	sort(res.begin(),res.end());
	for(string s:res)cout<<s<<'\n';
}

Measured memory_bytes: 7796
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int A = sc.nextInt();
      	int B = sc.nextInt();
      	int C = sc.nextInt();
      	if((A==B&&B!=C) || (B==C&&C!=A) || (C==A&&A!=B)) System.out.println("Yes");
      	else System.out.println("No");
    }
}

Measured memory_bytes: 35804
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#define ll long long 
const ll maxn=1ll;
ll n,m,num[maxn]; 
using namespace std;
int main()
{
	cin>>n>>m;
	cout<<n*n-m;
	return 0;
}

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

const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
const ll MOD1 = 998244353;
typedef pair<int,int> P;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define mp make_pair

int main(){
  int a[3];
  REP(i,3) cin >>a[i];
  cout << ((a[0] - a[2]) * (a[1] - a[2]) <= 0 ? "Yes":"No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>

using namespace std;

int main(){
    int N,i,j;
    cin >> N;
    int *t = new int[N];
    int *x = new int[N];
    int *y = new int[N];
    t[0] = 0;
    x[0] = 0;
    y[0] = 0;
    for(i=1;i<=N;i++){
            cin >> t[i] >> x[i] >> y[i];
    }
    int possibility = 1;
    for(i=0;i<N;i++){
        int dt = t[i+1] - t[i];
        int dx = abs(x[i+1] - x[i]);
        int dy = abs(y[i+1] - y[i]);
        if(dt<dx+dy){
            cout << "No" << endl;
            possibility = 0;
            break;
        }
        else if(dt%2!=(dx+dy)%2){
            cout << "No" << endl;
            possibility = 0;
            break;
        }
    }
    if(possibility==1) cout << "Yes" << endl;
}


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

using namespace std;

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

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD =  1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll l,r;
    ll ans = INF;
    cin>>l>>r;
    ll mod = 2019;
    ll n = l%mod;
    ll m = r%mod;

    if(r-l>=2018){
        cout<<0<<endl;
        return  0;
    }else if(n>=m){
        cout<<0<<endl;
        return  0;
    }

    rep(i,m-n+1){
        REP(j,i+1,m-n+1){
//            dbg((n+i));
//            dbg((n+j));
            ans = min(ans,((n+i)*(n+j))%mod);
        }
    }
    cout<<ans<<endl;
    return  0;
}


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

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		long val = 0;
		long now = a[0];
		if (a[0] <= 0) {
			val += 1 - a[0];
			now = 1;
		}
		for (int i = 1; i < n; i++) {
			now += a[i];
			if (i % 2 == 0) {
				if (now <= 0) {
					val += 1 - now;
					now = 1;
				}
			} else {
				if (now >= 0) {
					val += now + 1;
					now = -1;
				}
			}
		}
		long ans = val;

		val = 0;
		now = a[0];
		if (a[0] >= 0) {
			val += a[0] + 1;
			now = -1;
		}
		for (int i = 1; i < n; i++) {
			now += a[i];
			if (i % 2 != 0) {
				if (now <= 0) {
					val += 1 - now;
					now = 1;
				}
			} else {
				if (now >= 0) {
					val += now + 1;
					now = -1;
				}
			}
		}
		ans = Math.min(ans, val);
		System.out.println(ans);
	}
}


Measured memory_bytes: 48140