akhauriyash/Code-Regression huggingface dataset:
// ref. https://juppy.hatenablog.com/entry/2019/03/18/Educational_DP_Contest%28EDPC%29_G~K_Python_%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0_Atcoder#EDPC--L

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e15;
const ll MOD = 1000000007;  // 1e9 + 7

const ll N = 3005;
// dp[i][j] .. (sum x) - (sum y) value when start from [i,j].
ll dp[N][N];
ll a[N];
ll n;

// [i, j]
ll rec(ll i, ll j) {
  if (i > j) { return 0; } // no elements are left.
  if (dp[i][j] > -INF) { return dp[i][j]; }

  if ((j-i+1)%2 == n%2) { // first one
    ll left  = rec(i+1, j) + a[i];
    ll right = rec(i, j-1) + a[j];
    return dp[i][j] = max(left, right);
  } else {
    ll left  = rec(i+1, j) - a[i];
    ll right = rec(i, j-1) - a[j];
    return dp[i][j] = min(left, right);
  }
}

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  cin >> n;
  ll s = 0;
  rep(i, n) {
    cin >> a[i];
    s += a[i];
  }
  // initialization
  rep(i, n) rep(j, n) { dp[i][j] = -INF; }
  cout << rec(0, n-1) << endl;
}


Measured memory_bytes: 70912
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int ret = n / 25;
    n %= 25;
    ret += n / 10;
    n %= 10;
    ret += n / 5;
    n %= 5;
    ret += n;
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#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(a) (a).begin(),(a).end()
#define MOD 10007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
vector<int> G[5000];
int N,K;
int d[5000][5000];
int dp[5000];
void dijkstra(int s){
      priority_queue<P,vector<P>,greater<P> > Q;
      REP(i,N)d[s][i]=10000;
      Q.push(P(0,s));
      d[s][s]=0;
      while(!Q.empty()){
            P p=Q.top();Q.pop();
            int v=p.second;
            if(p.first>d[s][v])continue;
            REP(i,G[v].size()){
                  int to=G[v][i];
                  if(d[s][to]>d[s][v]+1){
                        d[s][to]=d[s][v]+1;
                        Q.push(P(d[s][to],to));
                  }
            }
      }
      return;
}
int main(){
      cin>>N>>K;
      int c[5000],r[5000];
      REP(i,N){
            cin>>c[i]>>r[i];
      }
      REP(i,K){
            int a,b;
            cin>>a>>b;a--;b--;
            G[a].PB(b);G[b].PB(a);
      }
      REP(i,N)dijkstra(i);
      memset(dp,-1,sizeof(dp));
      queue<int> Q;
      dp[0]=0;Q.push(0);
      while(!Q.empty()){
            int v=Q.front();Q.pop();
            REP(i,N){
                  if(d[v][i]<=r[v]&&(dp[i]==-1||dp[i]>dp[v]+c[v])){
                        Q.push(i);
                        dp[i]=dp[v]+c[v];
                  }
            }
      }
      cout<<dp[N-1]<<endl;
}

Measured memory_bytes: 99336
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
typedef pair<int, int> Pii;
typedef vector<int> Vi;
const int INF = (1<<25);
const int dx[]={1,0,1,-1}, dy[]={0,1,1,1};

int main() {
  int n;
  while(cin>> n, n) {
    char grid[256][256];
    int ans = 0;
    for(int i=0; i<n; i++) {
      for(int j=0; j<n; j++) {
	cin>> grid[i][j];
      }
    }

    for(int y=0; y<n; y++) {
      for(int x=0; x<n; x++) {
	if(grid[y][x] == '1') {
	  for(int i=0; i<4; i++) {
	    int nx=x+dx[i], ny=y+dy[i];
	    int cnt = 1;
	    while(nx >= 0 && ny >= 0 && nx < n && ny < n && grid[ny][nx] == '1') {
	      nx += dx[i]; ny += dy[i];
	      cnt++;
	    }
	    ans = max(ans, cnt);
	  }
	}
      }
    }

    cout<< ans<< endl;
  }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#include <cstdlib>  //abs()で絶対値を取得する（整数）
#include <cmath>    //abs()かfabs()で絶対値を取得する（少数）
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    string s;
    cin >> s;
    if (s == "AAA"||s == "BBB"){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
int main(void){
    int a,b,c,i;
    while(scanf("%d%d",&a,&b)!=EOF){
        c=a+b;
        for(i=1;;i++){
            c=c/10;
            if(c<=0){
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 600
import sys
i=0
N=int(input())
while i<N:
        a,b,c= map(int, input().split())
        a2=a*a
        b2=b*b
        c2=c*c
        if(a2==b2+c2 or b2==a2+c2 or c2==b2+a2):
            print('YES')
        else:
            print('NO')
        i=i+1



Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
 #define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  long long int a,e=0;cin>>a;
  vector<long long int>c(a);
  vector<long long int>d(a);
  string b;
  rep(i,a)c[i]=0;
  rep(i,a)d[i]=i;
  rep(i,a){
    cin>>b;
    if(b.at(0)=='M')c[0]++;
    if(b.at(0)=='A')c[1]++;
    if(b.at(0)=='R')c[2]++;
    if(b.at(0)=='C')c[3]++;
    if(b.at(0)=='H')c[4]++;
  }
  rep(i,3){
    for(int j=i+1;j<4;j++){
      for(int o=j+1;o<5;o++){
        e+=c[i]*c[o]*c[j];
      }
    }
  }
         cout<<e;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<random>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 1145141919
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
typedef pair<int, P> PP;
struct edge { int u, v, cost; };
int a[105];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	int ans = 0;
	int now = a[0], cnt = 0;
	rep(i, n+1) {
		if (a[i] == now)cnt++;
		else {
			ans += (cnt ) / 2;
			cnt = 1;
			now = a[i];
		}
	}
	cout << ans << endl;
}


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

int main(){

    int n;
    cin >> n;

    vector<int> c(n);

    rep(i,n){
        cin >> c[i];
    }

    sort(c.begin(),c.end());

    int a=0,b=0;

    rep(i,n){
        if(i%2==0){
            a+=c.back();
        }else{
            b+=c.back();
        }
        c.pop_back();
    }
    cout << a-b << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

typedef struct{
  int top,front,right,left,back,bottom;
}dice;

void diceroll(dice* d, char c);

int main(void){
  dice d;
  int i,n,top,front;
  char act[101];

  scanf("%d %d %d %d %d %d", &d.top, &d.front, &d.right, &d.left, &d.back,&d.bottom);
  scanf("%d", &n);

  for(i=0;i<n;i++){
    scanf("%d %d", &top, &front);
    if(d.top==top);
    else if(d.bottom==top) diceroll(&d,'N'),diceroll(&d,'N');
    else  if(d.front==top) diceroll(&d,'N');
    else if(d.back==top) diceroll(&d,'S');
    else if(d.right==top) diceroll(&d,'W');
    else if(d.left==top) diceroll(&d,'E');
   
    if(d.front==front) printf("%d\n",d.right);
    else if(d.right==front) printf("%d\n",d.back);
    else if(d.left==front) printf("%d\n",d.front);
    else if(d.back==front) printf("%d\n",d.left);

  }

  return 0;
}


void diceroll(dice* d, char c){
  int temp;

  switch(c){
  case 'E':
  temp=d->top;
  d->top=d->left;
  d->left=d->bottom;
  d->bottom=d->right;
  d->right=temp;
  break;
  case 'N':
  temp=d->top;
  d->top=d->front;
  d->front=d->bottom;
  d->bottom=d->back;
  d->back=temp;
  break;
  case 'S':
  temp=d->top;
  d->top=d->back;
  d->back=d->bottom;
  d->bottom=d->front;
  d->front=temp;
  break;
  case 'W':
  temp=d->top;
  d->top=d->right;
  d->right=d->bottom;
  d->bottom=d->left;
  d->left=temp;
  break;
  case 'R':
  temp=d->front;
  d->front=d->left;
  d->left=d->back;
  d->back=d->right;
  d->right=temp;
  break;
  case 'L':
  temp=d->front;
  d->front=d->right;
  d->right=d->back;
  d->back=d->left;
  d->left=temp;
  break;
  default:
    break;
  }


}

Measured memory_bytes: 1788
#include<stdio.h>

#define llu unsigned long long int

int main(void){

    llu N,A,B,ans = 0,mod;

    scanf("%llu %llu %llu",&N,&A,&B);

    if(A == 0){
        ans = 0;
    }else if(A >= N){
        ans = N;
    }else if(A+B >= N){
        ans = A;
    }else{
        ans += A*(N / (A+B));
        mod = N % (A+B);
        if(mod >= A){
            ans += A;
        }else{
            ans += mod;
        }
    }

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

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main() {
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll ze = 0;
    cout << min(a * x + b * y, min(c * 2 * x + max(ze, (y - x) * b), c * 2 * y + max(ze, (x - y) * a))) << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
#include <stdlib.h>

using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define m_t make_tuple
#define rep(i,n)  for(int i=0; i<(int) (n); i++)


const double pai = 3.1415926535897;
const int mod = 1000000007;
const int INF = 1000000021;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];


int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}
//x未満の要素数を返す二分探索関数
int b_s(vector<int>& vec, int xx) {
	return lower_bound(all(vec), xx) - vec.begin();
}
template<typename T>
void vecout(vector<T>& vec) { for (T t : vec) cout << t << " "; cout << endl; }
template<typename TT>
void vecin(vector<TT>& vec) {
	for (int i = 0; i < vec.size(); i++) {
		cin >> vec[i];
	}
}


// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
//グループが0個でもいいときはnにxを足す
// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	if (xx <= 1) {
		return 0;
	}
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}


signed main() {
	int l, r,d;
	cin >> l >> r>>d;
	l--;
	cout << r / d - l / d << endl;
}


Measured memory_bytes: 3484
S = input()
T = input()
s = len(S)
t = len(T)
dp = [[0] * (t + 1) for _ in range(s + 1)]
for i in range(s):
    for j in range(t):
        if S[i] == T[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j])
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1])
A = ''
i = s
j = t
while i > 0 and j > 0:
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j - 1]:
        j -= 1
    else:
        A = S[i - 1] + A
        i -= 1
        j -= 1
print(A)

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    int sub;
    int ans = 0;
    vector <int> a;
    int current;
    
    for(int i = 0; i < N; i++){
        cin >> sub;
        a.push_back(sub);
    }
    
    sort(a.begin(), a.end());
    
    int a_index = 0;
    while(a_index < N){
        int cnt = 0;
        
        if(a_index == N - 1){
            ans++;
            break;
        }
        
        if(a[a_index] != a[a_index + 1]){
            ans++;
            a_index++;
        }
        else{
            cnt = 1;
            while(a_index < N - 1 && a[a_index] == a[a_index + 1]){
                cnt++;
                a_index++;
            }
        
            a_index++;
        
            if(cnt % 2 != 0){
                ans++;
            }
        }
    }
    
    cout << ans << "\n";
}

Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include <stdio.h>
#include <bitset>
#include<math.h>
#include<list>
#include<map>
using namespace std;
typedef long long ll;
#define PI 3.14159265358979323846  


int main() {
	int n, ans;
	cin >> n;
	if (n % 2 == 0) {
		ans = n / 2;
	}
	else {
		ans = n / 2 + 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;


#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, m, x, i, j, ans = 1e18, temp, k;
    cin>>n>>m>>x;
    ll a[n][m], cost[n];
    for(i=0; i < n; i++) {
    	cin>>cost[i];
    	for(j = 0; j < m; j++) {
    		cin>>a[i][j];
    	}
    }
    for(i = 1; i < (1 << n); i++) {
    	bool valid = true;
    	ll cur = 0;
    	vector<ll> books(m, 0);
    	for(j = 0; j < n; j++) {
    		if(i & (1 << j)) {
    			cur += cost[j];
    			for(k = 0; k < m; k++) {
    				books[k] += a[j][k];
    			}
    		}
    	}
    	for(j = 0; j < m; j++){
    		if(books[j] < x) {
    			valid = false;
    		}
    	}
    	if(valid) {
    		ans = min(ans, cur);
    		// cout<<cur<<" "<<i<<"\n";
    	}
    }
    if(ans < 1e18) {
    	cout<<ans<<"\n";
    } else {
    	cout<<"-1\n";
    }
}

Measured memory_bytes: 3656
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main() {
	string s; cin >> s;
	int cnt = 0;
	rep(i, 0, s.size()) if (s[i] == 'p')cnt++;
	printf("%d", s.size() / 2 - cnt);
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<set>
#include<map>
#define ll long long
using namespace std;

int main() {
	string s;
	cin >> s;
	string s1 = s;
	reverse(s.begin(), s.end());
	if (s == s1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int L = sc.nextInt();
      double maxArea = 0.0;

      double leftLen = 0.0, rightLen = L * 1.0;
      while(Math.abs(rightLen - leftLen) > 1e-10) {
        double midLen1 = leftLen + (rightLen - leftLen) / 3;
        double midLen2 = rightLen - (rightLen - leftLen) / 3;
        double maxArea1 = maxArea(L - midLen1) * midLen1;
        double maxArea2 = maxArea(L - midLen2) * midLen2;
        maxArea = Math.max(maxArea, Math.max(maxArea1, maxArea2));
        if(maxArea1 < maxArea2)
          leftLen = midLen1;
        else
          rightLen = midLen2;
      }
      System.out.println(maxArea);
  }

  private static double maxArea(double l) {
    double leftLen = 0.0, rightLen = l;
    while(Math.abs(rightLen - leftLen) > 1e-10) {
        double midLen1 = leftLen + (rightLen - leftLen) / 3;
        double midLen2 = rightLen - (rightLen - leftLen) / 3;
        double area1 = midLen1 * (l - midLen1);
        double area2 = midLen2 * (l - midLen2);
        if(area1 < area2)
          leftLen = midLen1;
        else
          rightLen = midLen2;
    }
    double len = (rightLen + leftLen) / 2;
    return len * (l - len);
  }
}

Measured memory_bytes: 21844
#include<cstdio>
int main(){
	char s[10];
	scanf("%s",s + 1);
	int ok = 0;
	if(s[3] != s[4]||s[5] != s[6]) ok = 1;
	if(ok) printf("No\n");
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=3005,P=998244353;

int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int gcd(int a,int b){ return !b?a:gcd(b,a%b); }

int A,B,C,D,f[N][N];
int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
#endif
	cin>>A>>B>>C>>D;
	f[A][B]=1;
	rep(i,A,C)rep(j,B,D)
	{
		f[i][j]=add(f[i][j],
				sub(add(mul(f[i-1][j],j),mul(f[i][j-1],i)),
					mul(f[i-1][j-1],mul(i-1,j-1))));
	}
	cout<<f[C][D]<<endl;
	return 0;
}


Measured memory_bytes: 38792
const fs = require('fs')
const stdin = fs.readFileSync('/dev/stdin', 'utf8')

const tiles = stdin
  .split('\n')[0]
  .split('')

let count = 0
for(let i = 0; i < tiles.length + 1; i++){
  if(tiles[i] === tiles[i-1]){
    count++
    tiles[i] = tiles[i] === '0' ? '1' : '0'
  }
}

console.log(count)


Measured memory_bytes: 8268
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.AGC_Challenge
{
    class _008_B
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            int n = nk[0];
            int k = nk[1];
            long[] array = ReadLongs();
            long sum = 0;
            for (int i = 0; i < n; i++)
            {
                if (array[i] > 0) sum += array[i];
            }
            long plus = 0;
            long minus = 0;
            long delta = 0;
            for(int i = 0; i < k; i++)
            {
                if (array[i] > 0) plus += array[i];
                else minus += array[i];
                delta = Math.Max(-plus, minus);
            }
            for (int i = 1; i <= n - k; i++)
            {
                if (array[i - 1] > 0) plus -= array[i - 1];
                else minus -= array[i - 1];
                if (array[i + k - 1] > 0) plus += array[i + k - 1];
                else minus += array[i + k - 1];
                long next = Math.Max(-plus, minus);
                delta = Math.Max(delta, next);
            }
            Console.WriteLine(sum + delta);
        }

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


Measured memory_bytes: 29148
#include<bits/stdc++.h> 
using namespace std;
#define se second
#define fr first
#define int  long long int
#define pb push_back
#define inf 1e18
#define slld(x) scanf("%lld",&x)
#define plld(x) printf("%lld\n",x)
#define all(v) v.begin(),v.end()
#define CHAL_BAAP_KO_MT_SIKHA ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define MOD 998244353
#define endl "\n" 
/*
    Damn Fast:TheFuckinMastermind
    while(How to solve the Question?){
                Read the Question Again!!
           }
        do
            Practise
    #Motivation::::0/0  
*/
const int N=5e5;
vector<int> seg[4*N+1];
int a[N+1],ans[N+1];
vector<int> merge(vector<int> v1,vector<int> v2){
    int i=0,j=0;
    vector<int> v;
    while(i<v1.size() and j<v2.size()){
        if(v1[i]<v2[j]){
            v.pb(v1[i]);
            i++;
        }
        else{
            v.pb(v2[j]);
            j++;
        }
    }
    while(i<v1.size()){
        v.pb(v1[i]);
        i++;
    }
    while(j<v2.size()){
        v.pb(v2[j]);
        j++;
    }
    return v;
}
void build(int l,int r,int idx){
    if(l==r){
        seg[idx].pb(ans[l]);
        return;
    }
    int mid=(l+r)/2;
    build(l,mid,2*idx+1);
    build(mid+1,r,2*idx+2);
    seg[idx]=merge(seg[2*idx+1],seg[2*idx+2]);
}
int qury(int l,int r,int ll,int rr,int idx){
    if(l>rr or r<ll)
        return 0;
    if(ll<=l and rr>=r){
        return (lower_bound(seg[idx].begin(),seg[idx].end(),ll)-seg[idx].begin());
    }
    int mid=(l+r)/2;
    return qury(l,mid,ll,rr,2*idx+1)+qury(mid+1,r,ll,rr,2*idx+2);
}
signed main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin); 
    // freopen("out.txt","w",stdout);
    // #endif  
    CHAL_BAAP_KO_MT_SIKHA
    int n,q;
    cin>>n>>q;
    //vector<int> ans(n+1,0);
    map<int,int> mp;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(mp[a[i]]==0){
            ans[i]=0;
        }
        else{
            ans[i]=mp[a[i]];
        }
        mp[a[i]]=i;
    }
    build(1,n,0);
    while(q--)
    {
        int l,r;
        cin>>l>>r;
        cout<<qury(1,n,l,r,0)<<endl;
    }
}

Measured memory_bytes: 196412
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  if (K == 0) {
    cout << N * N << endl;
    return 0;
  }
  for (int i = K + 1; i <= N; i++) {
    ans += floor(N / (i)) * (i - K);
    ll a = N;
    a -= floor(N / i) * i;
    a -= (K - 1);
    ans += max<ll>(0, a);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define f first
#define s second
 
using ld = long double;
using ll = long long;
using ii = pair <int,int>;
using pll = pair <ll,ll>;
using vi = vector <int>;
using vll = vector <ll>;
using vii = vector <ii>;
using vpll = vector<pll>;


int main(){
 
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  
  int n;
  ll d;
  cin >> n >> d;
  int ans = 0;

  while(n--){
    ll x,y;
    cin >> x >> y;
    if(x*x + y*y <= d*d)
      ans++;
  }

  cout << ans << endl;

  return 0;
}

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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;

int N;
int A[1100][1100];
vector<pint> G[1100][1100];
vector<pint> rev[1100][1100];
int mem[1100][1100];
int dfs(int a, int b, int depth = 0) {
    if (depth > 1100000) {
        cout << -1 << endl;
        exit(0);
    }
    if (mem[a][b] != 0) { return mem[a][b]; }
    int ret = 0;
    for (int i = 0; i < G[a][b].size(); i++) {
        chmax(ret, dfs(G[a][b][i].first, G[a][b][i].second, depth + 1) + 1);
    }
    return mem[a][b] = ret;
}

signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) { for (int j = 0; j < N - 1; j++) { cin >> A[i][j], A[i][j]--; }}
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N - 2; j++) {
            int a1 = min(i, A[i][j]), b1 = max(i, A[i][j]);
            int a2 = min(i, A[i][j + 1]), b2 = max(i, A[i][j + 1]);
            G[a1][b1].push_back(pint(a2, b2));
            rev[a2][b2].push_back(pint(a1, b1));
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            if (rev[i][j].size() == 0) {
                G[1099][1099].push_back(pint(i, j));
            }
        }
    }
    int at = dfs(1099, 1099);
    if (at == 0) { at--; }
    cout << at << endl;
}


Measured memory_bytes: 156672
#include<set>
#include <unordered_set>
#include <unordered_map>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<math.h>
#include <string.h>

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=(a);i<=(int)(n);++i)
#define lpd(i,a,n) for(int i=(a);i>=(int)(n);--i)
#define clr(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define readll(x) scanf("%I64d",&x)
#define mod 1000000007
#define eps 1e-6
#define infi 1e9
#define infll 1e18
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<ll,ll> mll;

int n;
ll a[100004],temp[100004];

ll solve() {
    ll ans = 0;
    lp(i, 2, n) {
        if(a[i-1] > 0) {
            if(a[i]+a[i-1] < 0){
                a[i] += a[i-1];
                continue;
            }
            ans += abs(a[i]+1+a[i-1]);
            a[i] = -1;
        } else {
            if(a[i]+a[i-1] > 0){
                a[i] += a[i-1];
                continue;
            }
            ans += abs(a[i]-1+a[i-1]);
            a[i] = 1;
        }
    }
    return ans;
}
int main(){
    scanf("%d" ,&n);
    lp(i, 1, n) scanf("%lld" ,&a[i]);
    ll ans = 0;
    
    if(!a[1]){
        a[1] = 1;
        memcpy(temp, a, sizeof(a));
        ans = solve()+1;
        memcpy(a, temp, sizeof(temp));
        a[1] = -1;
        ans = min(ans, solve()+1);
    } else {
        memcpy(temp, a, sizeof(a));
        ans = solve();
        memcpy(a, temp, sizeof(temp));
        ll t = abs(a[1])+1;
        if(a[1] > 0) a[1] = -1;
        else a[1] = 1;
        ans = min(ans, solve()+t);
    }
    
    
    printf("%lld\n",ans);
    return 0;
}
/*
 abcda
 
 */

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

using namespace std;

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

    vector<unsigned long long> btn(N + 1, 0);
    for (int i = 1; i <= N; i++) {
        cin >> btn[i];
    }

    int push_count = 0;
    unsigned long long idx = 1;
    while (idx != 2) {
        if (btn[idx] == 0 || btn[idx] == idx) {
            cout << -1 << endl;
            return 0;
        }
        unsigned long long next_idx = btn[idx];
        btn[idx] = 0;
        idx = next_idx;
        push_count++;
    }
    cout << push_count << endl;
    return 0;
}


Measured memory_bytes: 1024
#ABC114D-756.py

from math import factorial

N = int(input())
answer = 0

primeN = (2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97)
amount = []

for i in primeN:
    amount.append(1)

for n in range(N):
    n = n + 1
    for m in range(len(primeN)):
        m = m + 1
        while n >= primeN[-m]:
            if n % primeN[-m] == 0:
                amount[-m] += 1
                n = n // primeN[-m]
            else: break

for i in amount:
    if i >= 75:
        answer += 1

i1, i2 = 0, 0
for i in amount:
    if i >= 15:
        i1 += 1
    elif i >= 5:
        i2 += 1
if i1 >= 1 and i1+i2 >= 2:
    answer += i1 * (i1+i2-1)

i3,i4 = 0, 0
for i in amount:
    if i >= 25:
        i3 += 1
    if i >= 3:
        i4 += 1
if i3 >= 1 and i4 >= 2:
    answer += i3 * (i4-1)

i5, i6 = 0, 0
for i in amount:
    if i >= 5:
        i5 += 1
    if i >= 3:
        i6 += 1
if i5 >= 2 and i6 >= 3:
    answer += (factorial(i5) // 2 // factorial(i5-2)) * (i6-2)

print(answer)


Measured memory_bytes: 3064
#include <stdio.h>
#define MAX_PIC 4
#define MAX_RANK 13


// ????????????2?¬??????????[??????][?????????]
int card[MAX_PIC][MAX_RANK];

// ??????????????????????????????????????????0????????????????????????
void CardInitialize(void){
	int i, j;
	
	for(i = 0; i < MAX_PIC; i++){
		for(j = 0; j < MAX_RANK; j++){
			card[i][j] = 0;
		}
	}
	
}

// ??\??????????????????????????§??????????????????
void CheckCards(int card_num){
	int i, picture_num, rank;
	char picture;
	
	for(i = 0; i < card_num; i++){
		// C?¨?????????????????§?
		scanf(" %c", &picture);
		scanf("%d", &rank);
		
		// ???????????????????????°?????????????????????
		switch(picture){
		case 'S': picture_num = 0; break;
		case 'H': picture_num = 1; break;
		case 'C': picture_num = 2; break;
		case 'D': picture_num = 3; break;
		}
		card[picture_num][rank-1] = 1;
	}
	
}

// ?¶????????????????????????¨?????????
void ShowCards(void){
	int i, j;
	char picture;
	
	for(i = 0; i < MAX_PIC; i++){
		// ??°??????????????????????????????????????????
		switch(i){
			case 0: picture = 'S'; break;
			case 1: picture = 'H'; break;
			case 2: picture = 'C'; break;
			case 3: picture = 'D'; break;
		}
		for(j = 0; j < MAX_RANK; j++){
			if(card[i][j] == 0){
				printf("%c %d\n", picture, j + 1);
			}
		}
	}
}


int main(void){
	// 2?¬?????????????for?????¨
	int i, j;
	// ??????(S,H,C,D)
	char picture;
	// ??\???????????????????????°????????????????????°???????????????
	int card_num, picture_num, rank;
	
	// ?????????
	CardInitialize();
	
	// ??????????????°?????\???
	scanf("%d", &card_num);
	
	// ??\?????????????????????????????????????????????1????????£??\??????
	CheckCards(card_num);
	
	// ???????????¨??¨??????????´¢??????0?????¨???????????¨?????????
	ShowCards();
	
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define MAX(a, b, c) max(max(a, b), c)
using namespace std;

int main(){
  int n,k;
  scanf("%d%d", &n, &k);
  
  double ans = 0.0;
  REP(i,n){
    double sub_p = 1.0/(double)n;
    double score = (double)i + 1.0;
    while(score < (double)k){
      score *= 2.0;
      sub_p *= 0.5;
    }
    ans += sub_p;
  }
  
  cout << setprecision(13) << ans << endl;
 
}

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

long long MOD = 1e9 + 7;

long long fast_pow(long long x, long long p){
    long long res = 1;
    while (p){
        if (p & 1){
            res *= x;
            res %= MOD;
        }

        p >>= 1;
        x *= x;
        x %= MOD;
    }

    return res;
}

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

    string s;
    cin >> s;
    
    long long ans = 0, len = s.length();
    vector<long long> fac(len + n + 1), inv(len + n + 1);
    fac[0] = fac[1] = 1;
    for (long long i = 2; i <= len + n; i++){
        fac[i] = (fac[i - 1] * i) % MOD;
    }

    inv[len + n] = fast_pow(fac[len + n], MOD - 2);
    for (long long i = len + n - 1; i >= 0; i--){
        inv[i] = (inv[i + 1] * (i + 1)) % MOD;
    }

    auto C = [&](long long n, long long m){
        long long res = 1;
        res = (((fac[n] * inv[m]) % MOD) * inv[n - m]) % MOD;
        return res;
    };

    for (long long i = 0; i <= n; i++){
        ans += (((fast_pow(25, n - i) * fast_pow(26, i)) % MOD) * C(len + n - i - 1, n - i)) % MOD;
        ans %= MOD;
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 35612
#include<bits/stdc++.h>
#define re register
#define LL long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read() {
	char c=getchar();int x=0;while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
const int inf=1e9;
const int maxn=1e5+5;
int d[maxn],cnt[16],dp[1<<16],vis[1<<16],n;
int dfs(int S) {
	if(!S) return 0;
	if(vis[S]) return dp[S];
	dp[S]=inf;vis[S]=1;
	for(re int i=1;i<16;++i) 
		for(re int j=i+1;j<16;++j) 
			if((S>>(j-1)&1)&&(S>>(i-1)&1)) {
				int x=S^(1<<(i-1))^(1<<(j-1));
				if(x>>((i^j)-1)&1) 
					dp[S]=min(dp[S],dfs(x^(1<<(i^j)-1))+2);
				else dp[S]=min(dp[S],dfs(x|(1<<(i^j)-1))+1);
			}
	return dp[S];
}
int main() {
	n=read();
	for(re int x,y,w,i=1;i<n;i++) {
		x=read(),y=read(),w=read();
		d[x]^=w,d[y]^=w;
	}
	for(re int i=0;i<n;i++) cnt[d[i]]++;
	int S=0,nw=0;
	for(re int i=1;i<16;++i) nw+=cnt[i]/2;
	for(re int i=1;i<16;++i) if(cnt[i]&1) S|=(1<<(i-1));
	printf("%d\n",nw+dfs(S)); 
	return 0;
}



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

int main() {
    int A, B;
    cin >> A >> B;
    int count = 0;
    for (int i = A; i <= B; i++) {
        string s = to_string(i);
        string t = s;
        reverse(t.begin(), t.end());
        if (s == t) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef long long ll;

ll gcd (ll x, ll y)
{
  if (y == 0)
    return x;
  else
    return gcd (y, x % y);
}

int main(void)
{
  ll a, b, c, d, lcm;
  scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
  
  lcm = c*d/gcd(c, d);
  
  printf("%lld", b-a+1 - (b / c - (a-1) / c + b / d - (a-1) / d - b / lcm + (a-1) / lcm));
    
  return 0;
}

Measured memory_bytes: 128
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

list = [a, b, c, d, e]

can = False
for i in range(len(list)):
  for j in range(len(list)):
    if i == j:
      continue
    if abs(list[i] - list[j]) <= k:
      can = True
    else:
      can = False
      break
      
if can:
  print("Yay!")
else:
  print(":(")


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
	int a,b;
	cin >> a >> b;
	if(a < b){
		cout << "a < b" << endl;
	}
	else if(a > b){
		cout << "a > b" << endl;
	}
	else if(a == b){
		cout << "a == b" << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(n)]
c = [list(map(int, input().split())) for _ in range(m)]
ans = []
INF = 10**9+7
for x in s:
  d = INF
  ind = INF
  for i,y in enumerate(c):
    exd = d
    d = min(d,abs(x[0]-y[0])+abs(x[1]-y[1]))
    if d != exd:
      ind = i
  ans.append(ind+1)
for x in ans:
  print(x)

Measured memory_bytes: 9096
// ACM-ICPCアジア地区予選2014 E. Automotive Navigation

#include <iostream>
#include <cstring>

using namespace std;

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int getDir(char c){
	if(c == 'N') return 0;
	if(c == 'E') return 1;
	if(c == 'S') return 2;
	return 3;
}

int main(){
	int n, x0, y0, t;
	int mp[51][51];
	int visit[2][51][51];
	while(cin >> n >> x0 >> y0 >> t){
		memset(mp, 0, sizeof(mp));
		memset(visit, 0, sizeof(visit));
		visit[0][x0][y0] = 15;
		for(int i=0;i<n;i++){
			int xs, ys, xe, ye; cin >> xs >> ys >> xe >> ye;
			if(xs > xe) swap(xs, xe);
			if(ys > ye) swap(ys, ye);
			if(xs == xe){
				for(int i=ys;i<ye;i++){
					mp[xs][i  ] |= (1<<0);
					mp[xs][i+1] |= (1<<2);
				}
			} else {
				for(int i=xs;i<xe;i++){
					mp[i  ][ys] |= (1<<1);
					mp[i+1][ys] |= (1<<3);
				}
			}
		}
		int cur = 0, next = 1;
		for(int i=0;i<t;i++){
			int d; char c; cin >> d >> c;
			int targetDir = getDir(c);
			for(int j=0;j<d;j++){
				memset(visit[next], 0, sizeof(visit[next]));
				for(int x=0;x<=50;x++){
					for(int y=0;y<=50;y++){
						for(int dir=0;dir<4;dir++){
							if(!(visit[cur][x][y]&(1<<dir))) continue;
							if(!(mp[x][y]&(1<<dir))) continue;
							int nx = x+dx[dir], ny = y+dy[dir];
							visit[next][nx][ny] |= (1<<dir);
						}
					}
				}
				for(int x=0;x<=50;x++){
					for(int y=0;y<=50;y++){
						int nmask = 0;
						for(int dir=0;dir<4;dir++){
							if(!(visit[next][x][y]&(1<<dir))) continue;
							int mask = (15^(1<<((dir+2)%4)))&mp[x][y];
							if(j==d-1 && dir != targetDir) mask &= (1<< targetDir);
							nmask |= mask;
						}
						visit[next][x][y] = nmask;
					}
				}
				swap(cur, next);
			}
		}
		for(int x=0;x<=50;x++){
			for(int y=0;y<=50;y++){
				if(visit[cur][x][y]) cout << x << " " << y << endl;
			}
		}
	}
}

Measured memory_bytes: 1204
A=int(raw_input())
B=int(raw_input())
C=int(raw_input())
X=int(raw_input())
ans = 0
for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if a * 500+b * 100+c * 50 == X:
        ans += 1
print ans



Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='p')ans++;
	}
	cout<<s.length()/2-ans<<endl;
}

Measured memory_bytes: 512
from collections import deque
import itertools

n,m,q = list(map(int,input().split()))
l = []
for i in range(q):
    line = list(map(int,input().split()))
    l.append(line)
ans = 0

comb = itertools.combinations_with_replacement(range(1,m+1),n)
for s in comb:
    tmp = 0
    for j in range(q):
        a,b,c,d = l[j]
        if c == s[b-1]-s[a-1]:
            tmp += d
    ans = max(ans,tmp)

print(ans)



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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef long long LL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_LARGE = 1000000100;

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

void Main()
{
	int n;
	cin>>n;
	
	VPII a(n);
	REP(i,n){
		int t;
		cin >> t;
		a[i] = make_pair(t,i);
	}

	SORT_ASC(a);

	REP(i,n){
		if(a[n-1].second == i){
			cout << a[n-2].first << endl;
		}
		else{
			cout << a[n-1].first << endl;
		}

	}


	

	return;
}

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

Measured memory_bytes: 3200
while true do
  a = gets
  break if a == nil
  a = a.split.map{|x| x.to_i}
  b = gets.split.map{|x| x.to_i}
  hit = 0
  blow = 0
  4.times do |i|
    if a[i] == b[i] then
      hit += 1
    end
  end
  
  4.times do |i|
    case a.index b[i]
    when i
    when nil
    else
      blow += 1
    end
  end

  puts "#{hit} #{blow}"
end

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

namespace AtTest.Virtual
{
    class AGC016_B
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] array = ReadInts();
            Array.Sort(array);
            if (array[n - 1] - array[0] > 1)
            {
                WriteLine("No");
                return;
            }
            if (array[n - 1] == array[0]
                && array[0] == n - 1)
            {
                WriteLine("Yes");
                return;
            }

            int smallCnt = 0;
            int largeCnt = 0;
            for(int i = 0; i < n; i++)
            {
                if (array[i] == array[n-1]) largeCnt++;
                else smallCnt++;
            }
            int min = 1;
            int max = largeCnt / 2;
            if (largeCnt>1&&min + smallCnt <= array[n - 1] 
                && array[n - 1] <= max + smallCnt)
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
            }
        }

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


Measured memory_bytes: 18912
N=int(input())
list = []

def standard(n, cur):
  if n == 0:
    add = ''.join(cur)
    if str(add).isnumeric():
        list.append(int(add))
  else:
    newC = chr(ord(cur[-1]) - 1)
    standard(n - 1, cur + [newC])
    newC2 = chr(ord(cur[-1]))
    standard(n - 1, cur + [newC2])
    newC3 = chr(ord(cur[-1]) + 1)
    standard(n - 1, cur + [newC3])

for i in range(10):
    for j in range(9):
        standard(i, [str(j+1)])

print(list[N-1])


Measured memory_bytes: 11032
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		if((s.charAt(2) == s.charAt(3)) && s.charAt(4) == s.charAt(5)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
	
	}

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

using namespace std;

int n,m,t,ans,k,a[2010][2010],b[2010][2010],c[2010][2010];
char mp[2010][2010];

int main()
{
	scanf("%d%d%d",&n,&m,&t);
	for(int i=1; i<=n; i++)
		scanf("%s",mp[i]+1);
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=m; j++)
		{
			a[i][j]=a[i][j-1]+a[i-1][j]-a[i-1][j-1];
			b[i][j]=b[i][j-1]+b[i-1][j]-b[i-1][j-1];
			c[j][i]=c[j][i-1]+c[j-1][i]-c[j-1][i-1];
			if(mp[i][j]=='1')a[i][j]++;
			if(mp[i][j-1]=='1'&&mp[i][j]=='1')b[i][j]++;
			if(mp[i-1][j]=='1'&&mp[i][j]=='1')c[j][i]++;
		}
	}
	while(t--)
	{
		int x,y,xx,yy;
		scanf("%d%d%d%d",&x,&y,&xx,&yy);
		k=a[xx][yy]-a[x-1][yy]+a[x-1][y-1]-a[xx][y-1];
		ans=b[xx][yy]-b[xx][y]-b[x-1][yy]+b[x-1][y];
		ans+=c[yy][xx]-c[yy][x]-c[y-1][xx]+c[y-1][x];
		printf("%d\n",k-ans);
	}
	return 0;
}

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

int main(int argc, char *argv[]){
  int N, x;
  std::cin >> N >> x;
  std::vector<int> list;
  for(int i = 0; i < N; i++){
    int v;
    std::cin >> v;
    list.push_back(v);
  }
  std::sort(list.begin(), list.end());
  int count = 0;
  for(int v : list){
    if(x < v){
      x = 0;
      break;
    };
    count++;
    x -= v;
  }
  if(x && count) count--;
  std::cout << count << std::endl;
  return 0;
}


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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> l(n);
  int m=-1;
  int sum=0;
  for(int i=0;i<n;i++){
    cin >> l[i];
    m=max(m,l[i]);
    sum+=l[i];
  }
  if(2*m<sum){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
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; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
vector<int> d[100022];
int tk[100022],ao[100022];
void dfs(int a,int b){
  ao[a] = b;
  rep(i,d[a].size()){
    int m = d[a][i];
    if(m==b)continue;
    dfs(m,a);
    tk[a]=max(tk[a],tk[m]+1);
  }
}
int main(){
  int n,u,v;cin>>n>>u>>v;
  rep(i,n-1){
    int a,b;cin>>a>>b;
    d[a].push_back(b);
    d[b].push_back(a);
  }
	dfs(v,-1);
	int dis = 0,tt = u;
	while(tt!=v)
	{
		dis++;
		tt = ao[tt];
	}
	dis = (dis-1)/2;
	while(dis--)
		u = ao[u];
	int len = tk[u];
	while(u!=v)
	{
		len++;
		u = ao[u];
	}
	cout<<(len-1)<<endl;
	return 0;
}


Measured memory_bytes: 12928