akhauriyash/Code-Regression huggingface dataset:
H, W = map(int, input().split())
S = H*W
ans = 10**10
for i in range(1,H):
  if (H-i)*W%2==0:
    m = (H-i)*W//2
    ans = min(ans, abs(i*W-m))
  else:
    if (H-i)<W:
      m1,m2 = (H-i)*(W//2), (H-i)*(W//2+1)
      x = max(abs(m1-m2), abs(m2-i*W), abs(m1-i*W))
      ans = min(ans,x)
    else:
      m1,m2 = W*((H-i)//2), W*((H-i)//2+1)
      x = max(abs(m1-m2), abs(m2-i*H), abs(m1-i*H))
      ans = min(ans,x)

for i in range(1,W):
  if H*(W-i)%2==0:
    m = H*(W-i)//2
    ans = min(ans, abs(i*H-m))
  else:
    if H>W-i:
      m1,m2 = (W-i)*(H//2), (W-i)*(H//2+1)
      x = max(abs(m1-m2), abs(m2-i*H), abs(m1-i*H))
      ans = min(ans,x)
    else:
      m1,m2 = H*((W-i)//2), H*((W-i)//2+1)
      x = max(abs(m1-m2), abs(m2-i*H), abs(m1-i*H))
      ans = min(ans,x)

print(ans)

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    int c=0, u=0;
    for(int i=2; i<s.size()-1;i++){
        if(s[i]=='C') c++;
    }
    for(int i=0; i<s.size(); i++){
        if(s[i]>=65&&s[i]<=90) u++;
    }
    if(s[0]=='A'){
        if(c==1 && u==2){
            cout <<"AC";
        }
        else cout<<"WA";
    }
    else cout<<"WA";
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cctype>
using namespace std;

int main()
{
	//long int sum[100] = {0};
	char str;
	int sum = 0;
	
	int n=0;
	while(1){
		while((str = getchar()) != '\n')
			sum += str - '0';
		if(sum == 0)	break;
		cout << sum << endl;
		sum = 0;
	}
	
	/*for(int i=0; i<n; i++)
		cout << sum[i] << endl;*/
	
	return 0;
}



Measured memory_bytes: 3096
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define PB push_back
#define MP make_pair
#define all(x) x.begin(),x.end()
#define MOD 1000000007

int main(){
	LL N;
	cin >> N;
	LL nek = LLONG_MAX;
	for(int i=0; i<5; i++){
		LL tmp;
		cin >> tmp;
		nek = min(nek, tmp);
	}
	LL ans = ceil((double)N/(double)nek) + 4;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int a, b; cin >> a >> b;
  cout << max(a + b, max(a - b, a * b)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P  = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    string s, t;
    cin >> s >> t;
    ll n = s.size();
    ll ans = 0;
    rep(i, n)
    {
        if(s[i] != t[i]) ++ans;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

ll MAX_N = 1e5;
vector<vector<ll> > graph(MAX_N);
vector<bool> visited(MAX_N);

// ALDS1_11_C
vector<ll> d(MAX_N);

// O(E)
void bfs(ll u){
    queue<pair<ll, ll> > Q; // v, dist
    visited[u] = true;
    Q.push(make_pair(u, 0));
    while(!Q.empty()){
        pair<ll, ll> p = Q.front(); Q.pop();
        ll u = p.first, dist = p.second;
        //
        d[u] = dist;
        for(ll v: graph[u]){
            if(!visited[v]){
                visited[v] = true;
                Q.push(make_pair(v, dist + 1));
            }
        }
    }
}

// ALDS1_11_C: verified
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n; cin >> n;
    for(ll i=0;i<n;i++){
        ll u, k; cin >> u >> k;
        for(ll j=0;j<k;j++){
            ll v; cin >> v;
            graph[u - 1].push_back(v - 1);
        }
    }
    fill(d.begin(), d.end(), -1);
    bfs(0);
    for(ll i=0;i<n;i++) cout << i + 1 << " " << d[i] << endl;
}



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


int main(){
  long long int i,j,x;
  int flag=0;
  cin >> x;

  for(i=-1000;i<1000;i++){
    for(j=-1000;j<1000;j++){
      if(pow(i, 5)-pow(j,5)==x){
        flag=1;
        break;
      }
    }
    if(flag==1)break;
  }
  
  cout << i <<" "<< j <<endl;
  return 0;
}


Measured memory_bytes: 4092
#include<iostream>
#include<string>
#include<map>
using namespace std;
map<char, string> M1;
string M2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-\'?";

void init(){
    string list = " \',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string codes[32] = {"101", "000000", "000011", "10010001",
			"010001", "000001", "100101", "10011010",
			"0101", "0001", "110", "01001", "10011011",
			"010000", "0111", "10011000", "0110",
			"00100", "10011001", "10011110", "00101",
			"111", "10011111", "1000", "00110",
			"00111", "10011100", "10011101", "000010",
			"10010010", "10010011", "10010000"};
    for ( int i = 0; i < list.size(); i++ ) M1[list[i]] = codes[i];
}

int getValue(string str){
    int v = 0, p = 1;
    for ( int i = 4; i >= 0; i-- ){
	if ( str[i] == '1' ) v += p;
	p *= 2;
    }
    return v;
}

main(){
    init();
    string line; 
    while(1){
	getline(cin, line);
	if ( cin.eof() ) break;
	string code = "";
	for ( int i = 0; i < line.size(); i++ ){
	    code += M1[line[i]];
	}
	while( code.size()%5 != 0 ) code+= "0";
	
	for ( int i = 0; i < code.size(); i+=5 ){
	    cout << M2[getValue( code.substr(i,5))];
	}
	cout << endl;
    }
}

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

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

  std::vector<int> X(N);
  std::vector<int> A(N);
  int p;
  for (size_t i = 0; i < N; i++) {
    std::cin >> p;
    X[i] = p;
    A[i] = p;
  }

  sort(X.begin(), X.end());
  int m_r = X[N/2], m_l = X[N/2-1];
  
  for (size_t i = 0; i < N; i++) {
    if (A[i] >= m_r) {
      std::cout << m_l << '\n';
    } else {
      std::cout << m_r << '\n';
    }
  }
 }


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <bitset>
using namespace std;

int main(){
	int n;
	cin>>n;
	bitset<100000> b=0;
	vector<int> box;
	int i =2;
	while(box.size()!=n){
		while(1){
			if(b[i]==0){
				if(i%5==2)box.push_back(i);
				if(box.size()==n)break;
				for(int j=1;j*i<100000;j++){
					b[i*j]=1;
				}
			}
			i++;
		}
	}
	for(int j=0;j<n;j++)cout<<box[j]<<" ";
	cout<<""<<endl;
	return 0;
}

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


int main(){
    int n; cin>>n;
    if (n == 1){
        cout << 1 << endl;
        return 0;
    }
    map<int, long long> counter;
    for (int i=1;i<=n;i++){
        int num = i;
        for (int j=2;j<=i;j++){
            while (num % j == 0){
                counter[j]++;
                num /= j;
            }
        }
    }
    long long divisors_num = 1;
    for (auto item : counter){
        divisors_num *= item.second + 1;
        divisors_num %= 1000000007;
    }
    cout << divisors_num << endl;
    return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>

using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_buck(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
#define mod 1000000007


int main(){
	ll N,M;
	cin>>N>>M;
	ll x,y,ans=0;
	x = M/2;
	y = M%2;
	if(x>=N){
		ans+=N;
		x-=N;
		ans=ans+(2*x+y)/4;
	}else{
		ans+=x;
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;
#define int long long
#define br cout<<"\n"
#define all(V) V.begin(),V.end()
#define rall(V) V.rbegin(),V.rend()
#define umap unordered_map
#define uset unordered_set

typedef vector<int> vi;
typedef vector<vi> vvi;

bool isPwrOf2(int x) { return x && (!(x&(x-1))); }
/*------------------------------------------------*/

/*------------------------------------------------*/

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    // #ifndef ONLINE_JUDGE
    //     freopen("./input.txt", "r", stdin);
    //     freopen("./output.txt", "w", stdout);
    // #endif
    /*------------------------------------------------*/
    int n; cin>>n;
    int cnt=0;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
        if(arr[i]%2==0){
            while(arr[i]%2==0){
                cnt++;
                arr[i] = arr[i]/2;
            }
        }
    }
    cout<<cnt;
    /*------------------------------------------------*/
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	int h[n];
	for(int i = 0; i < n; i++)
		cin >> h[i];
	int ans = 0;
	while(1){
		int l=-1;
		for(int i = 0; i < n; i++){
			if(h[i] > 0){
				l = i;
				break;
			}
		}
		if(l == -1)
			break;
		int r = n-1;
		for(int i = l+1; i < n; i++){
			if(h[i] <= 0){
				r = i-1;
				break;
			}
		}
		ans++;
		for(int i = l; i <= r; i++)
			h[i]--;
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void swap(int *a,int *b){
	int temp;
		temp=*a;
		*a=*b;
		*b=temp;
	}
	
int main(void){
	int x,y;
	
	int i;
	
	for(i=0;i<3000;i++){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0) break;
		else if(x>y){
			swap(&x,&y);
			printf("%d %d\n",x,y);
			}
		else printf("%d %d\n",x,y);
		}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<vector<bool>> s(h + 2, vector<bool>(w + 2));
    for (auto i : irange(0L, h)) {
        string ss;
        cin >> ss;
        for (auto j : irange(0L, w)) {
            s[i + 1][j + 1] = (ss[j] == '.');
        }
    }

    int64_t m = 0;
    vector<int64_t> dx{0, 0, 1, -1};
    vector<int64_t> dy{1, -1, 0, 0};
    for (auto i : irange(1L, h + 1)) {
        for (auto j : irange(1L, w + 1)) {
            if (!s[i][j]) {
                continue;
            }

            vector<vector<int64_t>> dist(h + 2, vector<int64_t>(w + 2, -1L));
            queue<pair<int64_t, int64_t>> q;

            dist[i][j] = 0;
            q.emplace(i, j);
            while (!q.empty()) {
                auto now = q.front();
                q.pop();

                for (auto idx : irange(0L, 4L)) {
                    auto next = now;
                    next.first += dy[idx];
                    next.second += dx[idx];

                    if (!s[next.first][next.second]) {
                        continue;
                    }

                    if (dist[next.first][next.second] >= 0) {
                        continue;
                    }

                    dist[next.first][next.second] =
                            dist[now.first][now.second] + 1;
                    q.push(next);
                }
            }

            for (auto i2 : irange(1L, h + 1)) {
                for (auto j2 : irange(1L, w + 1)) {
                    m = max(m, dist[i2][j2]);
                }
            }
        }
    }

    cout << m << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int i,n,sum=0;
	int a[10000];
	scanf("%d",&n);
	for(i=1;i<=2*n;i++)
	scanf("%d",&a[i]);
	sort(a+1,a+2*n+1);
	for(i=1;i<=2*n;i++)
	{
		if(i%2!=0)
		sum+=a[i];
		else
		continue; 
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
  int k,a,b;
  cin>>k>>a>>b;
  for(int i=a;i<=b;i++)
    {
       if(i%k==0)
       {
         cout<<"OK";
         exit(0);
       }
    }
    cout<<"NG";
    return 0;
    }
   

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

int main() {
  int n,m,ans = 0;
  cin >> n >> m;
  vector<vector<int>> s(m,vector<int>());
  rep(i,m) {
    int k;
    cin >> k;
    rep(j,k) {
      int s_i;
      cin >> s_i;
      s_i--;
      s[i].push_back(s_i);
    }
  }
  vector<int> p(m);
  rep(i,m) cin >> p[i];
  for(int bit = 0; bit < (1<<n); ++bit) {
    vector<int> c(m,0);
    for(int i = 0; i < m; ++i) {
      for(int j = 0; j < s[i].size(); ++j) {
      if(bit & (1<<s[i][j])) {
          c[i]++;
          c[i] %= 2;
        }
      }
    }
    if(c==p) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll modpow(ll a, ll n, ll mod_) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod_;
        a = a * a % mod_;
        n >>= 1;
    }
    return res;
}

const ll MAX_SIZE = 200005;
array<ll, MAX_SIZE> fac, inv, finv;
struct finit{
    finit(){
        // combination init
        fac[0] = 1;
        for (ll i = 1; i < MAX_SIZE; i++) fac[i] = fac[i - 1] * i % MOD;
        finv[MAX_SIZE - 1] = modpow(fac[MAX_SIZE - 1], MOD - 2, MOD);
        for(ll i = MAX_SIZE - 1; i > 0; i--) finv[i - 1] = finv[i] * i % MOD;
        
        //inv init
        repe(i, 1, MAX_SIZE) inv[i] = modpow(i, MOD - 2, MOD);
    }
} finit_;

ll perm(ll a, ll b) { return fac[a] * finv[a - b] % MOD; }

ll comb(ll a, ll b) { return fac[a] * finv[b] % MOD * finv[a - b] % MOD; }


int main() {
    ll N;
    cin >> N;
    ll ans = modpow(10, N, MOD);
    ans += MOD - modpow(9, N, MOD) * 2 % MOD;
    ans += modpow(8, N, MOD);
    cout << ans % MOD << endl;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

void decompose(string &s) {
    string temp = string(s.begin(), s.begin() + 5);
    if(temp == "maerd" || temp == "esare") {
        s.erase(s.begin(), s.begin() + 5);
    } else if(temp == "remae") {
        if(s[5] == 'r' && s[6] == 'd') {
            s.erase(s.begin(), s.begin() + 7);
        } else {
            cout << "NO" << endl;
            exit(0);
        }
    } else if(temp == "resar") {
        if(s[5] == 'e') {
            s.erase(s.begin(), s.begin() + 6);
        } else {
            cout << "NO" << endl;
            exit(0);
        }
    } else {
        cout << "NO" << endl;
        exit(0);
    }
}

int main(void) {
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    while(!S.empty()) {
        decompose(S);
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        double a = input.nextDouble();        
        System.out.printf("%.7f %.7f", a * a * Math.PI, a * 2 * Math.PI);
    }         
}

Measured memory_bytes: 19080
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

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

  int n;
  cin >> n;

  ll a[100001] = {};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  ll op1 = 0;
  ll total1 = 0;
  for (int i = 0; i < n; i++) {
    total1 += a[i];
    if (i % 2 == 0) {
      if (total1 <= 0) {
        op1 += abs(total1) + 1;
        total1 = 1;
      }
    } else {
      if (total1 >= 0) {
        op1 += abs(total1) + 1;
        total1 = -1;
      }
    }
  }

  ll op2 = 0;
  ll total2 = 0;
  for (int i = 0; i < n; i++) {
    total2 += a[i];
    if (i % 2 == 0) {
      if (total2 >= 0) {
        op2 += abs(total2) + 1;
        total2 = -1;
      }
    } else {
      if (total2 <= 0) {
        op2 += abs(total2) + 1;
        total2 = 1;
      }
    }
  }

  cout << min(op1, op2) << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int d = in.nextInt();
        boolean t = false;
        while (a > 0 && c > 0) {
            t ^= true;
            if (t) {
                c -= b;
            } else {
                a -= d;
            }
        }
        System.out.println(t ? "Yes" : "No");
    }
}

Measured memory_bytes: 35732
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#define PI atan2(0, -1)
#define EPS 1e-9
#define INF 5e18
#define MOD 1000000007

#define all(x) begin(x), end(x)
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

int N, M, ret = -1;
pair<int, int> st, en;
char grid [1010][1010];
bool visited [1010][1010];
deque<pair<int, pair<int, int>>> dq;

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

bool inBounds(int x, int y){
    return x > -1 && y > -1 && x < N && y < M;
}

int main(){
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
    cin >> N >> M >> st.f >> st.s >> en.f >> en.s;
    st.f--; st.s--; en.f--; en.s--;
    for(int i = 0; i < N; i++) cin >> grid[i];
    dq.push_back({0, st});
    while(dq.size() > 0){
        pair<int, pair<int, int>> state = dq.front(); dq.pop_front();
        if(state.s == en){
            ret = state.f;
            break;
        }
        int r = state.s.f, c = state.s.s;
        if(visited[r][c]) continue;
        visited[r][c] = true;
        for(int i = -2; i <= 2; i++)
            for(int j = -2; j <= 2; j++)
                if(inBounds(r+i, c+j) && !visited[r+i][c+j] && grid[r+i][c+j] == '.')
                    dq.push_back({state.f+1, {r+i, c+j}});
        for(int i = 0; i < 4; i++){
            int nr = r+dx[i], nc = c+dy[i];
            if(inBounds(nr, nc) && !visited[nr][nc] && grid[nr][nc] == '.')
                dq.push_front({state.f, {nr, nc}});
        }
    }
    cout << ret << '\n';
    return 0;
}

/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/


Measured memory_bytes: 6100
def ops_needed(x, target):
    if abs(target - x) < abs(x):
        return 0
    else:
        return target - x

def count_ops(a, first_target):
    total_ops = 0
    accum = 0
    for i, ai in enumerate(a):
        new_accum = accum + a[i]
        if i % 2 == 1:
            ops = ops_needed(new_accum, first_target)
        else:
            ops = ops_needed(new_accum, -1 * first_target)
        total_ops += abs(ops)
        accum = new_accum + ops
    return total_ops
        

if __name__ == '__main__':
    _ = int(input())
    a = list(map(int, input().split()))
    print(min(count_ops(a, 1), count_ops(a, -1)))


Measured memory_bytes: 14468
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#define PI acos(-1.0)
#define eps 1e-8
#define LL long long
#define moo 1000000007
#define INF -999999999
using namespace std;


int N,M,A,B,C,T;

struct matrix
{
       int a[55][55];
}origin,res;

matrix multiply(matrix x,matrix y)
{
       matrix temp;
       memset(temp.a,0,sizeof(temp.a));
       for(int i=0;i<N;i++)
       {
               for(int j=0;j<N;j++)
               {
                       for(int k=0;k<N;k++)
                       {
                            temp.a[i][j]=(temp.a[i][j]+(x.a[i][k]*y.a[k][j])%M)%M;
                       }
               }
       }
       return temp;
}

int s0[55];
void calc()
{
     while(T)
     {
        if(T&1)
            res=multiply(res,origin);
        T>>=1;
        origin=multiply(origin,origin);
     }
}
int main()
{
    //freopen("in.txt","r",stdin);
    while(scanf("%d%d%d%d%d%d",&N,&M,&A,&B,&C,&T)!=EOF)
    {
        if(N==0&&M==0&&A==0&&B==0&&C==0&&T==0)
            break;
        memset(origin.a,0,sizeof(origin));
        for(int i=0;i<N;i++)
            for(int j=0;j<N;j++)
            {
                if(i==j)
                    origin.a[i][j]=B;
                if(i==j+1)
                    origin.a[i][j]=C;
                if(j==i+1)
                    origin.a[i][j]=A;
            }
//        for(int i=0;i<N;i++)
//            for(int j=0;j<N;j++)
//                 printf("%d%c",origin.a[i][j],j==N-1?'\n':' ');
//        cout<<endl;
        memset(res.a,0,sizeof(res.a));
        for(int i=0;i<N;i++)
            res.a[i][i]=1;
        calc();
//        for(int i=0;i<N;i++)
//            for(int j=0;j<N;j++)
//                 printf("%d%c",res.a[i][j],j==N-1?'\n':' ');
//        cout<<endl;
        for(int i=0;i<N;i++)
            scanf("%d",&s0[i]);
        int ans[55];memset(ans,0,sizeof(ans));
        for(int i=0;i<N;i++)
        {
            for(int j=0;j<N;j++)
                    ans[i]=(ans[i]+(s0[j]*res.a[j][i])%M)%M;
        }
        for(int i=0;i<N;i++)
        {
            printf("%d%c",ans[i],i==N-1?'\n':' ');
        }
    }
    return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li res[200200];

int main() {

    li n;
    cin >> n;
    rep(i, n - 1) {
        li x;
        cin >> x;
        res[x - 1]++;
    }
    rin{
        cout << res[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 5148
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
	int i, s_size, t_size, ans;

	string s, t;

	cin>>s>>t;

	s_size=s.size(); t_size=t.size();
  
  	if(s_size<t_size){
    	cout<<"UNRESTORABLE"<<endl;
      	return 0;
    }

	if(ans=s.find(t)!=-1){
		for(i=0; i<s_size; i++){
			if(s[i]=='?'){
				s[i]='a';
			}
		}
		cout<<s<<endl;
	}else{
		for(i=s_size-1; i>=t_size-1; i--){
			ans=-1;
			int j=t_size-1, k=i;
			while(s[k]==t[j]||s[k]=='?'){
				if(j==0){
					ans=k; break;
				}
				k--; j--;
			}
			if(ans>=0) break;
		}
		//cout<<ans<<endl;
		if(ans>=0){
			int j=0;
			for(i=ans; i<ans+t_size; i++, j++){
				if(s[i]=='?'){
					s[i]=t[j];
				}
			}
			for(i=0; i<s_size; i++){
				if(s[i]=='?'){
					s[i]='a';
				}
			}
			cout<<s<<endl;
		}else{
			cout<<"UNRESTORABLE"<<endl;
		}

	}
}


Measured memory_bytes: 256
# Problem https://atcoder.jp/contests/abc088/tasks/abc088_a
# Python 3rd Try
yes = "Yes"
no = "No"


def solver(total, haveOneYen):

    result = False
    oneYenNeed = total % 500
    if oneYenNeed <= haveOneYen:
        result = True
    return result


if __name__ == "__main__":

    answer = ""
    N = int(input())
    A = int(input())
    answer = solver(N, A)
    if answer:
        print(yes)
    else:
        print(no)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long int
//#define d double
#define F first
#define S second
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(10)
const int M=1e9+7;
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)
#define pi pair<ll,ll>
//const int MOD=998244353;
const int MOD=1e9+7;
#define endl "\n"
const double PI = 3.141592653589793238460;
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
//bitset<N>bs;
//bitset<512>bb[512];
//vector<vector<int>>arr;

ll power(ll a,ll b)
{
    ll res=1;
    if(a==0)return 0;
    if(a==1)return 1;
    for(;b>0;b>>=1)
    {
        if(b&1)res=(res*a);
        if(res>MOD)res%=MOD;
        a=(a*a);
        if(a>MOD)a=a%MOD;
    }
    return res;
}

bool isPrime[1000001];
vector<ll>prime;

void seive(int limit)
{
    isPrime[0]=isPrime[1]=1;

    for(int i=2;i*i<=limit;i++)
    {
        if(!isPrime[i])
        for(int j=i*i;j<=limit;j+=i)
        {
            isPrime[j]=1;
        }
    }
    for(int i=2;i<=limit;i++)if(!isPrime[i])prime.pb(i);
}

int main()
{
    int n;
    cin>>n;
    ll arr[n];
    f(n-1)cin>>arr[i];

    ll cnt[n+1];
    memset(cnt,0,sizeof cnt);

    f(n-1)cnt[arr[i]]++;

    f(n)cout<<cnt[i+1]<<"\n";

}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto& e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())

ll MOD(ll x, ll m) {
    ll r = x % m;
    if (r < 0) {
        r += m;
    }
    return r;
}

ostream& operator<<(ostream& str, const pll& p) {
    str << p.first << " " << p.second;
    return str;
}

template <typename T>
void join(T& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << "\n";
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 9e18
#define MINF -INF

void solve() {
    ll n;
    cin >> n;
    string res;
    while (n > 0) {
        if (n % 26 == 0) {
            res.push_back('z');
            n--;
        } else {
            res.push_back('a' + (n%26) - 1);
        }
        n /= 26;
    }
    REVERSE(res);
    cout << res << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    // cin >> tt;
    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }

    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, k, r, s, p;
string t;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n >> k >> r >> s >> p >>t;
	
	ll ans = 0;
	bool use[n+1];
	rep(i, 1, n){
		if(i < k || t[i-1] != t[i-1-k]){
			if(t[i-1] == 'r'){ans += p; use[i] = true;}
			if(t[i-1] == 's'){ans += r; use[i] = true;}
			if(t[i-1] == 'p'){ans += s; use[i] = true;}
		}
		else{
			if(use[i-k]){
				use[i] = false;
			}
			else{
				if(t[i-1] == 'r'){ans += p; use[i] = true;}
				if(t[i-1] == 's'){ans += r; use[i] = true;}
				if(t[i-1] == 'p'){ans += s; use[i] = true;}
			}
		}
	}
	print(ans)
	return 0;
}

Measured memory_bytes: 592
#include <cstdio>
 
#include <iostream>
 
#include <cstring>
 
using namespace std;
 
typedef long long ll;
 
  
 
#define row 1001333  //取一个比h2(k)大的质数
 
#define col 20
 
  
 
char H[row][col];
 
  
 
ll h1(ll key){
 
    return key%row;
 
}
 
  
 
ll h2(ll key){
 
    return 1+(key%(row-1));
 
}
 
  
 
ll chtonum(char s){  //character to number
 
    if(s=='A') return 1;
 
    if(s=='C') return 2;
 
    if(s=='G') return 3;
 
    if(s=='T') return 4;
 
    return 0;
 
}
 
  
 
ll get_key(char s[]){  //生成key值
 
    ll sum=0,p=1;
 
    int len=strlen(s);
 
    for(ll i=0;i<len;i++){
 
        sum+=p*chtonum(s[i]);
 
        p*=5;
 
    }
 
    return sum;
 
}
 
  
 
void insert(char s[]){
 
    ll key,h;
 
    key=get_key(s);
 
    ll i =0;
 
    while(1){
 
        h=(h1(key)+i*h2(key))%row;  //根据key值生成对应的位置
 
        if(strcmp(H[h],s)==0) return ;//这个元素字典里已经有了
 
        else if (strlen(H[h])==0){
 
            strcpy(H[h], s);//如果该位置没有别的值，就把这个元素插进去
 
            return ;
 
        } 
 
        i++;//如果这个i对应的h的位置已经有元素了，那么继续寻找下一个i对应的位置
 
    }
 
}
 
  
 
bool find(char s[]){
 
    ll key,h;
 
    key=get_key(s);
 
    ll i=0;
 
    while(1){
 
        h=(h1(key)+i*h2(key))%row;
 
        if(strcmp(H[h],s)==0) return true;//如果找到了该元素
 
        else if (strlen(H[h])==0) return false;
 
        i++;
 
    }
 
    return false;
 
}
 
  
 
int main (){
 
    int n;
 
    char c[20],s[20];
 
    for(int i = 0;i<row;i++) H[i][0]='\0'; //把数组初始化 方便比较
 
    scanf("%d",&n);
 
    for(int i =0;i<n;i++){
 
        cin>>c>>s;
 
        if(c[0]=='i') insert(s);
 
        else {
 
            if(find(s)) cout<<"yes"<<endl;
 
            else cout<<"no"<<endl;
 
        }
 
    }
 
    return 0;
 
}


Measured memory_bytes: 22712
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    string ans="",s;cin>>s;
    for(int i=0;i<s.size()-8;i++){
        ans+=s[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3540
#!/bin/sh
read x y
 
if [ "${x::1}" != "-" -a ${y::1} != "-" ] || [ "${x::1}" = "-" -a ${y::1} = "-" ]
then
	if [ $x -lt $y ]
	then
		ans=$((y - x))
	elif [ $x -gt $y ]
	then
		ans=$((x - y + 2))
	fi
 
	if [ $y -eq 0 ]
	then
		ans=$((ans - 1))
	fi
	
	echo $ans
	exit
fi
 
if [ "${x::1}" != "-" -a ${y::1} = "-" ]
then
	if [ "${x}" = "${y/-/}" ]
	then
		echo 1
		exit
	fi
	
	yy="${y/-/}"
	
	if [ $x -gt $yy ]
	then
		ans=$((x - yy + 1))
	elif [ $x -lt $yy ]
	then
		ans=$((yy - x + 1))
	fi
  
	echo $ans
	exit
fi
 
if [ "${y::1}" != "-" -a ${x::1} = "-" ]
then
	if [ "${y}" = "${x/-/}" ]
	then
		echo 1
		exit
	fi
	
	xx="${x/-/}"
	
	if [ $y -gt $xx ]
	then
		ans=$((y - xx + 1))
	elif [ $y -lt $xx ]
	then
		ans=$((xx - y + 1))
	fi
 
	if [ $y -eq 0 ]
	then
		ans=$((ans - 1))
	fi
 
	echo $ans
	exit
fi


Measured memory_bytes: 504
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
const int INF = 100000000, mod = 1000000007;
using namespace std;

int main() {
    int h, w, n, panel[10010], left=1, sum=0;
    cin >> h >> w >> n;
    for (int i = 1; i <= n; i++) {
        int tmp;
        cin >> tmp;
        sum += tmp;
        for (int j = left; j < left + tmp; j++) panel[j] = i;
        left += tmp;
    }
    bool reverse = false;
    for (int i = 0; i < h; i++) {
        if (reverse) {
            for (int j = (i+1)*w; j >= i*w+1; j--) {
                cout << panel[j];
                if (j == i*w+1) cout << endl;
                else cout << ' ';
            }
            reverse = false;
        }
        else {
            for (int j = 1+i*w; j <= (i + 1)*w; j++) {
                cout << panel[j];
                if (j == (i + 1)*w) cout << endl;
                else cout << ' ';
            }
            reverse = true;
        }
    }
    return 0;
}

Measured memory_bytes: 384
n, m = gets.chomp.split(' ').map(&:to_i)
strs = Hash.new
m.times.map { strs[gets.to_i] = true }
MOD = 10**9+7
dp = Array.new(n+10, 0)
dp[0] = 1

n.times do |idx|
  if strs[idx]
    dp[idx] = 0
  else
    dp[idx+1] += dp[idx] if !strs[idx+1]
    dp[idx+2] += dp[idx] if !strs[idx+2]
  end
end
print dp[n] % MOD

Measured memory_bytes: 856828
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
typedef long long lint;
const lint MOD = 10e9;
typedef vector<int> vint;
typedef pair<int, int> pint;
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 modulo(int a, int b, int n) {
    long long x = 1, y = a;
    while(b > 0) {
        if(b % 2 == 1) {
            x = (x * y) % n; // multiplying with base
        }
        y = (y * y) % n; // squaring the base
        b /= 2;
    }
    return x % n;
}
/* templates */ /* templates */ /* templates */ /* templates */ /* templates */

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

    int N;
    cin >> N;
    int a[N + 1], b[N + 1], c[N + 1];
    rep(i, 1, N + 1) { cin >> a[i] >> b[i] >> c[i]; }
    int dp[N + 10][3];
    rep(i, 3) { dp[0][i] = 0; }
    rep(i, 1, N + 1) {
        dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]);
        dp[i][1] = max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i]);
        dp[i][2] = max(dp[i - 1][1] + c[i], dp[i - 1][0] + c[i]);
    }
    cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << "\n";
}

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

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

  // cout << s.substr(0 + (n / 2), 1);

  if(n%2 ==0 ){
    if(s.substr(0,n/2) == s.substr(n/2,n/2)){
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
}


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

#define PB push_back

int val[10];
vector<int> v[10];

main()
{
    int n,w;
    scanf("%d %d",&n,&w);
    for(int i=0;i<n;i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        for(int j=0;j<10;j++)
        {
            if(a==val[j])
            {
                v[j].PB(b);
                break;
            }
            else if(val[j]==0)
            {
                val[j]=a;
                v[j].PB(b);
                break;
            }
        }
    }
    for(int i=0;i<10;i++)
    {
        if(val[i]!=0)
        {
            sort(v[i].begin(),v[i].end());
            v[i].PB(0);
        }
    }
    int ans=0;
    int cal1=0,cal2=0,cal3=0,cal4=0;
    for(int i=v[0].size()-1;i>=0;i--)
    {
        long long use1=v[0].size()-i-1;
        long long limit1=w-use1*val[0];
        if(limit1<0)
            break;
            //printf("1:%d limit=%d\n",v[0][i],limit1);
        cal1+=v[0][i];
        ans=max(ans,cal1);
        if(limit1==0)
            break;

        for(int j=v[1].size()-1;j>=0;j--)
        {
            long long use2=v[1].size()-j-1;
            long long limit2=limit1-use2*val[1];
            if(limit2<0)
                break;
            //printf("    2:%d limit=%d\n",v[1][j],limit2);
            cal2+=v[1][j];
            ans=max(ans,cal1+cal2);
            if(limit2==0)
                break;

            for(int k=v[2].size()-1;k>=0;k--)
            {
                long long use3=v[2].size()-k-1;
                long long limit3=limit2-use3*val[2];
                if(limit3<0)
                    break;
                //printf("        3:%d limit=%d\n",v[2][k],limit3);
                cal3+=v[2][k];
                ans=max(ans,cal1+cal2+cal3);
                if(limit3==0)
                    break;

                for(int l=v[3].size()-1;l>=0;l--)
                {
                    long long use4=v[3].size()-l-1;
                    long long limit4=limit3-use4*val[3];
                    if(limit4<0)
                        break;
                    //printf("            4:%d limit=%d\n",v[3][l],limit4);
                    cal4+=v[3][l];
                    ans=max(ans,cal1+cal2+cal3+cal4);
                }
                cal4=0;
            }
            cal3=0;
        }
        cal2=0;
    }
    printf("%d\n",ans);
}


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

int K,T,a;
pair<int,int> A[110];
int main(){
	cin >> K >> T;
	priority_queue<pair<int,int>> Q;
	for(int i=0;i<T;i++){
		cin >> a;
		Q.push({a,i});
		A[i] = {a,i};
	}
	for(int i=0;i<K;i++){
		pair<int,int>  s = Q.top(),t = {-1,-1};
		Q.pop();
		if(!Q.empty()){
			t = Q.top();
			Q.pop();
			s.first--;
			t.first--;
			if(s.first!=0) Q.push({s.first,s.second});
			if(t.first!=0) Q.push({t.first,t.second});
			if(s.first==0 && t.first==0){
				cout << 0 << endl;
				return 0;
			}
		}else{
			cout << s.first -1 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

int main()
{
	int n;
	while(cin >> n,n){
		int s[100];

		for(int i = 0; i < n; i++)
			cin >> s[i];

		sort(s,s+n);

		int sum = 0;
		for(int i = 1; i < n-1; i++)
			sum += s[i];

		cout << sum / (n-2) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int a,b;
  cin >> a >> b;
  
  if ( (a*b+1)%2 == 0 ) {
    cout << "Odd" << endl;
  }
  
  else {
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int p, n;
  while(cin >> p >> n, p || n) {
    int u = 1, v = 1, x = n, y = 1;
    for(int i = 1; i <= n; i++) {
      for(int j = u*i/v; j <= n; j++) {
	if(j*j <= p*i*i) {
	  if(__gcd(i, j) != 1) continue;
	  if(u*i - j*v < 0) u = j, v = i;
	} else {
	  if(x*i - j*y > 0) x = j, y = i;
	  break;
	}
      }
    }
    cout << x << "/" << y << " " << u << "/" << v << endl;
  }
  return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N;i++)
typedef pair<int,int> Pi;
#define F first
#define S second
#define INF 1 << 28

inline void chmax(int &a,int b) {
  a = max(a,b);
}

inline void chmin(int &a,int b) {
  a = min(a,b);
}

int mx[] = {1,0};
int my[] = {0,1};

int main()
{
  int W, H, N;
  int A, B;
  while(cin >> W >> H,W || H) {
    int dp[20][20] = {0};
    dp[0][0] = 1;
    cin >> N;
    while(N--) {
      cin >> A >> B;--A,--B;
      dp[B][A] = -1;
    }
    Rep(i,H) {
      Rep(j,W) {
	if(!(~dp[i][j]))continue;
	Rep(k,2) {
	  int ny = i + my[k];
	  int nx = j + mx[k];
	  if(!~(dp[ny][nx]))continue;
	  if(ny > H || nx > W)continue;
	  dp[ny][nx] += dp[i][j];
	}
      }
    }
    cout << dp[H - 1][W - 1] << endl;
  }
  return 0;
}

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

const int N = 100;
int pos, cnt;
int In[N], Pre[N];

void construct_tree(int left, int right) {
  if (left < right) {
    int i, root = Pre[pos++];
    for (i = left; i < right; i++) {
      if (In[i] == root) break;
    }
    // left subtree
    construct_tree(left, i);
    // right subtree
    construct_tree(i+1, right);
    // print nodes in postorder
    if (cnt > 0) cout << " ";
    cout << root;
    cnt++;
  }
}

int main() {
  int i, n;

  cin >> n;
  // input
  for (i = 0; i < n; i++) cin >> Pre[i];
  for (i = 0; i < n; i++) cin >> In[i];

  // initialize
  cnt = 0;
  pos = 0;
  // output
  construct_tree(0, n);
  cout << endl;

  return 0;
}



Measured memory_bytes: 3080
#ifdef _DEBUG
#include ".vscode/debug_print.hpp"
#else
#define debug(...)
#endif
#include <bits/stdc++.h>

using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1050000000;
constexpr long long INF64 = 4000000000000000000;
constexpr int MOD7        = 1000000007;
constexpr int MOD53       = 998244353;
constexpr long double PI  = 3.14159265358979323846;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

void vprint() { std::cout << '\n'; }
template <class H, class... T> void vprint(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << '\n';
    vprint(std::forward<T>(args)...);
}
template <class T> void vprint(std::vector<T> &v) {
    for (auto &&i : v) {
        std::cout << i << '\n';
    }
}

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

    string s;
    scan(s);
    if (s[0] == '7' || s[1] == '7' || s[2] == '7') {
        print("Yes");
    } else {
        print("No");
    }

    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
using namespace std;
int main(){
  int N, M, C;
  cin >> N >> M >> C;
  
  int B[M];
  int A[N][M];
  
  for(int i=0; i < M; ++i){
    cin >> B[i];
  }
  for(int i=0; i < N; ++i){
    for(int j=0; j < M; ++j){
      cin >> A[i][j];
    }
  }
  
  int sum = 0;
  int count = 0;
  for (int i=0; i < N; ++i){
    for (int j=0; j < M; ++j){
      sum += A[i][j] * B[j];
    }
    if( sum + C > 0){
      count++;
    }
    sum = 0;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256