akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>
#include <assert.h>
#include <random>

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14


using namespace std;

// nまでの素数のリストを作成(nを含む) O(N log long N)
vector<int> make_prime_list(int n) {
    vector<bool> is_prime(n + 1, true);
    is_prime[0] = false;
    is_prime[1] = false;

    vector<int> prime_list;
    for (int i = 2; i < n + 1; ++i) {
        if (!is_prime[i]) { continue; }
        prime_list.emplace_back(i);

        for (int j = i; j < n + 1; j += i) {
            is_prime[j] = false;
        }
    }
    return prime_list;
}

int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    vector<int> prime_list = make_prime_list(1000100);

    int n;
    while(cin >> n) {
        int ans = 0;
        for(int i = 0;;++i)  {
            if(prime_list[i] <= n){
                ans++;
            }
            else {
                break;
            }
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3432
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  while(cin >> str){
    string st[8];
    st[0]=str;
    int i,j;
    for(i=1;i<8;i++) cin >> st[i];

    //for(i=0;i<8;i++) cout << st[i] << endl;
    //cout << endl;
    char o='0';
    for(i=0;i<8;i++){
      for(j=0;j<8;j++){
	if(st[i][j]=='1'){
	  if(j<7&&i<7){
	    if(st[i][j]=='1'&&
	       st[i+1][j]=='1'&&
	       st[i][j+1]=='1'&&
	       st[i+1][j+1]=='1'){
	      o='A';
	      break;
	    }
	  }
	  if(i<5){
	    if(st[i][j]=='1'&&
	       st[i+1][j]=='1'&&
	       st[i+2][j]=='1'&&
	       st[i+3][j]=='1'){
	      o='B';
	      break;
	    }  
	  }
	  if(j<5){
	    if(st[i][j]=='1'&&
	       st[i][j+1]=='1'&&
	       st[i][j+2]=='1'&&
	       st[i][j+3]=='1'){
	      o='C';
	      break;
	    }
	  }
	  if(0<j&&i<6){
	    if(st[i][j]=='1'&&
	       st[i+1][j]=='1'&&
	       st[i+1][j-1]=='1'&&
	       st[i+2][j-1]=='1'){
	      o='D';
	      break;
	    }
	  }
	  if(j<6&&i<7){
	    if(st[i][j]=='1'&&
	       st[i][j+1]=='1'&&
	       st[i+1][j+1]=='1'&&
	       st[i+1][j+2]=='1'){
	      o='E';
	      break;
	    }
	  }
	  if(j<8&&i<6){
	    if(st[i][j]=='1'&&
	       st[i+1][j]=='1'&&
	       st[i+1][j+1]=='1'&&
	       st[i+2][j+1]=='1'){
	      o='F';
	      break;
	    }
	  
	  }
	  if(j<8&&i<8){
	    if(st[i][j]=='1'&&
	       st[i][j+1]=='1'&&
	       st[i+1][j]=='1'&&
	       st[i+1][j-1]=='1'){
	      o='G';
	      break;
	    }
	  }
	}	
      }
    }
    cout << o << endl;
    //cin >> str;
  }
  return 0;
}

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

#define   ll             long long int
#define   pb             push_back
#define   mp             make_pair
#define   fast           ios_base::sync_with_stdio(false);cin.tie(NULL);
#define   ff             first
#define   ss             second
#define   nil           -10e+9
#define   initial         0
#define   waiting         1
#define   visit           2
#define   inf            10e+9
#define   mx             200005
#define   mxx            1000005
#define   mod            1000000007
#define   pr             pair<ll,ll>
#define   pp_queue       priority_queue<pr,vector<pr>, greater<pr> >
#define   dp_queue       priority_queue<int,vector<int>, greater<int> >
#define   sp_queue       priority_queue<int>
#define   fr(i,p,q)      for(int i=p;i<q;++i)
#define   frr(i,p,q)     for(int i=p;i<=q;++i)
#define   mem(a,b)       memset(a,b,sizeof(a))
#define   len(a)         (int)a.size()
#define   input          freopen("input.txt", "r", stdin);
#define   output         freopen("output.txt", "w", stdout);
#define   debug(arr,j,n) fr(i,j,n) cout<<arr[i]<<" ";

ll power(ll a,ll b){ll aa=1;while(b){if(b&1){aa=aa*a;aa%=mod;}a=a*a;a%=mod;b/=2;}return aa;}

using namespace std;

int main()
{
  string s,t;
  cin>>s>>t;
  int cnt=0;
  fr(i,0,3){
    if(s[i]==t[i]) cnt++;
  }
  cout<<cnt;
  return 0;
}

Measured memory_bytes: 256
q, h, s, d = map(int, input().split())
n = int(input())
l = [4 * q, 2 * h, s, d / 2]
ans = 0
if n >= 2:
  a = l.index(min(l))
  if a == 0:
    ans = 4 * q * n
  elif a == 1:
    ans = 2 * h * n
  elif a == 2:
    ans = s * n
  elif a == 3:
    if n % 2 == 0:
      ans = n // 2 * d
    elif n % 2 == 1:
      ans = n // 2 * d
      b = l.index(min(l[:3]))
      if b == 0:
        ans += 4 * q
      elif b == 1:
        ans += 2 * h
      elif b == 2:
        ans += s
else:
  b = l.index(min(l[:3]))
  if b == 0:
    ans = 4 * q * n
  elif b == 1:
    ans = 2 * h * n
  elif b == 2:
    ans = s * n
print(ans)

Measured memory_bytes: 9196
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  char field [100][100];
  for(int i = 0; i < 100; i++) {
    for(int j = 0; j < 100; j++) {
      if(i < 50) field[i][j] = '.';
      else field[i][j] = '#';
    }
  }

  // #.
  // .. という形のブロックを作ると、.の連結数を変えずに#の数だけ増やせる。
  //
  // それが、50 * 25 = 1250個作れるので、500 500の制約は余裕で対応出来る

  int white, black;
  cin >> white >> black;
  white--;
  black--;
  for(int i = 0; i < 100; i++) {
    for(int j = 0; j < 100; j++) {
      if(i < 50 and black > 0) {
        if(i % 2 == 0 and j % 2 == 0) {
          field[i][j] = '#';
          black--;
        }
        //50行目は仕切りのために塗らない
      } else if(i > 50 and white > 0) {
        if(i % 2 == 0 and j % 2 == 0) {
          field[i][j] = '.';
          white--;
        }
      }
    }
  }

  cout << "100 100" << endl;
  for(int i = 0; i < 100; i++) {
    for(int j = 0; j < 100; j++) {
      cout << field[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 888
N = int(input())
S = input()


def calculate(n, s):
    arr = list(s)
    result = []


    leftW = 0
    rightR = arr.count('R')


    if rightR == 0:
        print(0)
        return

    for i in range(n):
        val = arr[i]

        if val == 'R':
            rightR -= 1

        if val == 'W':
            leftW += 1

        result.append(max(leftW,rightR))

    if len(result) == 0:
        print(0)
    else:
        print(min(result))

calculate(N, S)


Measured memory_bytes: 18848
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <vector>

#define PI (3.14159265358979323846)
#define INF (1e+9)
#define DV_NUM (100000007)

using namespace std;
 
int main()
{

int N;
cin >> N;

int A[N];

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

bool isApproved = true; 

for(int k=0;k<N;k++){
 if( (A[k]%2 == 0 && ((A[k]%3==0)||(A[k]%5==0)))
    || A[k]%2 == 1 ){
    isApproved = isApproved && true;
 }else{
    isApproved = isApproved && false;
 }
}

string Answer;

if(isApproved == true){
    Answer = "APPROVED";
}else{
    Answer = "DENIED";
}

    cout << Answer << endl;
 
    return 0;
 
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        final int Mod = 1000000000+7;
        int[] rec= new int[N+1];
        long ans = 1;
        for(int i=2;i<=N;i++){
            int k=i;
            for(int j=2;j<=k;j++){
                while(k%j==0){
                    rec[j]++;
                    k = k/j;
                }
            }
            //if(k>0) rec[k]++;
        }
        for(int i=2;i<=N;i++){
            if(rec[i]>0) ans = ans*(rec[i]+1)%Mod;
        }
        System.out.println(ans%Mod);
    }
}


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

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint factorial[3000];

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

  if (s == 1 || s == 2) {
    cout << 0 << endl;
    return 0;
  }

  factorial[0] = 1; factorial[1] = 1;
  for(int i = 2; i < 3000; i++) {
    factorial[i] = factorial[i - 1] * i;
  }

  int maxDigits = s / 3;
  mint ans = 0;
  for(int d = 1; d <= maxDigits; d++) {
    int remaining = s - 3 * d;
    ans += factorial[d - 1 + remaining] / factorial[d - 1] / factorial[remaining];
  }

  cout << ans.x << endl;

  return 0;
}
/*
*/


Measured memory_bytes: 3660
#include <iostream>
#include <string>

int main() {
    auto s = new bool['z' - 'a' + 1];
    std::string str;
    std::cin >> str;
    for (auto c: str) {
        int i = c - 'a';
        if (s[i]) {
            std::cout << "no" << std::endl;
            return 0;
        }
        s[i] = true;
    }
    std::cout << "yes" << std::endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = (int)(n)-1; i >=0; i--)

using ll = long long;

int main(){
  vector<vector<int>> c(3,vector<int>(3));
  rep(i,3)rep(j,3)cin>>c.at(i).at(j);
  pair<int,int> h,v;
  h = make_pair(c.at(0).at(2)-c.at(0).at(0),c.at(0).at(1)-c.at(0).at(0));
  v = make_pair(c.at(2).at(0)-c.at(0).at(0),c.at(1).at(0)-c.at(0).at(0));
  int flag  = 0;
  rep1(i,3){
    pair<int,int> tmp = make_pair(c.at(i).at(2)-c.at(i).at(0),c.at(i).at(1)-c.at(i).at(0));
    if(tmp!=h)flag=1;
  } 
  rep1(i,3){
    pair<int,int> tmp = make_pair(c.at(2).at(i)-c.at(0).at(i),c.at(1).at(i)-c.at(0).at(i));
    if(tmp!=v)flag=1;
  }  
  if(flag)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<cmath>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<functional>
#define INF 1e16
#define N (1000000000+7)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> Q;


ll gcd(ll a, ll b) {
    if(b==0) return abs(a);
	else return gcd(b, a%b);
}

ll kaijo[2000010];
void init() {
	kaijo[0] = 1;
	for (ll i = 1;i < 2000010;i++)kaijo[i] = (kaijo[i - 1] * i) % N;
}
 
ll inv(ll x,ll power) {
	ll res = 1;
	ll k = power;
	ll y = x;
	while (k) {
		if (k & 1)res = (res*y) % N;
		y = (y%N*y%N) % N;
		k /= 2;
	}
	return res;
}
 
ll Comb(ll n, ll k) {
	if (n < 0 || k < 0 || (n - k) < 0)return 0;
	ll b = kaijo[n];
	ll c = kaijo[n - k];
	ll d = kaijo[k];
	ll cd = (c*d) % N;
	return ((b%N)*(inv(cd,N-2)) % N) % N;
}

int main(void){
    init();
    ll r1,r2,c1,c2;
    cin>>r1>>c1>>r2>>c2;
    ll ans=0;
    for(ll i=0;i<=r2;i++){
        ans = (ans+Comb(i+c2+1,c2))%N;
    }
    ans = (ans+N)%N;
    for(ll i=0;i<r1;i++){
        ans = (ans-Comb(i+c2+1,c2))%N;
        ans = (ans+N)%N;
    }
    ans = (ans+N)%N;
    for(ll i=0;i<=r2;i++){
        ans = (ans-Comb(i+c1,c1-1))%N;
        ans = (ans+N)%N;
    }
    ans = (ans+N)%N;
    for(ll i=0;i<r1;i++){
        ans = (ans+Comb(i+c1,c1-1))%N;
        ans = (ans+N)%N;
    }
    ans = (ans+N)%N;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 199;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
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;
    }
}

// 二項係数計算
ll 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;
}

//順列計算
ll PER(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

int main(){
    ll n,k;
    cin >> n >> k;
    int h[n+1];
    rep1(i,n) cin >> h[i];
    ll c[n+1]; //minimum cost
    rep1(i,n) c[i] = 0;
    for(int i = 2; i <= n; i++){
        ll tmp_min = c[i-1] + abs(h[i-1] - h[i]);
        rep1(j, k){
            if(i - j == 0) break;
            ll tmp_cost = c[i-j] +abs(h[i] - h[i-j]);
            if(tmp_min > tmp_cost) tmp_min = tmp_cost;
        }
        c[i] = tmp_min;
    }
    cout << c[n] << endl;
    return 0;
}

Measured memory_bytes: 4300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int K, X;
    cin >> K >> X;
    if(K * 500 >= X)
    {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
#define MOD 998244353
#define MAX 4040
void add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
int jc[MAX],jv[MAX],inv[MAX],n,k,tot[MAX];
int C(int n,int m){return 1ll*jc[n]*jv[m]%MOD*jv[n-m]%MOD;}
int main()
{
	scanf("%d%d",&k,&n);
	jc[0]=jv[0]=inv[0]=inv[1]=1;
	for(int i=2;i<=n+k;++i)inv[i]=1ll*inv[MOD%i]*(MOD-MOD/i)%MOD;
	for(int i=1;i<=n+k;++i)jc[i]=1ll*jc[i-1]*i%MOD;
	for(int i=1;i<=n+k;++i)jv[i]=1ll*jv[i-1]*inv[i]%MOD;
	for(int i=1;i<=k;++i)tot[i+1]+=1,tot[i+k+1]-=1;
	for(int i=1;i<=k+k;++i)tot[i]+=tot[i-1];
	for(int i=2;i<=k+k;++i)
	{
		int cnt=(tot[i]+1)/2,ans=0;
		for(int j=0,d=1;j<=cnt&&j+j<=n;++j,d=MOD-d)
			add(ans,1ll*d*C(cnt,j)%MOD*C(n-2*j+k-1,k-1)%MOD);
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0), cin.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 2e5 + 5;
const int inf = ~0u >> 1;
typedef pair<int, int> P;
#define REP(i, a, n) for (int i = a; i < (n); ++i)
#define PER(i, a, n) for (int i = (n)-1; i >= a; --i)
const ll mod = 1e9 + 7;
int fa[maxn];
ll cnt[maxn];
int find(int x) {
    if (fa[x] != x) fa[x] = find(fa[x]);
    return fa[x];
}
void merge(int r1, int r2)  //合并两个集合，r2合并到r1
{
    r1 = find(r1);
    r2 = find(r2);
    if (r1 != r2) {
        fa[r2] = r1;
        cnt[r1] += cnt[r2];
        cnt[r2] = 0;
    };
}

int main() {
    IO;
    int n, m;
    cin >> n >> m;
    REP(i, 1, n + 1) {
        fa[i] = i;
        cnt[i] = 1;
    }
    while (m--) {
        int a, b;
        cin >> a >> b;
        merge(a, b);
    }
    ll ans = 0;
    REP(i, 1, n + 1) {
        ans = max(ans, cnt[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5984
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int p=1e9+7;
int n,t,las;
char s[2][60];
long long ans;
int main(){
	scanf("%d",&n);
	scanf("%s%s",s[0]+1,s[1]+1);
	if (s[0][1]==s[1][1]){
		ans=3;
		t=2;
		las=1;
	}else{
		ans=6;
		t=3;
		las=2;
	}
	while (t<=n){
		if (s[0][t]==s[1][t]){
			if (las==1) ans=ans*2%p;
			t++;
			las=1;
		}else{
			if (las==1) ans=ans*2%p;else ans=ans*3%p;
			t+=2;
			las=2;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

static const int MAX =100;
static const int INF=(1<<21);
static const int WHITE =0;
static const int GRAY =1;
static const int BRACK =2;

int n,A[MAX][MAX];

int prim(){
  int x,minv,d[MAX],p[MAX],c[MAX];

  for(int i=0;i<n;i++){
    d[i]=INF;
    p[i]=-1;
    c[i]=WHITE;
  }

  d[0]=0;
  while(1){
    minv=INF;
    x=-1;
    for(int i=0;i<n;i++){
      if(minv>d[i] && c[i]!=BRACK){
	x=i;
	minv=d[i];
      }
    }
    if(x==-1)break;
    c[x]=BRACK;
    for(int v=0;v<n;v++){
      if(c[v]!=BRACK && A[x][v]!=INF){
	if(d[v]>A[x][v]){
	  d[v]=A[x][v];
	  p[v]=x;
	  c[v]=GRAY;
	}
      }
    }
  }
  int sum=0;
  for(int i=0;i<n;i++){
    if(p[i]!=-1)sum+=A[i][p[i]];
  }

  return sum;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int e;
      cin>>e;
      A[i][j]=(e==-1)?INF:e;
    }
  }

  cout<<prim()<<endl;
  return 0;
}



Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;

const int maxn=6111;
int n,a[maxn],b[maxn],ps[maxn];
char s[maxn],tmpv[maxn];

vector<string> vs;
void check(int l,int r)
{
	if(a[l]<b[l])
	{
		int tot=0;
		for(int i=l;i<=r;i++)
		{
			tmpv[tot++]='a';tmpv[tot++]='b';
			int tmp=i;
			while(i<=r&&a[i]<b[tmp])i++;
			i--;
		}
		tmpv[tot]=0;
		vs.pb(string(tmpv));
	}
	else
	{
		string opt="";
		for(int i=l;i<=r;i++)
		{
			int tot=0;
			for(int j=b[l];j<=a[r];j++)if(ps[j]>=i)tmpv[tot++]=s[j];
			tmpv[tot]=0;
			opt=max(opt,string(tmpv));
		}
		vs.pb(opt);
	}
}
int main()
{
	scanf("%d%s",&n,s+1);
	
	int cnta=0,cntb=0,last=0;
	for(int i=1;i<=n+n;i++)
	{
		if(s[i]=='a')
		{
			a[++cnta]=i;
			ps[i]=cnta;
		}
		else
		{
			b[++cntb]=i;
			ps[i]=cntb;
		}
		if(cnta==cntb)
		{
			check(last+1,cnta);
			last=cnta;
		}
	}
	
	string ans="";
	for(int i=(int)vs.size()-1;i>=0;i--)
	{
		if(vs[i]+ans>ans)ans=vs[i]+ans;
	}
	printf("%s\n",ans.c_str());
	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int h, w;
    while (cin >> h >> w, h || w)
    {
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
                    cout << '#';
                else
                    cout << '.';
            }
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3076
### constant

DELTA = 1e-5
ERROR = 1.0 - DELTA

### subroutines

def solve_eqn(n, mat, v)
  #p [mat, v]
  
  for i in (0...n)
    if mat[i][i] == 0
      for j in ((i + 1)...n)
        if mat[j][i] != 0
          tmp = mat[i]; mat[i] = mat[j]; mat[j] = tmp;
          tmp = v[i]; v[i] = v[j]; v[j] = tmp
          break
        end
      end
    end

    mii = mat[i][i]
    if mii != 1
      (i...n).each{|j| mat[i][j] /= mii}
      v[i] /= mii
    end

    for j in ((i + 1)...n)
      mji = mat[j][i]
      (i...n).each{|k| mat[j][k] -= mji * mat[i][k]}
      v[j] -= mji * v[i]
    end
  end
  #p [mat, v]

  (n - 1).downto(0) do |i|
    ((i + 1)...n).each{|j| v[i] -= mat[i][j] * v[j]}
  end
  #p v; exit

  v
end

### main

loop do
  d = gets.to_i
  break if d == 0

  v = Array.new(d + 3){gets.to_f}
  #p v

  mat = Array.new(d + 3){[]}
  for i in (0..(d + 2))
    for j in (0..d)
      mat[i][j] = i ** j
    end
  end
  #p mat

  found = nil

  for i0 in (0..(d + 2))
    for i1 in ((i0 + 1)..(d + 2))
      mat0 = []
      v0 = []
      for k in (0..(d + 2))
        if k != i0 && k != i1
          mat0 << mat[k].map{|col| Rational(col)}
          v0 << v[k]
        end
      end
      #p [mat0, v0]

      solve_eqn(d + 1, mat0, v0)
      #p v0; exit

      w0 = 0.0
      (0..d).each{|j| w0 += mat[i0][j] * v0[j]}
      delta0 = (w0 - v[i0]).abs

      w1 = 0.0
      (0..d).each{|j| w1 += mat[i1][j] * v0[j]}
      delta1 = (w1 - v[i1]).abs

      if delta0 > ERROR && delta1 <= DELTA
        found = i0
        break
      elsif delta1 > ERROR && delta0 <= DELTA
        found = i1
        break
      end
    end
    break if found
  end

  puts found
end

Measured memory_bytes: 6120
#include <stdio.h>
int main(void){
	
	int a,b;
	char c;
	
	while(1){
		scanf("%d %c %d",&a,&c,&b);
		if(c=='?')break;
		if(c=='+')printf("%d\n",a+b);
		if(c=='-')printf("%d\n",a-b);
		if(c=='*')printf("%d\n",a*b);
		if(c=='/')printf("%d\n",a/b);
	}
	
	return 0;
}


Measured memory_bytes: 2076
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(ll i = (ll)(n)-1;i >= 0;--i)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
//#define int ll
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  int n;
  cin >> n;
  vvi a(3,vi(n));
  REP(i,n) cin >> a.at(0).at(i) >> a.at(1).at(i) >> a.at(2).at(i);
  vvi dp(3,vi(n));
  REP(i,3) dp[i][0] = a[i][0];
  REP(i,n-1)REP(j,3){
    int mx = 0;
    REP(k,3){
      if(j==k) continue;
      mx = max(mx,dp[k][i]);
    }
    dp[j][i+1] = mx + a[j][i+1];
  }
  int ans = 0;
  REP(i,3) ans = max(ans,dp[i][n-1]);
  cout << ans << endl;
}

Measured memory_bytes: 2940
a,b,c,d=gets.split.map(&:to_i)

def cal(a,b,c)
  i = a/c * c >= a ? a/c : a/c + 1
  p = b/c
  p-i+1
end

puts b-a+1-(cal(a,b,c)+cal(a,b,d)-cal(a,b,c.lcm(d)))


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

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// Type / Class / Struct Definitions:
using namespace std;

using ll = long long;
using ull = unsigned long long;

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;

// Global Variables:

// Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

// ================ Main Loop ================
int main() {
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a;
        cin >> a;
        n -= a;
    }
    if(n >= 0) {
        cout << n << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}
// ===========================================

// Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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


Measured memory_bytes: 3596
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  lol n;
  cin >> n;
  int a[n + 5], b [n + 5];
  rep(i, n + 1){
    cin >> a[i];
  }
  rep(i, n){
    cin >> b[i];
  }
  lol ans = 0, nasu;
  rep(i, n){
    nasu = min(b[i], a[i]);
    ans += nasu;
    
    b[i] -= nasu;
    a[i] -= nasu;

    ans += min(a[i + 1], b[i]);
    a[i + 1] -= min(a[i + 1],b[i]);
    // cout << ans << " " << b[i];
  }
  cout << ans << '\n';
  return 0;
}


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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n, m, k;
    cin >> n >> m >> k;

    string ans = "No";
    for (i64 i = 0; i <= n; i++) {
        for (i64 j = 0; j <= m; j++) {
            if (i * m + j * n - 2 * i * j == k) ans = "Yes";
        }
    }
    cout << ans << endl;
}

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


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

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

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

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int ans = 0;

    int N, T; cin >> N >> T;
    //T-1分後に食べるものについて全探索できるといいな
    int tm[N+1] = {}, val[N+1] = {};
    rep(i, N) cin >> tm[i+1] >> val[i+1];
    int dp1[N+2][T], dp2[N+2][T];
    rep(i, N+2){
        rep(j, T){
            dp1[i][j] = dp2[i][j] = 0;
        }
    }
    for(int i = 1; i <= N; i++){
        //iを食べるかどうか
        for(int j = 0; j < T; j++){
            if(j-tm[i] >= 0) dp1[i][j] = max(dp1[i-1][j], dp1[i-1][j-tm[i]] + val[i]);
            else dp1[i][j] = dp1[i-1][j];
        }
    }
    for(int i = N; i >= 1; i--){
        for(int j = 0; j < T; j++){
            if(j-tm[i] >= 0) dp2[i][j] = max(dp2[i+1][j], dp2[i+1][j-tm[i]] + val[i]);
            else dp2[i][j] = dp2[i+1][j];
        }
    }


    for(int i = 1; i <= N; i++){
        //iをT-1分後に注文する
        //1から(i-1)まででj分, (i+1)からNまでで(T-1)-j分だけ割いたときに得られる満足度の最大を出す
        int res = 0;    
        for(int j = 0; j < T; j++){
            res = max(res, dp1[i-1][j] + dp2[i+1][(T-1)-j]);
        }        
        ans = max(ans, res+val[i]);
    }
    cout << ans << endl;
    return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ull unsigned long long
#define ld long double

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define rep1(i, n) rep1(i, 1, n + 1)

// #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
// #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()  //

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);
    //    cout << std::setfill('0') << std::setw(2);

    std::string S;
    std::cin >> S;

    bool f = true;
    if (S[0] != 'A') f = false;
    int cntS = 0;
    int cntC = 0;
    rep2(i, 2, S.size() - 1) {
        if (S[i] == 'C') cntC++;
    }
    rep2(i, 1, S.size()) {
        if (S[i] >= 'a' && S[i] <= 'z') cntS++;
    }
    if (cntC != 1 || cntS != S.size() - 2) f = false;
    if (f)
        cout << "AC" << endl;
    else
        cout << "WA" << endl;
    return 0;
}


Measured memory_bytes: 256
/**************************
  * Writer : Leo101
  * Problem : AT2557 Ball Coloring
  * Tags : 贪心
**************************/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#define gi get_int()
#define _FILE(s) freopen(#s".in", "r", stdin); freopen(#s".out", "w", stdout)
const int MAXN = 3e5;
int get_int()
{
	int x = 0, y = 1; char ch = getchar();
	while (!isdigit(ch) && ch != '-') ch = getchar();
	if (ch == '-') y = -1, ch = getchar();
	while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x * y;
}

std :: multiset<int> left, right;

class Data
{
public:
	int x, y;
} num[MAXN];
bool operator< (const Data& a, const Data &b)
{ return a.x < b.x; } 

long long getAns()
{ return 1ll * (*left.rbegin() - *left.begin()) * (*right.rbegin() - *right.begin()); }

int main()
{
	int n = gi;
	for (int i = 0; i < n; i++) {
		int x = gi, y = gi;
		if (x > y) std :: swap(x, y);
		num[i].x = x, num[i].y = y;
		left.insert(x); right.insert(y);
	}

	std :: sort(num, num + n);
	long long ans = getAns();

	for (int i = 0; i < n; i++) {
		int x = num[i].x, y = num[i].y;
		left.erase(left.find(x)); right.insert(x);
		right.erase(right.find(y)); left.insert(y);
		ans = std :: min(ans, getAns());
	}

	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 20608
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

bool dp[53][1000][1000];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, sum = 0;
    cin >> N;
    vector<int> T(N);
    for (int i = 0; i < N; i++) {
        cin >> T[i];
        sum += T[i];
    }
    dp[0][0][0] = true;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 1000; j++) for (int k = 0; k < 1000; k++) {
            if (!dp[i][j][k]) continue;
            int nj = j+T[i], nk = k+T[i];
            if (nj < 1000) dp[i+1][nj][k] = true;
            if (nk < 1000) dp[i+1][j][nk] = true;
            dp[i+1][j][k] = true;
        }
    }
    int ans = 3000;
    for (int i = 0; i < 1000; i++) for (int j = 0; j < 1000; j++) {
        if (!dp[N][i][j]) continue;
        int maxi = max(i, j);
        maxi = max(maxi, sum-i-j);
        ans = min(ans, maxi);
    }
    cout << ans << endl;
    return 0;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int W, H, N; cin >> W >> H >> N;
    int A[H][W]; rep(i, H) rep(j, W) A[i][j] = 0;
    rep(k, N){
        int x, y, a; cin >> x >> y >> a;
        if(a == 1){
            rep(i, H){
                for(int j = x-1; j >= 0; j--){
                    A[i][j] = 1;
                }
            }
        }
        else if(a == 2){
            rep(i, H){
                for(int j = x; j < W; j++){
                    A[i][j] = 1;
                }
            }
        }
        else if(a == 3){
            rep(j, W){
                for(int i = y-1; i >= 0; i--){
                    A[i][j] = 1;
                }
            }
        }
        else{
            rep(j, W){
                for(int i = y; i < H; i++){
                    A[i][j] = 1;
                }
            }
        }
        /*
        rep(i, H){
            rep(j, W){
                cout << A[i][j] << " ";
            }
            cout << endl;
        }
        */
    }

    int ans = 0;
    rep(i, H) rep(j, W) if(A[i][j] == 0) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

import java.util.*;
import java.io.*;
import static java.lang.System.*;

public class Main{
	public static void main(String[] args){
		int n,d;
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		d = sc.nextInt();

		out.println((n + d * 2) / (d * 2 + 1));
	}
}


Measured memory_bytes: 21588
#include<bits/stdc++.h>
#define maxn 200100
using namespace std;
typedef long long ll;
const ll inf=(ll)1e18;
struct data{
	ll x,y;
	data(){}
	data(ll x,ll y):x(x),y(y){}
	data operator+(const data& d)const{return data(min(x,d.x),min(y,d.y));}
	data operator+(const ll tg)const{return data(x+tg,y+tg);}
	template<typename _Tp>
	data operator+=(const _Tp tg){return (*this)=(*this)+tg;}
	void reset(){x=y=0;}
}s[maxn<<2];
ll atg[maxn<<2];
void mdy(int o,int l,int r,int k,ll x){
	if(l==r){
		s[o]+=data(x-l,x+l);
//		printf("{%lld}",x);
		return ;
	}
	int mid=l+r>>1;
	if(atg[o])s[o<<1]+=atg[o],s[o<<1|1]+=atg[o],atg[o<<1]+=atg[o],atg[o<<1|1]+=atg[o],atg[o]=0;
	if(k<=mid)mdy(o<<1,l,mid,k,x);
	else mdy(o<<1|1,mid+1,r,k,x);
	s[o]=s[o<<1]+s[o<<1|1];
}
ll query(int o,int l,int r,int ql,int qr,int flag){
	if(ql<=l&&r<=qr)return flag==0?s[o].x:s[o].y;
	int mid=l+r>>1;
	ll ret=inf;
	if(atg[o])s[o<<1]+=atg[o],atg[o<<1]+=atg[o],atg[o<<1|1]+=atg[o],s[o<<1|1]+=atg[o],atg[o]=0;
	if(ql<=mid)ret=min(ret,query(o<<1,l,mid,ql,qr,flag));
	if(qr>mid)ret=min(ret,query(o<<1|1,mid+1,r,ql,qr,flag));
	return ret;
}
void build(int o,int l,int r){
	s[o]=data(inf,inf);
	if(l==r)return ;
	int mid=l+r>>1;
	build(o<<1,l,mid),build(o<<1|1,mid+1,r);
}
ll cal(int o,int l,int r){
	if(l==r)return /*printf("[cal:%lld,%d]\n",s[o].x+l,l),*/s[o].x+l;
	int mid=l+r>>1;
	if(atg[o])s[o<<1]+=atg[o],atg[o<<1]+=atg[o],atg[o<<1|1]+=atg[o],s[o<<1|1]+=atg[o],atg[o]=0;
	return min(cal(o<<1,l,mid),cal(o<<1|1,mid+1,r)); 
}
int n,m,A,B,a[maxn];
int main(){
	scanf("%d%d%d%d",&n,&m,&A,&B);
	for(int i=1;i<=m;++i)
		scanf("%d",&a[i]);
	build(1,1,n);
	mdy(1,1,n,A,abs(a[1]-B));
	mdy(1,1,n,B,abs(a[1]-A));
	for(int i=2;i<=m;++i){
		ll x=query(1,1,n,1,a[i],0)+a[i];
		ll y=query(1,1,n,a[i],n,1)-a[i];
		s[1]+=abs(a[i]-a[i-1]),atg[1]+=abs(a[i]-a[i-1]);
//		printf("[%lld,%lld]",x,y);
		mdy(1,1,n,a[i-1],min(x,y));
//		cal(1,1,n),puts("");
	}
	printf("%lld",cal(1,1,n));
}

Measured memory_bytes: 16640
# A,Restaurnat
# すぬけくんはレストランに通うのが好きです。
# すぬけくんの行きつけのレストランは何を食べても1食800円で、15食食べる毎にその場で200円もらえます。
# すぬけくんは今まで合計N食食べました。今までに払った金額をｘ円、レストランにもらった金額をｙとして、x - yを求めなさい。
# 1 <= N <= 100

# N = 食数

N = int(input())

# x:今までに支払った金額
x = 800 * N
# print(x)

# y:レストランにもらった金額
y = int((N // 15) * 200)

answer = int(x - y)
print(answer)

Measured memory_bytes: 9124
S = str(input())
T = str(input())
lenS = len(S)
lenT = len(T)
splitS = []

for i in range(lenS - lenT +1):
    tempS = S[i : i+lenT]
    splitS.append(tempS)

answer = lenT
for tempS in splitS:
    count = 0
    for i in range(lenT):
        if tempS[i] != T[i]:
            count += 1
    answer = min(answer, count)
print(answer)

Measured memory_bytes: 9188
#include <iostream>

using namespace std;

int a[3][3];

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n,m;
  while(cin>>n>>m,n) {
    int c[m];
    REP(i,m)
      cin >> c[i];
    int x[n];
    REP(i,n)
      cin >> x[i];
    long long dp[256];
    REP(i,256) dp[i] = INF;
    dp[128] = 0;
    
    REP(i,n) {
      long long next[256];
      REP(j,256) next[j] = INF;
      REP(j,256) {
        if (dp[j]==INF) continue;
        REP(k,m) {
          long long hoge = max(min(j+c[k], 255), 0);
          next[hoge] = min(next[hoge], dp[j] + (hoge-x[i])*(hoge-x[i]));
        }
      }
      // REP(j,256){
      //   if (next[j]!=INF)
      //     printf("%d,%d ",j,next[j]);
      // }
      // cout << endl;
      memcpy(dp, next, sizeof(next));
    }
    cout << *min_element(dp, dp+256) << endl;
  }
}

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

using namespace std;

int main()
{
    string S,T;
    cin >> S >> T;
    int ans=0;
    for (int i=0;i < S.size();i++) {
        if(S[i]!=T[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3912
fun main(args: Array<String>) {

    var (A) = readInts()
    var (B) = readInts()
    var (H) = readInts()

    println((A + B) * H / 2)
}

fun readInts(): List<Int> = readStrings().map { it.toInt() }
fun readStrings(): List<String> = readLine()!!.split(" ")

Measured memory_bytes: 37904
import itertools

N = int(input())
X = []
Y = []

for i in range(N):
    [Xtmp,Ytmp] = list(map(int,input().split()))
    X.append(Xtmp)
    Y.append(Ytmp)


T = []
for i in range(N):
    T.append(i)

D = 0

def dist(x1,x2,y1,y2):
    return ((x1-x2)**2+(y1-y2)**2)**0.5

for v in itertools.permutations(T, N):
    Dtmp = 0
    for j in range(N-1):
        Dtmp += dist(X[v[j]],X[v[j+1]],Y[v[j]],Y[v[j+1]])
    D += Dtmp

P = 1
for j in range(1,N+1):
    P *= j

output = D/P

print(output)

Measured memory_bytes: 3064
function Main(input) {
  var list = input.split("\n");
  var listH = list[1].trim().split(" ").map(s => parseInt(s, 10));
  var N = list[0];
  var i = 0;
  var count = 1;
  var check = 0;
  var Max = 0;
  
  if (check == 0){
    for (i=0;i<N;i++){
      if (listH[i] >= Max){
        Max = listH[i]
      }
      if (Max <= listH[i+1]){
        count = count+1;
      }
    }
  }
  console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('o') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def solve(N, S, ans):

    for i in range(N - 2):
        if S[i]:
            if ans[i] == 0 and ans[i - 1] == 0:
                ans[i + 1] = 0
            elif ans[i] == 0 and ans[i - 1] == 1:
                ans[i + 1] = 1
            elif ans[i] == 1 and ans[i - 1] == 0:
                ans[i + 1] = 1
            elif ans[i] == 1 and ans[i - 1] == 1:
                ans[i + 1] = 0
        else:
            if ans[i] == 0 and ans[i - 1] == 0:
                ans[i + 1] = 1
            elif ans[i] == 0 and ans[i - 1] == 1:
                ans[i + 1] = 0
            elif ans[i] == 1 and ans[i - 1] == 0:
                ans[i + 1] = 0
            elif ans[i] == 1 and ans[i - 1] == 1:
                ans[i + 1] = 1

    ret = True
    for i in range(N - 2, N):

        if S[i]:
            if ans[i] == 0 and ans[i - 1] == 0:
                ret &= ans[(i + 1) % N] == 0
            elif ans[i] == 0 and ans[i - 1] == 1:
                ret &= ans[(i + 1) % N] == 1
            elif ans[i] == 1 and ans[i - 1] == 0:
                ret &= ans[(i + 1) % N] == 1
            elif ans[i] == 1 and ans[i - 1] == 1:
                ret &= ans[(i + 1) % N] == 0
        else:
            if ans[i] == 0 and ans[i - 1] == 0:
                ret &= ans[(i + 1) % N] == 1
            elif ans[i] == 0 and ans[i - 1] == 1:
                ret &= ans[(i + 1) % N] == 0
            elif ans[i] == 1 and ans[i - 1] == 0:
                ret &= ans[(i + 1) % N] == 0
            elif ans[i] == 1 and ans[i - 1] == 1:
                ret &= ans[(i + 1) % N] == 1

    return ret


def main():

    N = in_n()
    S = in_map()

    pattern = [(0, 0), (0, 1), (1, 0), (1, 1)]

    for p in pattern:
        ans = [0] * N
        ans[0], ans[-1] = p[0], p[1]
        if(solve(N, S, ans)):
            p = ''
            for i in range(N):
                if ans[i] == 0:
                    p += 'S'
                else:
                    p += 'W'
            print(p)
            exit()
    else:
        print(-1)


if __name__ == '__main__':
    main()


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

typedef long long int ll;
typedef long double ld;

#define Pb push_back
#define Mp make_pair

#define ff first
#define ss second

#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))

#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define db1(x) cout<<#x<<" : "<<x<<endl;
#define db2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define db3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;

const int N = 2e5+5;
ll n;
ll xr = 0;
ll a[N];

void solve()
{
   cin >> n;
   for(int i=1;i<=n;i++)
   {
      cin >> a[i];
      xr^=a[i];
   }
   for(int i=1;i<=n;i++)
   {
      ll val = xr^a[i];
      cout << val << " ";
   }
}

signed main()
{
  IOS;
  //freopen("input.txt", "rt", stdin);
  //freopen("output.txt", "wt", stdout);
  int t=1;
  //cin >> t;
  while(t--)
  {
    solve();
  }
  return 0;
}
/*==============================================================================================================================================================*/


Measured memory_bytes: 5200
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main() {
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i, N) { cin >> a[i]; }
    ll cnt = 1, rm_cnt = 0;
    rep(i, N) {
        if (a[i] == cnt) {
            cnt++;
        } else {
            rm_cnt++;
        }
    }
    if (cnt == 1) {
        cout << -1;
    } else {
        cout << rm_cnt;
    }
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
 
int N, banyak[100100], a, tot, maks=0;
 
int main() {
    cin >> N;
    for (int i = 1; i<= N; i++ ){
        cin >> a;
        banyak[a]++;
    }
    for (int i= 1;i<=100000; i++){
        tot = banyak[i] + banyak[i+1]+ banyak[i-1];
        if (maks < tot){
            maks=tot;
        }
    }
    cout << maks << endl;
}

Measured memory_bytes: 3836
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main()
{
	int n; cin>>n;
	string s; cin>>s;
	for(int i=0; i<s.size(); i++){
		int x=(s[i]-'A')+n;
		x%=26;
		s[i]='A'+x;
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);++i)
#define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i)
#define rep1(i,n) for(int (i)=1;(i)<=(n);++i)
#define rrep1(i,n) for(int (i)=(n);(i)>=1;--i)
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> DP;
typedef pair<long long,long long> LP;
typedef double db;
using namespace std;

ll r,b;
ll C[200000];
ll T[200000];
ll pos[200000];
ll dp[200000];

string s;

int main()
{
    cin>>b;
    cin>>s;
    rep(i,s.size()){
      if(s[i]=='R'){r++; b--;
      }
    }
    if(r>b) puts("Yes");
    else puts("No");
}


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

#define REP(i,a,b) for(int i = (a) ; i < (int)(b) ; ++i )
#define _REP(i,a,b) for(int i = (a) ; i <= (int)(b) ; ++i )
#define UREP(i,u) for(int i = p[(u)] ; i + 1 ; i = edge[i].next)
//iterator: for(int u:x),x is container
#define x(p) (p).first
#define y(p) (p).second
#define mp(x,y) make_pair((x), (y))
#define ll long long
#define inf 0x3f3f3f3f
#define mem(x,v) memset((x), (v), sizeof (x))
#define _ri1(x) scanf("%d", &(x))
#define _ri2(x,y) scanf("%lld%lld", &(x), &(y))
#define _ri3(x,y,z) scanf("%d%d%d", &(x), &(y), &(z))
#define _ri4(a,b,c,d) scanf("%d%d%d%d", &(a), &(b), &(c), &(d))
#define _pi1(a) printf("%d\n", (a))
#define _pi2(a,b) printf("%d%d\n", (a), (b))

#ifdef kinesis
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

ll h,w;

int main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
    //#endif // ONLINE_JUDGE
    scanf("%lld%lld", &(h), &(w));
    if(h==1||w==1){
        _pi1(1);
    }
    else printf("%lld\n",h*w/2 + ((h*w%2)>0));

    return 0;
}



Measured memory_bytes: 256