akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int kako[110];
string str;

void g(){
	int c;
	str="";
	while(c=getchar(),c<' ');
	while(c>=' '){
		str+=(char)c;
		c=getchar();
	}
}

int main() {
	while(g(),str[0]!='.'){
//cout<<str<<endl;
		int i;
		int k=0;
		string res="yes";
		for(i=0;i<str.size();i++){
			if(str[i]=='[')kako[k++]=1;
			else if(str[i]=='(')kako[k++]=2;
			else if(str[i]==']'){
				if(k==0||kako[k-1]!=1){
					res="no";
					break;
				}
				k--;
			}else if(str[i]==')'){
				if(k==0||kako[k-1]!=2){
					res="no";
					break;
				}
				k--;
			}
		}
		if(k!=0)res="no";
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {if (a > b) a = b;}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {if (a < b) a = b;}
void fail() { cout << -1 << endl; exit(0); }

typedef pair<int, int> pii; typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9+7;
constexpr int MAX = 50050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e18 + 1; constexpr int INF = 1e9 + 1;
//const int dx[4] = { 0,0,-1,1 }, dy[4] = { 1,-1,0,0 };

int A[200010], B[200010];
void solve() {
	int N; cin >> N;
	REP(i, N) {
		cin >> A[i];
	}
	int sum = 0;
	REP(i, N) {
		sum ^= A[i];

	}
	REP(i, N) {
		B[i] = A[i] ^ sum;
		print(B[i]);

	}
	//REP(i, N) {
	//	int res = 0;
	//	REP(j, N)if (j != i)res ^= B[j];
	//	pe(i); print(res);
	//}
	//print(ans);
}





signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//mt.seed((int)(time(0)));
	//int q;
	//cin >> q;
	//while (q--)
	solve();
}



Measured memory_bytes: 6708
#include "bits/stdc++.h"

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
    int n;
    while(cin>>n){
        double Aval = 999999999;
        int Anum = 999999999;

        
        if(n==0)break;
        
        rep(i,n){
            int num,h,w;
            cin>>num>>h>>w;
            double res = w*10000.0/( (h*h) );


            if( abs(Aval-22)>abs(res-22)-1e-9 ||  (abs( abs(Aval-22) - abs(res-22) )<1e-9 && num<Anum)  ){
                Aval = res;
                Anum = num;
            }
        }
        cout<<Anum<<endl;
    }
}

Measured memory_bytes: 1160
use std::io;

fn main() {
    let mut X = String::new();
    io::stdin().read_line(&mut X);
    let X = X.trim().parse::<i64>().unwrap().abs();

    let p = (2f64 * X as f64 + 0.25f64).sqrt();
    let t = (p - 0.5f64).ceil() as u64;

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

Measured memory_bytes: 4352
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
    int n,x;
    cin>>n>>x;
    vector<int> v(n);
    rep(i,n){
        cin>>v[i];
    }
    ll ans=0;
    if(v[0]>x){ans+=v[0]-x;v[0]=x;}
    for(int i=1;i<n;i++){

        if(v[i]+v[i-1]>x){
            ans+=v[i]+v[i-1]-x;
            v[i]=x-v[i-1];
        }
    }
    cout<<ans<<endl;


    return 0;
}



Measured memory_bytes: 640
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
const int mod=1000000007;
inline int ad(int x){return x>=mod?x-mod:x;}
inline int dec(int x){return x<0?x+mod:x;}
int inv[200010];
inline int power(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}return ans;
}
inline int C(int n,int m)
{
	int ans=1;
	for(int i=1;i<=m;i++)ans=1LL*ans*(n-i+1)%mod*inv[i]%mod;
	return ans;
}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    for(int i=1;i<=200000;i++)inv[i]=power(i,mod-2);
    int n=read(),l=read(),r=read();
    pr2(dec(dec(dec(power(2,n)-1)-C(n,l))-C(n,r)));
    return 0;
}

Measured memory_bytes: 896
//#define NDEBUG
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

static constexpr double PI = 3.1415926535897932;

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;

template<typename T>
class RadixHeap32 {
	using uint32 = std::uint_fast32_t;
	using P = std::pair<uint32, T>;
	uint32 bsr(const uint32 x) {
		if (!x)
			return 0;
#ifdef __GNUC__
		return 32 - __builtin_clz(x);
#else
		uint32 t = 16;
		for (uint32 i = 3; ~i; --i) {
			if (x & ~(((uint32)1 << t) - 1)) {
				t += (uint32)1 << i;
			}
			else {
				t -= (uint32)1 << i;
			}
		}
		if (x & ~(((uint32)1 << t) - 1))
			++t;
		return t;
#endif
	}
	std::vector<P> v[33];
	uint32 last, size;

public:
	RadixHeap32() : last(0), size(0) {}
	P pop() {
		assert(size);
		--size;
		if (v[0].empty()) {
			uint32 i = 1;
			while (v[i].empty())
				++i;
			last = std::numeric_limits<uint32>::max();
			for (P &d : v[i])
				last = std::min(last, d.first);
			for (P &d : v[i])
				v[bsr(last ^ d.first)].push_back(d);
			v[i].clear();
		}
		P ret = v[0].back();
		v[0].pop_back();
		return ret;
	}
	void push(P x) {
		assert(last <= x.first);
		++size;
		v[bsr(x.first ^ last)].push_back(x);
	}
	bool empty() { return !size; }
};
struct edge {
	uint32 to;
	uint32 cost;
};

int main(void) {
	uint32 k;
	std::cin >> k;
	std::vector<std::vector<edge>> G(k);
	for (uint32 i = 0;i < k;++i) {
		G[i].push_back({ i * 10 % k,0 });
		G[i].push_back({ (i + 1) % k,1 });
	}
	RadixHeap32<uint32> Q;
	static constexpr uint32 INF = std::numeric_limits<uint32>::max();
	std::vector<uint32> d(k, INF);
	Q.push({ 1,1 });
	d[1] = 1;
	uint32 v, c;
	while (!Q.empty()) {
		std::tie(c, v) = Q.pop();
		if (d[v] < c) continue;
		for (const edge &e : G[v]) {
			if (c + e.cost < d[e.to]) {
				d[e.to] = c + e.cost;
				Q.push({ d[e.to],e.to });
			}
		}
	}
	std::cout << d[0] << "\n";
	return 0;
}

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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

double kaijyo(int n){
    int k(1);
    for(int i=n;i>0;i--){
        k *= i;
    }

    return k;
}

double distance(int x[],int y[],int i,int j){
    int dx = (x[i] - x[j]) * (x[i] - x[j]);
    int dy = (y[i] - y[j]) * (y[i] - y[j]);
    return sqrt(dx+dy);
}

int main(){
    int x;
    cin >> x;

    cout << 10-x/200 << endl;

    return 0;
}

Measured memory_bytes: 3672
#include <iostream>

using namespace std;

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

    char a, b;
    int x = 0, y = 0;

    a = s[0];
    for (int i = 1; i < 4; i++)
    {
        if (s[i] != a)
        {
            b = s[i];
            break;
        }
        if (i == 3)
        {
            cout << "No" << endl;
            return 0;
        }
    }

    for (int i = 0; i < 4; i++)
    {
        if (s[i] == a)
        {
            x++;
        }
        else if (s[i] == b)
        {
            y++;
        }
    }

    if (x == 2 && y == 2)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,j,h,w;
    while(scanf("%d %d",&h,&w)){
        if(h==0 && w==0)
            break;
        for(i=1;i<=h;i++){
                for(j=1;j<=w;j++){
                    if(i==1 || i==h)
                        printf("#");
                     else if(j==1 || j==w)
                        printf("#");
                     else
                        printf(".");
                }
                printf("\n");
        }
        printf("\n");
    }



}



Measured memory_bytes: 2620
// 1_5_A
#include<stdio.h>

int main(void)
{
	int height, width, H, W;
	while(1){
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0){
			break;
		}

		for(height = 0; height < H; height++){
			for(width = 0; width <W; width++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
#define LL long long int

//how many times power of p can be used
int calc(int p) {
    for (int i = 1; ; i++) {
        if (i > p)
            return i - 1;
        else
            p -= i;
    }
}

int main() {
    LL N;
    int ans;

    cin >> N;

    ans = 0;
    for (LL div = 2; div * div <= N; div++) {
        if (N % div == 0) {
            int cnt = 0;
            while (N % div == 0) {
                cnt += 1;
                N /= div;
            }

            ans += calc(cnt);
        }
    }

    if (N != 1)
        ans += calc(1);

    cout << ans << endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll K, N;
    cin >> K >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    ll ma = 0;
    REP(i, N-1){
    	chmax(ma, A[i+1]-A[i]);
    }
    chmax(ma, A[0] + K-A[N-1]);
    cout << K - ma << endl;
    return 0;
}

Measured memory_bytes: 1792
D = int(input())
C = list(map(int, input().split()))
S = [tuple(map(int, input().split())) for _ in range(D)]
T = [int(input()) - 1 for _ in range(D)]
Z = 26

last = [-1] * Z
cnt = 0
for d, t in enumerate(T):
    last[t] = d
    up = S[d][t]
    down = sum(C[i] * (d - last[i]) for i in range(Z))
    cnt += up - down
    print(cnt)


Measured memory_bytes: 9388
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cctype>
#include<utility>

using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    if(n%2==0)
        printf("%d\n",n);
    else
        printf("%d\n",2*n);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int dx = x2 - x1;
  int dy = y2 - y1;
  int x3 = x2 - dy;
  int y3 = y2 + dx;
  int x4 = x3 - dx;
  int y4 = y3 - dy;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef pair<ll, ll> PL;
typedef long double ldouble;
typedef tuple<int,int,int> t3;

int main()
{
  string A;
  int cnt[26] = {};
  cin >> A;
  for(char c : A) cnt[c-'a']++;
  for(int i = 0; i < 26; i++){
    if(cnt[i] == 0){
      cout << A << (char)('a' + i) << "\n";
      return 0;
    }
  }
  string B = A;
  if(next_permutation(A.begin(), A.end())){
    for(int i = 0; i < A.size(); i++) if(A[i] != B[i]){
      cout << A.substr(0, i+1) << "\n";
      return 0;
    }
  }
  else printf("-1\n");
}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

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

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

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

	int n, k; cin >> n >> k;
	vi v(n); FOR(i, n) cin >> v[i];

	sort(all(v));

	ll ans = 1;
	if(v[0] >= 0){
		FOR(i, k){
			ans = ans * v[n-i-1] % MOD;
		}
	}else if(v[n-1] <= 0){
		if(k%2){
			FOR(i, k) ans = ans * v[n-i-1] % MOD;
		}else{
			FOR(i, k) ans = ans * v[i] % MOD;
		}
	}else{
		int l = 0, r = n-1;

		if(k%2){
			ans = ans * v[r] % MOD;
			r--;
			k--;
		}

		while(k){
			ll a1 = -1, a2 = -1;
			a1 = 1LL * v[l] * v[l+1];
			a2 = 1LL * v[r] * v[r-1];

			if(a1 > a2){
				a1 %= MOD;
				ans = ans * a1 % MOD;
				l+=2;
			}else{
				a2 %= MOD;
				ans = ans * a2 % MOD;
				r-=2;
			}

			k-=2;
		}
	}

	if(ans < 0) ans += MOD;
	
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3984
N,K=[int(i) for i in input().split()]
A=[int(i) for i in input().split()]
lastVisited=[-1]*N

curTown=1
k=0
while k<K:
    lastVisited[curTown-1]=k
    k+=1
    curTown=A[curTown-1]
    if lastVisited[curTown-1]>=0:
        p=k-lastVisited[curTown-1]
        k+=((K-k)//p)*p
        lastVisited=[-1]*N
        
print(curTown)


Measured memory_bytes: 32220
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
    int n; cin >> n;
    vector<tuple<int, double, double>> point;
    for (int i=0; i<n; i++) {
        double x, y;
        cin >> x >> y;
        point.push_back(make_tuple(i, x, y));
    }
    double sum = 0.0;
    do {
        for (int i=0; i<n-1; i++) {
            double tmp = 0;
            tmp += (get<1>(point[i]) - get<1>(point[i+1])) * (get<1>(point[i]) - get<1>(point[i+1]));
            tmp += (get<2>(point[i]) - get<2>(point[i+1])) * (get<2>(point[i]) - get<2>(point[i+1]));
            sum += sqrt(tmp);
        }
    } while (next_permutation(point.begin(), point.end()));
    for (int i=1; i<=n; i++) {
        sum /= i;
    }
    cout << fixed << setprecision(10);
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

bool field[1010][1010];

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

    int h, w;
    cin >> h >> w;
    queue< pair<int, int> > q;
    rep (i, h)
    {
        string s;
        cin >> s;
        rep (j, w)
        {
            if (s[j] == '#')
            {
                q.push(pair<int, int>{i, j});
                field[i][j] = true;
            }
        }
    }

    int ans = -1;
    int dy[] = {-1, 0, 1, 0};
    int dx[] = {0, -1, 0, 1};
    while (!q.empty())
    {
        ++ans;
        int s = q.size();
        rep (j, s)
        {
            pair<int, int> p = q.front(); q.pop();
            int y = p.first;
            int x = p.second;
            if (x - 1 >= 0 && !field[y][x - 1]) { q.push(make_pair(y, x - 1)); field[y][x - 1] = true; }
            if (y - 1 >= 0 && !field[y - 1][x]) { q.push(make_pair(y - 1, x)); field[y - 1][x] = true; }
            if (x + 1 <  w && !field[y][x + 1]) { q.push(make_pair(y, x + 1)); field[y][x + 1] = true; }
            if (y + 1 <  h && !field[y + 1][x]) { q.push(make_pair(y + 1, x)); field[y + 1][x] = true; }
        }
    }

    cout << ans << "\n";
    return 0;
}



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

int main(){
	long long s;
	cin>>s;
	
	const int v=1000000000;
	
	int x=(v-s%v)%v;
	int y=(s+x)/v;
	
	cout<<"0 0 1000000000 1 "<<x<<" "<<y<<endl;
}


Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    A,B,C,K=map(int,input().split())
    ans=0
    if A<K:
        K-=A
        ans+=A
        if B<K:
            K-=B
            ans-=K
    else:
        ans+=K
    print(ans)

if __name__ == '__main__':
    main()


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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

int num_people;
int num_testi[20];
int target[20][20];
int kind[20][20];

int BitCount(int i) {
  int bit_count = 0;
  REP(j,num_people) {
    if((i>>j) & 1) ++bit_count;
  }
  return bit_count;
}

/***** MAIN *****/
signed main() {
  cin >> num_people;
  REP(people_i,num_people) {
    cin >> num_testi[people_i];
    REP(testi_i,num_testi[people_i]) {
      int tmp;
      cin >> tmp >> kind[people_i][testi_i];
      target[people_i][testi_i] = --tmp;
    }
  }
  int ans = 0;
  REP(i,1<<num_people) {
    bool flag = true;
    REP(people_i, num_people) {
      if(!((i>>people_i)&1)) continue;
      REP(testi_i, num_testi[people_i]) {
        int tmp_kind = (i>>target[people_i][testi_i])&1;
        if(tmp_kind != kind[people_i][testi_i]) {
          flag = false;
          break;
        }
      }
      if(!flag) break;
    }
    if(flag) {
      ans = max(ans, BitCount(i));
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

int main() {
  int A,B,C,K;
  cin>>A>>B>>C>>K;
  string Ans="Yes";
  while(B<=A){if(K==0){Ans="No";break;}else{B=B*2;K=K-1;}}
  while(C<=B){if(K==0){Ans="No";break;}else{C=C*2;K=K-1;}}
  cout<<Ans<<endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<int>A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    bool ok = false;
    sort(A.begin(),A.end());
    for(int i = 1; i < N; i++) {
        if(A[i] == A[i-1]) {
            ok = true;
        }
    }
    if(ok) {
        cout << "NO" << endl;
    }
    else {
        cout << "YES" << endl;
    }
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
using namespace std;
long long n,maxn,ans,x;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        ans+=max(maxn-x,0ll);
        maxn=max(maxn,x);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <cstdint>
#include <climits>
#include <string>

using namespace std;

int main(void)
{
  int N, T;
  cin >> N >> T;
  vector<int> A(N);
  vector<int> mA(N);
  cin >> A[0];
  mA[0] = A[0];
  for(int i = 1; i < N; i++){
    cin >> A[i];
    mA[i] = min(mA[i - 1], A[i]);
  }

  int maxx = 0, maxxc = 0;
  for(int i = N - 1; i >= 1; i--){
    if(A[i] < mA[i - 1]) continue;
    if(A[i] - mA[i - 1] > maxx){
      maxx = A[i] - mA[i - 1];
      maxxc = 1;
    }else if(A[i] - mA[i - 1] == maxx){
      maxxc++;
    }
  }

  cout << maxxc << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator sl
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
V<LL>v;
map<LL,LL>u;
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z;
    string a;
    cin>>n;
    for(i=0,k=1; i<n; i++)
    {
        cin>>o;
        v.PSB(o);
    }
    for(i=0; i<n; i++)
    {
       l=__gcd(k,v[i]);
       k=(k/l);
       k*=v[i];
    }
    cout<<k<<endl;
    return 0;

}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int i;
  int m,n;
  int p[1000];
  int count,num;
  int last;
  int flag;

  while(1){
    scanf("%d %d",&n,&m);
    if(!n && !m)break;

    for(i=0;i<n;i++)p[i] = 1;

    count = 0;
    num = 0;
    while(1){
      if(p[num])count++;
      if(count == m){
	count = 0;
	p[num] = 0;
	last = num;
      }
      num++;
      if(num==n){
	num=0;
	flag=1;
	for(i=0;i<n;i++)if(p[i])flag=0;
	if(flag)break;
      }
    }

    printf("%d\n",last+1);
  }

  return 0;
}

Measured memory_bytes: 0
//😄😄😄😄😄😄😄😄😄😄😄😄😄
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pi>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define For(i,a,b) for(int i=a;i<b;i++)
#define debug(x) cout<<"DEBUG------> "<<x<<endl
#define endl "\n"
#define all(x) x.begin(),x.end()


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vi v(100000, 0);
	ll sum = 0;
	ll a;
	For(i, 0, n) {
		cin >> a;
		sum += a;
		v[a - 1]++;
	}
	cin >> a;
	while (a--) {
		ll c, d; cin >> c >> d;
		ll jj = v[c - 1];
		v[c - 1] = 0;
		v[d - 1] += jj;
		sum -= jj * c;
		sum += jj * d;
		cout << sum << endl;

	}

	return 0;
}


Measured memory_bytes: 3720
n = int(input())
guide = [input().split() for _ in range(n)]
for i in range(n):
    guide[i].append(i+1)
guide.sort(key = lambda x:int(x[1]), reverse = True)
guide.sort(key = lambda x:x[0])
for j in range(n):
    print(guide[j][2])

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

int main() {
  string s;
  cin >> s;
  
  int i;
  vector<int> x(26);
  for(i = 0; i < s.size(); i++){
    x.at(s.at(i) - 97)++;
  }
  
  bool frag = false;
  char k;
  for(i = 0; i < 26; i++){
    if(x.at(i) == 0){
      k = i + 97;
      frag = true;
      break;
    }
  }
  
  if(frag) cout << k << endl;
  else cout << "None" << endl;
}

Measured memory_bytes: 512
from collections import deque

n = int(input())
edges = [{} for i in range(n+1)]

for i in range(n-1):
    u,v,w = map(int, input().split())
    edges[u][v] = w%2
    edges[v][u] = w%2

colors = [-1]*(n+1)

d = deque()
d.append(1)
colors[1] = 0

while(len(d) > 0):
    now = d.pop()
    for key,val in edges[now].items():
        if(colors[key] == -1):
            colors[key] = (val + colors[now])%2
            d.append(key)

for i in range(1,n+1):
    print(colors[i])

Measured memory_bytes: 86688
using System;

class Program
{
  static void Main()
  {
    var n = int.Parse(Console.ReadLine());
    
    var existsRemainder = (n % 111) != 0;
    var answer = ((n / 111) + (existsRemainder ? 1 : 0)) * 111;
    Console.WriteLine(answer);
  }
}

Measured memory_bytes: 27420
N, M = map(int, input().split())
wls = [0]*N
ls = [0]*N
for i in range(M):
  p, s = input().split()
  p = int(p)-1
  if ls[p]==0:
    if s=='WA':
      wls[p] += 1
    else:
      ls[p] = 1
  else:
    continue
pena = 0
ac = 0
for i in range(N):
  if ls[i] == 1:
    ac += 1
    pena += wls[i]
print(ac, pena)

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

int main()
{
    int N;
    cin >> N;
    if(N % 10 == 2 || N % 10 == 4 || N % 10 == 5 || N % 10 == 7 || N % 10 == 9){
        cout << "hon" << endl;
    }else if(N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8){
        cout << "pon" << endl;
    }else{
        cout << "bon" << endl;
    }
}


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    string n;
    cin >> n;
    int count_2 = count(n.begin(), n.end(), '2');
    cout << count_2 << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static void Main(string[] args)
        {
            int[] A = ReadInts();
            Console.WriteLine((A.Sum() >= 22) ? "bust" : "win");
        }
    }
}


Measured memory_bytes: 13268
#include<cstdio>
#include<cstring> 
using namespace std;
char s[55], S[55] = {'C', 'O', 'D', 'E', 'F', 'E', 'S', 'T', 'I', 'V', 'A', 'L', '2', '0', '1', '6'};
int main()
{
	scanf("%s", s);
	int ans = 0;
	for(int i = 0; i < strlen(s); i++)
		if(s[i] != S[i]) ans++;
	printf("%d\n", ans);
	return 0;
}


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


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

    string S;
    cin >> S;

    int count=0;
    bool ans=true;
    if(S.at(0)!='A') ans=false;
    int x=S.size();
    for(int i=1;i<x;i++){
        if(isupper(S.at(i))){
            if(i>=2 && i<x-1 && S.at(i)=='C') count++;
            else ans=false;
        }
    }
    if(count != 1) ans=false;

    if(ans) cout << "AC" << endl;
    else cout << "WA" << endl;



}


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

const int MAX_N = 201000;
ll D, A;
int N;
pair<ll, ll> XH[MAX_N];
ll damage[MAX_N]; // damage[i] := i番目の要素はどれだけダメージを受けたか
int r_range[MAX_N]; // r_range[i] = j -> Xi に対して、 Xj - Xi <= 2Dを満たす最も右側の要素番号がj

int left_bound(ll A) {
    int left = -1;
    int right = N;
    while(abs(right-left) > 1) {
        int mid = (left + right)/2;
        if(XH[mid].first > A) right = mid;
        else left = mid;
    }
    return left;
}

void init(){
    sort(XH, XH + N);
    for(int i = 0; i < N; ++i) { r_range[i] = left_bound(XH[i].first + 2*D); }
    //for(int i = 0; i < N; ++i) printf("%d\n", r_range[i]);
}

int main()
{
    scanf("%d %lld %lld", &N, &D, &A);
    for(int i = 0; i < N; ++i) scanf("%lld %lld", &XH[i].first, &XH[i].second);

    init();
    ll res = 0;
    for(int i = 0; i < N; ++i) {
        XH[i].second -= damage[i];
        ll k = (max(0LL, XH[i].second) + A - 1)/A;
        res += k;
        damage[i] += A*k;
        damage[r_range[i] + 1] -= A*k;
        damage[i+1] += damage[i];
    }
    printf("%lld\n" , res);
    return 0;
}

Measured memory_bytes: 5760
N, K = map(int, input().split())
p = list(map(int, input().split()))
S = [0]*(N-K+1)
for i in range(K):
    S[0]+=p[i]+1
for i in range(1, N-K+1):
    S[i] = S[i-1]+p[K+i-1]+1-(p[i-1]+1)
print(max(S)/2)


Measured memory_bytes: 71792
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

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

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

}

use input::*;

fn main() {
    let (n, a): (usize, usize);
    input!(n, a);
    let v = input_vector::<usize>();
    let mut dp = vec![vec![vec![0; a * n + 1]; n + 1]; n + 1];
    dp[0][0][0] = 1;

    for i in 0..n + 1 {
        for j in 0..n + 1 {
            for k in 0..a * n + 1 {
                if i == 0 && j == 0 && k == 0 {
                    dp[i][j][k] = 1;
                } else if i >= 1 && k < v[i - 1] {
                    dp[i][j][k] = dp[i - 1][j][k];
                } else if i >= 1 && j >= 1 && k >= v[i - 1] {
                    dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - v[i - 1]];
                } else {
                    dp[i][j][k] = 0;
                }
            }
        }
    }

    let mut ans = 0_u64;
    for i in 1..n + 1 {
        ans += dp[n][i][i * a];
    }
    p(ans);
}

Measured memory_bytes: 67836
W, H, N = map(int, input().split())
area = [[0]*W for _ in range(H)]
x, y, a = [], [], []
for _ in range(N):
    xi, yi, ai = map(int, input().split())
    x.append(xi)
    y.append(yi)
    a.append(ai)


def show(area):
    for line in area:
        print(line)
    print("-----")


for i in range(N):
    # print("({}, {}, {})".format(x[i], y[i], a[i]))
    if a[i] == 1:
        for j in range(H):
            for k in range(x[i]):
                area[j][k] = 1
    if a[i] == 2:
        for j in range(H):
            for k in range(x[i], W):
                area[j][k] = 1
    if a[i] == 3:
        for j in range(H-y[i], H):
            for k in range(W):
                area[j][k] = 1
    if a[i] == 4:
        for j in range(0, H-y[i]):
            for k in range(W):
                area[j][k] = 1
    # show(area)
ans = 0
for i in range(H):
    for j in range(W):
        if area[i][j] == 0:
            ans += 1
print(ans)


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;

int main(){
  int n; cin >> n;

  bool flag = false;
  repm(i,1,10){
    if(n/i < 10 && n%i == 0){
      flag = true;
      break;
    }
  }

  cout << (flag ? "Yes":"No") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int N, sum=0;
	cin >> N;
	for(int i=1; i<=N; i++)
	{
		if(i%3 == 0 && i%5 == 0 )
		{
			continue;
		}
		else if(i%3 == 0)
			continue;
		else if(i%5 == 0)
			continue;
		else{
			sum += i;
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 3632
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N = int(readline())
X = readline().rstrip()
X = X[::-1]

C = X.count("1")

if C == 0:
    for i in range(N):
        print(1)
    exit()

if C == 1:
    # modC+1を求める
    Cp = [0]*(N+1)

    Cp[0] = 1
    for i in range(N):
        Cp[i+1] = Cp[i]*2%(C+1)
    sumcp = 0

    for i in range(N):
        if X[i] == "1":
            sumcp = (sumcp+Cp[i])%(C+1)


    # 1回操作を行うとmodC+1のときC以下、modC-1のときC-2以下になるのでそこまで前計算する

    List = [0]*(N+1)

    for i in range(1,N+1):
        # 立ってるbit数を数える
        cnt = 0
        for j in range(20):
            if i>>j&1:
                cnt += 1
        List[i] = List[i%cnt]+1

    ans = [0]*N

    for i in range(N):
        if X[i] == "1":# 0にするのでmodC-1
            ans[N-1-i] = 0
        else:# 0->1にするのでmodC+1
            a = (sumcp + Cp[i])%(C+1)
            ans[N-1-i] = List[a]+1
    for anss in ans:
        print(anss)

    exit()




# modC+1とmodC-1を求める
Cp = [0]*(N+1)
Cm = [0]*(N+1)

Cp[0] = 1
Cm[0] = 1

if C == 2:
    Cm[0] = 0

for i in range(N):
    Cp[i+1] = Cp[i]*2%(C+1)
    Cm[i+1] = Cm[i]*2%(C-1)
sumcp = 0
sumcm = 0

for i in range(N):
    if X[i] == "1":
        sumcp = (sumcp+Cp[i])%(C+1)
        sumcm = (sumcm+Cm[i])%(C-1)


# 1回操作を行うとmodC+1のときC以下、modC-1のときC-2以下になるのでそこまで前計算する

List = [0]*(N+1)

for i in range(1,N+1):
    # 立ってるbit数を数える
    cnt = 0
    for j in range(20):
        if i>>j&1:
            cnt += 1
    List[i] = List[i%cnt]+1

ans = [0]*N

for i in range(N):
    if X[i] == "1":# 0にするのでmodC-1
        a = (sumcm - Cm[i])%(C-1)
        ans[N-1-i] = List[a]+1
    else:# 0->1にするのでmodC+1
        a = (sumcp + Cp[i])%(C+1)
        ans[N-1-i] = List[a]+1
for anss in ans:
    print(anss)






Measured memory_bytes: 80500
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] A = new int [N];
        boolean [] boo = new boolean[N];
        for(int i=0; i<N; i++)A[i] = sc.nextInt()-1;
        int ans=0;
        int tmp = 0;
        while(tmp!=1){
            tmp = A[tmp];
            if(boo[tmp]){
                ans=-1;
                break;
            }
            boo[tmp]=true;
            ans++;
        }
        System.out.println(ans);
    }
}


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

using namespace std;

struct DATA{
  string s;
  int t;
  bool is;
  DATA(): s(){ t=0; is=false; }
};

void input1(DATA* d){
  int w, t, m, s;
  cin >> d->s >> w >> t;
  m = t/100;
  s = t - 100*m;
  d->t = 24*60*w + 60*m + s;
}

void input2(vector<DATA>* d){
  string s;
  cin >> s;
  for(vector<DATA>::iterator i=d->begin(); i!=d->end(); ++i){
    if(i->s == s){
      i->is = true;
      return;
    }
  }
}

bool comp_time(const DATA& a, const DATA& b){
  if(a.t != b.t) return a.t < b.t;
  return a.is;
}

int solve(vector<DATA>& data){
  sort(data.begin(), data.end(), comp_time);
  int n=0, t=0;
  bool f=false;
  for(int i=0; i<data.size(); ++i){
    if(t <= data[i].t){
      ++n;
      t = data[i].t + 30;
      f = data[i].is;
    }else{
      if(f && data[i].is) return -1;
      if(data[i].is){
	t = data[i].t + 30;
	f = true;
      }
    }
  }
  return n;
}

int main(){
  int n, m;
  string s;
  while(1){
    cin >> n;
    if(!n) break;
    vector<DATA> data(n, DATA());
    for(int i=0; i<n; ++i) input1(&data[i]);
    cin >> m;
    for(int i=0; i<m; ++i) input2(&data);
    cout << solve(data) << endl;
  }
  return 0;
}

Measured memory_bytes: 1260
#include<iostream>

using namespace std;

int main()
{
	int N,M,C;
	int A[20+1][20+1],B[20+1];
	int ans = 0;

	cin >> N >> M >> C;

	for(int i=0;i<M;i++)
	{
		cin >> B[i];
	}

	for(int i=0;i<N;i++)
	{
		for(int j=0;j<M;j++)
		{
			cin >> A[i][j];
		}
	}

	for(int i=0;i<N;i++)
	{
		int sum = C;
		for(int j=0;j<M;j++)
		{
			sum += (A[i][j]*B[j]);
		}
		if(sum > 0)ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
def inpl(): return [int(i) for i in input().split()]
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

N, M = inpl()
gcdnm = gcd(N, M)
S = input()
T = input()
S = ''.join([S[i*(N//gcdnm)] for i in range(gcdnm)])
T = ''.join([T[i*(M//gcdnm)] for i in range(gcdnm)])
if S == T:
    print(N*M//gcdnm)
else:
    print(-1)

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

int main(){
  string s;
  cin >> s;
  int min1 = 1000;
  for(int i=0;i<s.size()-2;i++){
    int num = (s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
    min1 = min(abs(753-num),min1);
  }
  cout << min1 << endl;
}
 

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

int main()
{
    int n, t;
    unsigned long bit = 0;
    char c;

    cin >> n;

    while (n--) {
        cin >> c >> t;
        bit |= 1UL << ((c % 14 - 1) % 4) * 13 + t - 1;
        // bitset<52> debug(bit);
        // cout << c << t << "\t" << debug << endl;
    }

    for (n = 0; n < 4 * 13; ++n) {
        if (!(bit & 1)) {
            cout << "SHCD"[n / 13] << " " << 1 + n % 13 << endl;
        }
        bit >>= 1;
    }

    return 0;
}

Measured memory_bytes: 1160
import scala.io.StdIn

/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {

    var str = StdIn.readLine()
    val q =  StdIn.readInt()

    for(_ <- 1 to q){

      val line = StdIn.readLine().split(" ")
      val cmd = line(0)
      val a = line(1).toInt
      val b = line(2).toInt

      cmd match {
        case "replace" => {
          val p = line(3)
          str = str.patch(a,p,b - a + 1)
        }
        case "reverse" => {
          str = str.patch(a,str.substring(a,b + 1).reverse,b - a + 1)
        }
        case "print"   => println(str.substring(a,b + 1))
      }
    }
  }
}

Measured memory_bytes: 45724
#include <iostream>
#include <vector>
#include <string>


using namespace std;

int main(){
    string s;
    cin >> s;
    
    if(s[0]!='A'){
        cout << "WA";return 0;
    }
    if(s[1]>='A' && s[1]<='Z'){
        cout << "WA";return 0;
    }
    int x=0;
    for(int i=2;i<s.size()-1;i++){
        if(s[i]=='C'){x++;continue;}
        if(s[i]>='A' && s[i]<='Z'){
            cout << "WA";return 0;
        }
    }
    if(x!=1){
        cout << "WA";return 0;
    }
    if(s[s.size()-1]>='A' && s[s.size()-1]<='Z'){
        cout << "WA";return 0;
    }
    
    cout <<"AC";
    


    return 0;
}


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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s; cin >> s;
  int cnt = 0;
  for(auto c: s){
    if(c == 'o')cnt++;
  }

  if(cnt + 15 - s.length() >= 8)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int intTime = sc.nextInt();
		int intH = 0;
		int intM = 0;
		int intS = 0;

		intH = intTime / (60 * 60);
		intM = (intTime - 3600 * intH ) / 60;
		intS = (intTime - 3600 * intH ) - (intM * 60);

		System.out.println(intH + ":" + intM + ":" + intS);
	}
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    long long last = n / i;
    ans += (1 + last)*last*i/2;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3632
n = int(input())
N = list(map(int, input().split()))
cnt = 0
for i in range(1, n-1):
    if N[i - 1] < N[i] and N[i] < N[i + 1]:
        cnt = cnt + 1
    elif N[i - 1] > N[i] and N[i] > N[i + 1]:
        cnt = cnt + 1
print(cnt)


Measured memory_bytes: 3060
N = int(input())

A = list(map(int, input().split()))

DEBUG = False

cnt = 0

for i in range(1, N):
    if A[i-1]>A[i]:
        diff = A[i-1]-A[i]
        cnt += diff
        A[i] += diff
        if DEBUG:print(f"A[{i-1}] = {A[i-1]}\t,\tA[{i}] = {A[i]}\t,\tcnt = {cnt}")

print(cnt)

Measured memory_bytes: 32136
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  double p[3000];
  double dp[3000] = {};
  dp[0] = 1;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> p[i];
  }
  for(int i=0; i<n; i++){
    for(int j=i; j>=0; j--){
      dp[j+1] += dp[j] * p[i];
      dp[j] *= (1-p[i]);
    }
  }
  double sm = 0;
  for(int i=ceil(n/2.0);i<=n;i++){
	sm += dp[i];    
  }
  cout << setprecision(12) << sm << endl;
}

Measured memory_bytes: 256
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[] kuro=new int[2*A-1];
		String[] kuros=new String[2*A-1];
		String ans="";
		for(int i=0; i<2*A-1; i++) {
			kuro[i]=B-A+1+i;
			if(i==0) {
				ans=""+kuro[i];
			}else {
				ans+=" "+kuro[i];
			}
			
		}
		
		System.out.println(ans);
	  }	          	
}

Measured memory_bytes: 21844