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

using namespace std;
using ll = long long;

int main()
{
    int l, k;
    cin >> l >> k;

    vector<vector<ll>> dp(l + 1, vector<ll>(2, 0));  //0-black
    dp[0][1] = 1;
    for (int i = 0; i <= l; i++) {
        if (i + 1 <= l) {
            dp[i + 1][1] += dp[i][0];
        }
        if (i + 1 <= l) {
            dp[i + 1][0] += dp[i][1];
        }
        if (i + k <= l) {
            dp[i + k][0] += dp[i][1];
        }
    }

    ll sum = 0;
    for (int i = 1; i <= l; i++) {
        sum += dp[i][0];
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3164
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x,no,ma=0;
		int n=sc.nextInt();
		int[] rauzu=new int[53];
		for(x=1;x<=n;x++){
			String mark=sc.next();
			no = sc.nextInt();
			if(mark.equals("S")){ma=0;
		}else if(mark.equals("H")){ma=13;
		}else if(mark.equals("C")){ma=26;}
		else {ma=39;}
		rauzu[no+ma]=1;
		}
		for(x=1;x<=52;x++){
			if(rauzu[x]!=1){
				if(x<=13){System.out.println("S "+x);}
				else if(x<=26){System.out.println("H "+(x-13));}
				else if(x<=39){System.out.println("C "+(x-26));}
				else if(x<=53){System.out.println("D "+(x-39));}
			}
		}
		}
}

Measured memory_bytes: 18060
#include<cstdio>
#include<cstring>

char s[222222];
int len;
int q[222222], r;

int main() {
	scanf("%s", s);
	len = strlen(s);
	r=0;
	int rem = 0;
	for(int i=0;i<len;i++) {
		q[r++] = s[i];
		if(r>1 && q[r-1]=='T' && q[r-2]=='S') {
			rem += 2;
			r-=2;
		}
	}
	printf("%d\n", len-rem);
	
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define crap ios_base::sync_with_stdio(0);cin.tie(0)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define endl "\n"
#define int ll

using namespace std;
const int N = 100000+15;
int n,k;
int A[105];
int i;
int dp[N][2];
int solve(int stones,int turn){
    
   
	
   for( i=0;i<n;i++){
   	if(A[i]<=stones) break;
   }

   if(i==n){
   	return 1^turn;
   }
   //else return turn;

   if(dp[stones][turn]!=-1) return dp[stones][turn];
   
   dp[stones][turn]=1^turn;
   for(int i=0;i<n;i++){
      if(stones-A[i]>=0 && solve(stones-A[i], 1^turn)==turn){
      	
      		dp[stones][turn]=turn;
      		break;
      	
      }
   }
   
  return dp[stones][turn];
 

}

int32_t main()
{
   
   
    crap;
    memset(dp,-1,sizeof(dp));
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>A[i];

 	int ok = solve(k,0);
    if(ok==0) cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}

Measured memory_bytes: 6528
# import numpy as np
# import math
# import copy
from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    K = int(input())

    pre = [i for i in range(1,10)]
    now = []

    if K <= 10:
        print(K)
        sys.exit()

    count = 9

    for i in range(2,11):
        for j in pre:
            for k in range(-1,2):
                d = j % 10 + k
                if (d < 0) | (d > 9):
                    continue
                temp = j * 10 + d
                now.append(temp)
                count += 1
                if count == K:
                    print(temp)
                    sys.exit()
        pre = now



main()


Measured memory_bytes: 7540
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	static const ULL M = 1000000007;

	void Solve() {
		UL N; cin >> N;
		ULL A, B; cin >> A >> B;
		vector<ULL> S(N); rep(i, N) cin >> S[i];
		if (A > B) swap(A, B);
		vector<UL> P(N);
		{
			UL q = 0;
			rep(p, N) {
				while (q < S.size()) {
					if (S[p] - S[q] < B) break;
					q++;
				}
				P[p] = q;
			}
		}
		vector<ULL> dp(N + 1); dp[0] = 1;
		UL q = 0;
		rep(p, N) {
			dp[p + 1] += dp[P[p]];
			dp[p + 1] += dp[p];
			dp[p + 1] %= M;
			if (p != 0) if (S[p] - S[p - 1] < A) {
				dp[p + 1] += M - dp[p - 1]; dp[p + 1] %= M;
				dp[p] += M - dp[p - 1]; dp[p] %= M;
				for (; q <= p - 1; q++) dp[q] = 0;
			}
			if (p >= 2) if (S[p] - S[p - 2] < A) { cout << 0 << endl; return; }
		}
		cout << dp[N] << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <cstring>
#include <queue>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define Cout(obj) cout << obj << endl
#define Size(obj) (int)(obj).size()
#define fcout cout << fixed << setprecision(10)
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

int dp[100010];

int dfs(int i, vector<int> &vec, int L)
{
    if(dp[i] != -1) return dp[i];

    int ans = 0;

    if(vec[i] < vec[i + 1]) ans = max(ans, dfs(i + 1, vec, L));
    if(vec[i] < vec[i - 1]) ans = max(ans, dfs(i - 1, vec, L));

    return dp[i] = ans + (L - vec[i]);
}

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

    int N, L;
    cin >> N >> L;
    vector<int> vec(N);

    REP(i, N)
    {
        cin >> vec[i];
    }

    memset(dp, -1, sizeof(dp));

    int ans = 0;

    REP(i, N)
    {
        ans = max(ans, dfs(i, vec, L));
    }

    Cout(ans);

    return 0;
}


Measured memory_bytes: 6628
N = gets.to_i
S = gets.chomp
answer = []
e = S.count('E')
a = e 

for i in 0..N-1

    if S[i] == 'E'

        a -= 1
        answer[i] = i+2*a+1-e

    else

        answer[i] = i+2*a-e 

    end

end

puts answer.min

Measured memory_bytes: 4868
import java.util.Scanner;


public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();
		
		int N = 100*r + 10*g + b;
		
		if(N%4==0){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
		
	}

}


Measured memory_bytes: 20820
n = int(input())
a = list(map(int,input().split()))

aa = [0]*(n+1)

for i in range(n):
    aa[i+1] = aa[i] + a[i]

sm = sum(a)
ans = sm
for i in range(n):
    ans = min(ans,abs(sm-2*aa[i]))

print(ans)

Measured memory_bytes: 89936
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int m,n;
	if (c%b==0) m=c/b;else m=c/b+1;
	if (a%d==0) n=a/d;else n=a/d+1;
	if (m<=n) cout<<"Yes";else cout<<"No";
}

Measured memory_bytes: 3624
import bisect

n = int(input())
l = list(map(int,input().split()))

l.sort()
#print(l)
ans = 0
for i in range(n-1):
	a = l[i]
	for j in range(i+2,n):
		b = l[j]
		c = bisect.bisect_left(l,b-a+1)
		if j - c > 0:
			if i >= c:
				ans += j-i-1
			else:
				ans += j-c
		#print(i,j,c,ans)

print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

signed main() {
  ll N;
  cin >> N;
  vector<ll> A, B, C;
  rep(j, 3) {
    rep(i, N) {
      ll t;
      cin >> t;
      if (j == 0) {
        A.pb(t);
      }
      if (j == 1) {
        B.pb(t);
      }
      if (j == 2) {
        C.pb(t);
      }
    }
  }
  SORT(A);
  SORT(B);
  SORT(C);

  ll ans = 0;
  rep(i, N) {
    ll num = B[i];
    ll indexA = lower_bound(ALL(A), num) - A.begin();
    ll indexC = upper_bound(ALL(C), num) - C.begin();
    // debug(i);
    // debug(num);
    // debug(indexA);
    // debug(indexC);
    ans += indexA * (N - indexC);
  }
  COUT(ans);

  return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(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)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int a, b;
    cin >> a >> b;
    cout << max({a+b, a-b, a*b}) << endl;
    return 0;
}


Measured memory_bytes: 764
from sys import stdin
input = stdin.readline

N, M, K = map(int, input().split())
mod = 998244353


C = [-1] * (N + 1)


def comb(n, r):
    if r > n - r:
        C[r] = C[n - r]

    if r == 0:
        C[0] = 1

    if C[r] != -1:
        return C[r]
    else:
        C[r] = comb(n, r - 1) * (n + 1 - r) * pow(r, mod - 2, mod)
        C[r] %= mod
        return C[r]


ans = 0

for i in range(K + 1):
    ans += M * pow(M - 1, N - 1 - i, mod) * comb(N - 1, i)
    ans %= mod

print(ans)
# print(C)


Measured memory_bytes: 80188
#include <iostream>

using namespace std;
using llong = long long;

llong weights[100000];
llong N,K;

llong used_num(llong P){
  llong num = 0;
  llong track=0;
  llong i=0;
  for(llong j=0;j<K;++j){
    while(track+weights[i]<=P){
      track += weights[i];
      i++;
      if(i==N) return N;
    }
    track = 0;
  }
  return i;
}

int main(){
  cin >> N >> K;
  for(llong i=0;i<N;++i){
    cin >> weights[i];
  }
  llong Pl=0,Pr=1000000000;
  llong P;
  while(Pl+1<Pr){
    P = (Pl+Pr)/2;
    if(used_num(P)>=N)
      Pr = P;
    else
      Pl = P;
  }

  cout << Pr << endl;
  return 0;
}

Measured memory_bytes: 3848
n, m = [int(x) for x in input().split()]

s = input()
c = n

h = []
while True:
	d = m
	while d > 0:
		if c - d >= 0:
			if s[c - d] == '0':
				break
		d -= 1

	if d == 0:
		print(-1)
		break
	
	c -= d
	h.append(str(d))
	if c == 0:
		h.reverse()
		print(' '.join(h))
		break

Measured memory_bytes: 10100
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    i64 N, A, B;
    read(N, A, B);

    vector<i64> h(N);
    rep(i, N) read(h[i]);

    sort(all(h), greater<>());

    const auto divCeil = [](i64 a, i64 b) {
        return (a + b - 1) / b;
    };

    const auto canKill = [&](const i64 cnt) {
        i64 needCnt_A = 0;
        rep(i, N) {
            needCnt_A += divCeil(max<i64>(0, h[i] - B * cnt), A - B);
        }
        return needCnt_A <= cnt;
    };

    i64 ok = INF;
    i64 ng = 0;
    while (ok - ng > 1) {
        const i64 mid = (ok + ng) / 2;
        if (canKill(mid)) ok = mid;
        else ng = mid;
    }

    print(ok);

    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>

using namespace std;

int main(void){
	char buf[1000][33], word[33];
	int bufnum = 0, same[1000], i, smax, lmax;
	memset(same,0,sizeof(same));
	while(scanf("%s",word) != EOF){
		for(i = 0;i < bufnum;i++){
			if(!strcmp(word,buf[i])){
				same[i]++;
				break;
			}
		}
		if(bufnum == i){
			strcpy(buf[bufnum],word);
			same[bufnum++]++;
		}
	}
	smax = 0, lmax = 0;
	for(i = 0;i < bufnum;i++){
		if(smax < same[i]){
			smax = same[i];
		}
		if(lmax < strlen(buf[i])){
			lmax = strlen(buf[i]);
		}
	}
	for(i = 0;i < bufnum;i++){
		if(smax == same[i])
			printf("%s ",buf[i]);
	}
	int cnt1 = 0, cnt2 = 0;
	for(i = 0;i < bufnum;i++){
		if(lmax == strlen(buf[i]))
			cnt1++;
	}
	for(i = 0;i < bufnum;i++){
		if(lmax == strlen(buf[i])){
			printf("%s",buf[i]);
			cnt2++;
			if(cnt1 != cnt2){
				printf(" ");
			}
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1008
#include <stdio.h>
int main() {
    long long x, k, d;
    scanf("%lli%lli%lli", &x, &k, &d);
    if (x < 0) x *= -1;
    long long n1 = x / d;
    if (n1 >= k) {
        printf("%lli", x - k * d);
        return 0;
    }
    k -= n1;
    x %= d;
    if (k & 1) x = d - x;
    printf("%lli", x);
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define pb push_back
#define fi first
#define se second
 
const ll MOD = 1000000007;
const string RGB = "RGB"; 

int main() {
   int N; scanf("%d", &N);
   vector<int> a(N);
   int maxIndex = 0;
   for (int i = 0; i < N; ++i) {
      scanf("%d", &a[i]);
      if (a[i] > a[maxIndex])
         maxIndex = i;
   }
   int maxIndex2 = 0 + (maxIndex == 0);
   for (int i = 0; i < N; ++i) {
      if (i != maxIndex && a[i] >= a[maxIndex2])
         maxIndex2 = i;
   }
   for (int i = 0; i < N; ++i) {
      if (i == maxIndex) {
         printf("%d\n", a[maxIndex2]);
      } else {
         printf("%d\n", a[maxIndex]);
      }
   }
   return 0;
}

Measured memory_bytes: 2432
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pl;

#define FST first
#define SND second

const int MAX_N = 1000;                  // 10^5
// const int MAX_N = 100000;                  // 10^5
// const int MAX_N = 100000;                  // 10^5
// const int MAX_N = 1000000000;              // 10^9
// const ll  MAX_N = 1000000000000000000;     // 10^18
// const int BASE  = 1000000000 + 7;          // 10^9 + 7
// const int INFI  = 1000000000 + 7;          // 10^9 + 7
// const ll INFL  = 1000000000000000000 + 7; // 10^18 + 7

int N;
string S;

void solve() {
  int level = 0, cnt = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '(') {
      level++;
    } else {
      if (level == 0) {
        cnt++;
      } else {
        level--;
      }
    }
  }

  string ans = string(cnt, '(') + S + string(level, ')');

  cout << ans << endl;
}

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

  solve();

  return 0;
}


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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

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

    if(n >= 10)
        cout << r;
    else
        cout << r + 100 * (10 - n);

    return 0;
}


Measured memory_bytes: 256
import itertools
while True:
    n,x=map(int,raw_input().split())
    if n==0 and x==0:
        break
    a=[]
    c=0
    for i in range(n):
        a.append(i+1)
    for i in itertools.combinations(a,3):
        if sum(i)==x:
            c+=1
    print c


Measured memory_bytes: 4700
#include<bits/stdc++.h>
using namespace std;
char ch[2020][2020];
int mp[2020][2020],a[2020][2020];
int h[2020][2020],l[2020][2020],r[2020][2020];
int st[2020],top;
int n,m,ans;
int main()
{
	scanf("%d%d",&n,&m);
	ans=max(n,m);
	for (int i=1;i<=n;++i) scanf("%s",ch[i]+1);
	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j)
		{
			if (ch[i][j]=='#') mp[i][j]=1;
			else mp[i][j]=0;
		}
	for (int i=1;i<n;++i)
		for (int j=1;j<m;++j)
			a[i][j]=1- (mp[i][j]^mp[i+1][j]^mp[i][j+1]^mp[i+1][j+1]);
	--n; --m;
	
/*	for (int i=1;i<=n;++i)
	{
		for (int j=1;j<=m;++j) printf("%d ",a[i][j]);
		printf("\n");
	}
	printf("\n");*/

	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j)
		{
			if (a[i][j]==0) h[i][j]=0;
			else h[i][j]=h[i-1][j]+1;
		}
	for (int i=1;i<=n;++i)
	{
		top=0;
		for (int j=1;j<=m;++j)
		{
			while (top && h[i][st[top]]>=h[i][j]) --top;
			if (top) l[i][j]=st[top]+1;
			else l[i][j]=1;
			++top; st[top]=j;
		}

		top=0;
		for (int j=m;j>=1;--j)
		{
			while (top && h[i][st[top]]>=h[i][j]) --top;
			if (top) r[i][j]=st[top]-1;
			else r[i][j]=m;
			++top; st[top]=j;
		}
	}

	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j)
			ans=max(ans,(r[i][j]-l[i][j]+2) * (h[i][j]+1));
	printf("%d\n",ans);
	return 0;
}

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> a(H, vector<char>(W));
    rep(i, H) {
        rep(j, W) {
            cin >> a.at(i).at(j);
        }
    }
    rep(i, W + 2) {
        cout << '#';
    }
    cout << endl;
    rep(i, H) {
        cout << '#';
        rep(j, W) {
            cout << a.at(i).at(j);
        }
        cout << '#' << endl;
    }
    rep(i, W + 2) {
        cout << '#';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int S[13], H[13], C[13], D[13];
    for(int i=0; i<13; i++){
        S[i] = i+1;
        H[i] = i+1;
        C[i] = i+1;
        D[i] = i+1;
    }
    int n;
    cin >> n;
    char mark; int num;
    for(int i=0; i<n; i++){
        cin >> mark >> num;
        if(mark == 'S') S[num-1] = -1;
        else if(mark == 'H') H[num-1] = -1;
        else if(mark == 'C') C[num-1] = -1;
        else if(mark == 'D') D[num-1] = -1;
    }
    for(int i=0; i<4; i++){
        if(i == 0){
            for(int j=0; j<13; j++){
                if(S[j] == j+1) cout << "S " << j+1 << endl;
            }
        }else if(i == 1){
            for(int j=0; j<13; j++){
                if(H[j] == j+1) cout << "H " << j+1 << endl;
            }
        }else if(i == 2){
            for(int j=0; j<13; j++){
                if(C[j] == j+1) cout << "C " << j+1 << endl;
            }
        }else if(i == 3){
            for(int j=0; j<13; j++){
                if(D[j] == j+1) cout << "D " << j+1 << endl;
            }
        }
    }
}


Measured memory_bytes: 3024
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,i,j;
    int n0=0;
    int n1=0;
    string p;
    cin>>p;
    c=p.size();
    for(i=0;i<c;i++){
        if(i%2==0){
            if(p[i]=='1')
            n0++;
            else
            n1++;
        }
        else if(p[i]=='1')
        n1++;
        else
        n0++;
    }
    
    if(n1<n0)
    cout<<n1<<endl;
    else
    cout<<n0<<endl;
}


Measured memory_bytes: 512
n = int(input())
XYH = [list(map(int, input().split())) for _ in range(n)]
  
XYH.sort(key=lambda x:x[2],reverse=True)
sx = XYH[0][0]
sy = XYH[0][1]
sh = XYH[0][2]
  
for i in range(0,101):
  for j in range(0,101):
    anss = sh + abs(sx-i) + abs(sy-j)
    for k in range(n):
      if XYH[k][2] == max(anss - abs(XYH[k][0]-i) - abs(XYH[k][1]-j),0):
        pass
      else:
        break
    else:
      an = [i, j, anss]
      print(*an)
      exit()



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){long long n,j,i,p,r=0;
cin>>n;
for(i=sqrt(n);i>=1;i--){
    if(n%i==0){
        p=i;break;
    }
}j=n/p;
cout<<p+j-2;
    
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) {
        cin >> a[i];
        --a[i];
    }

    int cnt = 0, now = 0;
    while (cnt <= N) {
        now = a[now];
        ++cnt;

        if (now == 1) {
            cout << cnt << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 640
/*
	Author: Luis Manuel D�az Bar�n (LUISMO)
	Problem:
	Online Judge:
	Idea:
*/
#include<bits/stdc++.h>
// Types
#define ll long long
#define ull unsigned long long
// IO
#define sf scanf
#define pf printf
#define mkp make_pair
#define fi first
#define se second
#define endl "\n"

using namespace std;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll inf = 1e16 + 3;
const int mod = 1e9 + 7;
const int lim = 2e5 + 2;

ll N, W;

ll dp[lim];
ll vi[lim];
ll wi[lim];
bool mark[lim];

void solve()
{
    cin >> N >> W;

    for(int i = 1; i <= N; i++)
    {
        cin >> wi[i] >> vi[i];
    }

    ll answ = 0;

    mark[0] = true;
    for(int item = 1; item <= N; item++)
    {
        for(int w = W; w > 0; w--)
        {
            if(w - wi[item] >= 0 && mark[w - wi[item]])
            {
                dp[w] = max(dp[w], vi[item] + dp[w - wi[item]]);
                mark[w] = true;

                answ = max(answ, dp[w]);
            }
        }
    }
    cout << answ;
}

void fastIO()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
}

void IO()
{
	if(fopen("d:\\lmo.in","r") != NULL)
	{
		freopen("d:\\lmo.in","r",stdin);
	}
	else if(fopen("/media/Beijing/lmo.in","r") != NULL)
	{
		freopen("/media/Beijing/lmo.in", "r", stdin);
	}
}

int main()
{
	IO();

	fastIO();

	solve();
}


Measured memory_bytes: 2432
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.A
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			int a = cin.NextInt();
			if (a >= 3200) Console.WriteLine(cin.Next());
            else Console.WriteLine("red");

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 13140
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

while 1:
    n = int(input())
    if n == 0:
        break
    ans_1 = len(primes(2*n))
    ans_2 = len(primes(n))
    print(ans_1-ans_2)


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

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

int main()
{
	while (true) {
		int t, n;
		cin >> t >> n;
		
		if (t == 0 && n == 0) {
			break;
		}

		int map[geta * 2][geta * 2];
		for (int i = 0; i < geta * 2; i++) {
			for (int j = 0; j < geta * 2; j++) {
				map[i][j] = 0;
			}
		}

		for (int i = 0; i < n; i++) {
			int x, y;
			cin >> x >> y;

			map[y + geta][x + geta] = 1;
		}

		int startx, starty;
		cin >> startx >> starty;

		int ans = 1;
		int now = 0;
		queue<pair<int, int>> q;
		q.push({ starty + geta,startx + geta });
		map[starty + geta][startx + geta] = 1;

		while (q.empty() == false) {
			unsigned int count = q.size();

			while (count > 0) {
				pair<int, int> temp = q.front();
				q.pop();
				count--;

				for (int i = 0; i < 6; i++) {
					int ny = temp.first + dy[i];
					int nx = temp.second + dx[i];

					/*
					if (ny >= 0 && ny < 61 && nx >= 0 && nx < 61 && map[ny][nx] == 0) {
						q.push({ ny,nx });
						map[ny][nx] = 1;
						ans++;
					}
					*/

					if (ny >= 0 && ny < geta * 2 && nx >= 0 && nx < geta * 2 && map[ny][nx] == 0) {
						q.push({ ny,nx });
						map[ny][nx] = 1;
						ans++;
					}
				}
			}

			now++;
			if (now == t) {
				break;
			}
		}

		cout << ans << endl;
	}

	return 0;
}

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

void main_()
{
    ll N, X;
    vector<ll> xs;
    cin >> N >> X;
    copy_n(istream_iterator<ll>(cin), N, back_inserter(xs));

    auto ans = accumulate(
        begin(xs), end(xs),
        abs(X - xs.front()),
        [X](auto acc, auto n) {
            return __gcd(acc, abs(X - n));
        });

    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 1400
def combination(n, x):
    count = 0
    for i in range(1, n-1):
        for j in range(i+1, n):
            if x - i - j in range(j+1, n+1):
                count += 1
    print(count)


n, x = 1, 1
while n != 0 or x != 0:
    n, x = map(int, input().split())
    if n != 0 or x != 0:
        combination(n, x)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long int
int main()
{
 vector<int>v;
 int a;
 for(int i=1;i<=3;i++)
 {
     cin>>a;
     v.pb(a);
 }
 sort(v.begin(),v.end());
 cout<<0.5*v[0]*v[1]<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

//The Most Powerful Spell
public class Main{

	static class E{
		public int s;
		public int t;
		public String spell;
		public E(int s, int t, String spell) {
			super();
			this.s = s;
			this.t = t;
			this.spell = spell;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int LEN = 6*39*2;
		while(true){
			int n = sc.nextInt();
			int a = sc.nextInt();
			int s = sc.nextInt();
			int g = sc.nextInt();
			if((n|a|s|g)==0)break;
			List<E> edge = new ArrayList<E>();
			for(int i=0;i<a;i++){
				edge.add(new E(sc.nextInt(), sc.nextInt(), sc.next()));
			}
			String[][] dp = new String[n][LEN+1];
			boolean[][] flag = new boolean[n][LEN+1];
			String[] ans = new String[n];
			Arrays.fill(ans, "");
			for(int i=0;i<n;i++)for(int j=0;j<=LEN;j++)dp[i][j]=null;
			dp[s][0] = "";
			flag[s][0] = true;
				for(int j=0;j<=LEN;j++){
					for(int i=0;i<n;i++){
						if(flag[i][j]){
							flag[i][j] = false;
							for(E e:edge){
								if(e.s == i){
									String next = dp[i][j] + e.spell;
									if(next.length() <= LEN && (dp[e.t][next.length()]==null || next.compareTo(dp[e.t][next.length()])<0)){
										flag[e.t][next.length()] = true;
										dp[e.t][next.length()] = next;
										if(ans[e.t].equals("") || next.compareTo(ans[e.t]) < 0){
											ans[e.t] = next;
										}
									}
								}
							}
						}
					}
				}
			System.out.println(ans[g].equals("")||ans[g].length()>=(n-1)*6?"NO":ans[g]);
		}
	}
}

Measured memory_bytes: 29000
#include<stdio.h>

 int main()
{
  int n, w, i, j, y=0, l, m, k;
  scanf("%d", &n);
  int data[n];
  char c[12];

  for(i = 0; i < n; i++){
    scanf("%s %d", c, &w);

    if(c[0] == 'i'){
      data[i]=w;
    }

    else if(c[6] == 'F'){
      i -= 2;
      n -= 2;
    }

    else if(c[6] == 'L'){
      i--;
      n--;
      y++;
    }

    else{
      i--;
      n--;
      l=0;
      for(j = i; j >= 0; j--){

    if(l > 0) break;

    if(w == data[j]){
      k = 0;
      m = i-j;
      l++;
      while(m!=k++)
    data[j + k - 1]=data[j + 1 + k - 1];
      i--;n--;
    }
      }
    }
  }
  for(i = 0; i < n-y; i++){
    if(i == n-y-1)
      printf("%d\n",data[n-1-i]);
    else
      printf("%d ",data[n-1-i]);
  }
  return 0;
}

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

namespace Miscelleneous {
   class Program {
      public static int cin() { return int.Parse(Console.ReadLine()); }
      public static int[] cins() {
         string[] ss = Console.ReadLine().Split(' ');
         int[] Res = new int[ss.Length];
         for (int i = 0; i<ss.Length; i++) Res[i]=int.Parse(ss[i]);
         return Res;
      }
      public static void print(object s) { Console.WriteLine(s.ToString()); }
      static void Main(string[] args) {
         var N = cin();
         int[] ss;
         for (int i = 0; i<N; i++) {
            ss=cins();
            print(Build(ss)?"YES":"NO");
         }
      }

      static bool Build(int[] input) {
         var X = new Queue<int>();
         foreach (int x00 in input) X.Enqueue(x00);
         Stack<int> S1=new Stack<int>(),S2=new Stack<int>();
         S1.Push(X.Dequeue());
         bool b1,b2,res=true;
         while (X.Count>0) {
            b1=S1.Peek()<X.Peek();
            b2=S2.Count==0||S2.Peek()<X.Peek();
            if (!b1&&!b2) { res=false; break; 
            } else if (b1&&!b2) S1.Push(X.Dequeue());
            else if (!b1&&b2) S2.Push(X.Dequeue());
            else if (S2.Count==0) S1.Push(X.Dequeue());
            else if (S2.Peek()<S1.Peek()) S1.Push(X.Dequeue());
            else S2.Push(X.Dequeue());
         }
         return res;
      }
   }
}

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

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		tree T=new tree(n);
		
		for(int i=0;i<n;i++) {
			int u=Integer.parseInt(in.next()), k=Integer.parseInt(in.next());
			int b=-1;
			for(int j=0;j<k;j++) {
				int c=Integer.parseInt(in.next());
				T.T[c].p=u;
				if(j==0) {
					T.T[u].l=c;
				}
				else {
					T.T[b].r=c;
				}
				b=c;
			}
		}
		
		PrintWriter out=new PrintWriter(System.out);
		for(int i=0;i<n;i++) {
			out.printf("node %d: parent = %d, ", i, T.T[i].p);
			out.printf("depth = %d, %s, ", T.getDepth(i, 0), T.getCat(i));
			out.println(T.getChilds(i));
		}
		out.flush();
	}

}

class treeNode{
	int p=-1,l=-1,r=-1;
}

class tree{
	static treeNode T[];
	
	tree(int n){
		T=new treeNode[n];
		for(int i=0;i<n;i++) {
			T[i]=new treeNode();
		}
	}
	
	static void insert(int u,int c) {
		T[c].p=u;
		if(T[u].l==-1)T[u].l=c;
		else {
			int i=T[u].l;
			while(true) {
				if(T[i].r==-1) {
					T[i].r=c;
					break;
				}
				i=T[i].r;
			}
		}
	}
	
	static int getDepth(int i,int d) {
		if(T[i].p!=-1) d=getDepth(T[i].p,++d);
		return d;
	}
	
	static String getCat(int u) {
		String str;
		if(T[u].p==-1)str="root";
		else if(T[u].l==-1)str="leaf";
		else str="internal node";
		return str;
	}
	
	static List<Integer> getChilds(int u){
		List<Integer> c=new ArrayList<>();
		if(T[u].l!=-1) {
			int i=T[u].l;
			while(i!=-1) {
				c.add(i);
				i=T[i].r;
			}
		}
		return c;
	}
}



Measured memory_bytes: 199196
#include<bits/stdc++.h>
#include <iostream>
#include <algorithm>
using namespace std;
unordered_map<long long,long long>m;
#define MAX 10000001
int main()
{
    long long n,k,a[100005],sum=0,i;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(a[0]>k)
    {
        sum=a[0]-k;
        a[0]-=sum;
    }
    for(i=1;i<n;i++)
    {
        if(a[i]+a[i-1]>k)
        {
            sum+=(a[i]+a[i-1]-k);
            a[i]-=(a[i]+a[i-1]-k);
        }
        //cout<<sum<<" "<<endl;
    }
    cout<<sum;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int count;
  int p=0;
  int y=0;
  int w=0;
  int g=0;
  cin >> count;
  for(int i=0;i<count;i++){
    string word;
    cin >> word;
    if (word == "P"){
      p = 1;
    }
    if (word == "Y"){
      y = 1;
    }
    if (word == "W"){
      w = 1;
    }
    if (word == "G"){
      g = 1;
    }
  }
  if (p+y+w+g == 3){
    cout << "Three" <<endl;
  }else if (p+y+w+g == 4){
    cout << "Four" <<endl;
  }
 
 
   	
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N, M;
    cin >> N >> M;
    priority_queue<ll> pque;
    rep(i, N) {
        ll a;
        cin >> a;
        pque.push(a);
    }
    rep(i, M) {
        ll a = pque.top();
        pque.pop();
        pque.push(a / 2);
    }
    ll ans = 0;
    while (!pque.empty()) {
        ans += pque.top();
        pque.pop();
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <utility>
#include <stdint.h>

using namespace std;

int main()
{
  int N, K, S;
  cin >> N >> K >> S;

  for (int n=0; n<K; ++n)
    cout << S << ' ';
  for (int n=K; n<N; ++n)
    cout << (S==1000000000 ? 999999999 : 1000000000) << ' ';
  cout << endl;

  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N+1), B(N);
    rep(i, N+1) cin >> A[i];
    rep(i, N) cin >> B[i];

    ll ans = min(A[0], B[0]);
    B[0] = max(0LL, B[0]-A[0]);

    for (int i=1; i<=N; ++i) {
        if (i == N) {
            ans += min(A[i], B[i-1]);
        }
        else {
            ll tmp = B[i-1] + B[i];
            ans += min(A[i], tmp);
            B[i] = max(0LL, B[i] - max(0LL, A[i]-B[i-1]));
        }
    }

    cout << ans << endl;

}


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

int W[312345];
int E[312345];
int N;
string S;
int main () {
    cin >> N >> S;
    int ans = 99999999;
    for(int i=0; i<N; i++) W[i+1] += (S[i] =='W'?W[i]+1:W[i]);
    for(int i=N-1; i>0; i--) E[i-1] += (S[i] =='E'?E[i]+1:E[i]);
    for(int i=0; i<N; i++) ans = min(ans,W[i] + E[i]);

    cout << ans << endl;
    return 0;
}


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

int main() {

	int a, b, c, f = 0;
	cin >> a >> b >> c;
	for (int x = a; x <= b; x++) {
		if (c%x == 0) {
			f++;
		}
	}
	cout<<f<<endl;

	return 0;

}

Measured memory_bytes: 3068
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <string>
using namespace std;

#define COLOR_SIZE 200000LL+1

long long ishi(long long* C, long long N, long long start, long long* D, long long* E){
  if(D[start] != 0){
    return D[start];
  }

  long long result;
  if(start >= N-1){
    result = 1;
  }else{
    long long tmpC = C[start];

    if(E[start] != 0 && E[start] != start+1){
      result = (ishi(C, N, start+1, D, E) + ishi(C, N, E[start], D, E)) % 1000000007LL;

    }else{
      result = ishi(C, N, start+1, D, E);
    }


  }

  //cout << "from " << start << ":" << result << "\n";
  //cout << "E[" << start << "]:" << E[start] << "\n";
  D[start] = result;
  return result;
}


int main(){
  long long N;
  cin >> N;

  long long C[N+1] = {}; // 色
  long long D[N+1] = {}; // 動的計画
  long long E[N+1] = {}; // 直後の同色のインデックス
  long long F[COLOR_SIZE] = {}; // 色ごとの最新のインデックス

  for(int i=1;i<=N;i++){
    cin >> C[i];
    if(F[C[i]] != 0){
      E[F[C[i]]] = i;
    }
    F[C[i]] = i;
  }

  long long result = ishi(C, N, 1, D, E);

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


Measured memory_bytes: 22144
#include <bits/stdc++.h>
using namespace std;
 
int main (){
 
  int n;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++) cin >> a[i];
  
  int sum=0, maxj=0;
  for(int i=0; i<n; i++){
    int p = a[i];
  	maxj = max(maxj,p);
    sum += p;
  }
  if(maxj*2 < sum){
  	cout << "Yes" << endl;
  }
  else {
  	cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int x,y,gcd,m,n;
  scanf("%d %d",&x,&y);
  if(x >= y) {
    m = x;
    n = y;
  }
  else {
    m = y;
    n = x;
  }
  while(n != 0) {
    gcd = n;
    n = m % n;
    m = gcd;
  }
  printf("%d\n",m);
  return 0;
}

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

const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int w, h, board[101][101], xg, yg;
bool visited[101][101];

bool search(int x, int y, int c) {
    if (x == xg && y == yg) {
        return true;
    }
    visited[y][x] = true;
    for (int i = 0; i < 4; i++) {
        int px = x + dx[i], py = y + dy[i];
        if (px < 1 || w < px || py < 1 || h < py) continue;
        if (visited[py][px] || board[py][px] != c) continue;
        if (search(px, py, c)) return true;
    }
    return false;
}

int main() {
    int i, j, xs, ys, n, c, d, x, y;

    while (cin >> w >> h, w) {
        for (i = 1; i <= h; i++) {
            for (j = 1; j <= w; j++) {
                board[i][j] = 0;
                visited[i][j] = false;
            }
        }
        cin >> xs >> ys;
        cin >> xg >> yg;
        cin >> n;
        while (n--) {
            cin >> c >> d >> x >> y;
            int bw = d==0? 4: 2;
            int bh = 6 - bw;
            for (i = y; i < y+bh; i++) {
                for (j = x; j < x+bw; j++) {
                    board[i][j] = c;
                }
            }
        }

        if (board[ys][xs] == board[yg][xg] &&
            search(xs, ys, board[ys][xs])) {
            cout << "OK";
        }
        else {
            cout << "NG";
        }
        cout << endl;
    }
    return 0;
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loop2(num) for (lli j = 0 ; j < num ; j ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }
#define looppu(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . push_back (x) ;}
#define loopin(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . insert (x) ;}

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back ()
#define pof pop_front ()

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

signed main ()
{
    fastio
    ll a ; cin >> a ;
    cout << ceil(a / 2.0) << endl ;
    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



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

using namespace std;


#define PI 3.14159265
#define int long long



main(){

	int a, b, c; cin >> a >> b >> c;

	set <int> s;
	s.insert(a);
	s.insert(b);
	s.insert(c);

	cout << (s.size() == 2 ? "Yes" : "No") << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define FOR(i, n) for (int(i) = 0; (i) < n; (i)++)
#define PI (3.141592653589)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
#define MOD 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
    cout.precision(10);
    // Those who cannot acknowledge themselves, will invariably fail
    int a, b, c;
    cin >> a >> b >> c;
    int cap = a - b;
    c -= cap;
    cout << max(0, c);

    return 0;
}

Measured memory_bytes: 256
def main() -> None:
    S = input()
    a = S[:2]
    b = S[2:]
    if ('00' < a < '13') and ('00' < b < '13'):
        print("AMBIGUOUS")
    elif '00' < a < '13':
        print("MMYY")
    elif '00' < b < '13':
        print("YYMM")
    else:
        print("NA")


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cmath>

using namespace std;

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

typedef long double D;
typedef pair<D, D> P;

#define sq(x) ((x) * (x))
typedef vector<D> Vector;
typedef vector<Vector> Matrix;
 
const D EPS = 1e-8;

Vector gauss_jordan(const Matrix &A, const Vector &b){
  int n = A.size();
  Matrix B(n, Vector(n+1));
  rep(i, n){
    rep(j, n){
      B[i][j] = A[i][j];
    }
  }
 
  rep(i, n){
    B[i][n] = b[i];
  }
 
  rep(i, n){
    int pivot = i;
    REP(j, i, n){
      if(abs(B[j][i]) > abs(B[pivot][i])){
	pivot = j;
      }
    }
 
    swap(B[i], B[pivot]);
 
    if(abs(B[i][i]) < EPS)return Vector();
 
    REP(j, i+1, n+1)B[i][j] /= B[i][i];
    rep(j, n){
      if(i != j){
	REP(k, i+1, n+1){
	  B[j][k] -= B[j][i] * B[i][k];
	}
      }
    }
  }
 
  Vector x(n);
  rep(i, n)x[i] = B[i][n];
  return x;
}

int main() {
  int n;
  cin >> n;
  vector<P> vp(n);
  rep (i, n) cin >> vp[i].first >> vp[i].second;
  Matrix M;
  rep (i, 3) {
    Vector V(3);
    M.push_back(V);
  }
  Vector V(3);
  rep (i, n) {
    M[0][0] += 2 * vp[i].first * vp[i].first;
    M[0][1] += 2 * vp[i].first * vp[i].second;
    M[0][2] += 2 * vp[i].first;
    V[0] -= 2 * vp[i].first * (sq(vp[i].first) + sq(vp[i].second));
    M[1][0] += 2 * vp[i].second * vp[i].first;
    M[1][1] += 2 * vp[i].second * vp[i].second;
    M[1][2] += 2 * vp[i].second;
    V[1] -= 2 * vp[i].second * (sq(vp[i].first) + sq(vp[i].second));
    M[2][0] += 2 * vp[i].first;
    M[2][1] += 2 * vp[i].second;
    M[2][2] += 2;
    V[2] -= 2 * (sq(vp[i].first) + sq(vp[i].second));
  }
  V = gauss_jordan(M, V);
  printf("%.12Lf %.12Lf %.12Lf\n", V[0], V[1], V[2]);
  return 0;
}

Measured memory_bytes: 2324
#include <bits/stdc++.h>
#define ll long long int
#define INF 1000000000000
#define MOD 1000000007
#define DEBUG(x) cerr<<'>'<<#x<<':'<<x<< endl
using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long double L;
    cin >> L;
    long double ans = L * L * L, div = 27.0;
    ans =  ans/div;
    printf("%.6Lf\n", ans);    
    return 0;
}


Measured memory_bytes: 256
"""
重さと価値がそれぞれw_i,v_iであるようなn個の品物がある.
これらの品物の中から, 重さの総和がWを超えないように選んだ時の,
価値の総和の最大値を求めよ.
1<=n<=100, 1<=w_i<=10^7, 1<=v_i<=100, 1<=W<=10^9
"""
#-------------------------------------------------------------------------------

#入力
INF = 2000000000
n, W = map(int, input().split())
w = [0]*n
v = [0]*n
for i in range(n):
    w[i], v[i] = map(int, input().split())
V = sum(v)
dp = [[INF for i in range(V + 1)] for j in range(n + 1)]

#ここからメイン
dp[0][0] = 0
for i in range(n):
    for j in range(V + 1):
        if j < v[i]:
            dp[i + 1][j] = dp[i][j]
        else:
            dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i])
ans = 0
for i in range(V + 1):
    if dp[n][i] <= W:
        ans = i
print(ans)


Measured memory_bytes: 171120