akhauriyash/Code-Regression huggingface dataset:
n, m, k = map(int, input().split())
lsta = list(map(int, input().split()))
lstb = list(map(int, input().split()))
a = [0]
b = [0]

for _ in range(n):
    a.append(lsta[_] + a[_])
    
for _ in range(m):
    b.append(lstb[_] + b[_])
    
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: 127088
N=int(input())

def prime_factorize(N):
    a = []
    while N % 2 == 0:
        a.append(2)
        N //= 2
    f = 3
    while f * f <= N:
        if N % f == 0:
            a.append(f)
            N //= f
        else:
            f += 2
    if N != 1:
        a.append(N)
    return a

import collections
c = collections.Counter(prime_factorize(N))

X=list(c.values())
ans=0
for i in range(len(c.values())):
    for j in range(1,100):
        if X[i]<(j+1)*j/2:
            ans+=j-1
            break

print(ans)

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

using namespace std;

int main(){
	int n,d,sum=0;
	cin>>n>>d;
	double x,y;
	for(int i=1;i<=n;i++){
		cin>>x>>y;
		if(sqrt(x*x+y*y)<=d*1.0)sum++;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define invrepr(i, a, b) for (int i = b - 1; i >= a; i--)
#define invrep(i, n) invrepr(i, 0, n)
const int MOD = 1e9 + 7;;

int main() {
    string s,t;
    cin >> s >> t;
    int n=s.size();
    bool flag=0;
    rep(i,n) {
        bool ismatched=1;
        rep(j,n) {
            if (s[j] != t[(i+j)%n]) ismatched=0;
        }
        if (ismatched) flag=1; 
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
main(){
  int n,sum=0;
  cin>>n;
  string a;
  cin>>a;
  while(n--){
    string t;
    cin>>t;
    for(int i=1;i<t.size();i++){
      for(int k=0;k<t.size();k++){
        string x;
        for(int j=k;j<t.size();j+=i){
          x+=t[j];
          if(x==a){
            sum++;
            goto L;
          }
        }
      }
    }
    L:;
  }
  cout<<sum<<endl;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> a(3*N);
  for(int i=0; i<3*N; i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  
  long ans=0;
  for(int i=0;i<2*N;i++){
    if(i%2==1){
      ans+=a[i];
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1408
import sys
from collections import Counter
from collections import deque
import math
import fractions
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
l=[lmp() for i in range(n)]
if l[0][0]<l[0][1]+l[0][2] or l[0][0]%2!=(l[0][1]+l[0][2])%2:
    print("No")
    exit()
for i in range(n-1):
    t,x,y=l[i+1][0]-l[i][0],abs(l[i+1][1]-l[i][1]),abs(l[i+1][2]-l[i][2])
    if t<x+y or t%2!=(x+y)%2:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 29344
/*  ex4_2
    B30095    */
#include <stdio.h>
#include <math.h>
 
int main(void){
    int TreesNum, distance;
    scanf("%d %d", &TreesNum, &distance);

    int visibleTreesNum = 2 * distance + 1;  // number of visible trees
    int inspectorNum = ceil((double)TreesNum / visibleTreesNum);  // number of inspectors needed
    
    printf("%d", inspectorNum);

    return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  cin >> N;
  REP(i,N){
	char c;
	cin >> c;
	if(c == 'Y'){
	  cout << "Four" << endl;
	  return 0;
	}
  }
  cout << "Three" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 2e5+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
int h[maxn],a[maxn];
struct T
{
    int l,r,mid;
    ll val;
}tree[maxn<<2];
void push_up(int rt)
{
    tree[rt].val=max(tree[rt<<1].val,tree[rt<<1|1].val);
}
void build(int rt,int l,int r)
{
    tree[rt].l=l;
    tree[rt].r=r;
    if(l==r)
    {
        tree[rt].val=0;
        return ;
    }
    int mid=tree[rt].mid=((l+r)>>1);
    build(rt<<1,l,mid);
    build(rt<<1|1,mid+1,r);
    push_up(rt);
}
void update(int rt,int pos,ll val)
{
    if(tree[rt].l==tree[rt].r)
    {
        tree[rt].val=val;
        return ;
    }
    if(pos<=tree[rt].mid) update(rt<<1,pos,val);
    else update(rt<<1|1,pos,val);
    push_up(rt);
}
ll query(int rt,int l,int r)
{
    if(tree[rt].l>r||tree[rt].r<l) return -1;
    if(tree[rt].l>=l&&tree[rt].r<=r) return tree[rt].val;
    ll maxx=0;
    if(l<=tree[rt].mid) maxx=max(maxx,query(rt<<1,l,r));
    if(r>tree[rt].mid) maxx=max(maxx,query(rt<<1|1,l,r));
    return maxx;
}
ll dp[maxn];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n;
    scanf("%d",&n);
    build(1,1,n);
    for(int i=1;i<=n;i++) scanf("%d",&h[i]);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    dp[1]=a[1];
    update(1,h[1],a[1]);
    for(int i=2;i<=n;i++)
    {
        ll tmp=query(1,1,h[i]);
        dp[i]=tmp+a[i];
        update(1,h[i],dp[i]);
    }
    ll ans=0;
    for(int i=1;i<=n;i++) ans=max(dp[i],ans);
    printf("%lld\n",ans);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}



Measured memory_bytes: 18048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        if((A+B) >= C)
        	System.out.println("Yes");
        else
        	System.out.println("No");
	}

}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define P pair<int, int>
/*

1000*1000*25
らむだしき
https://qiita.com/y_shindoh/items/17d9fa334a2cb8e74bfa#%E3%83%A9%E3%83%A0%E3%83%80%E5%BC%8F%E3%81%AE%E3%83%91%E3%83%A9%E3%83%A1%E3%83%BC%E3%82%BF-compare-%E3%81%B8%E3%81%AE%E4%BB%A3%E5%85%A5
*/
struct Z{
  ll y;
  ll x;
  ll depth;
};

ll H,W,y,x,depth,oo=1e12,xs,ys,xg,yg,ans=oo;
vector<ll> y_vec={1,0,-1,0};
vector<ll> x_vec={0,1,0,-1};
vector<vector<ll>> A;
auto comp = [](Z a, Z b) {return a.depth > b.depth;};
priority_queue<Z, vector<Z>, decltype(comp)> Q{comp};

void bfs(){
  while(!Q.empty()){
    Z now=Q.top(); Q.pop();
    y=now.y, x=now.x, depth=now.depth;
    if(y==yg && x==xg){
      ans = A[yg][xg];
      return ;
    }
    for(ll i=0; i<4; i++){
      Z next={y+y_vec[i], x+x_vec[i], depth};
      if(A[next.y][next.x]==-1) continue;
      if(A[next.y][next.x]<=depth) continue;
      A[next.y][next.x]=depth;
      Q.push(next);
    }
    for(ll i=-2; i<=2; i++){
      for(ll j=-2; j<=2; j++){
        Z next={y+i, x+j, depth+1};
        if(A[next.y][next.x]==-1) continue;
        if(A[next.y][next.x]<=next.depth) continue;
        A[next.y][next.x]=next.depth;
        Q.push(next);
//cout<<" d:"<<next.depth<<endl;          
      }
    }
  }
}

//A[y][x], A(x,y)として管理
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  cin>>H>>W;
  cin>>ys>>xs>>yg>>xg;
  ys++;
  xs++;
  yg++;
  xg++;
  A.assign(H+4, vector<ll>(W+4,-1));
  for(int i=2; i<H+2; i++){
    for(int j=2; j<W+2; j++){
      char a; cin>>a;
      if(a=='#') continue;
      A[i][j]=oo;
    }
  }
  A[ys][xs]=0;
  Z start={ys,xs,0};
  Q.emplace(start);
  bfs();
  if(ans==oo) ans=-1;
  cout<<ans<<endl;
  
/*for(int i=2; i<H+2; i++){
  for(int j=2; j<W+2; j++)
    cout<<A[i][j];
  cout<<endl;
  }*/
}


Measured memory_bytes: 11644
n, m = map(int, input().split())
ac = set()
pena = 0
# 問題はn問あり，問題番号は1からスタートするので*(n+1)にすれば十分
wa = [0] * (n+1)
for i in range(m):
    # p:問題番号，s:判定
    p, s = input().split()
    p = int(p)
    if p in ac:
        continue
    if s == 'AC':
        # ACする前のWA数を追加
        pena += wa[p]
        # ACした問題番号の追加
        ac.add(p)
    else:
        # WA数を1増やす
        wa[p] += 1
print(len(ac), pena)

Measured memory_bytes: 12780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long double PI = 3.14159265358979323846;

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

    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    ll sum = 0;
    for (int i = 0; i < m; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    if (sum > n) {
        cout << -1 << '\n';
    } else {
        cout << n - sum << '\n';
    }

    return 0;
}


Measured memory_bytes: 3616
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
num = 0
for i in A:
    ans += B[i-1]
    if num != 0 and i - num == 1:
        ans += C[i-2]
    num = i
    
print(ans)

Measured memory_bytes: 9140
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = int64_t;

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; }
const int INF = 1'001'001'001;
const ll INFL = (1LL<<60);
const double eps = (1e-9);

const ll mod = 1e9 + 7;

void warshall_floyd(const int& n, vector<vector<int>>& d) {
  rep(k, n) rep(i, n) rep(j, n) chmin(d[i][j], d[i][k] + d[k][j]);
}

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

  int h, w;
  cin >> h >> w;

  vector<vector<int>> c(10, vector<int>(10));
  rep(i, 10) rep(j, 10) {
    cin >> c[i][j];
  }

  warshall_floyd(10, c);

  ll ans = 0;
  rep(i, h) rep(j, w) {
    int a; cin >> a;
    if (a == -1 || a == 1) continue;
    ans += c[a][1];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<stack>
#include<vector>

using namespace std;

vector<int> vec[101];
bool ch[101]={};
bool visited[101]={};
int dp[101]={};
int maxx = -1;
int maxNODE = -1;


void DFS(int i,int val){
    if(val > maxx)maxx = val;
    dp[i] = max(dp[i],val);
    //printf("%d ",i);
    int len = vec[i].size();
    for (int k=0; k<len; k++) {
        if(!ch[vec[i][k]]){
            visited[vec[i][k]] = true;
            ch[vec[i][k]] = true;
            DFS(vec[i][k],val+1);
            ch[vec[i][k]] = false;
        }
    }
}

int main(){
    maxx = -1;
    maxNODE = -1;
    int n,a,b;
    scanf("%d",&n);
    if(n == 0)return 0;
    for (int i=0; i<n; i++) {
        scanf("%d %d",&a,&b);
        vec[a].push_back(b);
        vec[b].push_back(a);
        if(a>b)if(maxNODE < a)maxNODE = a;
        if(a<b)if(maxNODE < b)maxNODE = b;
    }
    for (int i=1; i<=maxNODE; i++) {
        visited[i] = true;
        ch[i] = true;
        DFS(i,1);
        ch[i] = false;
    }
    for (int i=1; i<=maxNODE; i++) {
        if(maxx == dp[i]){
            ch[i] = true;
            DFS(i,1);
            ch[i] = false;
            break;
        }
    }
    printf("%d\n",maxx);
    for (int i=1; i<=maxNODE; i++) {
        visited[i] = false;
        vec[i].clear();
    }
    main();
    
    
}

Measured memory_bytes: 2804
#include<bits/stdc++.h>
#define maxn 200009
#define LL long long
#define pb push_back
using namespace std;
int a[maxn],sum,rt,f[maxn],sz[maxn],head[maxn],edge=0,fa[maxn];
bool vis[maxn];
LL dis[maxn];
struct da{
  int nex,to,w;
}e[maxn*2];
struct data{
  int x,y;LL w;
};
vector<data>E;
vector<int>vec;
inline void add(int from,int to,int w){
  e[++edge]=(da){head[from],to,w};
  head[from]=edge;
}
int find(int x){if(fa[x]!=x)fa[x]=find(fa[x]);return fa[x];}
void findrt(int x,int fa){
  f[x]=0,sz[x]=1;
  for(int i=head[x];i;i=e[i].nex){
    int v=e[i].to;
    if(v==fa || vis[v]) continue;
    findrt(v,x),sz[x]+=sz[v];
    f[x]=max(f[x],sz[v]);
  }
  f[x]=max(f[x],sum-sz[x]);
  if(f[x]<f[rt]) rt=x;
}
void dfs(int x,int fa){
  vec.pb(x);
  for(int i=head[x];i;i=e[i].nex) {
    int v=e[i].to;
    if(v==fa || vis[v]) continue;
    dis[v]=dis[x]+e[i].w;
    dfs(v,x);
  }
}
void solve(int x){
  vis[x]=1;vec.clear();
  dis[x]=0,dfs(x,0);int p=x;
  for(int i=0;i<vec.size();i++){
    dis[vec[i]]+=a[vec[i]];
    if(dis[vec[i]]<dis[p]) p=vec[i];
  }
  for(int i=0;i<vec.size();i++)
    E.pb((data){vec[i],p,dis[vec[i]]+dis[p]});
  for(int i=head[x];i;i=e[i].nex){
    int v=e[i].to;if(vis[v]) continue;
    sum=sz[v],rt=0,findrt(v,x);
    solve(rt);
  }
}
inline bool cmp(const data &A,const data &B){
  return A.w<B.w;
}
int main(){
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++) scanf("%d",a+i),fa[i]=i;
  for(int i=1,x,y,z;i<n;i++)
    scanf("%d%d%d",&x,&y,&z),add(x,y,z),add(y,x,z),E.pb((data){x,y,1ll*a[x]+a[y]+z});
  sum=n,rt=0,f[0]=1e9,findrt(1,0),solve(1);
  sort(E.begin(),E.end(),cmp);
  LL ans=0;
  for(int i=0;i<E.size();i++){
    int u=E[i].x,v=E[i].y;
    if(find(u)!=find(v)) ans+=E[i].w,fa[find(u)]=find(v);
  }
  printf("%lld\n",ans);
  return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

#define UQns(v) v.erase(unique(ALL(v)), v.end())
#define UQ(v) sort(ALL(v)); UQns(v)

int k;

int S(string s) {
	int sum = 0;
	inc(i, s.size()) { sum += s[i] - '0'; }
	return sum;
}

int comp(LL a, LL b) {
	string s = to_string(a);
	string t = to_string(b);
	
	LL x = a * S(t);
	LL y = b * S(s);
	// cout << a << " -- " << b << ": " << x << ", " << y << endl;
	if(x == y) { return  0; }
	if(x <  y) { return -1; }
	if(x >  y) { return +1; }
}

int main() {
	/*
	cout << comp(1, 10) << endl;
	cout << comp(443699999, 443699999) << endl;
	cout << comp(443699999, 443799999) << endl;
	// return 0;
	*/
	
	cin >> k;
	
	vector<LL> v, w;
	//inc1(i, 2000000) { if(comp(i, i + 1) <= 0) { w.PB(i); } }
	
	incII(i, 0, 14) {
		inc(j, 1000) {
			LL x = j;
			inc(k, i) { x = x * 10 + 9; }
			if(x != 0) { w.PB(x); }
		}
	}
	UQ(w);
	
	int ws;
	do {
		ws = w.size();
		// cout << "size: " << w.size() << endl;
		v = w;
		w.clear();
		inc(i, v.size() - 1) {
			if(comp(v[i], v[i + 1]) <= 0) { w.PB(v[i]); }
		}
		w.PB(v.back());
	} while(ws > w.size());
		
	// inc(i, w.size()) { cout << w[i] << endl; }
	assert(k <= w.size());
	// inc(i, k) { printf("%18lld\n", w[i]); }
	inc(i, k) { cout << w[i] << endl; }
	
	return 0;
}


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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int a,b,c;
    cin>>a>>b>>c;
    cout<< c << " " << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
int main (void){
        int N,a=0,b=0,c=0,d=0,ans=0;
        char S[20];
        scanf("%d\n",&N );
        for (int i = 0; i < N; i++) {
          scanf("%s",S);
          for (int i = 0; i < strlen(S)-1; i++) {
            if (S[i]=='A'&&S[i+1]=='B') {
              ans+=1;
            }
          }
          if (S[0]=='B'&&S[strlen(S)-1]=='A') {
            d++;
          }else if(S[strlen(S)-1]=='A'){
            b++;
          }else if (S[0]=='B'){
            c++;
          }else{
            a++;
          }
        }
        if (b>c) {
          ans+=c;
        }else{
          ans+=b;
        }
        ans+=d;
        if (b+c==0) {
          ans-=1;
          if (d==0) {
            ans++;
          }
        }
        printf("%d\n",ans );
        return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  lint n, s = 0, x;
  cin >> n;
  v1i v(n);
  rep(i, n) cin >> v[i];
  x = v[0];
  rep(i, n) s += (v[i])-1;
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
def solve():
    N = int(input())
    S = input()
    max_spieces = 0
    for i in range(1, N):
        pre = set(S[:i])
        post = set(S[i:])
        intersection_num = len(pre&post)
        if intersection_num > max_spieces:
            max_spieces = intersection_num
            
    print(max_spieces)
    
solve()

Measured memory_bytes: 2940
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	if n%2 == 1 {
		n *= 2
	}
	fmt.Println(n)
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int H, W, N;
  cin >> H >> W >> N;
  set<pair<int, int>> se;
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    se.emplace(a, b);
  }
  vi64 ans(10);
  set<pair<int, int>> already;
  each(s, se) {
    int a, b;
    tie(a, b) = s;
    for (int i = -1; i <= 1; i++) {
      for (int j = -1; j <= 1; j++) {
        int ca = a + i;
        int cb = b + j;
        if (ca <= 0 || ca >= H - 1 || cb <= 0 || cb >= W - 1) continue;
        if (already.count(make_pair(ca, cb))) continue;
        int cnt = 0;
        for (int k = -1; k <= 1; k++) {
          for (int l = -1; l <= 1; l++) {
            int x = ca + k;
            int y = cb + l;
            if (se.count(make_pair(x, y))) cnt++;
          }
        }
        ans[cnt]++;
        already.emplace(ca, cb);
      }
    }
  }
  ans[0] = (i64) (H - 2) * (W - 2);
  reps(i, 9) ans[0] -= ans[i];
  rep(i, 10) cout << ans[i] << endl;
}


Measured memory_bytes: 47104
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

const int MAXN = 200100;
int Q[MAXN];
int seen[MAXN];

void dfs(const Graph &G, int v) {
    seen[v] = 1;

    for (auto nv : G[v]) {
        if (seen[nv] == 1) continue;
        Q[nv] += Q[v];
        dfs(G, nv);
    }
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, q;
    cin >> n >> q;

    Graph G(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    rep(i, q) {
        int p, x;
        cin >> p >> x;
        --p;
        Q[p] += x;
    }

    dfs(G, 0);

    rep(i, n) {
        cout << Q[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 24320
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int get(int n, int k)
{
	if (n%k == 0)return n / k;
	int t = max(1, (n - n / k*k) / (n / k + 1));
	return get(n - t*(n / k + 1), k);
}
int main()
{
	int num;
	scanf("%d", &num);
	int x = 0;
	for (int p = 0; p < num; p++)
	{
		int n, k;
		scanf("%d%d", &n, &k);
		x ^= get(n, k);
	}
	printf((x != 0) ? "Takahashi\n" : "Aoki\n");
}


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

int main()
{
    int N,M;
    cin>>N>>M;
    int A[105];
    memset(A,0,sizeof(A));
    for(int I=1;I<=M;I++)
    {
        int x,y;
        cin>>x>>y;
        A[x]++;
        A[y]++;
    }
    for(int I=1;I<=N;I++)
        cout<<A[I]<<endl;
    return 0;
}



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

#define MAX 101

int main() {
    int r, c;
    scanf("%d %d", &r, &c);

    int *table[MAX];
    int d;
    int rowSum[MAX];
    int colSum[MAX];
    int total;

    total = 0;
    for (int i=0; i<MAX; ++i) {
        rowSum[i] = 0;
        colSum[i] = 0;
    }

    for (int i=0; i<r; ++i) {
        table[i] = (int*)malloc(sizeof(int) * c);
        for (int j=0; j<c; ++j) {
            scanf("%d", &d);
            table[i][j] = d;
            rowSum[i] += d;
            colSum[j] += d;
            total += d;
        }
    }

    for (int i=0; i<r; ++i) {
        for (int j=0; j<c; ++j) {
            printf("%d ", table[i][j]);
        }
        printf("%d\n", rowSum[i]);
        free(table[i]);
    }
    for (int j=0; j<c; ++j) {
        printf("%d ", colSum[j]);
    }
    printf("%d\n", total);
    return 0;
}



Measured memory_bytes: 2128
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    ll numb = b / x;
    if (a == 0) {
        cout << numb + 1LL << endl;
    }
    else {
        cout << numb - (a - 1LL) / x << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();

		for(long i = 1 ; i <= 1000; i++){
			for(long j = -1000; j < i; j++){
				if(Math.pow(i, 5) - Math.pow(j, 5) == x){
					System.out.println(i + " " +j);
					return;
				}
			}
		}
	}

}


Measured memory_bytes: 27120
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    b = list(set(s))
    a = len(list(set(s)))
    if a == 2 and s.count(b[0]) == s.count(b[1]) == 2:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = II()
    p = LI()
    ans = 0
    for i in range(1,n-1):
        if (p[i - 1] < p[i] and p[i] < p[i + 1]) or (p[i + 1] < p[i] and p[i] < p[i - 1]):
            ans += 1
    print(ans)
    return

#C
def C():
    n = II()
    d = LI()
    d.sort()
    ans = 0
    for i in range(10**5+1):
        if n // 2 == bisect_left(d, i):
            ans += 1
    print(ans)
    return


def combination_mod(n, k, mod):
    # power_funcを用いて(nCk) mod p を求める 
    # nCk = n!/((n-k)!k!)を使用

    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    a = factorial(n) % mod
    b = factorial(k) % mod
    c = factorial(n - k) % mod
    return (a * power_func(b, mod - 2, mod) * power_func(c, mod - 2, mod)) % mod
    
def power_func(a, b, mod):
    # a^b mod p を求める
    # bを2進数分解して高速累乗

    if b == 0: return 1
    if b % 2 == 0:
        d = power_func(a, b // 2, mod)
        return d * d % mod
    if b % 2 == 1:
        return (a * power_func(a, b - 1, mod)) % mod

#D
def D():
    n, k = LI()
    ans = 0
    for i in range(1,k+1):
        a = combination_mod(n - k + 1, i, mod)
        b = combination_mod(k - 1, i - 1, mod)
        print((a*b)%mod)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 39920
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LaL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
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(b<a){a=b;return 1;}return 0;}
using namespace std;

int main(){
  int N,M,X,ans=10000000;
  cin>>N>>M>>X;
  bool CAN=false;
  
  int C[N],A[N][M];
  REP(i,N){
    cin>>C[i];
    REP(j,M) cin>>A[i][j];
  }

  for(int bit=0; bit<(1<<N); ++bit){
    int cnt=0,AA[M];
    REP(i,M) AA[i]=0;
    bool SAFE=true;
    
    vector<int> S;
    for(int i=0; i<N; ++i){
      if(bit&(1<<i)) S.push_back(i);
    }
    
    REP(i,S.size()){
      REP(j,M) AA[j]+=A[S.at(i)][j];
      cnt+=C[S.at(i)];
    }
    
    REP(i,M){
      if(AA[i]<X) SAFE=false;
    }
    
    if(SAFE){
      if(ans>cnt) ans=cnt;
      CAN=true;
    }
  }
  
  if(CAN)cout<<ans<<endl;
  else cout<<-1<<endl;
  
  return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int K = sc.nextInt();
		int ak = Math.min(K, A);
		K -= ak;
		int bk = Math.min(K, B);
		K -= bk;
		int ck = K;
		System.out.println(ak - ck);
		sc.close();
	}
}


Measured memory_bytes: 35520
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
int a(void);
int b(void);
int main(void) {
	b();
	return 0;
}

int a(void) {
	int N;
	std::cin >> N;
	int res = N * N;
	std::cout << res;
	return 0;
}

int b(void) {
	int N;
	std::cin >> N;
	std::string S;
	std::cin >> S;

	if (S.size() % 2 == 0) {
		bool flag = true;
		for (int i = 0; i < S.size() / 2; i++) {
			if (S[i] != S[i + S.size() / 2]) {
				flag = false;
			}
		}
		if (flag) {
			std::cout << "Yes";
		}
		else {
			std::cout << "No";
		}
		
	}
	else {
		std::cout << "No";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define p_b push_back
#define pl pair<ll,ll>
#define m_p make_pair
#define MOD 1000000007
#define F(i,a,b) for(i=a;i<b;i++)
#define RF(i,a,b) for(i=a;i>=b;i--)
#define nfs ios_base::sync_with_stdio(false);cin.tie(NULL)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin >> n >> m;
    ll i;
    ll arr[n];
    priority_queue<ll> p;

    for(i=0;i<n;i++)
    {
        cin >> arr[i] ;
        p.push(arr[i]);

    }

    while(m--)
    {

        ll temp = p.top();
        p.pop();
        temp /= 2;
        p.push(temp);
    }


    ll sum = 0;
    for(i=0;i<n;i++)
    {

        sum += p.top();
        p.pop();

    }
    cout << sum << endl;


    return 0;

}


Measured memory_bytes: 1912
#include<iostream>
#include<string>
#include<vector>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    int n, K;
    cin >> n >> K;
    int d[K];
    rep(i,K) cin >> d[i];
    int i;
    for(i=n; i<1000000; i++){
        bool ck = true;
        string str = to_string(i);
        int len = str.length();
        for(int j=0; j<len; j++){
            for(int k=0; k<K; k++){
                int tmp=(int)str[j]-48;
                //cout << d[k] << tmp << endl;
                if(d[k]==tmp){
                    ck = false;
                    //cout << "break" << endl;
                    break;
                }
                if(!ck){
                    break;
                }
            }
        }
        if(ck){
            break;
        }
    }
    cout << i << endl;

    return 0;
}

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

const ll MOD = 1000000007;

int main(){
  int n;
  cin >> n;
  ll ans = 0;
  ll sum = 0;
  rep(i,n){
    int a;
    cin >> a;
    ans = (ans + sum*a)%MOD;
    sum = (sum + a)%MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
using ll = long long;

ll dig(ll n) {
    ll ret = 0;

    while (n) {
        n /= 10;
        ret++;
    }

    return ret;
}

int main() {
    ll n;
    ll ans = 0;

    cin >> n;

    for (ll i = 1; i <= n; i++) {
        if (dig(i) & 1) ans++;
    }

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


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {

  // 1行目がinput[0], 2行目がinput[1], …に入る
  // var input1 = input.split("\n");
  // var input1 = input.split(" ");
  // var n = Number(input1[0].split(' ')[0])
  // var k = Number(input1[0].split(' ')[1])
  // var nums = input1[1].split(' ').map(function (v) { return Number(v) })

  let n = Number(input)

  // console.log(input1
  //   , n
  //   , k
  //   , nums)

  // var results = 0
  // var arrayNum = 0

  // for (var i = nums.length; i > 0; i--) {
  //   arrayNum += i
  // }

  // const retArr2 = new Array(arrayNum).fill(0).map(function (v, idx) {
  //   var getNum = 1

  //   var idx2 = idx
  //   // console.log('bg', idx, getNum)
  //   while ((idx2 - (nums.length - getNum + 1)) >= 0) {

  //     getNum++
  //     // console.log(idx2)
  //     idx2 = idx2 - (nums.length - getNum + 1)
  //     // console.log(idx2, nums.length, getNum, (nums.length - getNum + 2))
  //   }
  //   console.log('ed', idx2, getNum)


  //   const retArr = new Array(getNum).fill(null).map(function (v99, idx3) {
  //     return nums[idx2 + idx3]
  //   })


  //   if (getNum > 3) {
  //     throw new Error()
  //   }

  //   return {
  //     getNum: getNum,
  //     sum: retArr//.reduce(function (prev, curr) { return prev + curr }, 0)
  //   }
  // })

  // console.log(retArr2)

  // while (getNum < nums.length) {

  //   for (var n1 = 0; n1 < nums.length - getNum + 1; n1++) {
  //     var n = nums.length - getNum + 1
  //     var sumNums = new Array(n).fill(0)

  //     sumNums = sumNums.map(function (v, idx) {
  //       return new Array(getNum).fill(0).map(function (v2, idx2) {
  //         return nums[n1 + idx2]
  //       }).reduce(function (prev, curr) { return prev + curr }, 0)
  //     })

  //     console.log("sumNums1", sumNums)

  //     sumNums = sumNums.map(function (v3) {
  //       if ((v3 % k) === getNum) {
  //         return 1
  //       } else {
  //         return 0
  //       }
  //     }).reduce(function (prev, curr) { return prev + curr }, 0)
  //     console.log("sumNums2", sumNums)

  //     console.log("sumNums", sumNums, results)
  //     results += sumNums
  //   }

  //   getNum++
  //   console.log("getNum", getNum, nums.length, results)
  // }

  // //文字列から10進数に変換するときはparseIntを使います
  // // var a = parseInt(i[0], 10);
  // // var b = parseInt(i[1], 10);
  // // var c = parseInt(i[2], 10);
  // var i1 = i.map(v => parseInt(v, 10))

  if (n >= 30) {
    console.log("Yes");
  } else {
    console.log("No");
  }

  //出力
  // console.log(results, results);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29684
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,j,k;
  cin>>n;
  int arr[n][3];
  for(i=0;i<n;i++)
  {
      for(j=0;j<3;j++)
       cin>>arr[i][j];
  }
  int ans[n][3];
  for(i=0;i<3;i++)
   ans[0][i]=arr[0][i];
  for(i=1;i<n;i++)
  {
      ans[i][0]=arr[i][0]+max(ans[i-1][1],ans[i-1][2]);
      ans[i][1]=arr[i][1]+max(ans[i-1][0],ans[i-1][2]);
      ans[i][2]=arr[i][2]+max(ans[i-1][0],ans[i-1][1]);
  }
  int an=0;
  for(i=0;i<3;i++)
   an=max(an,ans[n-1][i]);
  cout<<an;
  return 0;
}

Measured memory_bytes: 2560
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <cassert>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <complex>
using namespace std;

#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, b, a) for(int i=(b)-1;i>=(a);--i)
#define FILL(A,value) memset(A,value,sizeof(A))

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define Pi 3.14159265358979
#define x0 ikjnrmthklmnt
#define y0 lkrjhkltr
#define y1 ewrgrg

typedef long long Int;
typedef unsigned long long UInt;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<Int, Int> PLL;
typedef pair<double, double> PDD;
typedef complex<double> base;

const int INF = 1000000000;
const int BASE = 1000000007;
const int MAX = 10000007;
const int MAX2 = 7777;
const int MAXE = 100000;
const int ADD = 1000000;
const int MOD = 1000000007;
const int CNT = 800;

int A[107][107];

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("distance.in",  "r", stdin);
    //freopen("distance.out", "w", stdout);
    //freopen("out.txt" , "w" , stdout);

	int h,w;
	cin>>h>>w;
	vector<PII>B;
	FOR(i,0,h)
	{
		if (i%2==0)
			FOR(j,0,w)
				B.push_back(MP(i,j));
		else
			RFOR(j,w,0)
				B.push_back(MP(i,j));
	}
	int n;
	cin >> n;
	FOR(i,1,n+1)
	{
		int x;
		cin >> x;
		FOR(j,0,x)
		{
			A[B.back().first][B.back().second] = i;
			B.pop_back();
		}
	}

	FOR(i,0,h)
	{
		FOR(j,0,w)
		{
			cout << A[i][j] << ' ';
		}
		cout << endl;
	}

    return 0;
}
















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

public class Main{
	class data{
		int x;
		int y;
		int c;

		data(int x,int y,int c){
			this.x=x;
			this.y=y;
			this.c=c;
		}
	}
	public int bfs(int w,int h,int[][] w_x,int[][] w_y){
		int[] sx={0,1,0,-1};
		int[] sy={1,0,-1,0};
		int res=0;
		int[][] fie;
		fie=new int[w+1][h+1];
		for(int i=0;i<w+1;i++)for(int j=0;j<h+1;j++)fie[i][j]=w*h;
		Queue<data> q=new LinkedList<data>();
		q.add(new data(0,0,0));
		fie[0][0]=0;
		while(!q.isEmpty()){
			data d=q.poll();
			for(int i=0;i<4;i++){
				int nx=d.x+sx[i];
				int ny=d.y+sy[i];
				if(nx==w-1 && ny==h)return d.c+1;
				if(nx>=0 && nx<w && ny>=0 && ny<h){
					if(fie[nx][ny]!=w*h)continue;
					if(i==0 && w_y[d.x][d.y]==1)continue;
					if(i==1 && w_x[d.x][d.y]==1)continue;
					if(i==2 && w_y[d.x][d.y-1]==1)continue;
					if(i==3 && w_x[d.x-1][d.y]==1)continue;
					fie[nx][ny]=d.c+1;
					q.add(new data(nx,ny,d.c+1));
				}
			}
		}
		return 0;
	}
	public void run(){
		Scanner sc=new Scanner(System.in);
		while(1>0){
			int w=sc.nextInt();
			int h=sc.nextInt();
			if(w+h==0)break;
			int[][] w_x,w_y;
			w_x=new int[w][h];
			w_y=new int[w][h];
			for(int i=0;i<h-1;i++){
				for(int j=0;j<w-1;j++)w_x[j][i]=sc.nextInt();
				for(int j=0;j<w;j++)w_y[j][i]=sc.nextInt();
			}
		for(int j=0;j<w-1;j++)w_x[j][h-1]=sc.nextInt();
			System.out.printf("%d\n",bfs(w,h,w_x,w_y));
		}
	}
	public static void main(String args[]){
		new Main().run();
	}
}

Measured memory_bytes: 63636
// clang-format off
	#include <bits/stdc++.h>
	using namespace std; using ll = long long; using uint = unsigned int;
	#define SFINAE(x, ...)	template <class, class = void> struct x : false_type {}; template <class T> struct x<T, void_t<__VA_ARGS__>> : true_type {};
	SFINAE(DefaultIO, decltype(cout << declval<T &>()))
	SFINAE(IsTuple, typename tuple_size<T>::type)
	SFINAE(Iterable, decltype(begin(declval<T>())))
	template <class T> constexpr char Space(const T &) { return (Iterable<T>::value or IsTuple<T>::value) ? '\n' : ' '; }
	template <auto &os> struct Writer {
		template <class T> void Impl(T const &t) const {
			if constexpr (DefaultIO<T>::value) os << t;
			else if constexpr (Iterable<T>::value) { int i = 0; for (auto &&x : t) ((i++) ? (os << Space(x), Impl(x)) : Impl(x)); }
			else if constexpr (IsTuple<T>::value) apply([this](auto const &... args) { int i = 0; (((i++) ? (os << ' ', Impl(args)) : Impl(args)), ...);}, t);
			else static_assert(IsTuple<T>::value, "No matching type for print");
		}
		template <class F, class... Ts> auto &operator()(F const &f, Ts const &... ts) const { return Impl(f), ((os << ' ', Impl(ts)), ...), os << '\n', *this; }
	};
	template <auto &is> struct Reader {
		template <class T> auto& operator()(T &t) const {
			if constexpr (DefaultIO<T>::value) is >> t;
			else if constexpr (Iterable<T>::value) for (auto &x : t) (*this)(x);
			else if constexpr (IsTuple<T>::value) apply([this](auto &... args) { ((*this)(args), ...); }, t);
			else static_assert(IsTuple<T>::value, "No matching type for read");
			return *this;
		}
	};
	#ifdef NARUT_LOCAL
	#define Debug(...) cerr << "\033[0;31m", Writer<cerr>{}(__VA_ARGS__), cerr << "\033[0m\n"
	#else
	#define Debug(...) 0
	#endif
	[[maybe_unused]] constexpr Reader<cin> Cin; [[maybe_unused]] constexpr Writer<cout> Cout;
	#define FOR(i, j, n) for (int i = int(j); i < int(n); ++i)
	#define ROF(i, j, n) for (int i = int(n) - 1; i >= int(j); --i)
// clang-format on





auto Main() {
	int x,n;
	cin>>x>>n;
	vector<int> P(n);
	Cin(P);

	for(int d=0;;d++) {
		auto y = x-d;
		if(count(begin(P), end(P), y)==0) return y;
		y = x+d;
		if(count(begin(P), end(P), y)==0) return y;
	}	
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
#ifdef NARUT_LOCAL
	assert(freopen("io/test.in", "r", stdin));
	cin.exceptions(cin.badbit | cin.failbit);
	cerr << fixed << setprecision(10);
#endif

	cout<<Main();
}


Measured memory_bytes: 3652
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int ans = 0;
        while(a<=b){
            if(c%a++==0){
                ans ++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 26296
// Best practice
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <functional> // for less 
 
#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; 
 
#define fbo find_by_order
#define ook order_of_key
 
signed main() {
   tezz
   
   string s;
   cin >> s;
   int n=s.length();
   for(int i=0; i<n; i++){
       if(i%2==0){
           if(s[i]=='L'){
               cout << "No";
               return 0;
           }
       }
       else{
           if(s[i]=='R'){
               cout << "No";
               return 0;
           }
       }
   }
   cout << "Yes";
   
   return 0;
}
 


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

int main()
{
    ll A, B, C, K;

    cin >> A >> B >> C >> K;

    // std::cout << min(K, A) - min(C - A, K - A);

    ll remainingCount = K;
    // Aを全部引く
    if (remainingCount <= A)
    {
        cout << K;
        return 0;
    }

    remainingCount -= A;

    // Bを全部引く
    if (remainingCount <= B)
    {
        cout << A;
        return 0;
    }

    remainingCount -= B;

    // Cを引く
    cout << A - remainingCount;

    return 0;
}


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

int main(void) {
  int A, B;
  cin >> A >> B;

  int answer = 0;
  int counter = 0;
  for (int a = 1; a < 10; a++) {
    for (int b = 0; b < 10; b++) {
      for (int c = 0; c < 10; c++) {
        int x = 10001 * a + 1010 * b + 100 * c;
        if (x >= A && x <= B) {
          answer++;
        }
      }
    }
  }

  cout << answer << endl;
}

Measured memory_bytes: 768
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
flg = True
r = v - w
y = abs(b - a)
if r < 0:
    flg = False

if t * r < y:
    flg = False

if flg:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9184
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0]
for i in range(n):
    b.append(b[-1]+a[i])
max=0
for j in range(k,len(b)):
    if max<b[j]-b[j-k]:
        max=b[j]-b[j-k]
print((max+k)/2)




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

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

    //good luck kittu!
    ll n; cin>>n;
    if(n&1) return cout<<"0\n", 0;

    ll ans = 0, den = 10, t;
    while(den <= n){
        ans += n/den;
        den *= 5;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256