akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
n=int(input())
k=int(input())

def sol1(n):
    l=len(str(n))
    #print(int(str(n)[0])+9*(l-1))
    return int(str(n)[0])+9*(l-1)

def sol2(n):
    ret=0
    a=int(str(n)[0])
    l=len(str(n))-1
    ret+=sol1(n-a*10**l)
    ret+=(a-1)*sol1(10**l-1)
    ret+=9*9*l*(l-1)//2
    return ret

def sol3(n):
    ret=0
    a=int(str(n)[0])
    l=len(str(n))-1
    ret+=sol2(n-a*10**l)
    ret+=(a-1)*sol2(10**l-1)
    ret+=9*9*9*l*(l-1)*(l-2)//6
    return ret


if k==1:
    print(sol1(n))
elif k==2:
    print(sol2(n))
elif k==3:
    print(sol3(n))


Measured memory_bytes: 38384
s=raw_input()
n=len(s)
ans=0
for i in xrange(1<<n-1):
    new=[]
    for j in xrange(n-1):
        if i>>j&1:
            new.append(j)
    news=""
    for j in xrange(n):
        if j in new:
            news+=s[j]+"+"
        else:
            news+=s[j]
    tmp=""
    for j in news:
        if j=="+":
            ans+=int(tmp)
            tmp=""
        else:
            tmp+=j
    if tmp!="":
        ans+=int(tmp)
print(ans)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int dp[2525];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, z, w, a[2525];
	cin>>n>>z>>w;
	REP(i, n){
		cin>>a[i];
	}
	if(n==1){
		cout<<abs(a[0]-w)<<'\n';
	}
	else{
		cout<<max(abs(a[n-1]-w), abs(a[n-2]-a[n-1]))<<'\n';
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))
 
 
using namespace std;
 
 
typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<LL> vL;
typedef vector<bool> vb;
typedef pair<int,vi> iv;
typedef pair<LL,LL> pLL; 
typedef long double LD;
typedef unordered_set<int> ui;



int main(){
	std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	string s;
	cin>>s;
	int n = (int)s.size();
	vi dp(n+1,n);
	dp[0] = 0;
	unordered_map<int, int> pos;
	pos[0] = 0;
	for(int i=0, cur = 0;i<n;++i){
		int j = int(s[i]-'a');
		cur ^= (1<<j);
		if(pos.count(cur)) dp[i+1] = min(dp[pos[cur]]+1, dp[i+1]);
		for(int c=0;c<26;++c){
			int tmp = cur ^ (1<<c);
			if(pos.count(tmp)) dp[i+1] = min(dp[i+1], dp[pos[tmp]]+1);
		}
		if(pos.count(cur)){
			if(dp[pos[cur]]> dp[i+1]) pos[cur] = i+1;
		}
		else pos[cur] = i+1;
	}

	cout<<dp[n]<<endl;
	return 0;
}












Measured memory_bytes: 9436
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
using namespace std;

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
    priority_queue<ll> pq;
    ll n, tmp;
    cin >> n;
    REP(i, n){
        cin >> tmp;
        pq.push(tmp);
    }

    bool on=true;
    ll a = 0;
    ll ans = 0;
    while(!pq.empty()){
        if(pq.top() == a){
            on = (!on);
            if(on) ans++;
            else ans--;
        }else{
            on = true;
            ans++;
        }
        a = pq.top();
        pq.pop();
    }

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

Measured memory_bytes: 1400
from itertools import permutations as per
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
PQ = list(per(list(range(1, N + 1))))

a = PQ.index(P) + 1
b = PQ.index(Q) + 1

print(abs(a - b))

Measured memory_bytes: 13784
import java.util.*;

class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //入力
        int N = sc.nextInt();
        int M = sc.nextInt();
        int X = sc.nextInt();
        int[] C = new int[N];
        int[][] A = new int[N][M];

        for(int i=0;i<N;i++) {
            C[i] = sc.nextInt();
            for(int j=0;j<M;j++) {
                A[i][j] = sc.nextInt();
            } 
        }

        //出力の値(ダメな時 -1)
        int out = 0;

        //不可能チェック
        boolean check = true;
        //全アルゴリズム別に得点を全て累計
        for(int i=0; i<M; i++) {
            int tmp = 0;
            for(int j=0; j<N; j++) {
                tmp += A[j][i];
            }
            if(tmp < X) {
                check = false;
                break;
            }
        }
        if(check == false) {
            out = -1;
        } else {
            //最小金額の初期値
            int min = 0;
            for(int i=0; i<N; i++) {
                min += C[i];
            }

            //全通り(N冊)
            int ptn = (int)Math.pow(2,N); 
            for(int i=0; i<ptn; i++) {
                int cost = 0;
                int[] score = new int[M];
                for(int j=0; j<N; j++) {
                    if(((i)&(int)Math.pow(2,j)) != 0) {
                        cost += C[j];
                        for(int k=0; k<M; k++) {
                            score[k] += A[j][k];
                        }
                    }
                }
                //scoreチェック
                boolean scheck = true;
                for(int l = 0; l<M; l++) {
                    if(score[l] < X) {
                        scheck = false;
                        break;
                    }
                }
                if(scheck == true) {
                    if(cost < min) {
                        min = cost;
                    }
                }
            }
            out = min;
        }
        // 出力
        System.out.println(out);
        /*int[] score = new int[M];

        for(int i=0;i<N;i++) {
            for(int j=0;j<M;j++) {
                score[j] += A[i][j]; 
                if(score[j] < M) 
                    f = false; //もし，スコアがM以下なら(一つでもあればfalse)
                cost = Math.min(cost,C[i]);
            }
            
        }
        if(f = false) System.out.println(-1);
        else System.out.println(sum);
        */
    }
}

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

int main() {
  int N, X, T;
  cin >> N >> X >> T;
  if (N % X != 0)
    cout << (N/X+1)*T << endl;
  else if (N % X == 0)
    cout << (N/X)*T << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
	vector<int> data;
	UnionFind(int n) : data(n, -1) {}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	bool merge(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (data[y] < data[x]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}
};
int main() {
	int N, K, L;
	cin >> N >> K >> L;
	UnionFind uf1(N), uf2(N);
	for (int i = 0; i < K; ++ i) {
		int x, y;
		cin >> x >> y;
		-- x; -- y;
		uf1.merge(x, y);
	}
	for (int i = 0; i < L; ++ i) {
		int x, y;
		cin >> x >> y;
		-- x; -- y;
		uf2.merge(x, y);
	}
	vector<pair<int,int>> a(N);
	map<pair<int,int>, int> b;
	for (int i = 0; i < N; ++ i) {
		pair<int,int> p = {uf1.root(i), uf2.root(i)};
		a[i] = p;
		++ b[p];
	}
	for (int i = 0; i < N; ++ i) {
		if (i) cout << " ";
		cout << b[a[i]];
	}
	cout << endl;
}


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

string rev(string s) {
    return string(s.rbegin(), s.rend());
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int n; cin >> n;
    rep(i, 0, n) {
        string s; cin >> s;
        set<string> ss;
        rep(i, 0, s.length()) {
            ss.insert(s.substr(0, i) + s.substr(i));
            ss.insert(rev(s.substr(0, i)) + s.substr(i));
            ss.insert(s.substr(0, i) + rev(s.substr(i)));
            ss.insert(rev(s.substr(0, i)) + rev(s.substr(i)));
            ss.insert(s.substr(i) + s.substr(0, i));
            ss.insert(s.substr(i) + rev(s.substr(0, i)));
            ss.insert(rev(s.substr(i)) + s.substr(0, i));
            ss.insert(rev(s.substr(i)) + rev(s.substr(0, i)));
        }
        cout << ss.size() << endl;
    }
}


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

int main(){
    int N;
    cin >> N;
    N = N % 10;
    if (N == 3) {
        cout << "bon" << endl;
    } else if (N == 0 || N == 1 || N == 6 || N == 8) {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <cassert>
#define SIZE 100005
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

typedef long long int ll;

ll inv[SIZE],fac[SIZE],finv[SIZE];
ll A[SIZE];

void make()
{
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<SIZE;i++)
	{
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		fac[i]=fac[i-1]*(ll) i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
ll C(int a,int b)
{
	if(a<b) return 0;
	return fac[a]*(finv[b]*finv[a-b]%MOD)%MOD;
}
int main()
{
	make();
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%lld",&A[i]);
	ll ret=0;
	ll s=0;
	for(int i=1;i<=n;i++)
	{
		ll way=fac[n-i]*C(n,i)%MOD;
		s+=inv[i];
		s%=MOD;
		ret+=(ll) A[i-1]*(ll) way%MOD*(ll) s%MOD*fac[i]%MOD;
		ret%=MOD;
	}
	s=0;
	for(int i=1;i<=n;i++)
	{
		ll way=fac[n-i]*C(n,i)%MOD;
		s+=inv[i];
		s%=MOD;
		ret+=(ll) A[n-i]*(ll) way%MOD*(ll) s%MOD*fac[i]%MOD;
		ret%=MOD;
	}
	for(int i=0;i<n;i++)
	{
		ret-=(ll) A[i]*fac[n]%MOD;
		if(ret<0) ret+=MOD;
	}
	printf("%lld\n",ret);
	return 0;
}



Measured memory_bytes: 3328
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  
  auto dfs = [&](auto& Self, int num, string st) -> void{
    //dump(num, st);
    if(num == n){
      print(st);
      return;
    }
    ll cnt[26] = {0};
    rep(i, SZ(st)){
      cnt[st[i]-'a']++;
    }
    for(char i = 'a'; i < 'z'; i++){
      Self(Self, num+1, st+i);
      if(!cnt[i-'a']){
        break;
      }
    }
  };
  dfs(dfs, 0, "");
}


Measured memory_bytes: 1536
l,r = gets.split.map(&:to_i)

mod = 2019

w = l/mod
l %= mod
r -= mod*w

min = 2020

if r>=mod
  p 0
elsif 
  for i in l..r
    for j in i+1..r
      a = i*j%mod
      min = a if min > a
    end
  end
  p min
end


Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
typedef long long ll;
int main() {
  int m=0,n,v=1,p=0,ans=0,ans3=0,memo,memob;
  string worda,wordb;
  bool flag;
  cin>>worda>>wordb;
  cout<<wordb<<worda<<endl;




  //vector<vector<bool>> sinsetsu(15,vector<bool>(14)),usotsuki(15,vector<bool>(14));
  //vector<vector<int>> sss(15,vector<int>(14))
  //vector<vector<int>> sss(h,vector<int>(w));
  //vector<int> a(k),b(k);
  //char x;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

template <size_t T>
bool nextBitset(bitset<T> &bs, int digit)
{
    if(bs.none())
        return false;
    bitset<T> x, y, z;
    x = bs.to_ulong() & (~(bs.to_ulong()) + 1ULL);
    y = bs.to_ulong() + x.to_ulong() + 0ULL;
    z = bs & ~y;
    if(bs[digit-1] && bs == z)
        return false;
    bs = ((z.to_ulong() / x.to_ulong()) >> 1) + 0ULL;
    bs |= y;
    return true;
}

class RollingHash
{
private:
    static const int X, M;
    long long hash;
public:
    RollingHash(const string& s){
        int n = s.size();
        hash = 0;
        for(int i=0; i<n; ++i){
            hash *= X;
            hash += s[i];
            hash %= M;
        }
    }
    long long getHash() const{
        return hash;
    }
};
const int RollingHash::X = 1685440109; // 素数
const int RollingHash::M = 2000000087; // 合同式の法（素数）

/*****************************************************************/

bool check(const vector<string>& s)
{
    int h = s[0].size();
    int w = s.size();

    map<long long, vector<int> > index;
    for(int i=0; i<h; ++i){
        string t(w, ' ');
        for(int j=0; j<w; ++j)
            t[j] = s[j][i];
        long long hash1 = RollingHash(t).getHash();
        index[hash1].push_back(i);

        reverse(t.begin(), t.end());
        long long hash2 = RollingHash(t).getHash();
        index[hash2].push_back(i);
    }

    bool isSame = false;
    for(auto& p : index){
        auto& v = p.second;
        if(v.size() % 2 != 0)
            return false;

        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());

        if(v.size() % 2 != 0){
            if(isSame)
                return false;
            isSame = true;
        }
    }
    return true;
}

bool solve(const vector<string>& s)
{
    int h = s.size();
    int w = s[0].size();

    bitset<12> bs((1<<(h/2))-1);
    do{
        vector<string> t;
        for(int i=0; i<h; ++i){
            if(bs[i])
                t.push_back(s[i]);
        }
        for(int i=0; i<h; ++i){
            if(!bs[i])
                t.push_back(s[i]);
        }

        sort(t.begin() + h / 2, t.end());
        do{
            if(check(t))
                return true;
        }while(next_permutation(t.begin() + h / 2, t.end()));
    }while(nextBitset(bs, h-1));

    return false;
}

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i=0; i<h; ++i)
        cin >> s[i];

    if(solve(s))
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  string s;
  bool flag = true;
  cin >> s;
  if (s.size() == 2) {
    if (s[0] == s[1]) {
      flag = false;
      cout << "1 2" << endl;
    }
  }
  rep(i, s.size()-2) {
    if (s[i] == s[i+1] || s[i] == s[i+2] || s[i+1] == s[i+2]) {
      flag = false;
      cout << i+1 << ' ' << i+3 << endl;
      break;
    }
  }
  if (flag)
    cout << "-1 -1" << endl;
}


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

using namespace std;

//#define FILE_IO

typedef pair<int, int> pii;
typedef pair<int, pii> p3i;

int N, K;
vector<p3i> v;
int sum[2][2005][2005];

int getsum(int c, int x, int y, int xx, int yy)
{
    int ans = sum[c][xx][yy];
    if(x > 0)   ans -= sum[c][x - 1][yy];
    if(y > 0)   ans -= sum[c][xx][y - 1];
    if(x > 0 && y > 0)  ans += sum[c][x - 1][y - 1];
    return ans;
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d", &N, &K);
    for(int i = 1; i <= N; i++)
    {
        int x, y; char ch;
        scanf("%d%d %c", &x, &y, &ch);
        int c = (ch == 'B');
        x %= (2 * K); y %= (2 * K);
        sum[c][x][y]++;
    }

    for(int c = 0; c < 2; c++)
        for(int i = 0; i < 2 * K; i++)
            for(int j = 0; j < 2 * K; j++)
            {
                if(i > 0)   sum[c][i][j] += sum[c][i - 1][j];
                if(j > 0)   sum[c][i][j] += sum[c][i][j - 1];
                if(i > 0 && j > 0)  sum[c][i][j] -= sum[c][i - 1][j - 1];
            }

    int ans = 0;
    for(int c = 0; c < 2; c++)
        for(int i = 0; i < K; i++)
            for(int j = 0; j < K; j++)
            {
                int cnt = getsum(c, 0, 0, i, j) + getsum(c ^ 1, 0, j + 1, i, j + K) + getsum(c, 0, j + K + 1, i, 2 * K - 1) +
                          getsum(c ^ 1, i + 1, 0, i + K, j) + getsum(c, i + 1, j + 1, i + K, j + K) + getsum(c ^ 1, i + 1, j + K + 1, i + K, 2 * K - 1) +
                          getsum(c, i + K + 1, 0, 2 * K - 1, j) + getsum(c ^ 1, i + K + 1, j + 1, 2 * K - 1, j + K) + getsum(c, i + K + 1, j + K + 1, 2 * K - 1, 2 * K - 1);
                ans = max(ans, cnt);
            }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 31744
gets # n
hs = gets.split.map(&:to_i)

# h, c
_, c =
  hs.reduce([0, 0]) do |state, h|
    h_max, c = state
    [h_max < h ? h : h_max, c + (h_max <= h ? 1 : 0)]
  end

p c


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

using namespace std;

typedef long long int64;


int main()
{
  string A;
  cin >> A;

  int sum[26] = {};
  for(auto &c : A) sum[c - 'a']++;
  int64 ret = 1LL * A.size() * (A.size() + 1) / 2;
  for(int i = 0; i < 26; i++) ret -= 1LL * sum[i] * (sum[i] + 1) / 2;
  cout << ret + 1 << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>

int main() {
  int n, k;
  int tmp;
  int xs[100000]={};
  int min=0x7fffffff;

  scanf("%d %d", &n, &k);


  for(int i=0;i<n;i++){
    scanf("%d", &xs[i]);
  }

  for(int i=0;i<n-k+1;i++){
    tmp = abs(xs[i]) + abs(xs[i+k-1]-xs[i]);
    if(tmp<min)
      min = tmp;
    tmp = abs(xs[i+k-1]) + abs(xs[i]-xs[i+k-1]);
    if(tmp<min)
      min = tmp;
  }

  printf("%d\n",min);

  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string num;

    cin >> num;

    for(int i=0; i<num.size(); i++)
    {
        if(num[i] == '7')
        {
            cout << "Yes";
            return 0;
        }
    }
    
    cout << "No";


}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int main() {
    int x;
    cin >> x;
    vector<int> dp(x + 1);
    dp[0] = 1;

    auto f = [&] (int n) {
        if (n < 0) return 0;
        return dp[n];
    };

    for (int i = 1; i <= x; ++i) {
        dp[i] = f(i - 100) || f(i - 101) || f(i - 102) || f(i - 103) || f(i - 104) || f(i - 105);
    }

    cout << dp[x] << endl;

    return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

template <typename T>
struct BIT_tree{

    public:
        BIT_tree(vector<T> v) : _n(v.size()), data(v.size(), 0){
            for(int i = 0;i < _n;++i){
                add(i, v[i]);
            }
        }
    
        //0-indexedで受け取り, 内部は1-indexedで作動
        void add(int i, T x){
            ++i;
            while(i <= _n){
                data[i-1] += x;
                i += i & -i;
            }
        }
        
        //0-indexedで受け取り, [l, r)に加算, 1-indexedで渡す
        T sum(int l, int r){
            return sum(r) - sum(l);
        }
        
        ll lower_bound(T w){
            if(w < 0) return -1;
            int x = 0, r = 1;
            while(r < _n) r = r<<1;
            int len;
            for(len = r;len > 0;len = len >> 1){
                if(x + len < _n && data[x + len] < w){
                    w -= data[x+len];
                    x += len;
                }
            }
            return x;
        }

    private:
        int _n;
        std::vector<T> data;

        T sum(int r){
            T s = 0;
            while(r > 0){
                s += data[r-1];
                r -= r & -r;
            }
            return s;
        }
};

int main()
{
    ll i,j;
    ll n,q;
    cin >> n >> q;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    BIT_tree<ll> bit(a);
    rep(i,q){
        ll c;
        cin >> c;
        if(c == 0){
            ll p,x;
            cin >> p >> x;
            bit.add(p, x);
        }else{
            ll l, r;
            cin >> l >> r;
            cout << bit.sum(l, r) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 14844
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
int main() {
	int n, m; std::cin >> n >> m;
	std::vector<std::vector<int>> nodes(n);
	for (auto i = 0; i < m; ++i) {
		int u, v; std::cin >> u >> v;
		nodes[u - 1].push_back(v - 1);
	}
	int start, goal; std::cin >> start >> goal;
	start--; goal--;
	std::vector<std::vector<int>> memo(n, std::vector<int>(3, -1));
	memo[start][0] = 0;
	std::queue<std::pair<int, int>> queue; queue.push(std::make_pair(start, 0));
	while (!queue.empty()) {
		auto top = queue.front(); queue.pop();
		for (const auto next : nodes[top.first]) {
			if (memo[next][(top.second + 1) % 3] == -1) {
				memo[next][(top.second + 1) % 3] = memo[top.first][top.second] + 1;
				queue.push(std::make_pair(next, (top.second + 1) % 3));
			}
		}
	}
	if (memo[goal][0] == -1) {
		std::cout << "-1\n";
	}
	else {
		std::cout << memo[goal][0] / 3 << std::endl;
	}
}


Measured memory_bytes: 11136
h, w = map(int, input().split())

grid = []
del_cnt = 0
for i in range(h):
    row = input()
    if '#' in row:
        grid.append(row)
    else:
        del_cnt += 1
ans = []
for i in range(w):
    col = ""
    for j in range(h-del_cnt):
        col += grid[j][i]
    if '#' in col:
        ans.append(i)

for i in range(h-del_cnt):
    tmp = ""
    for a in ans:
        tmp += grid[i][a]
    print(tmp)

Measured memory_bytes: 9216
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;


struct Edge {
  Edge(int _from, int _to, int _cost) : from(_from), to(_to), cost(_cost) {}
  int from, to, cost;

  bool operator<(const Edge& other) const {
    return cost < other.cost;
  }
};


class UF {
public:
  UF(int n) : e(n, -1) {}

  int find(int x) {
    return e[x] < 0 ? x : e[x] = find(e[x]);
  }

  bool same(int a, int b) {
    return find(a) == find(b);
  }

  bool unite(int a, int b) {
    a = find(a), b = find(b);
    if (a == b) return false;
    if (e[a] > e[b]) swap(a, b);
    e[a] += e[b]; e[b] = a;
    return true;
  }

private:
  vector<int> e;
};



void solve(int n, int k) {
  vector<Edge> edges;
  edges.reserve(k);

  for (int i = 0; i < k; ++i) {
    int u, v, c;
    scanf("%d %d %d", &u, &v, &c);
    edges.push_back(Edge(u, v, c));
  }

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

  UF uf(n);
  int counter = 0;
  int ans = 0;
  for (size_t i = 0; i < edges.size(); ++i) {
    if (counter >= n-1) break;
    Edge e = edges[i];
    if (!uf.same(e.from, e.to)) {
      ans += e.cost;
      uf.unite(e.from, e.to);
      ++counter;
    }
  }

  printf("%d\n", ans);
}

int main() {

  int n, k;
  scanf("%d %d", &n, &k);

  solve(n, k);
  return 0;
}



Measured memory_bytes: 3452
n,m,x = map(int,input().split())
a = list(map(int,input().split()))

dis_l = 0
dis_r = 0

l = [0]*(n+1)
for i in range(m):
    l[a[i]] += 1

e = l[:x]
f = l[x+1:n+1]

if e.count(1) < f.count(1):
    print(e.count(1))
else:
    print(f.count(1))


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cassert>
using namespace std;

 
const int mod = 1000000007;

 
const int MAX = 1000000;

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}


int main() {

    long long x, y;
    cin >> x >> y;

    if((x + y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    long long count = (x + y) / 3;

    x -= count;
    y -= count;


    if(x < 0 || y < 0) {
        cout << 0 << endl;
        return 0;
    }


    /*
    Init();

    cout << nCr(sum, minCount) << endl;
    */

    COMinit();
    cout << COM(x + y, x) << endl;

    return 0;


}

Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define pii pair<int,pair< int , int> >  
long long MOD  = 1e9+7;


signed main(){
    fast;
    int n;
    cin >> n;
    vector <int> a(n);
    for(int i=0 ; i<n ; i++){
    	cin >> a[i];
    }
    sort(all(a));
    int count = 0;
    for( int i = n-1; i >= 1; i--){ 
        int l = 0, r = i-1; 
        while( l < r){ 
            if( a[l] + a[r] > a[i]){ 
                count += r - l ;  
                r--;   
            } 
            else 
                l++;  
        } 
    } 
    cout << count << endl;
}


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

int n, q, a, b, c;
string req;
vector<int> ls[100005];

template <class T>
struct Unionfind {
  //木の番号
  vector<int> par;
  //木の階層
  vector<int> treerank;
  //辺の重み
  vector<T> weight;
  //コンストラクタ
  Unionfind(int n = 1, T initialnum = 0) {
    stree(n + 1, initialnum);
  }
  //木の生成、初期化
  void stree(int n = 1, T initialnum = 0) {
    par.resize(n);
    treerank.resize(n);
    weight.resize(n);
    for(int i = 0; i < n; ++i) {
      par[i] = i;
      treerank[i] = 0;
      weight[i] = initialnum;
      ls[i].push_back(i);
    }
  }
  //木の根を調べる
  int root(int x) {
    if(par[x] == x) return x;
    int rx = root(par[x]);
    weight[x] += weight[par[x]];
    return par[x] = rx;
  }
  //同一の木にあるか調べる
  bool chtree(int x, int y) { return root(x) == root(y); }
  //重み計算
  T calcw(int x) {
    root(x);
    return weight[x];
  }
  //木に追加
  //すでに同じグループにいた場合、計算せずに0を返す。
  bool unitree(int x, int y, T w = 0) {
    for(int i = 0; i < ls[y].size(); ++i)
      if(par[ls[y][i]] == y) weight[ls[y][i]] -= w;

    for(int i = 0; i < ls[x].size(); ++i)
      if(par[ls[x][i]] == x) weight[ls[x][i]] -= w;

    weight[x] += w;
    weight[y] += w;
    w += calcw(x);
    w -= calcw(y);
    x = root(x);
    y = root(y);

    if(x == y) return 0;
    if(treerank[x] < treerank[y]) {
      ls[y].insert(ls[y].end(), ls[x].begin(), ls[x].end());
      par[x] = y;
      weight[x] = -w;
    }
    else if(treerank[y] < treerank[x]) {
      ls[x].insert(ls[x].end(), ls[y].begin(), ls[y].end());
      par[y] = x;
      weight[y] = w;
    }
    else {
      ls[x].insert(ls[x].end(), ls[y].begin(), ls[y].end());
      par[y] = x;
      ++treerank[x];
      weight[y] = w;
    }
    return 1;
  }
  // xとyの差を計算
  //もしxとyが同じグループになかったら-1を返す
  T calcdiff(int x, int y) {
    if(!chtree(x, y)) return -1;
    return calcw(y) - calcw(x);
  }
};

int main() {
  int i;
  cin >> n >> q;
  Unionfind<int> uf(n);
  for(i = 0; i < q; ++i) {
    cin >> req;
    if(req == "IN") {
      cin >> a >> b >> c;
      uf.unitree(a, b, c);
    }
    else {
      int ans;
      cin >> a >> b;
      ans = uf.calcdiff(a, b);
      if(!uf.chtree(a,b))
        cout << "WARNING"<<endl;
      else
        cout << ans << endl;
    }
  }
}


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

using namespace std;

typedef long long ll;
typedef long double real;
typedef pair<int, int> duo;

#define TT template<typename T>
TT T    sq(T x){ return x*x; }
TT int  ubnd(vector<T>& v,T x){ return upper_bound(v.begin(), v.end(), x) - v.begin(); }
TT int  lbnd(vector<T>& v,T x){ return lower_bound(v.begin(), v.end(), x) - v.begin(); }
TT void sort(T& v){ sort(v.begin(), v.end()); }
TT void revs(T& v){ reverse(v.begin(), v.end()); }
TT void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TT void show(T& v,char d=' ',char e='\n'){for(int i=0;i<v.size();++i)cout<<v[i]<<((i==v.size()-1)?e:d);}
TT void inpt(vector<T>& v,int n){ v.reserve(n);for(int i=0;i<n;++i){T x; cin>>x; v.push_back(x);} }
TT T In(){ T x; cin >> x; return x; }

static inline void fast_io(){ ios::sync_with_stdio(0); cin.tie(0); }
static inline int in(){ int x; scanf("%d", &x); return x; }
static inline string instr(){ string x; cin >> x; return x; }
static inline ll pow_mod(ll a, ll k, ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
static inline ll mod_inv(ll a, ll p){ return pow_mod(a,p-2,p); }
static const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
static const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
static const int Mod = 1000000000;

int main()
{
  int n, m;
  set<string> cnt;
  cin >> n;
  for (int i = 0; i < n; i++) cnt.insert(instr());
  cin >> m;
  bool is_opened = false;
  for (int i = 0; i < m; i++){
    string s = instr();
    if (cnt.count(s)){
      if (is_opened) cout << "Closed";
      else cout << "Opened";
      cout << " by " << s << "\n";
      is_opened = !is_opened;
    }
    else {
      cout << "Unknown " << s << "\n";
    }
  }
  return (0);
}

// priority_queue queue deque first second front top push pop map set stringstream max_element min_element insert count find

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};
 
  
 

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

  int p,a;
  cin>>p>>a;

  cout<<ceil(p/(1.0*a));
   
}


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

k = 0
suc = 0
for i in range(n):
    if b[i]+suc >= a[i]:
        k += a[i]
        if suc >= a[i]:
            suc = b[i]
        else:
            suc = b[i]+suc-a[i]
    else:
        k += b[i]+suc
        suc = 0

if suc >= a[n]:
    k += a[n]
else:
    k += suc
    
print(k)

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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;



int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<ll> a(n), b(n+1);
	rep(i,n) cin >> a[i];
	ll sm = accumulate(all(a), 0LL);
	rep(i,n) b[i+1] = b[i] + a[i];
	ll ans = 1LL<<50;
	rep2(i,1,n){
		ll cq = sm - b[i];
		ll sa = abs(b[i] - cq);
		if(ans > sa) ans = sa ;
		//printf("%d::%lld:cc=%lld %lld\n ",i, b[i], cq, ans);
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;


int main(){
  ll n;
  cin >> n;

  std::vector<ll> a(n);
  rep(i,n-1) cin >> a.at(i);

  map<ll,ll> x;


  ll number;
  for(ll i=0;i<n-1;i++){
    number=a.at(i);
    x[number]=x[number]+1;
  }

  for(ll i=1;i<n+1;i++){
    cout << x[i] << endl;
  }


  }


Measured memory_bytes: 17252
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long lli;
 
int main() {
	lli n, t, p, q=0;
    cin >> n >> t;
    vector<lli> v;
    for(lli i=0; i<n; i++)
    {
      cin >> p;
      v.push_back(p);
    }
    sort(v.begin(), v.end());
    for(lli i=0; i<t; i++)
    {
      q=q+v[i];
    }
     cout << q << endl;
  return 0;
}

Measured memory_bytes: 3588
/*

*/
#include<bits/stdc++.h>

using namespace std;
using ll=long long;
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define rep(i, n) rep2(i,0,n)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  ll h,w;
  cin>>h>>w;
  if(h == 1 || w == 1){
   cout << 1 << endl;
   } else {
   cout << (h * w + 1) / 2 << endl;
  }
}


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

int main(void){
        double a,b,c,d,e,f;
        double x,y;
        while(cin>>a>>b>>c>>d>>e>>f) {
                x=(e*c-b*f)/(a*e-b*d);
                y=(-d*c+a*f)/(a*e-b*d);
                if(x<=1e-10 and -1*x<=1e-10)x=0;
                if(y<=1e-10 and -1*y<=1e-10)y=0;
                printf("%.3f %.3f\n",x,y);
        }
        return 0;
}



Measured memory_bytes: 3188
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <iostream>

using namespace std;
const int MAX = 100000;

int main() {
  ios::sync_with_stdio(false);
  int n, a, b;
  string s;
  int c = 0, d = 0;
  cin >> n >> a >> b >> s;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'a') {
      if (c < a + b) {
        c++;
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    } else if (s[i] == 'b') {
      if (c < a + b && d < b) {
        c++;
        d++;
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    } else if (s[i] == 'c') {
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 848
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int a; cin >> a;
    string s; cin >> s;
    if(a >= 3200){
        cout << s << '\n';
    }else{
        cout << "red" << '\n';
    }
}


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


Measured memory_bytes: 2592
#include <cstdio>
#include <cstring>
using namespace std;

typedef unsigned int U;
#define L 1<<21
bool HA[L];
char T[256];

int main() {
    U n, s, t;
    char c;
    T['A'] = (char)1, T['C'] = (char)2, T['G'] = (char)3, T['T'] = (char)4;
    scanf("%d", &n);
    while ( getchar() != '\n' );
    for ( register U i = 0; i++ < n; ) {
        s = 0;
        t = 1;
        bool flag = ( c = getchar() ) == 'i';
        while ( ( c = getchar() ) != ' ' );
        while ( ( c = T[getchar()] ) != 0 ) {
            s += c * t;
            t *= 4;
        }
        if ( flag ) {
            HA[s] = true;
        } else {
            puts( HA[s] ? "yes" : "no" );
        }
    }
    return 0;
}

Measured memory_bytes: 2096
h,w=gets.split.map(&:to_i)
matrix=[]
h.times{matrix << gets.chomp.split("")}
i=0
j=0
check=false
while i<matrix.size
  if matrix[i].all?{|a| a=="."}
    matrix.delete_at(i)
  else
    i+=1
  end
end
while j<matrix[0].size
  i=0
  while i<matrix.size
    if matrix[i][j]=="."
      check=true
    else
      check=false
      break
    end
    i+=1
  end
  if check then matrix.each{|arr| arr.delete_at(j)} else j+=1 end
end
matrix.each{|arr| puts arr.join("")}


Measured memory_bytes: 2556
# coding: utf-8
# coding: Shift_JIS
# coding: EUC-JP
# coding: cp932
import math
while 1:
    a,b = map(int,input().split())
    if a+b == 0:
        break
    for i in range(a):
        str = ""
        for j in range(b):
            if (i % 2 == 0 and j % 2 == 0) or (i % 2 == 1 and j % 2 == 1):
                str = str+"#"
            else:
                str = str+"."

        print(str)
    print()


Measured memory_bytes: 5668
n,m,x = gets.chomp.split(' ').map(&:to_i)
arr = gets.chomp.split(' ').map(&:to_i)
p = m
while p > 0
  if x > arr[p-1]
    break
  end
  p -= 1
end
if p < m - p
  puts p
else
  puts m - p
end

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

using ll = long long;
using Field = vector<vector<ll>>;
using Graph = vector<vector<ll>>;
using VI = vector<int>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VC = vector<char>;
using PI = pair<int, int>;

#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

long double A, B;

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

    cin >> A >> B;
    cout << (ll)(A * B + 0.001) << endl;

    return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 100000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;
int main(){
  string s,t,dum;
  std::cin >> s;
  std::cin >> t;
  for (int i = s.size()-t.size(); i >=0 ; i--) {
    /* code */
    
    dum=s;
    rep(j,t.size())dum[i+j]=t[j];
    rep(j,s.size()){
      if(s[j]=='?'||s[j]==dum[j]){
        if(j==s.size()-1){
          rep(k,dum.size()){
            if(dum[k]=='?')dum[k]='a';
          }
          std::cout << dum << std::endl;
          exit(0);
        }
        continue;
      }
      else break;
      
    }
  }
  std::cout <<  "UNRESTORABLE"<< std::endl;
}

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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	int s, w;
	cin >> s >> w;
	if(w >= s) {
		cout << "unsafe\n";
	}
	else 
		cout << "safe\n";

	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

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

int main() {
  //input
  int M1, D1, M2, D2;
  cin >> M1 >> D1;
  cin >> M2 >> D2;
  //calc
  int answer = D2 == 1 ? 1 : 0;
  //output
  cout << answer << endl;
}

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

int main() {
	int N, T, c[1000], t[1000];
	
	cin >> N >> T;
	for (int i = 0; i < N; ++i) cin >> c[i] >> t[i];

	int min = c[0];
	int count = 0;
	for (int i = 0; i < N; ++i) {
		if (t[i] <= T && c[i] < min) min = c[i];
		if (T < t[i]) ++count;
	}

	if (count == N) cout << "TLE" << endl;
	else cout << min << endl;
}




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

using namespace std;

using ll = long long;

const int MX = 200 * 1000 + 7;
bool was[MX];

int res[MX];

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n, x;
    cin >> n >> x;
    n = 2 * n - 1;
    if (x == n || x == 1) {
        cout << "No\n";
        return 0;
    }
    res[n / 2] = x;
    res[n / 2 - 1] = 1;
    res[n / 2 + 1] = n;
    was[x] = was[1] = was[n] = true;
    int ptr = 1;
    cout << "Yes\n";
    for (int i = 0; i < n; i++) {
        if (res[i] == 0) {
            while (was[ptr]) {
                ptr++;
            }
            res[i] = ptr;
            was[ptr] = true;
        }
    }
    for (int i = 0; i < n; i++) {
        cout << res[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

int N;
string T;

bool BSsolve(int S){
    if(S<=0)return true;
    vector<string> G;
    map<string,int> M;
    for(int i=0;i+S<=T.size();i++){
        G.push_back(T.substr(i,S));
    }
    sort(G.begin(),G.end());
    REP(i,G.size()-1){
        if(G[i]==G[i+1] && M[G[i]]==0){
            int p=T.find(G[i]);
            int q=T.rfind(G[i]);
            if(p!=std::string::npos && q!=std::string::npos && p+G[i].size()<=q){
                M[G[i]]=1;
                return true;
            }
        }
    }
    return false;
}
int BinarySearch(int m,int M,int count){
    int L=min(m,M),R=max(m,M),mid;
    L--;
    while(abs(R-L)>1&&count>0){
        mid=(L+R)/2;
        //cout << mid << endl;
        if(BSsolve(mid)){
            L=mid;
        }else{
            R=mid;
        }
        count--;
    }
    return L;
}

signed main(void){
    cin >> N;
    cin >> T;
    int L=BinarySearch(0,N,INF);
    cout << L << endl;
    
    return 0;
}



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

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

  int r, u, n;
  cin >> r >> u >> n;
  int l = 0, d = 0;
  
  int x, y, a;
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> a;
    if (a == 1) l = max(l, x);
    else if (a == 2) r = min(r, x);
    else if (a == 3) d = max(d, y);
    else if (a == 4) u = min(u, y);
  }
  cout << max(0, u - d) * max(0, r - l) << '\n';
  return 0;
}

Measured memory_bytes: 256