akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
N = int(input())
S = input()
C = Counter(S)

cnt = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            try:
                a = S.index(str(i))
                b = S[a+1:].index(str(j))
                c = S[a+b+2:].index(str(k))
            except ValueError:
                continue
            cnt += 1
            # print(S[a]+S[a+b+1]+S[a+b+c+2],S[a:],S[a+b:],S[a+b+c:])
print(cnt)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1000000007;

template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}

const int MAX = 1200000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

int main()
{
	COMinit();
	ll n,a,b;
	cin >> n >> a >> b;
	ll ans = mod_pow(1LL*2,n,INF);
	ll x=1,y=1;
	for(ll i = 1;i<=a;i++)
	{
		x = ((n-i+1)*x)%INF;
	}
	for(ll i = 1;i<=b;i++)
	{
		y = ((n-i+1)*y)%INF;
	}
	x = x*finv[a]%INF;
	y = y*finv[b]%INF;
	
	ans = (ans - x + INF)%INF;
	ans = (ans - y + INF)%INF;
	ans = (ans - 1 + INF)%INF;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 28416
H, W = map(int, input().split())
S = [input()for _ in[0]*H]
cells = [[0]*(W+2)for _ in[0]*(H+2)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            for k in range(3):
                for l in range(3):
                    if cells[i+k][j+l] != '#':
                        cells[i+k][j+l] += 1
            cells[i+1][j+1] = '#'
print('\n'.join(''.join(map(str,row[1:W+1]))for row in cells[1:H+1]))

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


int main(){
  int n,i,ans;
  string s;
  cin >> n;
  cin >> s;
  ans=0;
  for(i=0;i<n-2;++i){
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class D
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		int n = h[0], k = h[1];
		var p = Read();

		int M = p.Take(k).Sum(), t = M;
		for (int i = 0; i < n - k; i++)
			M = Math.Max(M, t += p[i + k] - p[i]);
		Console.WriteLine((M + k) / 2.0);
	}
}


Measured memory_bytes: 31196
n = int(input())
h = list(map(int, input().split()))

dp = [10 ** 10] * n
dp[0] = 0

for i in range(n):
    if i + 1 < n:
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))

    if i + 2 < n:
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))

print(dp[n - 1])


Measured memory_bytes: 13924
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,y,a,b;
  cin >> x >> y;
  
  if (y%2 == 1) {
    cout << "No" << endl;
  }
  else if (2*x <= y && y <= 4*x) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
  
}

Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
 
vector<string> ans;
map<string,int> change;
int N;
vector<string> t[200];
bool visited[200];
 
void rec(int pos){
  if(visited[pos])return;
  visited[pos]=true;
  int size=t[pos].size();
  for(int i=1;i<size;i++){
    int w=change[t[pos][i]];
    if(w==0)ans.push_back(t[pos][i]);
    else rec(w);
  }
}
 
 
void solve(){
  rec(1);
  sort(ans.begin(),ans.end());
  int cnt=0;
  for(int i=0;i<(int)ans.size();i++){
    //cout<<ans[i]<<endl;
    if(i&&ans[i]==ans[i-1])continue;
    cnt++;
  }
  cout<<cnt<<endl;
}
 
void init(){
  ans.clear();
  change.clear();
  for(int i=0;i<200;i++){
    visited[i]=false;
    t[i].clear();
  }
}
 
int main(){
  string str,tmp;
  while(cin>>N&&N){
    init();
    for(int i=1;i<=N;i++){
      cin>>str;
      int len=str.size();
      tmp="";
      for(int j=0;j<len;j++){
    if(str[j]==','||str[j]=='.'||str[j]==':')t[i].push_back(tmp),tmp="";
    else tmp.push_back(str[j]);
      }
      change[t[i][0]]=i;
    }
    solve();
  }
  return 0;
}

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

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

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

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int h,w;
	cin >>h >>w;
	vector<string> ba(h, " ");
	rep(i,h) cin >> ba[i];
	
	const int dr[]={0,1,0,-1,0};
	const int inf = 1<<28;
	vector<vector<int> > dd(h, vector<int>(w, inf));
	queue< pii > que;
	int sy=0, sx=0;
	que.push(pii(sy,sx)); dd[sy][sx]=0;
	while(!que.empty()){
		int cy,cx; tie(cy,cx) = que.front();
		que.pop();
		rep(i,4){
			int ny=cy+dr[i], nx=cx+dr[i+1];
			if(ny<0 || ny>=h || nx<0 || nx>=w) continue;
			if(dd[ny][nx] == inf && ba[ny][nx]=='.'){
				que.push( pii(ny, nx) );
				dd[ny][nx] = dd[cy][cx] + 1;
			}
		}
		if(dd[h-1][w-1] < inf) break;
	}
	
	
	int hs = dd[h-1][w-1];
	int sct =0;
	rep(i,h) rep(j,w) if(ba[i][j]=='.') sct++;
	if(hs == inf) puts("-1");
	else cout << sct - hs -1 <<"\n";
	return 0;
	
}


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

using namespace std;

typedef long long ll;

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 ll MOD = 1000000007;

// auto mod int
// ref. https://github.com/atcoder-live/library/blob/master/mint.cpp
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

vector<ll> S;
vector<ll> T;

// dp[i][j] means the number of patterns for S[0..(i-1)] containing S[i-1] and T[0..(j-1)] containing T[j-1]
mint dp[2005][2005];
mint sdp[2005][2005];

// ref. solution2 of http://drken1215.hatenablog.com/entry/2019/06/21/230200
int main(void) {
    ll N, M;
    cin >> N >> M;

    S.resize(N + 1, 0);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }

    T.resize(M + 1, 0);
    for (int i = 0; i < M; i++) {
        cin >> T[i];
    }

    dp[0][0] = 1;
    for (int i = 0; i <= N; i++) sdp[i][0] = 1;
    for (int i = 0; i <= M; i++) sdp[0][i] = 1;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            sdp[i][j] = sdp[i - 1][j] + sdp[i][j - 1] - sdp[i - 1][j - 1];
            if (S[i - 1] == T[j - 1]) {
                dp[i][j] = sdp[i - 1][j -1];
                sdp[i][j] += dp[i][j];
            }
        }
    }

    // mint ans = 0;
    // for (int i = 0; i < N + 1; i++) {
    //     for (int j = 0; j < M + 1; j++) {
    //         printf("%lld ", dp[i][j].x);
    //         ans += dp[i][j];
    //     }
    //     printf("\n");
    // }

    // for (int i = 0; i < N + 1; i++) {
    //     for (int j = 0; j < M + 1; j++) {
    //         printf("%lld ", sdp[i][j].x);
    //     }
    //     printf("\n");
    // }

    cout << sdp[N][M].x << endl;

    return 0;
}


Measured memory_bytes: 63104
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
int main(){
    int n ;
    cin >> n ;
    vector<int> a (n) ;
    int tot = 0 ;
    rep(i, n) {
        cin >> a[i] ;
        tot ^= a[i] ;
    }
    rep(i, n){
        int k = tot ^ a[i] ;
        cout << k << " " ;
    }
    cout << endl ;
}

Measured memory_bytes: 3964
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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

// 無限大の値
const ll  LINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  int n;
  cin >> n;
  cout << n * 800 - ((n / 15) * 200) << endl;
  return 0;
} 

Measured memory_bytes: 3588
#template
def inputlist(): return [int(k) for k in input().split()]
#template
N = int(input())
li = [0]*N
for i in range(N):
    A,B = inputlist()
    li[i] = [B,A]
li.sort()
suma = li[0][1]
if suma > li[0][0]:
    print("No")
    exit()
for i in range(1,N):
    suma += li[i][1]
    if suma > li[i][0]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 35676
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  cout << n*n*3 << endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
    cin>>n;int h[n+1];for(int i=0;i<n;i++)cin>>h[i];h[n]=1000000001;
    int ans=0,cnt=0;
    for(int i=0;i<=n;i++){
        if(h[i]>=h[i+1])cnt++;
        else {ans=max(ans,cnt);cnt=0;}
    }
    cout<<ans<<endl;
    }

Measured memory_bytes: 640
//
//  main.cpp
//  AOJ
//
//  Created by 佐々木勇星 on 2018/09/29.
//  Copyright © 2018年 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main(int argc, const char * argv[]) {
    int a;
    cin >> a;
    
    for(int i = 1; i < a + 1; i++){
        if(i % 3 == 0 || i % 10 == 3 || i / 10 % 10 == 3 || i / 100 % 10 == 3 || i / 1000 % 10 == 3){
            cout << " " << i ;
        }
        
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define pb pop_back
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define Sim template<class n
Sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
Sim> auto operator << (ostream &p, n y) -> 
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
Sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
Sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
Sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "
const int M = 1024 * 1024;

int n;
map<int, int> mapa;

int main()
{
	//ios_base::sync_with_stdio(0);
	//cin.tie(NULL);
	scanf("%d", &n);
	LL sum = 0;
	FOR(i, 1, n)
	{
		int a;
		scanf("%d", &a);
		mapa[a]++;
		sum += a;
	}
	if (sum == 0)
	{
		printf("Yes\n");
		return 0;
	}
	if (n % 3 != 0)
	{
		printf("No\n");
		return 0;
	}
	int xo = 0;
	for (auto x : mapa)
	{
		if (x.s % (n / 3) != 0)
		{
			printf("No\n");
			return 0;
		}
		for (int i = 0; i < x.s / (n / 3); i++)
		{
			xo ^= x.f;
		}
	}
	if (xo != 0)
	{
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 3840
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
signed main() {
	int n;
	int a[30];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 1; i < n - 1; i++) {
		if ((a[i - 1] < a[i] || a[i + 1] < a[i]) && (a[i - 1] > a[i] || a[i + 1] > a[i])) {
			ans++;
		}
	}
	cout << ans << endl;
}

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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

map<ll,ll> Divs(ll N)
{
    map<ll,ll> ret;
    ll N_copy = N;
    for(ll i=2;i*i<=N;i++)
    {
        while(N_copy%i==0)
        {
            N_copy/=i;
            ret[i]++;
        }
    }
    if(N_copy!=1) ret[N_copy]++;
    return ret;
}

ll tri(ll N)
{
    ll i;
    for(i=1;;i++)
    {
        if(((i+1)*(i+2)/2)>N) break;
    }
    return i;
}

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

    map<ll,ll> divs = Divs(N);

    ll ans = 0;

    for(auto x : divs)
    {
        ans += tri(x.second);
    }

    OUT0(ans);

    return 0;
}

Measured memory_bytes: 3708
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
L = [0]
for i in range(1, N):
    L.append(gcd(A[i-1], L[i-1]))
R = [0]
for i in range(1, N):
    R.append(gcd(R[i-1], A[N-i]))
R.reverse()
ans = []
for i in range(0, N):
    ans.append(gcd(L[i], R[i]))
print(max(ans))


Measured memory_bytes: 16136
#配列初期化
a = [[0 for i2 in range(3)] for i1 in range(3)]
chk = [[0 for i2 in range(3)] for i1 in range(3)]

a[0] = [int(x) for x in input().split()]
a[1] = [int(x) for x in input().split()]
a[2] = [int(x) for x in input().split()]

# 整数を一つ入力
N = int(input())

for k in range(N):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if b == a[i][j]:
                chk[i][j] = 1
bingo = 0

if chk[0][0]*chk[0][1]*chk[0][2] == 1:
    bingo = 1
if chk[1][0]*chk[1][1]*chk[1][2] == 1:
    bingo = 1
if chk[2][0]*chk[2][1]*chk[2][2] == 1:
    bingo = 1

if chk[0][0]*chk[1][0]*chk[2][0] == 1:
    bingo = 1
if chk[0][1]*chk[1][1]*chk[2][1] == 1:
    bingo = 1
if chk[0][2]*chk[1][2]*chk[2][2] == 1:
    bingo = 1

if chk[0][0]*chk[1][1]*chk[2][2] == 1:
    bingo = 1
if chk[0][2]*chk[1][1]*chk[2][0] == 1:
    bingo = 1

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


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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()

#define uint8_t unsigned char
#define uint16_t unsigned short
#define uint32_t unsigned int
#define uint64_t unsigned long long

#define int8_t signed char
#define int16_t signed short
#define int32_t signed int
#define int64_t signed long long

using namespace std;

int main(int argc, char const* argv[])
{
    int x[5] = {};
    REP(i,5) cin >> x[i];

    REP(i,5) {
    	if (x[i] == 0) {
        	cout << i+1 << endl;
        }
    }

    return 0;
}




Measured memory_bytes: 3592
import numpy as np
h, w, m = map(int, input().split())
H = [0 for _ in range(h)]
W = [0 for _ in range(w)]
ps = []
for _ in range(m):
  x, y = map(lambda p: int(p)-1, input().split())
  H[x] += 1
  W[y] += 1
  ps.append([x, y])
  
H = np.array(H)
W = np.array(W)
arrh = H == H.max()
arrw = W == W.max()
area = arrh.sum() * arrw.sum()
ans = int(H.max() + W.max())
for p in ps:
  if arrh[p[0]] and arrw[p[1]]:
    area -= 1
if area > 0:
  print(ans)
else:
  print(ans-1)

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

signed main(){
    int N, M, X, Y, x[100], y[100];
    cin >> N >> M >> X >> Y;
    REP(i, N) cin >> x[i];
    REP(i, M) cin >> y[i];
    sort(x, x + N);
    sort(y, y + M);
    if(max(X, x[N - 1]) < min(Y, y[0])){
        PRINT("No War");
    }else{
        PRINT("War");
    }
    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    H=[int(_) for _ in input().split()]
    count=0
    max_count=0
    for i in range(n-1):
        if H[i+1]<=H[i]:
            count+=1
            max_count=max(count,max_count)
        else:count=0
    print(max_count)
if __name__=='__main__':
    main()

Measured memory_bytes: 14252
let rec check str maxN bufN =
  let len = (String.length str) in
  if len = 0 then maxN
  else
    let headS = str.[0] in
    let newStr = String.sub str 1 (len - 1) in
    if headS = 'A' || headS = 'T' || headS = 'C' || headS = 'G' then
      let newBufN = bufN + 1 in
      if maxN <= newBufN then
        check newStr newBufN newBufN
      else
        check newStr maxN newBufN
    else
    if maxN <= bufN then
      check newStr bufN 0
    else
      check newStr maxN 0
let () = Scanf.scanf "%s\n"
    (fun str -> check str 0 0)
         |> print_int

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 10000000000000000
#define mod 2019

ll mypow(ll a,ll b){
	ll num=1;
	while(b>0){
		num*=a;
		b--;
	}
	return num;
}

int main(){
	ll n,k,i;cin>>n>>k;//n:サイコロの目のmax　k:とりたい得点
	vector<ll> ans;

	ll MAX=-1;
	for(i=1;i<=n;i++){//i:サイコロの目
		ll num=0,ins=k;
		
		ins/=i;
		while(ins>0){
			ins/=2;
			num++;
		}

		for(ll j=0;j<=32;j++){
			if(k%i==0 && k/i==mypow(2,j)){
				num--;
				break;
			}
		}

		ans.push_back(mypow(2,num));
		MAX=max(MAX,mypow(2,num));
	}

	
	ll sum=0;
	for(i=0;i<ans.size();i++){
		sum+=MAX/ans[i];
	}

	double answer=(sum+.0)/(MAX*n+.0);

	printf("%.12f\n",answer);
	return 0;
}

Measured memory_bytes: 1400
n = int(input())
h = list(map(int, input().split()))
ok = [False for _ in range(n)]
ans = 0
while not all(ok):
    l = ok.index(False)
    for i in range(l, n):
        if ok[i] == True:
            break
        else:
            r = i
    m = min(h[l:r+1])
    ans += m
    for i in range(l, r + 1):
        h[i] -= m
        if h[i] == 0:
            ok[i] = True
print(ans)

Measured memory_bytes: 3064
from collections import Counter
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
CA = Counter(A)
Q = int(stdin.readline().rstrip())
ans = sum(A)
for i in range(Q):
    b, c = [int(_) for _ in stdin.readline().rstrip().split()]
    ans += (c-b)*CA[b]
    CA[c] += CA[b]
    CA[b] = 0
    print(ans)

Measured memory_bytes: 24000
#include <bits/stdc++.h>
#define MOD (ll)(1e9 + 7)
#define MAX (ll)(2e5 + 4)
#define INF (ll)(1e17)
using namespace std;
using ll =  long long;
using ld = long double;

vector<pair<ll, ll>> ve[MAX];

int main () {
	ll n, m;
	cin >> n >> m;
	for (ll i = 0; i < m; i++) {
		ll l, r, c;
		cin >> l >> r >> c;
		ve[l].push_back (make_pair (c, r));
	}
	ll ne = 1, dp[n + 1];
	for (int i = 0; i <= n; i++) {
		dp[i] = INF;			
	}
	dp[1] = 0;
	set <pair<ll, ll>> sp;
	ll co = 0;
	for (ll i = 1; i < n; i++) {
		for (auto x : ve[i]) {
			sp.insert (make_pair (dp[i] + x.first, x.second));
		}
		while (sp.size () && sp.begin () -> second <= i) {
			sp.erase (sp.begin ());
		}
		if (sp.size ()) {
			dp[i + 1] = min (dp[i + 1], sp.begin () -> first);
		}
		else {
			cout << "-1\n";
			return 0;
		}
	}
	cout << dp[n] << "\n";
}
		
		
		


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in(),K=in();
	vector<int> P=vecin(N);
	vector<double> PD(N),S(N+1,0);
	REP(i,N){
		PD[i] = (((1+P[i])*P[i])/2.0)/P[i];
		S[i+1] = S[i]+PD[i];
	}
	int maxI=0;
	double maxV=-1;
	for(int i=0;i+K<=N;i++){
		double V=S[i+K]-S[i];
		if(V>maxV){
			maxV=V;
			maxI=i;
		}
	}
	
	out(maxV);
	return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
 ll n=100000;
  ll arr[100000+1];
  arr[0]=arr[1]=0;
  
  for(ll i=2;i<=100000;i++)arr[i]=1;
  
  for(ll i=2;i*i<=n;i++){
   
    if(arr[i]){
     for(ll j=i*i;j<=n;j=j+i)arr[j]=0;
      
      
      
    }
    
    
    
  }
  
  
  ll q;
  cin>>q;
  for(ll i=q;;i++){
   if(arr[i]){
    cout<<i;
     break;
     
     
     
   }
    
  }
  
  
  
  
  
  
  
  
  return 0;
  
  
  
  
}


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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

////////////////////////////////////////////////////////////////////

const int N = 2e5 + 5;

int A[N], L[N], R[N];

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n; cin >> n;
	for (int i = 1; i <= n; i++) cin >> A[i];
	for (int i = 1; i <= n; i++) {
		L[i] = i - 1;
		while (L[i] > 0 && A[L[i]] > A[i]) L[i] = L[L[i]];
	}
	for (int i = n; i >= 1; i--) {
		R[i] = i + 1;
		while (R[i] <= n && A[R[i]] > A[i]) R[i] = R[R[i]];
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++) ans += 1LL * A[i] * (R[i] - i) * (i - L[i]);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    set<char> D;
    for(int i = 0; i < K; ++i) {
        char c;
        cin >> c;
        D.insert(c);
    }

    for(;; ++N) {
        string S = to_string(N);
        bool valid = true;
        for(char c: S) {
            if(D.count(c) > 0) {
                valid = false;
            }
        }
        if(valid)
            break;
    }

    cout << N << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

int main(){
	int a,b,c,count = 0;
	scanf("%d %d %d",&a,&b,&c);
	for(int i = a; i <= b; i++){
		if(c%i == 0) count++;
	}
	printf("%d\n",count);
}





Measured memory_bytes: 2760
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		
		if (a < b){
			System.out.println("a < b");
		}else if (a > b){
			System.out.println("a > b");
		}else if (a == b){
			System.out.println("a == b");
		}
		scan.close();
	}
}


Measured memory_bytes: 26304
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <fstream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define gap                        ' '
#define EPS                        1e-9
#define mod                        1e9+7
#define P_INF                      1e9+17
#define N_INF                     -1e9+17
#define PI                         2*acos(0.0)
#define IFORI(Name)                for(auto &data : Name)
#define IFORO(Name)                for(auto data : Name)
#define FOR(start, end)            for(int i=start; i<end; i++)
#define FORR(start, end)           for(int j=start; j<end; j++)
#define RFOR(start, end)           for(int k=start-1; k>=end; k--)
#define unique(a)                  a.resize(unique(a.begin(), a.end()) - a.begin())

typedef double ld;
typedef long long int ll;
typedef unsigned long long int ul;
using namespace std;

class BStringPalindrome {
public:
    void solve(std::istream &in, std::ostream &out) {
        string s;
        in >> s;
        int len = s.size();
        if (s == string(s.rbegin(), s.rend())) {
            string right = s.substr(0, ((len - 1) / 2));
            string left = s.substr(((len + 3) / 2) - 1, len -1);
            //out<<right<<gap<<left<<endl;
            if (right == string(right.rbegin(), right.rend())) {
                if (left == string(left.rbegin(), left.rend())) {
                    out << "Yes" << endl;
                } else {
                    out << "No" << endl;
                }
            } else {
                out << "No" << endl;
            }
        } else {
            out << "No" << endl;
        }
    }
};


int main() {
     std::ios_base::sync_with_stdio(0);
     std::cin.tie(nullptr);
     BStringPalindrome solver;
     std::istream& in(std::cin);
     std::ostream& out(std::cout);
     solver.solve(in, out);
     return 0;
}


Measured memory_bytes: 256
class Factorial:
    def __init__(self, max_fact, mod):
        #mod should be prime number
        #using homogeneous_product(n,r), max_fact ≧ max(n+r-1)
        f = [1] * (max_fact + 1)
        for idx in range(2, max_fact + 1):
            f[idx] = f[idx - 1] * idx
            f[idx] %= mod
        if mod > max_fact:
            fi = [pow(f[-1], mod - 2, mod)]
            for idx in range(max_fact, 0, -1):
                fi += [fi[-1] * idx % mod]
            fi = fi[::-1]
        else:
            fi = [pow(n, mod - 2, mod) for n in f]
        self.mod = mod
        self.f = f
        self.fi = fi

    def factorial(self, n):
        return self.f[n]

    def factorial_inverse(self, n):
        return self.fi[n]

    def combination(self, n, r):
        f = self.f
        fi = self.fi
        return f[n] * fi[r] * fi[n - r] % self.mod

    def permutation(self, n, r):
        return self.f[n] * self.fi[n - r] % self.mod

    def homogeneous_product(self, n, r):
        f = self.f
        fi = self.fi
        return f[n + r - 1] * fi[r] * fi[n - 1] % self.mod


max_fact = 10**6
mod = 10**9 + 7
fact_instance = Factorial(max_fact, mod)
comb = fact_instance.combination
perm = fact_instance.permutation
combrep = fact_instance.homogeneous_product

S = int(input())
ans = 0
for n in range(1, S // 3 + 1):
    ans += combrep(n, S - 3 * n)
    ans %= mod
print(ans)


Measured memory_bytes: 95776
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 count = 0;
		for (int i = a; i <= b; i++) {
			if (c % i == 0) {
				count++;
			}
		}
		System.out.println(count);
	}
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int H, W, N; scanf("%d %d %d", &H, &W, &N);
  vector<pair<int, int>> v;
  int r, c;
  for (int i = 0; i < N; ++i) {
    scanf("%d %d", &r, &c);
    for (int dr = 0; dr <= 2; ++dr) {
      for (int dc = 0; dc <= 2; ++dc) {
        int nr = r - dr, nc = c - dc;
        if (1 <= nr and nr + 2 <= H and 1 <= nc and nc + 2 <= W) {
          v.push_back(make_pair(nr, nc));
        }
      }
    }
  }

  ll white = 1LL * (H - 3 + 1) * (W - 3 + 1);
  sort(v.begin(), v.end());
  vector<ll> ans(10, 0);
  int n = v.size();
  for (int i = 0; i < n; ) {
    int j = i;
    while (j < n and v[j] == v[i]) { ++j; }
    int cnt = j - i;
    ++ans[cnt];
    --white;
    i = j;
  }
  ans[0] = white;
  for (int i = 0; i < 10; ++i) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}


Measured memory_bytes: 10220
#include <bits/stdc++.h>
//#include "debug.h"
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
double startTime;
double getCurrentTime() {
return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
//freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int k;
  string s;
  cin>>k>>s;
  if(s.size()<=k)cout<<s<<endl;
  else cout<<(s.substr(0,k)+"...")<<"\n";
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld PI = 3.14159265358979323846;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ld a, b, h, m; cin >> a >> b >> h >> m;
	cout << fixed << setprecision(20);
	cout << sqrtl(a * a + b * b - 2 * a * b * cos(abs(6 * m - (30 * h + m/2)) * PI/180));

	return 0;
}

Measured memory_bytes: 4184
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
//#define mp make_pair
#define pb push_back
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<int, pii>
#define pdi pair<double, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head

const int N = 305, M = 9e4 + 10;
const int MOD = 998244353;
const int INV2 = 499122177;
int a[N], dp[N][M], pp[M], n, s = 0;
LL q_pow(LL n, LL k) {
    LL res = 1;
    while(k) {
        if(k&1) res = (res * n) % MOD;
        n = (n * n) % MOD;
        k >>= 1;
    }
    return res;
}
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), s += a[i];
    dp[0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < M; ++j) {
            dp[i][j] = (2*dp[i-1][j]) % MOD;
        }
        for (int j = a[i]; j < M; ++j) {
            dp[i][j] = (dp[i][j] + dp[i-1][j-a[i]]) % MOD;
        }
    }
    pp[0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = M-1; j >= a[i]; --j) pp[j] = (pp[j] + pp[j-a[i]]) % MOD;
    }
    if(s%2 == 0)dp[n][s/2] = (dp[n][s/2]-pp[s/2]) % MOD;
    LL ans = q_pow(3, n);
    int up = (s+1)/2;
    for (int i = up; i < M; ++i) ans = (ans - dp[n][i]*3LL%MOD) % MOD;
    printf("%lld\n", (ans + MOD) % MOD);
    return 0;
}


Measured memory_bytes: 106368
n, y = map(int, input().split())
y = y / 1000
judge = 0
for i in range(n+1):
    for j in range(n+1):
        if i*1 + j*5 + (n-i-j)*10 == y and n-i-j>= 0:
                judge = 1
                print(n-i-j, j, i)
                break
    else:
        continue
    break

if judge == 0:
    print(-1,-1,-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, k;
	cin >> n >> k;
	int cnt = 0;
	while (n) {
		n /= k;
		++cnt;
	}
	cout << cnt << '\n';
 	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict as dd, Counter
N = int(input())
edges = [None] * (N-1)
es = dd(dict)
for i in range(N-1):
    a, b = map(int, input().split())
    es[a][b] = es[b][a] = i

q = []
q.append((1, -1))
while q:
    i, used = q.pop()
    color = 0
    for to, eid in es[i].items():
        if edges[eid] is not None:
            continue
        color += 1
        if color == used:
            color += 1
        edges[eid] = color
        q.append((to, color))

ct = Counter(edges)
print(len(ct))
for e in edges:
    print(e)

Measured memory_bytes: 51048
#初期値に関する処理がないのでNG
import sys

N = int(input())
arr = [list(map(int,input().split())) for i in range(N)]

#初期値対応
if arr[0][0] < arr[0][1] + arr[0][2]:
    print("No")
    exit()

for i in range(len(arr)-1):
    if arr[i+1][0]-arr[i][0] < abs(arr[i+1][1]-arr[i][1])+abs(arr[i+1][2]-arr[i][2]) or (arr[i+1][0]-arr[i][0])%2 != (abs(arr[i+1][1]-arr[i][1])+abs(arr[i+1][2]-arr[i][2]))%2:
        print("No")
        exit()

print("Yes")

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

bool ok(char c){
    return c == 'A' || c == 'T' || c == 'C' || c == 'G';
}
int main()
{
    string s;
    cin >> s;
    int ans = 0;
    int tmp = 0;
    bool connect = false;
    for(int i=0; i<s.size(); i++){
        if(ok(s[i])){
            tmp++;
            ans = max(ans, tmp);
        }else{
            tmp = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

string S;
int p;

int dfs();
int number();

void print_pos()
{
    cerr << S << endl;
    for (int i=0; i<=p-1; i++) cerr << " ";
    cerr << "^" << endl;
}

int ans = 0;
int dfs(int level)
{
    vector<int> nums;
    while (p < S.size()) {
#ifdef DEBUG
        DUMP2(p, level);
        print_pos();
#endif
        if (S[p] == '[') {
            p++; // skip '['
            nums.push_back(dfs(level+1));
        } else if (S[p] == ']') {
#ifdef DEBUG
            rep(i, nums.size()) {
                cerr << '[' << nums[i] << ']';
            }
            cerr << endl;
#endif
            p++; // skip ']'
            sort(nums.begin(), nums.end());
            int res = 0;
            for (int i=0; i<((int)nums.size()+1)/2; i++) res += nums[i];
            if (level == 1) ans = res;
#ifdef DEBUG
            DUMP(res);
#endif
            return res;
        } else if (isdigit(S[p])) {
            int res = number();
            p++;
            return res;
        }
    }
    return -1;
}

int number()
{
    int num = 0;
    while (isdigit(S[p])) {
        num *= 10;
        num += (S[p] - '0');
        p++;
    }
    return (num+1)/2;
}

int solve(string A)
{
    S = A;
    p = 0;
    ans = 0;
#ifdef DEBUG
    cerr << S << endl;
#endif
    dfs(0);
    return ans;
}

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

    int D; cin >> D;
    rep(_, D) {
        string A;
        cin >> A;
        cout << solve(A) << endl;
    }
}




Measured memory_bytes: 3196
#include <iostream>
using namespace std;
int main() {
	string S;
	cin >> S;
	if (S[0]==S[1] || S[1]==S[2] || S[2]==S[3] ) {
		cout << "Bad" << endl;
    } 
	else {
		cout << "Good" << endl;
	}
	return 0;
}

Measured memory_bytes: 3572
#include<iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	int t=n%10;
	if(t==2||t==4||t==5||t==7||t==9)
	cout<<"hon";
	else if(t==3)
	cout<<"bon";
	else
	cout<<"pon";
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define PB push_back
#define PPB pop_back
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, int> psi;

static const int INF = 1LL << 60;
static const int MAX_N = 100005;

int n, m, k, s, p, q, iszom[MAX_N], d[MAX_N];
vector<pii> G[MAX_N];
vector<int> tG[MAX_N];

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

    cin >> n >> m >> k >> s >> p >> q;

    for (int i = 0; i < k; ++i) {
        int c;
        cin >> c;
        iszom[c] = 1;
    }

    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        tG[a].PB(b);
        tG[b].PB(a);
    }
    {
        fill(d, d + MAX_N, INF);
        queue<pii> que;
        for (int i = 2; i < n; ++i) {
            if (!iszom[i]) continue;
            que.push({ i, 0 });
            d[i] = 0;
        }

        while (que.size()) {
            pii p = que.front();
            que.pop();
            if (p.second == s) continue;
            int v = p.first;

            for (int i = 0; i < tG[v].size(); ++i) {
                int to = tG[v][i];
                if (d[to] <= d[v] + 1) continue;
                d[to] = d[v] + 1;
                que.push({ to, d[v] + 1 });
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (iszom[i]) continue;
        for (int j = 0; j < tG[i].size(); ++j) {
            int to = tG[i][j];
            if (iszom[to]) continue;
            G[i].PB({ to, to == n ? 0 : d[to] <= s ? q : p});
            G[to].PB({ i, i == n ? 0 : d[i] <= s ? q : p});
        }
    }
    {
        fill(d, d + MAX_N, INF);
        priority_queue<pii, vector<pii>, greater<pii>> que;
        que.push({ 1, 0 });
        d[1] = 0;

        while (que.size()) {
            pii p = que.top();
            que.pop();
            int v = p.first;

            for (int i = 0; i < G[v].size(); ++i) {
                int to = G[v][i].first, cost = G[v][i].second;
                if (d[to] <= d[v] + cost) continue;
                d[to] = d[v] + cost;
                que.push({ to, d[to] });
            }
        }
    }

    cout << d[n] << endl;
}

Measured memory_bytes: 33052
#include <cstdio>
#include <algorithm>

using namespace std;

#define rep1(i,x) for(int i=1;i<=(x);++i)

int d[100001];

int main()
{
	int N, M; scanf("%d %d", &N, &M);

	rep1(i, N - 1) {
		int s; scanf("%d", &s);
		d[i] = s + d[i - 1];
	}

	int ans = 0;

	int now = 0;

	rep1(i, M) {
		int a; scanf("%d", &a);
		int nxt = now + a;
		ans += d[max(now, nxt)] - d[min(now, nxt)];
		ans %= 100000;
		now = nxt;
	}

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

Measured memory_bytes: 1416
#include <iostream>

using namespace std;

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    int count=1;
    n=n-m-k*2;
    while(n>=(m+k)){
        n-=(m+k);
        count++;
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 100000+10;
const int mod = 1e9 + 7;
int n;
vector<int> id;
int vis[M];
ll fact[M];

ll inv (ll x) {
	ll ret = 1;
	for (int i=mod-2; i; i>>=1) {
		if (i&1) ret = ret*x%mod;
		x = x*x%mod;
	}
	return ret;
}

ll C(int n,int k) {
	if (n<k) return 0;
	return fact[n] * inv(fact[n-k]) %mod * inv(fact[k]) %mod;
}

int main () {
	int len = -1;
	fact[0] = 1;
	scanf ("%d", &n);
	++n;
	for (int i=1, x; i<=n; ++i) {
		fact[i] = fact[i-1]*i%mod;
		scanf ("%d", &x);
		if (!vis[x]) {
			vis[x] = i;
		} else len = i - vis[x]+1;
	}
	printf ("%d\n", n-1);
	for (int k=2; k<=n; ++k) {
		ll ans = C(n-2, k) + C(n-2, k-2) + (2*C(n-2, k-1) - C(n-len, k-1));
		//ll ans = C(n, k) - (n-len, k-1);
		printf ("%lld\n", (ans+mod)%mod);
	}
	return 0;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int sign(int x) { return (x > 0) - (x < 0); }
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int cdiv(int a, int b) { return (a - 1 + b) / b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const deque<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const set<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
    string S;
    cin >> S;
    int N = S.length();
    auto lcp = lcp_array(S, suffix_array(S));
    int ans = N * (N + 1) / 2 - accumulate(all(lcp), 0LL);
    cout << ans << endl;
}


Measured memory_bytes: 15608