akhauriyash/Code-Regression huggingface dataset:
w, h, n = map(int, input().split())
li = []

for i in range(n):
    li.append([int(i) for i in input().split()])

flag = [[0 for i in range(w)] for j in range(h)]
count = 0

for i in range(n):
    if(li[i][2] == 1):
        for x in range(li[i][0]):
            for y in range(h):
                flag[y][x] = 1
    elif(li[i][2] == 2):
        for x in range(li[i][0], w):
            for y in range(h):
                flag[y][x] = 1
    elif(li[i][2] == 3):
        for x in range(w):
            for y in range(li[i][1]):
                flag[y][x] = 1
    elif(li[i][2] == 4):
        for x in range(w):
            for y in range(li[i][1], h):
                flag[y][x] = 1

for x in range(w):
    for y in range(h):
        if(flag[y][x] == 0):
            count+=1

print(count)

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
bool chmax(T &a, const T &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

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

  int n;
  cin >> n;
  int a = n % 10;

  if (a == 2 || a == 4 || a == 5 || a == 7 || a == 9)
    cout << "hon\n";
  else if (a == 3)
    cout << "bon\n";
  else
    cout << "pon\n";
  return 0;
}

Measured memory_bytes: 3652
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long ll;

#define pc __builtin_popcount

void rec(int A, int B, int mask) {
    debug() << imie(A) imie(B) imie(mask);
    if(pc(mask) == 1) {
        assert(pc(A ^ B) == 1);
        printf("%d %d ", A, B);
        return;
    }
    // for(int i = 0; i < 17; ++i) {
        // if((A ^ (1 << i)) == B) {
            // printf("%d %d ", A, B);
            // return;
        // }
    // }
    for(int i = 0; i < 17; ++i) {
        if((mask & (1 << i)) && (((A & (1 << i)) != (B & (1 << i))))) {
            int m2 = mask ^ (1 << i);
            int s = m2;
            while(true) {
                // debug() << imie(A) imie(B) imie(i) imie(m2) imie(s);
                // debug() << imie(s) imie(B & m2) imie(A & m2) imie(pc(s)) imie(pc(A&m2));
                if((B & m2) != s && (A & m2) != s && pc(s) % 2 != pc(A & m2) % 2) {
                    int tmp = (A ^ (A & m2)) | s;
                    rec(A, tmp, m2);
                    rec(tmp ^ (1 << i), B, m2);
                    return;
                }
                assert(s != 0);
                s = (s - 1) & m2;
            }
        }
    }
}

int main() {
	int n, A, B;
    scanf("%d%d%d", &n, &A, &B);
    if(pc(A) % 2 == pc(B) % 2) {
        puts("NO");
        return 0;
    }
    puts("YES");
    rec(A, B, (1 << n) - 1);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double


#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define int ll
const ll mod =1e18;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll maxn = 400000+10;
const int K = 31;
ll power(ll x, ll n) {
  ll res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
  }
  return res;
}

int32_t main()
{
 
   IOS
	int n,m;
    cin>>n>>m;
    for(int i  = 0 ;i<m;i++){
        int x;
        cin>>x;
        n-=x;
    }
    cout<<(n<0?-1:n)<<endl;
    
   

}

Measured memory_bytes: 3652
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
static const LL INF = 1LL << 60;

void solve(long long N, std::vector<long long> &a) {
	LL ans = 0;
	for (LL i = 0; i < N; ++i) {
		LL x = a[i] / (N + 1);
		if (x > 100) {
			a[i] -= (x - 100) * (N + 1);
			ans += (x - 100) * (N + 1);
		}
	}
	int index;
	while (index = max_element(a.begin(), a.end()) - a.begin(), a[index] >= N) {
		++ans;
		for (LL i = 0; i < N; ++i) {
			a[i] += i == index ? -N : 1;
		}
	}
	cout << ans << endl;
}

int main() {
    long long N;
	std::cin >> N;
	std::vector<long long> a(N);
	for (int i = 0; i < N; i++) {
		std::cin >> a[i];
	}
	solve(N, a);
	return 0;
}


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

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  if(n*a > b){
    cout << b << endl;
  }else if(n*a < b){
    cout << a*n << endl;
  }else{
    cout << b << endl;
  }
}


Measured memory_bytes: 256
// Inshallah, Boys played well !!

#include <bits/stdc++.h>
using namespace std;
#define author Saurabh
#define pii pair<int,int> 
#define vpi vector<pair<int,int> >
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ff(i,s,e) for(int i=s;i<=e;i++)
#define fb(i,e,s) for(int i=e;i>=s;i--)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test int t;scanf("%d",&t);while(t--)
#define setp(x) setprecision(x)
int main(){
    fast;
     float n;
    cin >> n;
    setp(2);
    cout << 3.14*2*n;

}


Measured memory_bytes: 3804
import java.util.Scanner;

/**
 *
 * @author cs18097
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int allmenber = sc.nextInt();
        String menbercoller = sc.next();
        String redcoller = menbercoller.replace("B", "");
        int rednumber = redcoller.length();
        if (rednumber * 2 > allmenber) {
            System.out.print("Yes");
        } else {
            System.out.print("No");
        }
    }
    
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i, N) cin >> h[i];
    sort(h.begin(), h.end());
    int ans = h[K - 1] - h[0];
    FOR(i, K - 1, N) {
        ans = min(ans, h[i] - h[i - K + 1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
# D - Patisserie ABC
n,m=map(int,input().split())
x,y,z=[],[],[]
for i in range(n):
    xx,yy,zz=map(int,input().split())
    x.append(xx)
    y.append(yy)
    z.append(zz)

o=[]
for i in range(2**3):
    op = [0]*3
    for j in range(3):
        if ((i>>j)&1):
            op[3-1-j]=1
    o.append(op)
ans=0
for oo in o:
    l=[]
    for i in range(n):
        t=0
        if oo[0]:t+=x[i]
        else:t-=x[i]
        if oo[1]:t+=y[i]
        else:t-=y[i]
        if oo[2]:t+=z[i]
        else:t-=z[i]
        l.append(t)
    l.sort()
    ans=max(abs(sum(l[:m])),abs(sum(l[n-m:])),ans)
print(ans)

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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)          \
  sort(x.begin(), x.end()); \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << "(" << #x << ", " << #y << ") = " \
                          << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

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

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

  int c = (a - 2) / (b - 1) + 1;

  cout << c << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,m,a,b,i;
    cin>>n>>m;
    int ans[n+1]={0};
    for (i=0;i<m;i++)
    {
        cin>>a>>b;
        ans[a]++;
        ans[b]++;
    }
    for (i=1;i<=n;i++)
        cout<<ans[i]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include "math.h"
using namespace std;

bool isSingle(long x)
{
    int squart = sqrt(x);

    for (long i = 2; i < squart; i++)
    {
        double a = x % i;
        if (a == 0)
        {
            return false;
        }
    }
    return true;
}
int main()
{
    long x;
    cin >> x;
    long count = x;
    while (isSingle(count) == false)
    {
        count++;
    }

    cout << count << endl;
    return 0;
}

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

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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  int q;
  cin >> s >> q;
  bool r = false;
  string beg, end;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      r = !r;
    } else {
      int f;
      char c;
      cin >> f >> c;
      f--;
      if (f ^ r) {
        end += c;
      } else {
        beg += c;
      }
    }
  }
  reverse(beg.begin(), beg.end());
  string ans = beg;
  for (auto&& c : s) {
    ans += c;
  }
  for (auto&& c : end) {
    ans += c;
  }
  if (r) reverse(ans.begin(), ans.end());
  cout << ans;
  return 0;
}


Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

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; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

int main() {
    int N; cin>>N;
    ll cnt[10][10];
    memset(cnt,0,sizeof(cnt));

    for(int i=1;i<=N;++i){
        int start=i,end=i%10;
        while(start>=10) start/=10;
        cnt[start][end]++;
        //cout<<i<<":"<<start<<" "<<end<<endl;
    }
    ll ans=0ll;
    for (int i = 1; i < 10; ++i) {
        for (int j = 1; j < 10; ++j) {
            if(i==j) ans+=cnt[i][j]*cnt[i][j];
            else ans+=cnt[i][j]*cnt[j][i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

#include <sstream>
#include <string>

#include <vector>
#include <array>

#include <list>
#include <queue>

#include <map>
#include <set>

#include <algorithm>
#include <memory>

#define PI 3.141592653589793238462643383279
#define For(v,i) for (int v = 0;v < (i);v++)

using namespace std;

int main() {

	int k, t;
	vector<int> a;

	cin >> k >> t;

	a.resize(t);
	for (int i = 0; i < t; i++)
		cin >> a[i];

	int bn = -1;
	for (int i = 0; i < k; i++)
	{
		int m = 0;
		int n = -1;
		For(j, t)
		{
			if (a[j] > m && j != bn)
			{
				m = a[j];
				n = j;
			}
		}

		if (n == -1)
		{
			int add = 0;
			for (const auto& v : a)
			{
				add += v;
			}
			cout << add << endl;
			return 0;
		}

		a[n]--;

		bn = n;
	}

	cout << 0 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

int main()
{
  string s;
  cin >> s;
  int n = s.size();

  if (s[0] == '0' || s[n - 1] == '1') {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n - 1; ++i) {
    if (s[i] != s[n - 2 - i]) {
      cout << -1 << endl;
      return 0;
    }
  }

  vector<int> st = {1};
  for (int i = 0; i < n - 1; ++i) {
    cout << st.back() << " " << i + 2 << endl;
    if (s[i] == '1') st.push_back(i + 2);
  }

  return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<ll, ll>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

VVI G(100005, VI());
VI visited(100005, false);
VI dis(100005, -1);

int dfs(auto u)
{
  if (dis[u] != -1) return dis[u];
  visited[u] = true;
  if (G[u].empty()) return dis[u] = 0;
  int res = -1;
  REPx(x, G[u]) res = max(res, dfs(x));
  return dis[u] = res + 1;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  REP(i, M)
  {
    int x, y;
    cin >> x >> y;
    x--; y--;
    G[x].push_back(y);
  }
  int ans = -1;
  REP(i, N)
  {
    if (visited[i]) continue;
    ans = max(ans, dfs(i));
  }
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 8576
#include<stdio.h>
int main(){
	int h,n,i,sum=0,a;
	scanf("%d%d",&h,&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		sum+=a;
	}
	if(sum>=h){
		printf("Yes");
	}else printf("No");
}

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
if 0 in a:
    print(0)
    exit(0)
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
        print(-1)
        exit(0)
else:
    print(ans)


Measured memory_bytes: 21652
#include <stdio.h>
int abs(int n){
		if(n<0){
		return -1*n;}else
		return n;}
int main(void)
{int N,A,M,B,C,x,i,a,b,c,l,r,g,m,tmp;
	scanf("%d%d%d",&r,&g,&b);
if((r*100+g*10+b)%4==0){
	printf("YES");}
	else
	printf("NO");


	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N =100005;
int a[N],b[N];
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int cnt=(c+b-1)/b;
	if(d*(cnt-1)<a){
		printf("Yes\n");
	}else printf("No\n");
	
}

Measured memory_bytes: 3648
N=int(input())
L=list(map(int,input().split()))
ANS=0
FLG=-1
CNT=1
for i in L:
  if i == CNT:
    FLG=0
    CNT+=1
  else:
    ANS+=1
if FLG != -1:
  print(ANS)
else:
  print(-1)

Measured memory_bytes: 24744
#include <bits/stdc++.h>
using namespace std;
signed main() {
	int a, b; scanf ("%d %d", &a, &b);
	int mn = a * 2, mx = a * 4;
	if (mn <= b && mx >= b && b % 2 == 0) puts ("Yes");
	else puts ("No");
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
int n,m;
long long b[100005],c[100005];
int a[100005];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	long long tot=0;
	for(int i=1;i<n;i++)
	{
		int l=a[i],r=a[i+1];
		if(l<r)
		{
			b[1]+=(r-l);
			b[l+1]-=(r-l);
			b[l+1]+=(r+1);
			c[l+1]-=1;
			b[r+1]-=(r+1);
			c[r+1]+=1;
			b[r+1]+=(r-l);
			b[m+1]-=(r-l);
		}
		else
		{
			b[1]+=(r+1);
			b[r+1]-=(r+1);
			b[r+1]+=(r+m-l);
			b[l+1]-=(r+m-l);
			c[1]-=1;
			c[m+1]+=1;
			c[r+1]+=1;
			c[l+1]-=1;
			b[l+1]+=(r+m+1);
			b[m+1]-=(r+m+1);
		}
	}
	for(int i=2;i<=m;i++)b[i]+=b[i-1],c[i]+=c[i-1];
	long long ans=1e16;
	for(int i=1;i<=m;i++)ans=min(ans,b[i]+i*c[i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include<algorithm>
using namespace std;
bool check(string s,int i,int j) {
    string ss = s.substr(i,j-i+1);
    string sss= ss;
    reverse(ss.begin(),ss.end());
    return ss==sss;
}
int main() {
	// your code goes here
	string s;
	cin>>s;
	int n=s.length();
	bool f1 =false,f2=false,f3=false;
	f1=check(s,0,n-1);
	f2=check(s,0,(n-1)/2-1);
	f3 = check(s,(n+3)/2-1,n-1);
	if(f1&&f2&&f3) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    string S;
    cin >> N >> S;

    int ans = 0;
    for (int i = 1; i < N - 1; i++) {
        vector<vector<int> > cnt(2, vector<int>(26));
        for (int j = 0; j < i; j++) {
            cnt[0][S[j] - 'a']++;
        }
        for (int j = i; j < N; j++) {
            cnt[1][S[j] - 'a']++;
        }
        int tmp = 0;
        for (int i = 0; i < 26; i++) {
            if (cnt[0][i] != 0 && cnt[1][i] != 0) tmp++;
        }
        ans = max(ans, tmp);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include<stdio.h>

#define N 100000

int binarySearch(int*,int,int);

int main(){
  int i,j,a,n=0,m;
  int S[N],T;

  scanf("%d",&i);

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

  scanf("%d",&j);

  for(a=0;a<j;a++){
    scanf("%d",&T);
    m=binarySearch(S,T,i);
    if(m==-1) continue;
    else n++;
  }

  printf("%d\n",n);
  
  return 0;
}

int binarySearch(int *A,int key,int right){
  int left=0,mid;

  while(left<right){
    mid=(left+right)/2;
    if(A[mid]==key) return mid;
    else if(key<A[mid]) right=mid;
    else left=mid+1;
  }

  return -1;
}



Measured memory_bytes: 2108
#include <iostream>
#include<math.h>

using namespace std;


int main() {

    string S;
    cin >> S;


    int A, B, C, D;

    A = stoi(S.substr(0, 1).c_str());
    B = stoi(S.substr(1, 1).c_str());
    C = stoi(S.substr(2, 1).c_str());
    D = stoi(S.substr(3, 1).c_str());

    // + + +
    if (A + B + C + D == 7) {
        cout << A << "+" << B << "+" << C << "+" << D << "=7" << endl;
        return 0;
    }

    // + + -
    if (A + B + C - D == 7) {
        cout << A << "+" << B << "+" << C << "-" << D << "=7" << endl;
        return 0;
    }

    // + - +
    if (A + B - C + D == 7) {
        cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;
        return 0;
    }

    // + - -
    if (A + B - C - D == 7) {
        cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;
        return 0;
    }

    // - + +
    if (A - B + C + D == 7) {
        cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;
        return 0;
    }

    // - + -
    if (A - B + C - D == 7) {
        cout << A << "-" << B << "+" << C << "-" << D << "=7" << endl;
        return 0;
    }

    // - - +
    if (A - B - C + D == 7) {
        cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;
        return 0;
    }

    // - - -
    if (A + B + C - D == 7) {
        cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;
        return 0;
    }
}


Measured memory_bytes: 256
<?php
//error_reporting(0);
//$s = trim(fgets(STDIN));
list($N,$K) = explode(" ",trim(fgets(STDIN)));
//$P = explode(" ",trim(fgets(STDIN)));
$H = array_map('intval',explode(" ",trim(fgets(STDIN))));
//function chmax(&$a,$b) {if ($a<$b){$a=$b;return true;}return false;}
//function chmix(&$a,$b) {if ($a>$b){$a=$b;return true;}return false;}

rsort($H);

$sum = 0;
for($i=$K;$i<$N;$i++) {
  $sum += $H[$i];
}
printf("%d\n",$sum);


Measured memory_bytes: 31476
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int c[3][3];
	for(int i = 0;i < 3;i++){
		for(int j = 0;j < 3;j++)cin >> c[i][j];
	}

	int b[3] = {c[0][0],c[0][1],c[0][2]};
	int a[3] = {0,c[1][0] - b[0],c[2][0] - b[0]};

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

	cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int md=1e9+7;
int v[1005],t[1005];
int main()
{
	int n,ans=0;
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
		if(v[i]==0)
		{
			for(int j=i;j<=n;j+=i)
			{
				int tt=j;
				ans=0;
				while(tt%i==0)tt/=i,ans++;
				t[i]=t[i]+ans;
				v[j]=1;
			}
		}
	}
	ans=1;
	for(int i=1;i<=n;i++)ans=1ll*ans*(t[i]+1)%md;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if(k*50+j*100+i*500 == X):
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
# coding: utf-8
# Your code here!
N,K=[int(i) for i in input().split()]

num = 0
if K==0:
    print(N*N)
else:
    for b in range(K+1,N+1):
        num += (b-K)*(N//b) + max(0,N%b-(K-1))
    print(num)

#nnn=0
#for a in range(1,N+1):
#    for b in range(1,N+1):
#        if a%b >= K:
#            nnn+=1
#print(nnn)
            


Measured memory_bytes: 2940
#include<stdio.h>
 
typedef struct{
  char suit;
  char num;
  int idx;
}Card;
 
void print(Card* A, int N){
  int i;
  for(i = 0; i < N; i++){
    if(i) printf(" ");
    printf("%c%c",A[i].suit,A[i].num);
  }
  printf("\n");
}
 
void is_stable(Card* A, int N){
  int i;
  for(i = 0; i+1 < N; i++)
    if(A[i].num == A[i+1].num && A[i].idx > A[i+1].idx){
      printf("Not stable\n");
      return;
    }
  printf("Stable\n");
}
 
void swap(Card* a, Card* b){
  Card tmp = *a;
  *a = *b;
  *b = tmp;
}
 
int bubble_sort(Card* A, int N){
  int i,j, cnt=0;
  for(i = 0; i < N; i++)
    for(j = N-1; j >= i+1; j--)
      if(A[j].num < A[j-1].num){
    swap(&A[j],&A[j-1]);
    cnt++;
      }
  return cnt;
}
 
int selection_sort(Card* A, int N){
  int i,j,cnt=0;
  for(i = 0; i < N; i++){
    int mini = i;
    for(j = i; j < N; j++) if(A[j].num < A[mini].num) mini = j;
    cnt += (i==mini?0:1);
    swap(&A[i],&A[mini]);
  }
  return cnt;
}
 
int main(){
  int i,N;
  Card data1[40],data2[40];
  scanf("%d\n",&N);
  for(i = 0; i < N; i++) scanf("%c%c ",&data1[i].suit, &data1[i].num);
  for(i = 0; i < N; i++){
    data2[i] = data1[i];
    data1[i].idx = data2[i].idx = i;
  }
  bubble_sort(data1,N);
  selection_sort(data2,N);
  print(data1,N);
  is_stable(data1,N);
  print(data2,N);
  is_stable(data2,N);
  return 0;
}


Measured memory_bytes: 1988
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (unfoldr)

main :: IO ()
main = do
  (n : k : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Integer]
  let
    as = unfoldr next (1, n - k + 1)
    next (i, a) = Just (a, (succ i, ((a * (n - k + 1 - i) * (k - i)) `div` ((i + 1) * i))))
  mapM_ (print . (`mod` modulus)) (take (fromInteger k) as)

modulus = 10 ^ 9 + 7 :: Integer

unsafeSignedDecimal :: T.Text -> Integer
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 1020
#include<stdio.h>
int main(void)
{
	int a;
	int b;
	scanf("%d",&a);
	scanf("%d",&b);
	if(a < b){
		printf("a < b\n");
	}else if(a > b){
		printf("a > b\n");
	}else if(a == b){
		printf("a == b\n");
	}
	return 0;
}

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


int main() {
  
  int N ,X;
  cin >> N >> X;
  
  int min = 1001001001;
  int counter = 0;
  
  for(int i =0; i < N; i++){
    int m;
    cin >> m;
    
    if(min > m){
      min = m; //最小で作れる種類の量
    }
    
    X -= m; //残り粉の量
    counter++;
  }
  
  int ans = counter + X / min;
  
  cout << ans << endl;
  

 
}


           

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<int> a(5);
	rep(i, 5) cin >> a[i];
	rep(i, 5) {
		if (a[i] == 0) {
			cout << i + 1 << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 3628
n, k = map(int, input().split())
h = list(map(int, input().split()))

ans = [0] * n

for i in range(1, n):
    l = min(i, k)
    hs = h[i]
    ans[i] = min([abs(hs - h[i - j])+ans[i-j] for j in range(1, l+1)])
    # j : 戻り幅
#print(ans)
print(ans[-1])

Measured memory_bytes: 52448
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    map<int, int> mp;
    ll ans = 0;
    rep(i, N) {
        int tmp;
        cin >> tmp;
        A[i] = tmp;
        mp[tmp]++;
        ans += tmp;
    }
    int Q;
    cin >> Q;
    rep(i, Q) {
        ll B, C;
        cin >> B >> C;
        int cnt = mp[B];
        ll tmp = B*cnt;
        ans -= tmp;
        mp[B] = 0;
        ans += C*cnt;
        mp[C] += cnt;
        cout << ans << endl;
    }
    return 0;
// ll
}

Measured memory_bytes: 8024
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0

H = i()

while H > 1:
    count += 1
    H = H//2
print(2**(count + 1)-1)


Measured memory_bytes: 9988
import Foundation
func toTuple<T>(_ args: [T]) -> (T, T) { (args[0], args[1]) }
func toTuple<T>(_ args: [T]) -> (T, T, T) { (args[0], args[1], args[2]) }
func toTuple<T>(_ args: [T]) -> (T, T, T, T) { (args[0], args[1], args[2], args[3]) }
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }
func readDoubles() -> [Double] { readLine()!.split(separator: " ").map { Double($0)! } }
func readStrings() -> [String] { readLine()!.split(separator: " ").map { String($0) } }

let n = Int(readLine()!)!
let (t, a) = toTuple(readDoubles())
let hi = readDoubles()

var d = 9999.0
var ans = 0
for i in 0..<n {
  let tt = t - hi[i] * 0.006
  if d > abs(a - tt) {
    ans = i + 1
    d = abs(a - tt)
  }
}
print(ans)

Measured memory_bytes: 13312
#include <iostream>
#include <algorithm>

using namespace std;

int main( void )
{
	int n, m;
	int map[20000];
	while(cin >> n >> m, n | m) {
		int nm = n + m;
		for(int i=0; i < nm; ++i)
			cin >> map[i];
		sort(map, map+nm);
		int Max = map[0];
		--nm;
		for(int i=0; i < nm; ++i)
			Max = max(Max, map[i+1]-map[i]);
		cout << Max << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<char> sc(N, '0');
  ll s;
  char c;
  vector<bool> check(N, false);
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    s -= 1;
    if (check[s] && sc[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    check[s] = true;
    sc[s] = c;
  }
  if (N > 1 && check[0] && sc[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  if (N > 1 && !check[0]) {
    sc[0] = '1';
  }
  string ans_str(sc.begin(), sc.end());
  cout << ans_str << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int m,n;cin>>m>>n,m|n;){
		vi bs(n);
		rep(i,n) cin>>bs[i];
		
		vvi dp(m,vi(n)); //dp[i][j]:iツ氾板姪堋づ慊づづ個段ツづ泳ツ氾板姪堋づ慊づづ個本ツづーツ置ツつュ
		rep(i,n)
			dp[0][i]=i==0?bs[i]:dp[0][i-1]+bs[i];
		repi(i,1,m){
			rep(j,n){
				dp[i][j]=dp[i-1][j];
				for(int k=0;k<=j;k++){
					int temp=0;
					for(int l=k+1;l<=j;l++)
						temp+=bs[l];
					dp[i][j]=min(dp[i][j],max(dp[i-1][k],temp));
				}
			}
		}
		
		cout<<dp[m-1][n-1]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>

using namespace std;

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

int main () {
    int n;
    string s;
    cin >> n >> s;
    ll r(0), g(0), b(0);
    for (int i=0; i<n; ++i){
        if(s[i] == 'R')
            r++;
        else if (s[i] == 'G')
            g++;
        else
            b++;

    }
    ll res = r*g*b;
    for (int j=0; j<n; ++j) {
        for (int i=0; i<j; ++i) {
            int k = j + (j-i);
            if (k < n) {
                if (s[i] == s[j]) continue;
                if (s[i] == s[k]) continue;
                if (s[j] == s[k]) continue;
                res--;
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <random>
using namespace std;
int main() {
  int n;
  cin >> n;
  int ans = n;
  for (int i = 0; i <= n; i += 9) {
	  int c9 = i;
	  int c6 = n - i;
	  int c  = 0;
	  while (c9 > 0) {
		  c  += c9 % 9;
		  c9 /= 9;
		}
	  while (c6 > 0) {
		  c  += c6 % 6;
		  c6 /= 6;
		}
	  ans = min(c, ans);
	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

int main() {
    int A, B;
    cin >> A >> B;
    string S;
    cin >> S;

    if (S.length() == A + B + 1 && S[A] == '-') {
        REP(i, A + B + 1) {
            if (i == A || ('0' <= S[i] && S[i] <= '9')) continue;
            else {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            long N = cin.ReadLong;
            long[] H = cin.ReadLongArray(N);
            long min = int.MaxValue;
            string ans = "Yes";
            for(long i = N-1; i >=0; i--)
            {
                if (H[i] > min+1)
                {
                    ans = "No";
                    break;
                }
                else if(H[i]==min+1)
                {
                    continue;
                }
                else
                {
                    min = H[i];
                    continue;
                }
            }
            Console.WriteLine(ans);
            
        }
            

                
    }  
            


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


Measured memory_bytes: 29276
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
  int a, b, c, k; cin >> a >> b >> c >> k;
  if(a >= k){
    cout << k << endl;
  }
  if(a+b >= k && a < k){
    cout << a << endl;
  }
  if(a+b < k){
    cout << 2*a-k+b << endl;
  }
  return 0;
}

Measured memory_bytes: 3672
import math
import sys
import collections


mod = 1000000007
sys.setrecursionlimit(mod)
fact = {1: 1}


def run(n, m):
    # print('{}を{}個の数列で表現'.format(m, n))
    ans = 1
    primes = []
    for i in range(2, m):
        if m == 1:
            break
        if i*i > m:
            break
        if m % i == 0:
            cnt = 0
            while m % i == 0:
                cnt += 1
                m //= i
                primes.append(i)
            ans *= comb(cnt+n-1, n-1)
            ans %= mod
    # counts = collections.Counter(primes)
    # print(counts)
    # for (_, v) in counts.items():
    #     ans *= comb(v+n-1, n-1)
    #     ans %= mod
    if m != 1:
        ans *= n
        ans %= mod
    return ans


def comb(n, r):
    if r > (n-r):
        r = n-r
    mul = 1
    div = 1
    for i in range(r):
        mul *= n-i
        div *= i+1
        mul %= mod
        div %= mod
    # mul = math.factorial(n) // math.factorial(n - r)
    # div = math.factorial(r)
    # mul = factorial(n) // factorial(n - r)
    # div = factorial(r)
    mul %= mod
    div %= mod
    return (mul * modpow(div, (mod-2))) % mod


'''
def factorial(n):
    if n in fact:
        return fact[n]
    else:
        fact[n] = n*factorial(n-1)
        return fact[n]
'''


def modpow(a, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        halfp = p // 2
        half = modpow(a, halfp)
        return int((half * half) % mod)
    else:
        return int((a * modpow(a, p-1)) % mod)


def main():
    n, m = map(int, input().split())
    print(run(n, m))


if __name__ == '__main__':
    main()


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

int main() {
    int n, k;
    cin >> n >> k;
    vector <int> p(n, -1);
    rep (i, k) {
        int a, b;
        cin >> a >> b;
        p[--a] = --b;
    }
    vector <vector <vector <int>>> dp(n, vector <vector <int>> (3, vector <int> (3, 0)));
    rep (i, 3) rep (j, 3) {
        dp[0][p[0] == -1 ? i : p[0]][p[1] == -1 ? j : p[1]] = 1;
    }

    rep (i, n - 1) {
        if (i < n - 2 && p[i + 2] != -1) {
            rep (j, 3) rep (k, 3) if (j != k || k != p[i + 2]) {
                (dp[i + 1][j][p[i + 2]] += dp[i][k][j]) %= 10000;
            }
        }
        else {
            rep (j, 3) rep (k, 3) rep (l, 3) if (j != k || k != l) {
                (dp[i + 1][j][k] += dp[i][l][j]) %= 10000;
            }
        }
    }

    int cnt = 0;
    rep (i, 3) rep (j, 3) (cnt += dp[n - 2][i][j]) %= 10000;
    cout << cnt << endl;

    return 0;
}


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


int main(){
    deque<char> deq;
    string s;
    cin >> s;
    for(char c : s){
        deq.push_back(c);
    }
    bool reversed = false;
    ll q;
    cin >> q;
    REP(i, q){
        ll ti;
        cin >> ti;
        if(ti == 1){
            reversed = !reversed;
        }else{
            assert(ti == 2);
            ll fi;
            char ci;
            cin >> fi >> ci;
            if(fi == 1 && !reversed){
                deq.push_front(ci);
            }else if(fi == 1 && reversed){
                deq.push_back(ci);
            }else if(fi == 2 && !reversed){
                deq.push_back(ci);
            }else{
                assert(fi == 2 && reversed);
                deq.push_front(ci);
            }
        }
    }

    while(!deq.empty()){
        if(!reversed){
            char ci = deq.front(); deq.pop_front();
            cout << ci;
        }else{
            char ci = deq.back(); deq.pop_back();
            cout << ci;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 896
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

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

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int a, b;
  cin >> a >> b;
  vector<int> A = {a + b, a - b, a * b};
  sort(A.begin(), A.end());
  cout << A.back() << endl;
  return 0;
}


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

#define   M             100005
#define   ll            long long
#define   PI            atan(1.0)*4
#define   mst(x,v)      memset(x,v,sizeof(x))
#define   inf           (int)1e9

typedef   pair<int,int> P;

int a[4][4];

int main() {
	int f=0;
	for(int i=0;i<3;i++) 
		for(int j=0;j<3;j++)
			scanf("%d",&a[i][j]);
	
	for(int i=0;i<3;i++) {
		for(int j=0;j<2;j++) {
			a[i][j]=a[i][j+1]-a[i][j];
		}
	}
	
	for(int i=0;i<2;i++) {
		for(int j=0;j<2;j++) {
			if(a[i][j]!=a[i+1][j])
				f=1;
		}
	}
	
	if(f) puts("No");
	else  puts("Yes");
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200020;
int n, a[maxn], s;
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i ++) {
        scanf("%d" , a+i);
        s ^= a[i];
    }
    for (int i = 0; i < n; i ++) {
        printf("%d ", (a[i] ^ s));
    }
    return 0;
}


Measured memory_bytes: 4536
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

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

bool solve(vector<vector<int>> &A, const vector<int> b, const int N) {
    vector<vector<bool>> flag(3, vector<bool>(3, false));

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (A[j][k] == b[i]) {
                    flag[j][k] = true;
                }
            }
        }
    }

    // yoko
    for (int i = 0; i < 3; i++) {
        if (flag[i][0] && flag[i][1] && flag[i][2]) {
            return true;
        }
    }
    
    // tate
    for (int i = 0; i < 3; i++) {
        if (flag[0][i] && flag[1][i] && flag[2][i]) {
            return true;
        }
    }

    // right down
    if (flag[0][0] && flag[1][1] && flag[2][2]) {
        return true;
    }

    // left down
    if (flag[0][2] && flag[1][1] && flag[2][0]) {
        return true;
    }


    return false;
}

int main(void) {
    vector<vector<int>> A(3, vector<int>(3));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            int a;
            cin >> a;
            A[i][j] = a;
        }
    }

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

    if (solve(A, b, N)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define lc (rt<<1)
#define rc (rt<<11)
#define mid ((l+r)>>1)

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
const int MAX_N = 3025;
double arr[MAX_N],dp[MAX_N][MAX_N*2];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n;scanf("%d",&n);
    double ans = 0;
    for(int i = 1;i<=n;++i) scanf("%lf",&arr[i]);
    dp[1][3000+1] = arr[1],dp[1][3000-1] = 1-arr[1];
    for(int i = 2;i<=n;++i)
    {
        for(int j = 0;j<=3000+n;++j)
        {
            if(j) dp[i][j] += dp[i-1][j-1]*arr[i];
            dp[i][j] += dp[i-1][j+1]*(1-arr[i]);
        }
    }
    for(int i = 3000+1;i<=3000+n;++i) ans+=dp[n][i];
    printf("%.9f\n",ans);
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 141952
N, K = map(int, input().split())
cnt = [0]*100001
S = set()
for i in range(N):
  a, b = map(int, input().split())
  cnt[a-1] += b
  S.add(a)

acc = 0
for s in sorted(S):
  acc += cnt[s-1]
  if acc >= K:
    print(s)
    break


Measured memory_bytes: 10348