akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
  int n,m;
  for(;cin>>n>>m,n;)
    {
      int data[n+1][1261];
      memset(data,-1,sizeof(data));
      int r;
      cin>>r;
      for(int i=0;i<r;i++)
	{
	  int t,nn,m,s;
	  cin>>t>>nn>>m>>s;
	  int num;
	  if(s==1)
	    num=m;
	  else
	    {
	      //     t++;
	      num=-1;
	    }
	  for(int i=t;i<1261;i++)
	      data[nn][i]=num;
	}
      int q;
      cin>>q;
      for(int i=0;i<q;i++)
	{
	  int ts,te,mm;
	  cin>>ts>>te>>mm;
	  int cnt=0;
	  for(int tt=ts;tt<te;tt++)
	    {
	      bool flag=false;
	      for(int i=1;i<=n&&!flag;i++)
		{
		  //  cout<<"i tt data,"<<i<<" "<<tt<<" "<<data[i][tt]<<endl;
		  if(data[i][tt]==mm)
		    flag=true;
		}
	      if(flag)
		{
		  //   cout<<"in "<<tt<<endl;
		  cnt++;
		}

	    }
	  cout<<cnt<<endl;
	}
    }
}

Measured memory_bytes: 6000
from collections import Counter
H,W,N = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N)]

c = Counter()
for a,b in AB:
    for i in range(a-1,a+2):
        for j in range(b-1,b+2):
            if not 1 < i < H: continue
            if not 1 < j < W: continue
            c[(i,j)] += 1

ans = [0]*10
for k,v in c.items():
    ans[v] += 1
z = (H-2)*(W-2) - sum(ans)
ans[0] = z

print(*ans,sep='\n')

Measured memory_bytes: 165576
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	string s;
	
	cin >> s;
	
	if((s.length() % 2 == 0 && !(s[0] == s[s.length()-1])) || (!(s.length() % 2 == 0) && s[0] == s[s.length()-1]))
		cout << "Second";
	else
		cout << "First";
	
	return 0;
}

Measured memory_bytes: 512
n, k = map(int, input().split())
P = list(map(int, input().split()))
S = [0] * (n+1)
for i in range(n):
    S[i+1] = S[i] + (P[i] + 1) / 2

ans = 0
for i in range(k,n+1):
    ans = max(ans, S[i] - S[i-k])
print(ans)

Measured memory_bytes: 25060
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
 
using namespace std;


void solve(){
	double a,b,x,k;
	cin>>a>>b>>x;
	k = 2*(b/a - x/(a*a*a));

	if(a*a*b/2.0 <=x) cout<<atan(k)*180/(3.141592653);
	else cout<<atan(b*a*b/(2*x))*180/3.141592653;
}


int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout<<fixed<<setprecision(12);
	int t =1; //cin>>t;
	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}
	return 0;

}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()

using namespace std;

namespace Dump {
#define dump(...) Dump::print(#__VA_ARGS__, __VA_ARGS__)
static std::vector<string> dumpKey;
static string dumpKeyBuf;

void print() { cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
  if (dumpKey.empty()) {
    dumpKeyBuf = head;
    dumpKeyBuf.erase(std::remove_if(dumpKeyBuf.begin(), dumpKeyBuf.end(),
                                    [](char c) { return c == ' '; }),
                     dumpKeyBuf.end());

    std::istringstream stream(dumpKeyBuf);
    string field;
    while (std::getline(stream, field, ','))
      dumpKey.push_back(field);

    reverse(dumpKey.begin(), dumpKey.end());
  } else {
    cerr << dumpKey.back() << ":" << head << "  ";
    dumpKey.pop_back();
  }
  Dump::print(std::move(tail)...);
}
}

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pii; // p.first p.second

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

struct LIS {
  vi id;
  vi value;
  vi lis;        //最長増加部分
  int lis_index; // LIS index
  // const int INF = 100000000;

  LIS(vector<long long> v) : id(v.size()), value(v.size(), 1e8) {
    int size = v.size();
    for (int i = 0; i < size; ++i) {
      id[i] = distance(value.begin(),
                       lower_bound(value.begin(), value.end(), v[i]));
      value[id[i]] = v[i];
    }

    int ma = *max_element(id.begin(), id.end());
    lis.resize(ma + 1);
    for (lis_index = size - 1; lis_index >= 0; --lis_index)
      if (id[lis_index] == ma)
        lis[ma--] = v[lis_index];
    lis_index++;
  }

  int getIndex() const { return lis_index; }

  int getSize() const { return lis.size(); }

  vi get() const { return lis; }
};

void solve(long long N, vector<long long> d) {
  sort(ALL(d));
  LIS lis(d);
  cout << lis.getSize() << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  vector<long long> d(N - 1 + 1);
  for (int i = 0; i <= N - 1; i++) {
    cin >> d[i];
  }
  solve(N, d);
  return 0;
}


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

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,M;cin>>N>>M;
  ll a[M];
  for(ll i=0;i<M;i++){
    cin>>a[i];
  }
  a[M]=INF;
  ll dp[N+10]={1};
  ll j=0;
  for(ll i=0;i<N;i++){
    while(j<M&&a[j]<i)j++;
    if(i==a[j])continue;
    dp[i+1] = (dp[i+1]+dp[i])%MOD;
    dp[i+2] = (dp[i+2]+dp[i])%MOD;
  }
  cout<<dp[N]<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    int A,B,C; cin >> A >> B >> C;
    if(A - B >= C) cout << 0 << endl;
    else cout << C - A + B << endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
ans = 0
for i in range(len(S)):
    if len(S) > 10:
        break
    if len(T) != len(S) + 1:
        break
    if S[i] == T[i]:
        ans = 1
    else:
        ans = 0
        break

if ans == 1:
    print('Yes')
else:
    print('No')


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

using ll=long long;
int main(){
    int n,k;
    cin>>n>>k;
    vector<ll> d(n),t(n);
    set<int> ts;
    for(int i=0;i<n;i++){
        cin>>t[i]>>d[i];
        t[i]--;
        ts.insert(t[i]);
    }
    vector<vector<int>> sushi(n);
    for(int i=0;i<n;i++){
        sushi[i].push_back(0);
        sushi[t[i]].push_back(d[i]);
    }
    for(int i=0;i<n;i++){
        sort(sushi[i].begin(),sushi[i].end());
    }
    vector<int> idx(n);
    iota(idx.begin(),idx.end(),0);
    sort(idx.begin(),idx.end(),[&](int lhs,int rhs){return sushi[lhs].back()>sushi[rhs].back();});
    int lim=min(k,(int)(ts.size()));
    priority_queue<ll,vector<ll>,greater<>> que;
    ll res=0;
    ll sum=0;
    ll qsum=0;
    for(ll x=1;x<=lim;x++){
        sum+=sushi[idx[x-1]].back();
        sushi[idx[x-1]].pop_back();
        for(auto &e:sushi[idx[x-1]]) que.push(e),qsum+=e;
        while(que.size()>k-x){
            qsum-=que.top();
            que.pop();
        }
        res=max(res,sum+qsum+x*x);
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 12800
def solve():
    a, b = map(int, input().split())
    s_i, s_j = 1, 0
    t_i, t_j = 0, 1
    while b:
        q, r = divmod(a, b)
        s_i, s_j = s_j, s_i - q * s_j
        t_i, t_j = t_j, t_i - q * t_j
        a, b = b, r
    print(s_i, t_i)

solve()

Measured memory_bytes: 7780
N = int(input())
sixes = [6 ** i for i in range(1, 7)]
nines = [9 ** i for i in range(1, 6)]
coin = [1] + sixes + nines
INF = 10**6
dp = [INF] * 100010
dp[0] = 0  # dp[i]:i円引き出すのに必要な回数
for money in range(1, N + 1):
    dp[money] = min([dp[money-i] + 1 for i in coin if i <= money])
print(dp[N])


Measured memory_bytes: 3828
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K,H,W, mi1,mi2,sum,B[100000],C[102];
LL ans;
LL no;
bool b,bb[1000000000];
string s,t;

int main() {
	cin >> N;
	LL now = 0;
	ans = 0;
	for (int i = 0; i <N; i++) {
		cin >> B[i];
		now += B[i];
		if (B[i] == 0) {
			ans += now / 2;
			now = 0;
		}
	}
	ans += now / 2;
	cout << ans << endl;



	return 0;
}



Measured memory_bytes: 3068
H, W = map(int, input().split())
A = [[a for a in input()] for _ in range(H)]

ans = True
h = 0
w = 0
B = [[1 if a == '#' else 0 for a in a_list] for a_list in A]
while (ans) and not (h == H - 1 and w == W - 1):
    B[h][w] = 0
    if h == H - 1:
        if A[h][w + 1] == '.':
            ans = False
        else:
            w += 1
    elif w == W - 1:
        if A[h + 1][w] == '.':
            ans = False
        else:
            h += 1
    else:
        sh = A[h + 1][w]
        sw = A[h][w + 1]
        if sh == '#' and sw == '#':
            ans = False
        elif sh == '.' and sw == '.':
            ans = False
        elif sh == '#' and sw == '.':
            h += 1
        else:
            w += 1

s = sum([sum(b_list) for b_list in B])
if ans and s == 1:
    print("Possible")
else:
    print("Impossible")


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


ll sum[2005][2005];
const ll MOD = 1e9+7;
int main(){
    int n,m;
    cin>>n>>m;
    vector<ll>s(n+1,0);
    vector<ll>t(m+1,0);
    rep(i,n){
        cin>>s[i+1];
    }
    rep(i,m){
        cin>>t[i+1];
    }
    rep(i,2005) sum[0][i]=1;
    rep(i,2005) sum[i][0]=1;
    REP(i,n){
        REP(j,m){
            if(s[i]==t[j]){
                sum[i][j]=(sum[i-1][j]+sum[i][j-1])%MOD;
            }
            else{
                sum[i][j]=(0-sum[i-1][j-1]+sum[i-1][j]+sum[i][j-1]+MOD)%MOD;

            }
        }
    }
    cout<<sum[n][m]<<endl;
    return 0;
}

Measured memory_bytes: 31616
n, k = map(int,input().split())
A = list(map(int,input().split()))

def gcd(x, y):
    while x != 0 and y != 0:
        x, y = min(x,y), max(x,y)
        y %= x
    return x

a = A[0]
for i in range(1, n):
    a = gcd(a, A[i])
    # print(a)

# print(a)

if k <= max(A) and k % a == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 62576
#line 1 "/workspaces/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "main.cpp"

constexpr int m = 26;

// i日目のスコアを計算する
ll calc_day(const int i, const int ans, const ll s, const vl &c, const vi &last) {
  ll ret = 0;
  ret += s;
  REP(j, m) {
    if (j != ans)
      ret -= c[j] * (i + 1 - last[j]);
  }
  return ret;
}

// d日目までのスコアを計算する
ll calc_ans(const int d, const vi &ans, const vector<vl> &s, const vl &c, vi &last) {
  ll ret = 0LL;
  REP(i, d) { ret += calc_day(i, ans[i], s[i][ans[i]], c, last); }
  return ret;
}

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

  int d;
  cin >> d;

  vl c(m);
  REP(i, m) { cin >> c[i]; }

  vector<vl> s(d, vl(m, 0));
  REP(i, d) {
    REP(j, m) { cin >> s[i][j]; }
  }

  vi ans(d), last(m, 0);

  REP(i, d) { ans[i] = i % m + 1; }
  REP(i, d) {
    ll ma = -1e9;
    ll mai = -1;
    REP(j, m) {
      ll tmp = calc_day(i, j, s[i][j], c, last);
      // 次の日の減少量も見る
      int prev = last[j];
      last[j] = i + 1;
      tmp += calc_day(i + 1, -1, 0, c, last);
      if (ma < tmp) {
        chmax(ma, tmp);
        mai = j;
      }
      last[j] = prev;
    }
    last[mai] = i + 1;
    ans[i] = mai + 1;
  }

  REP(i, d) { cout << ans[i] << endl; }

  return 0;
}


Measured memory_bytes: 3752
N=int(input())
A=list(map(int,input().split()))
ans=0
for x in range(N):
    if A[x]%2==0:
        if A[x]%3==0 or A[x]%5==0:
            ans+=1
    elif A[x]%2!=0:
        ans+=1
if ans==N:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3064
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('\n');
   let xs1 = xs[0].trim().split(' ').map(v=>parseInt(v,10));
   let xs2 = xs[1].trim().split(' ').map(v=>parseInt(v,10));
   let HP = xs1[0];
   let N = xs1[1];
   let attack = 0
   
   for(let i =0; i<N; i++){
      attack +=xs2[i]; 
   }
   if(HP <= attack){
   	 console.log('Yes');
   }else{
     console.log('No');
   }

}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 16716
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
const bool DEBUG = 0;
#include <iostream>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>
#include <iomanip>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef tuple<ll, ll> P;
typedef tuple<ll, ll, ll> P3;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<P> VP;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

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

#define LFOR(i,a,b) for(ll i=(a);i<(b);++i)
#define LREP(i,n) LFOR(i,0,n)
#define LRFOR(i,a,b) for(ll i=(b)-1;i>=(a);--i)
#define LRREP(i,b,a) LRFOR(i,0,n)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(int)(c).size())
#define REACH(i,c) RREP(i,(int)(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define BR cout << "\n"

#define dump(x) if(DEBUG)cerr<<"[" << __LINE__ << "] "<<#x<<"="<<(x)<<"\n"
#define dump2(x,y) if(DEBUG)cerr<<"["<<__LINE__<< "] "<<#x<<"="<<(x)\
  <<" , "<<#y<<"="<<(y)<<"\n"
#define dump3(x,y,z) if(DEBUG)cerr<<"["<<__LINE__<< "] "<<#x<<"="<<(x)\
  <<" , "<<#y<<"="<<(y)<<"\n"\
  <<" , "<<#z<<"="<<(z)<<"\n"

#define SAY(x) if(DEBUG) cerr << "[" << __LINE__ << "] " << (x) << "\n"

#define YES(x) cout<<((x)?"YES":"NO")<<"\n"
#define Yes(x) cout<<((x)?"Yes":"No")<<"\n"
#define yes(x) cout<<((x)?"yes":"no")<<"\n"

int int_in(){int n;cin>>n;return n;}
ll ll_in(){ll n;cin>>n;return n;}
string string_in(){string n;cin>>n;return n;}
#define ini int_in()
#define inl ll_in()
#define ins string_in()

#define inside(x,y) (0<=(x)&&(x)<w&&0<=(y)&&(y)<h)

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

ll ans;
int dp[8001];

bool solve() {
  omajinai;
  //#####//
  string s=ins;
  s+="T";
  int tx=ini,ty=ini;
  int n=s.size();
  bool first=1;
  bool flag =1;
  int c=0;
  VI xs,ys;
  int sumx=0,sumy=0;
  REP(i,n){
	  if(s[i]=='T'){
		  if(first){
			  tx-=c;
		  }else{
			  (flag?xs:ys).PB(c);
			  (flag?sumx:sumy) += c;
			  dump2(flag,sumx);
		  }
		  c=0;
		  flag^=1;
		  first=0;
	  }else{
		  c++;
	  }
  }
  dump(1);
//  SORT(xs);
//  SORT(ys);
  int gx = sumx - tx;
  int gy = sumy - ty;
  dump2(sumx,tx);
  dump2(sumy,ty);
  if(gx<0)return 0;
  if(gy<0)return 0;
  if(gx%2)return 0;
  if(gy%2)return 0;
  gx/=2;
  gy/=2;
  if(gx>8000)return 0;
  if(gy>8000)return 0;
  dump(2);
  dp[0]=1;
  REP(i,xs.size()){
	  RREP(j, 8001){
		  if(j-xs[i]>=0)dp[j]|=dp[j-xs[i]];
	  }
  }
  if(!dp[gx])return 0;
  memset(dp, 0, sizeof dp);
  dp[0]=1;
  REP(i,ys.size()){
	  RREP(j, 8001){
		  if(j-ys[i]>=0)dp[j]|=dp[j-ys[i]];
	  }
  }
  if(!dp[gy])return 0;
  return 1;
}

int main(){
	Yes(solve());
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

const ll MAX = 1e9;

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

  V<string> c(h);
  rep(i, h) cin >> c[i];

  V<V<int>> ans(h, V<int>(w, 0));
  int s = 0;
  rep(i, h) {
    if (c[i].find("#") != c[i].npos) {
      s = i;
      break;
    }
  }
  int n = 0;
  for (int i = s; i < h; i++) {
    if (c[i].find("#") == c[i].npos) {
      ans[i] = ans[i - 1];
      continue;
    }
    n++;
    int f = c[i].find("#");
    rep(j, f + 1) ans[i][j] = n;
    for (int j = f + 1; j < w; j++) {
      if (c[i][j] == '#') n++;
      ans[i][j] = n;
    }
  }
  for (int i = h - 1; i >= 0; i--) {
    if (ans[i][0] == 0) ans[i] = ans[i + 1];
  }

  rep(i, h) {
    rep(j, w) printf("%d ", ans[i][j]);
    printf("\n");
  }
}


Measured memory_bytes: 4252
#include<stdio.h>
int Hira[101][101];
int Sawa[101];
/*
行列の意味
1から2に行きたいときは1行目の２列目を見れば良い
*/
void tree(int m) {
	int i, j, k = 1, Ryo[100], kom, min, kei = 0;
	Ryo[0] = 0;
	Sawa[0] = 1;
	for (i = 1; i < m; i++) {
		Sawa[i] = 0;
	}
	for (;;) {
		kom = 9999;
		for (i = 0; i < k; i++) {
			for (j = 0; j < m; j++) {
				if (Hira[Ryo[i]][j] < kom && Hira[Ryo[i]][j] != -1 && Sawa[j] != 1) {
					kom = Hira[Ryo[i]][j]; min = j;
				}
			}
		}
		if (k != m) {
			Ryo[k] = min;
			Sawa[min] = 1;
			kei += kom;
			k++;
		}
		else break;
	}
	printf("%d\n", kei);
}

int main() {
	int n, i, j;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			scanf("%d", &Hira[i][j]);
		}
	}
	tree(n);
	return 0;
}


Measured memory_bytes: 2108
N, Y = map(int, input().split())

money = [10000, 5000, 1000]
ans = []
for i in range(N+1):
    for j in range(N+1):
        buff = N - i - j
        if buff >= 0:
            if Y == money[0]*i + money[1]*j + money[2]*buff:
                ans = [i, j, buff]
                print(*ans)
                exit()


print(*[-1, -1, -1])

Measured memory_bytes: 40940
n = int(input())
a = [0] * 10**5
for x in range(1, 101):
	for y in range(1, 101):
		for z in range(1, 101):
			a[x**2 + y**2 + z**2 + x*y + y*z + z*x] += 1
for i in range(1, n + 1):
	print(a[i])

Measured memory_bytes: 75228
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define M 1000000007
#define ll long long int
#define F first
#define S second
#define INF (ll)1000000000
const int N = 1e5 + 5;
#define maax(a,b,c) max((int)a,max((int)b,(int)c))
#define miin(a,b,c) min((int)a,min((int)b,(int)c))
#define mp make_pair
#define in long long int
#define ep emplace_back
#define all(a) a.begin(),a.end()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define inf (long long) 1e18
#define vl vector<ll>
#define sz(a) (ll)a.size()
#define mem(a,b) memset(a,b,a.size())
#define fr(i,m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define fre(i,m, n) for (int i = (int)(n); i <= (int)(m); i--)
#define rall(x) (x).rbegin(), (x).rend()
typedef long long LL;
typedef pair<int, int> PII;	
int solve()
{
	
    return 0;
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
    int a[3][3];
    fr(i,0,3) 
    {
    	fr(j,0,3)
    	{
    		cin>>a[i][j];
		}
	}
	int f=0,t;cin>>t;vector<int>b(t);map<int,int>m;
	while(t--) cin>>b[t],m[b[t]]++;
	fr(i,0,3) 
	{
		if((m[a[0][i]]+m[a[1][i]]+m[a[2][i]])>2)
		{
			cout<<"Yes\n";return 0;
		}
		if((m[a[i][0]]+m[a[i][1]]+m[a[i][2]])>2)
		{
			cout<<"Yes\n";return 0;
		}
	}
	((m[a[0][0]]+m[a[1][1]]+m[a[2][2]])>2 || (m[a[0][2]]+m[a[1][1]]+m[a[2][0]])>2)?cout<<"Yes":cout<<"No";
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
  int n,x;
  cin>>n>>x;
  int mini=1000;
  rep(i,n){
    int m;
    cin>>m;
    x-=m;
    mini=min(mini,m);
  }
  cout<<n+x/mini<<endl;
}


Measured memory_bytes: 3628
from bisect import bisect_left

A, B, Q = map(int, input().split())
s_list = [int(input()) for _ in range(A)]
t_list = [int(input()) for _ in range(B)]
x_list = [int(input()) for _ in range(Q)]

inf = float("inf")

s_list = [-inf] + s_list + [inf]
t_list = [-inf] + t_list + [inf]

for x in x_list:

    s_i = bisect_left(s_list, x)
    t_i = bisect_left(t_list, x)

    ans = inf
    for s in (s_list[s_i - 1], s_list[s_i]):
        for t in (t_list[t_i - 1], t_list[t_i]):
            d1 = abs(s - x) + abs(t - s)
            d2 = abs(t - x) + abs(s - t)
            ans = min(ans, d1, d2)
    print(ans)


Measured memory_bytes: 16772
#include <bits/stdc++.h>
#define ll long long
#define ld lond double
#define pll pair < long long , long long>
#define p_b push_back
#define all(x) x.begin(),x.end();
#define fi first
#define se second
using namespace std;

int main()
{
    int n;
    cin >> n;
    map < string , int > m;
    for( int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        m[s]++;
    }
    int mx= -1;
    for( auto it = m.begin(); it!=m.end(); it++)
    {
        mx = max(mx,it->second);
    }
    for( auto it = m.begin(); it!=m.end(); it++)
    {
        if(mx==it->second)
        {
            cout << it->fi<< endl;
        }
    }
}


Measured memory_bytes: 25216
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def operation(box:list, frm:int, to:int):
    box[frm] -= 1
    box[to] += 1
    
n,m = li()
box = [1 for _ in range(n)]
cand = [False for _ in range(n)]
cand[0] = True
ope = []
for _ in range(m):
    x,y = li_()
    ope.append((x,y))
    
for x,y in ope:
    operation(box,x,y)
    if (not cand[y]) and cand[x]:
        cand[y] = True
    
    if cand[x] and box[x] > 0:
        cand[x] = True
        
    elif cand[x] and box[x] == 0:
        cand[x] = False
        
print(sum(cand))

Measured memory_bytes: 18180
#include<stdio.h>
int p[131072],invp[131072],q[131072],invq[131072];
int f[131072],g[131072],invf[131072];
int tmp[131072];
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&p[i]);
		invp[p[i]]=i;
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&q[i]);
		invq[q[i]]=i;
	}
	for(int i=1;i<=n;i++)
	{
		g[i]=q[invp[invq[p[i]]]];
		f[i]=i;
	}
	int kk=(k-1)/6;
	while(kk)
	{
		if(kk&1)
		{
			for(int i=1;i<=n;i++)
			{
				tmp[i]=f[g[i]];
			}
			for(int i=1;i<=n;i++)
			{
				f[i]=tmp[i];
			}
		}
		for(int i=1;i<=n;i++)
		{
			tmp[i]=g[g[i]];
		}
		for(int i=1;i<=n;i++)
		{
			g[i]=tmp[i];
		}
		kk>>=1;
	}
	for(int i=1;i<=n;i++)
	{
		invf[f[i]]=i;
	}
	for(int i=1;i<=n;i++)
	{
		if(k%6==1)
		{
			printf("%d",f[p[invf[i]]]);
		}
		else if(k%6==2)
		{
			printf("%d",f[q[invf[i]]]);
		}
		else if(k%6==3)
		{
			printf("%d",f[q[invp[invf[i]]]]);
		}
		else if(k%6==4)
		{
			printf("%d",f[q[invp[invq[invf[i]]]]]);
		}
		else if(k%6==5)
		{
			printf("%d",f[q[invp[invq[p[invq[invf[i]]]]]]]);
		}
		else
		{
			printf("%d",f[q[invp[invq[p[p[invq[invf[i]]]]]]]]);
		}
		if(i==n)
		{
			putchar('\n');
		}
		else
		{
			putchar(' ');
		}
	}
	return 0;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int Mod = 998244353;
const int MAXN = 3e5 + 10;
int n,a,b,k,fac[MAXN],inv[MAXN];
inline int Pow(int a, int b,int ans=1) {
    for(;b;b>>=1,a=a*a%Mod) if(b&1) ans=ans*a%Mod;
    return ans;
}
inline void init() {
    fac[0]=1;
    for(int i=1;i<MAXN;i++) {
        fac[i]=(fac[i-1]*i)%Mod;
    }
    inv[MAXN-1]=Pow(fac[MAXN-1],Mod-2);
    for(int i=MAXN-2;i>=0;i--) {
        inv[i]=inv[i+1]*(i+1)%Mod;
    }
}
inline int C(int n,int m) {
    if(n<m) return 0;
    return fac[n]*inv[m]%Mod*inv[n-m]%Mod;
}
signed main() {
    cin>>n>>a>>b>>k;
    int ans=0;
    init();
    for (int i = 0; i <= n; i++) {
        if(a*i>k) break;
        if((k-a*i)%b) continue;
        int cnt=(k-a*i)/b;
        if(cnt>n) continue;
        ans=(ans+C(n,i)%Mod*C(n,cnt)%Mod+Mod)%Mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
int main(void){
   int m,f,r;
   
   while(1){
       scanf("%d %d %d",&m,&f,&r);
       if(m==-1&&f==-1&&r==-1) break;
       
       if(m==-1||f==-1) printf("F\n");
       else if(m+f>=80) printf("A\n");
       else if(m+f>=65) printf("B\n");
       else if(m+f>=50) printf("C\n");
       else if(m+f>=30){
           if(r>=50) printf("C\n");
           else printf("D\n");
       }
       else printf("F\n");
   }
   return 0;
}


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

int main(){
  int N; cin >> N;
  int a[100];
  for(int i=0; i<N; i++){
    cin >> a[i];
  }
  
  int mincost=10000000;
  for(int j=-100; j<=100; j++){
    int cost=0;
    for(int i=0; i<N; i++){
      cost+=(j-a[i])*(j-a[i]);
    }
    mincost=min(mincost,cost);
  }
  cout << mincost << endl;
}

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

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

#define REPR(i,n) for(int i =n; i >=0; --i)

#define REP_(i,m,n) for(int i =m; i <n; ++i)

#define INF 2e9

#define ll long long

//const ll MOD = 1000000007;

//const  long double PI=(acos(-1));

//const  long double EPS=0.0000000001;

bool judge(int x){
    for(int i =2; i <= sqrt(x); i++)
    if(x%i==0) return false;
    return true;
}

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

    for(int i = x; i <= (x+100000); i++){
        if(judge(i)){
            cout << i << endl;
            break;
        }
    }

    return 0;
}

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


int main()
{
	ll n,m;cin>>n>>m;
	ll a[n+1];
	for(ll i=1;i<=n;i++)cin>>a[i];
	
	if(n==1)
	{
		if(a[1]<=m)cout<<"0\n";
		else
		{
		n=a[1]-(a[1]-m);cout<<n<<endl;
		}
	}
	else
	{
		ll count=0;
		for(int i=2;i<=n;i++)
		{
	      if(a[i]+a[i-1]<=m)continue;
	      else
	      {
	       ll cut=a[i]+a[i-1]-m;
	       if(a[i]>=cut){
	       a[i]=a[i]-cut;
	       count+=cut;continue;}
	       
	       if(a[i]<cut){
	       count+=a[i];
	       cut-=a[i];
	        a[i]=0;

	       if(a[i-1]>=cut){
	       a[i-1]-=cut;
	       count+=cut;}
	       	
	       }
	       
	       
	      }
		}
		cout<<count<<endl;
	}
	
}

Measured memory_bytes: 1024
while True:
    a,op,b = input().split()
    if op == "+":
        print(int(a)+int(b))
    elif op == "-":
        print(int(a)-int(b))
    elif op == "*":
        print(int(a)*int(b))
    elif op == "/":
        print(int(a)//int(b))
    elif op == "?":
        break


Measured memory_bytes: 5596
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

fn main() {
    let n: usize = util::get();
    let a: Vec<i64> = util::gets();

    let total = a.iter().fold(0, |a1, &a2| a1 + a2);
    let mut snuke = 0;
    let mut min_diff = (a[0] * 2 - total).abs();
    for &x in &a[..n - 1] {
        snuke += x;
        min_diff = min(min_diff, (2 * snuke - total).abs());
    }

    println!("{}", min_diff);
}


Measured memory_bytes: 10492
import collections

import sys
big=998244353

n = int(input())
d = list(map(int, input().split()))
d_sort = sorted(d)


if d[0]!=0:
  print(0)
  sys.exit(0)

for i in range(n-1):
  if d_sort[i+1]-d_sort[i]>1:
    print(0)
    sys.exit(0)


def cho(node0,node1):
  #tmp0 = 2**node0-1
  #tmp0 = tmp0%big
  #tmp1 = 2**(node1*(node1-1)/2)
  #tmp1 = tmp1%big
  return (node0**node1) % big


c = collections.Counter(d)

if c[0]!=1:
  print(0)
  sys.exit(0)

count=1
for i in range(max(d)):
  count *= cho(c[i], c[i+1])
  #print("i=", i, c[i], c[i+1], cho(c[i], c[i+1]))
  count=count%big

print(count)







Measured memory_bytes: 20696
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	string s;
	cin>>s;
	string ans="";
	fx(s.size()){
		if(s.at(x)!='B'){
			ans+=s.at(x);
		}else{
			if(ans!=""){
				if(ans.size()==1){
					ans="";
				}else{
					ans=ans.substr(0,ans.size()-1);
				}
			}
		}
	}
	ce(ans)
	
}


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

int main() {
    int N, M, X, Y, xmax = -101, ymin = 101;
    cin >> N >> M >> X >> Y;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        xmax = max(xmax, a);
    }
    for (int i = 0; i < M; i++) {
        int a;
        cin >> a;
        ymin = min(ymin, a);
    }
    if (xmax >= ymin) {
        cout << "War" << endl;
        return 0;
    }
    for (int i = xmax + 1; i < ymin + 1; i++) {
        if (X < i && i <= Y) {
            cout << "No War" << endl;
            return 0;
        }
        if (i == ymin) {
            cout << "War" << endl;
        }
    }
}

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

using namespace std;

const long long int MAX_N = 200010;

long long int parr[MAX_N];
long long int rankk[MAX_N];

void init(long long int n) {
	for (long long int i = 0; i < n; i++) {
		parr[i] = i;
		rankk[i] = 0;
	}
}

long long int find(long long int x) {
	if (parr[x] == x) {
		return x;
	}
	else {
		return parr[x] = find(parr[x]);
	}
}

void unite(long long int x, long long int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;

	if (rankk[x] < rankk[y]) {
		parr[x] = y;
	}
	else {
		parr[y] = x;
		if (rankk[x] == rankk[y]) {
			rankk[x]++;
		}
	}
}

bool same(long long int x, long long int y) {
	if (find(x) == find(y)) {
		return true;
	}
	return false;
}


int main() {
	long long int n;
	cin >> n;
	vector<long long int> p(n);
	for (long long int i = 0; i < n; i++) {
		cin >> p[i];
	}
	
	init(n + 1);

	vector<long long int> d(n+1, 0);
	for (long long int i = 0; i < n; i++) {
		if (d[p[i]] == 0) {
			d[p[i]] = 1;
		}
		if (d[p[i] - 1] == 1) {
			unite(p[i] - 1, p[i]);
		}
	}
	
	long long int ans = 0;

	for (long long int i = 1; i <= n; i++) {
		ans = max(ans, i-find(i)+1);
	}

	cout << n-ans << endl;

	return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;

typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

//constexpr long long MOD = (ll) 1e9+7;
constexpr long long MOD = 998244353;

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

struct Edge {
	int to, cap, rev;
	Edge(int _to, int _cap, int _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, int from, int to, int cap, bool revFlag, int revCap) {
	G[from].push_back(Edge(to, cap, G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, G[from].size() - 1));
}


void solve() {
	ll n, k;
	cin >> n >> k;
	n -= n / k * k;
	ll ans = n;
	chmin(ans, abs(n - k));
	cout << ans << en;
}

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

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}


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

using namespace std;

int main(){
    int n;
    int now=0;
    int ans=0;
    string s;

    cin>>n>>s;

    

    for(int i=0;i<n;i++){
        if(s[i]=='I')now++;
        else if(s[i]=='D')now--;

        if(now>ans){
            ans=now;
        }

        // cout<<now<<" "<<ans<<endl;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>
#include<queue>
#include<deque>

#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--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000001
using namespace std;
typedef long long ll;

ll k;
string s;
string res;
string hoge;

int main(){
  std::cin >> s;
  std::cin >> k;
  res = "1";
  rep(i,0,s.size()){
    hoge = s[i];
    if(hoge!=res){
      res = hoge;
      break;
    }
    if(k==(i+1))break;
  }
  std::cout << res << '\n';
}


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

int main() {
  int N, K;
  cin >> N >> K;
  string S;

  cin >> S;

  vector<int> Nums;

  int now = 1;
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == (char)('0' + now))
      cnt++;
    else {
      Nums.push_back(cnt);
      now = 1 - now;
      cnt = 1;
    }
  }
  if (cnt != 0)
    Nums.push_back(cnt);

  if (Nums.size() % 2 == 0)
    Nums.push_back(0);

  int Add = 2 * K + 1;
  int ans = 0;

  for (int i = 0; i < Nums.size(); i += 2) {
    int tmp = 0;

    int left = i;
    int right = min(i + Add, (int)Nums.size());
    for (int j = left; j < right; j++) {
      tmp += Nums[j];
    }
    ans = max(tmp, ans);
  }

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

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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

void solve(long long N, std::vector<long long> A) {
  ll cur = 1000;
  ll kabu = 0;
  REP(i, N - 1) {
    if (A[i] < A[i + 1]) {
      ll n = cur / A[i];
      cur -= n * A[i];
      kabu += n;
    }
    if (A[i] > A[i + 1]) {
      cur += kabu * A[i];
      kabu = 0;
    }
  }
  if (kabu > 0) {
    cur += kabu * A[N - 1];
  }
  cout << cur << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


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

int main(){
  string S;
  cin >> S;
  int ans;
  string week[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  for (int i=0; i < 7; i++){
    if(week[i] == S){
      ans = 7 - i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	N := nextInt()
	ans := 1000000000000000000
	for i := 1; i*i <= N; i++ {
		A := i
		if N%A == 0 {
			B := N / A
			ans = min(ans, max(len(strconv.Itoa(A)), len(strconv.Itoa(B))))
		}

	}

	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    ll cnt;
    cnt = 0;

    string s, t;
    cin >> s;
    cin >> t;

    for(ll i = 0; i < s.length(); i++) {
        if(s[i] != t[i]) {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3916
from collections import Counter
import math
import statistics
import itertools
a=input()
# b=input()
# c=[]
# for i in a:
#     c.append(int(i))
# A,B,C= map(int,input().split())
# f = list(map(int,input().split()))
# g = [input() for _ in range(a)]
# h = []
# for i in range(a):
#     h.append(list(map(int,input().split())))
# a = [[0] for _ in range(H)]#nizigen

if a[-1]=="s":
    print(a+"es")
else:
    print(a+"s")

Measured memory_bytes: 10920
// C++ code to find number of distinct numbers
// in a subarray
#include<bits/stdc++.h>
using namespace std;

const int MAX = 1000001;

// structure to store queries
struct Query
{
	int l, r, idx;
};

// cmp function to sort queries according to r
bool cmp(Query x, Query y)
{
	return x.r < y.r;
}

// updating the bit array
void update(int idx, int val, int bit[], int n)
{
	for (; idx <= n; idx += idx&-idx)
		bit[idx] += val;
}

// querying the bit array
int query(int idx, int bit[], int n)
{
	int sum = 0;
	for (; idx>0; idx-=idx&-idx)
		sum += bit[idx];
	return sum;
}

void answeringQueries(int arr[], int n, Query queries[], int q)
{
	// initialising bit array
	int bit[n+1];
	memset(bit, 0, sizeof(bit));

	// holds the rightmost index of any number
	// as numbers of a[i] are less than or equal to 10^6
	int last_visit[MAX];
	memset(last_visit, -1, sizeof(last_visit));

	// answer for each query
	int ans[q];
	int query_counter = 0;
	for (int i=0; i<n; i++)
	{
		// If last visit is not -1 update -1 at the
		// idx equal to last_visit[arr[i]]
		if (last_visit[arr[i]] !=-1)
			update (last_visit[arr[i]] + 1, -1, bit, n);

		// Setting last_visit[arr[i]] as i and updating
		// the bit array accordingly
		last_visit[arr[i]] = i;
		update(i + 1, 1, bit, n);

		// If i is equal to r of any query store answer
		// for that query in ans[]
		while (query_counter < q && queries[query_counter].r == i)
		{
			ans[queries[query_counter].idx] =
					query(queries[query_counter].r + 1, bit, n)-
					query(queries[query_counter].l, bit, n);
			query_counter++;
		}
	}

	// print answer for each query
	for (int i=0; i<q; i++)
		cout << ans[i] << endl;
}

// driver code
int main()
{
	int a[MAX];
	int n,q;
	ios_base::sync_with_stdio(0);

    cin.tie(NULL);
	cin>>n>>q;
	for(int i=0;i<n;i++)
        cin>>a[i];

	Query queries[q+2];
	for(int i=0;i<q;i++)
	{
        cin>>queries[i].l>>queries[i].r;
        queries[i].l--;
        queries[i].r--;
        queries[i].idx  = i;
	}

	sort(queries, queries+q, cmp);
	answeringQueries(a, n, queries, q);



	return 0;
}


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

int main(){
  int n,k; cin >>n>>k;
  string s; cin >>s;
  vector<int> v;  //連続した0と1の数を入れていく
  char copy=s[0];
  if(s[0]=='0')v.push_back(0);
  for(int i=0;i<n;i++){
    int num=0;
    while(copy==s[i]){ //同じ数が連続している限りnumに足していく
      num++;
      i++;
    }
    copy=s[i];
    i--;
    v.push_back(num);
  }
  int ans=0;//答え更新用
  int cnt=0;//何項の数列の総和かカウントする
  int sum=0;//総和を記憶する
  int size=v.size()/2;
  if(k>=size){
    cout << n << endl;
    return 0;
  }
  for(int i=0;i<v.size();i++){
    while(cnt<2*k+1){
      sum+=v[i];
      cnt++;
      i++;
      if(i==v.size())break;
    }
    ans=max(ans,sum);
    if(i==v.size())break;
    sum-=v[i-2*k];
    sum-=v[i-2*k-1];
    cnt-=2;
    i--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define long long long int
using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b;    

    return 0;
}

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

int main(void)
{
	int N, X;
	cin >> N >> X;
	vector<int> D(N + 1);
	D[0] = 0;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		D[i + 1] = D[i] + tmp;
	}
	int count = 0;
	for (int i = 0; i <= N; i++) {
		if (D[i] <= X)count++;
		else break;
	}
	cout << count << endl;

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> A(n), B(n), C(n - 1);
  for (int i = 0; i < n; i++) cin >> A[i];
  for (int i = 0; i < n; i++) cin >> B[i];
  for(int i = 0; i < n-1; i++) cin >> C[i];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += B[A[i] - 1];
    if (i == n - 1) break;
    if (A[i] + 1 == A[i + 1]) cnt += C[A[i]-1];
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>

int main(int argc, char *argv[])
{
        int H, W;
        int i, j;

        while (1) {
                scanf("%d %d", &H, &W);
                if (H == 0 && W == 0) break;

                for (i = 0; i < H; i++) {
                        for (j = 0; j < W; j++) {
                                if (i == 0 || i == H - 1) {
                                        printf("#");
                                } else {
                                        if (j == 0 || j == W - 1) printf("#");
                                        else printf(".");
                                }
                        }
                        printf("\n");
                }
                printf("\n");
        }

        return 0;
}

Measured memory_bytes: 572