akhauriyash/Code-Regression huggingface dataset:
from collections import deque
import bisect

INF = float("inf")

N = int(input())
C = list(map(int, input().split()))
uvp = [list(map(int, input().split())) for i in range(N-1)]

edge = [[0]*(N+1) for i in range(N+1)]
utov = [[] for i in range(N+1)]

for u, v, p in uvp:
    edge[u][v] = edge[v][u] = p
    utov[u].append(v)
    utov[v].append(u)

for i in range(1, N):
    if (C[i-1] > 0):
        edge[i][N] = INF
        utov[i].append(N)
        utov[N].append(i)


def bfs(s, g, n):
    bfs_map = [-1]*n
    bfs_map[s] = 0
    q = deque()
    q.append(s)

    while q:
        u = q.popleft()
        for v in utov[u]:
            if (edge[u][v] > 0) and (bfs_map[v] < 0):
                bfs_map[v] = bfs_map[u] + 1
                q.append(v)

    return bfs_map

def update(s, g, bfs_map):
    f = INF
    distance = bfs_map[g]
    p = [[None, None] for i in range(distance)]
    y = g
    for i in range(distance)[::-1]:
        p[i][1] = y
        for x in utov[y]:
            if (edge[x][y] > 0) and (bfs_map[x] == i):
                if (edge[x][y] < f):
                    f = edge[x][y]
                y = x
                p[i][0] = x
                break
        else:
            return 0
    for x,y in p:
        edge[x][y] -= f
        edge[y][x] += f
    return f

def dinic(s, g, n):
    max_flow = 0
    while True:
        bfs_map = bfs(s, g, n)
        if (bfs_map[g] < 0):
            return max_flow
        cap = update(s, g, bfs_map)
        while (cap > 0):
            max_flow += cap
            cap = update(s, g, bfs_map)

print(dinic(0, N, N+1))


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

int main() {
	// your code goes here
    int n,i;
    long long a[200005],s[200005]={0},sum,ans=1e16;
    cin >> n;
    for(i=1;i<=n;i++){
        cin >> a[i];
        s[i]=s[i-1]+a[i];
    }
    sum=s[n];
    for(i=0;i<=n;i++){
        ans=min(ans,abs(s[i]-(sum-s[i])));
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
int main(){
int a,b,c,m=0,n=0;
while(scanf("%d,%d,%d",&a,&b,&c)!=EOF){
if(a-b==0)
m++;
if(a*a+b*b-c*c==0)
n++;
}
printf("%d\n%d\n",n,m);
return 0;
}

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

int main(void){
  int k,s;
  cin>>k>>s;
  int cnt=0;
  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
      int z=s-x-y;
      if(0<=z&&z<=k) cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}

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

int main() {
  int n;
  cin>>n;
  vector<int> b(n);
  rep(i,n){
    cin>>b[i];
    b[i]--;
  }
  
  vector<int> ans;
  rep(k,n){
    for(int i=n-1;i>=0;i--){
      if(b[i]==i){
        ans.pb(b[i]+1);
        for(int j=i;j<=n-2;j++) b[j]=b[j+1];
        b[n-1]=-1;
        break;
      }
    }
  }
  
  if(int(ans.size())!=n) puts("-1");
  else{
    rep(i,n) cout << ans[n-i-1] << endl;
  }
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    map<vector<int>, int> ans;
    rep(i, n) d[i] = i + 1;
    int j = 1;
    do {
        ans[d] = j;
        j++;
    }while(next_permutation(d.begin(), d.end()));
    vector<int> p(n), q(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];
    cout << abs(ans[p] - ans[q]) << endl;
    

}

Measured memory_bytes: 8580
/*
AOJ 2407
Computer Onesan
2014/6/9 WA 48/74
*/
#include <stdio.h>
#define WARI 1000000 
int M,N; //global
int memo[101][2][2][2];
//last=last movement (0,1,2,-1,-2)
unsigned int power(n,x)
{
  if(x==0)
    return(1);
  else
    return(n*power(n,x-1) % WARI);
}
// never go left pattern
unsigned int f(int y0,int x0,int y1,int x1)
{
  return(power(3,x1-x0));
}
// go left center line x1=>x2
// S->v    --->
// v<--    ^<--
// --->    S->^
int g(int y0,int x0,int y1,int x1)
{
  if(x1>x0 && y1==2 && y0==0)
    return(1);
  if(x1>x0 && y1==0 && y0==2)
    return(1);
  return(0);
}
unsigned long long solve_3(int y0,int x0,int y1,int x1,int last)
{
  // last means last movement if 1  ---V
  //                                V---
  // (called gyaku-S)               --->
  unsigned long long ret;
  int i;
  unsigned long long wk,wk2;

  if(x1==x0)  //updown only
    {
      if(last)
	return(1);
      else
	return(0);
    }
  
  if(x1-x0==1)
    {
      if(last==0 && ((y0==0 && y1==2)||(y1==0 && y0==2))) 
	return(1);
      else if(last==1)
	return(3);
      else
	return(0);
    }
  if(ret=memo[x1-x0][y0/2][y1/2][last])  
    return(ret);


  ret=0;
  if(last)
    {
      for(i=x0;i<=x1;i++)
       {
	 if(i<x1)
	   {
	     wk2 = f(y0,x0,0,i)*solve_3(0,i+1,y1,x1,0);
	     wk2 %= WARI;
	     ret += wk2;
	     ret %= WARI;
	     wk2 = f(y0,x0,2,i)*solve_3(2,i+1,y1,x1,0);
	     wk2 %= WARI;
	     ret += wk2;
	   }
	 else
	   ret += f(y0,x0,0,i);
	 ret %= WARI;
       }
    }
  else 
    {
      for(i=x0+1;i<=x1;i++)
	{
	  if(y0==0)
	    {
	      if(i<x1)
		{
		  wk2 = solve_3(2,i+1,y1,x1,1)+solve_3(2,i+1,y1,x1,0);
		  wk2 %= WARI;
		  wk = g(y0,x0,2,i)*wk2;
		  wk %= WARI;
		  ret  += wk;
		}
	      else
		ret +=1;
	    }
	  else if(y0==2)
	    {
	      if(i<x1)
		{
		  wk2 = solve_3(0,i+1,y1,x1,1)+solve_3(0,i+1,y1,x1,0);
		  wk2 %= WARI;
		  wk  = g(y0,x0,0,i)*wk2;
		  wk %= WARI;
		  ret  += wk;
		}
	    }
	  ret %= WARI;
	}
     }

  memo[x1-x0][y0/2][y1/2][last]=ret;  
  return(ret);
}
s3(int N)
{
  return((solve_3(0,0,2,N,1)
	  +solve_3(0,0,2,N,0)) % WARI
	 );
}

int s2(int N)
{
  return(power(2,N));
}
int solve23(int N,int M)
{
  if(M==2)
    return(s2(N));
  if(M==3)
    return(s3(N));
}
main()
{
  int ret;

#ifdef DEBG
  int i,j;
  for(i=2;i<=100;i++)
    for(j=2;j<=3;j++)
      {
	ret=solve23(i,j);
	printf("%d %d %d\n",i,j,ret);
      }
#else
  scanf("%d %d",&N,&M);
  ret=solve23(N,M+1);
  printf("%d\n",ret);
#endif
  return(0);
}

Measured memory_bytes: 604
import sys
input = sys.stdin.readline

import numpy as np

# 可換なら6回周期。6個計算すると、交換子で共役とったものだとわかる。

N,K = map(int,input().split())

P,Q = [np.array(input().split(), dtype=np.int32) for _ in range(2)]

P -= 1
Q -= 1

def inv(a):
    x = np.empty_like(a)
    x[a] = np.arange(len(x))
    return x

def mult_inv(a,b):
    # ab^{-1}
    c = np.empty_like(a)
    c[b] = a
    return c

def mult(a,b):
    return mult_inv(a,inv(b))

def power(a,n):
    if n == 0:
        return np.arange(len(a))
    x = power(a,n//2)
    x = mult(x,x)
    return mult(a,x) if n&1 else x

A = [P,Q]
for _ in range(4):
    A.append(mult_inv(A[-1],A[-2]))

q,r = divmod(K-1,6)
QP_Q_P = mult(mult_inv(mult_inv(Q,P),Q),P)
left = power(QP_Q_P,q)
right = inv(left)
answer = mult(mult(left, A[r]), right) + 1

print(' '.join(answer.astype(str)))

Measured memory_bytes: 33740
/*--------------------------------
  Author: The Ace Bee
  Blog: www.cnblogs.com/zsbzsb
  This code is made by The Ace Bee
--------------------------------*/
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <map>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
	s = 0; int f = 0; char c = getchar();
	while (!isdigit(c)) f |= (c == '-'), c = getchar();
	while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
	s = f ? -s : s;
}

typedef long long LL;
typedef pair < int, int > pii;
const int _ = 100010;

int n, m, k; LL ans[11];
map < pii, int > _map;
struct node{ int x, y; }a[_];

inline bool cmp(const node& n, const node& m)
{ return n.x == m.x ? n.y < m.y : n.x < m.x; }

int main() {
	read(n), read(m), read(k);
	for (rg int i = 1; i <= k; ++i)
		read(a[i].x), read(a[i].y);
	
	ans[0] = max(0ll, 1ll * (n - 2) * (m - 2));
	
	sort(a + 1, a + k + 1, cmp);
	
	pii p;
	for (rg int i = 1; i <= k; ++i)
		for (rg int x = max(1, a[i].x - 2); x <= min(n - 2, a[i].x); ++x)
			for (rg int y = max(1, a[i].y - 2); y <= min(a[i].y, m - 2); ++y)
				p = make_pair(x, y), --ans[_map[p]], ++_map[p], ++ans[_map[p]];
	
	for (rg int j = 0; j < 10; ++j) printf("%lld\n", ans[j]);
	
	return 0;
}


Measured memory_bytes: 57216
num=int(input())
stl =[''.join(sorted(input())) for i in range(num)]

#duplicate=[x for x in set(stl) if stl.count(x) > 1]

t = {}
for i in range(num):
  if stl[i] in t:
    t[stl[i]] += 1
  else:
    t[stl[i]] = 1
print(sum(t[k] * (t[k] -1) // 2 for k in t))


Measured memory_bytes: 19404
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define fi first
#define se second
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
   ll a,b,c;
   cin>>a>>b>>c;
   cout<<c<<" "<<a<<" "<<b<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int x[8];
	rep(i, 8) {
		x[i] = i;
	}
	int n, m; cin >> n >> m;
	int out = 0;
	int d[8][8] = {};
	rep(i, m) {
		int a, b; cin >> a >> b; a--; b--;
		d[a][b] = d[b][a] = 1;
	}
	bool f = true;
	rep(i, n-1) {
		if (!d[i][i + 1])f = false;
	}
	if (f)out++;
	while (next_permutation(x+1, x + n)) {
		f = true;
		rep(i, n-1) {
			if (!d[x[i]][x[i + 1]])f = false;
		}
		if (f)out++;
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define loop(i, a, b) for(int i = a; i < b; i++) 
#define rep(i, a) loop(i, 0, a)
using namespace std;
const int MOD = 1000000007;
const int inf = 1e8;
using vi = vector <int>;
using vvi = vector <vi>;
using vc = vector <char>;
using vvc = vector <vc>;
using vs = vector <string>;
using vvs = vector <vs>;
//g++ -std==c++14
//setprecision(10)
int x[8] = {1, 1, 1, 0, 0,-1,-1,-1};
int y[8] = {1, 0,-1, 1,-1, 1, 0,-1};
int h, w;
vvc mp;
int main(){
    cin >> h >> w;
    mp = vvc (h, vc (w));
    rep(i, h)rep(j, w) cin >> mp[i][j];
    rep(i, h){
        rep(j, w){
            int count = 0;
            if(mp[i][j] == '#')continue;
            rep(k,8){
                if(i + y[k] < 0 || h <= i + y[k] || j + x[k] < 0 || w <= j + x[k]);
                else if(mp[i + y[k]][j + x[k]] == '#')
                    count++;
            }
            mp[i][j] = '0' + count;
        }
    }
    rep(i, h){
        rep(j, w){
            cout << mp[i][j];
        }
        cout << endl;
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222


ll len[11], num[11], x[11];
ll y[11];

void dfs(ll cur) {
  if (cur == n) {
    ll sum = 0;
    rep(i, 3) if (!num[i]) return;
    rep(i, 3) {
      sum += llabs(y[i] - x[i]);
      if (num[i] > 1) sum += (num[i] - 1) * 10;
    }
    ans = min(ans, sum);
    return;
  }
  rep(i, 3) {
    num[i]++;
    x[i] += len[cur];
    dfs(cur + 1);
    num[i]--;
    x[i] -= len[cur];
  }
  dfs(cur + 1);
}


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


  cin >> n >> y[0] >> y[1] >> y[2];
  rep(i, n) cin >> len[i];
  ans = inf;
  dfs(0);
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
int n;
cin>>n;
long long power = 1;
for(int i = 1;i<=n;i++){
	power = (power * i)%1000000007;
}

cout<< power <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef std::uint64_t u64;
typedef std::int64_t  i64;
typedef std::uint32_t u32;
typedef std::int32_t  i32;

using namespace std;

int main(int argc, const char* argv[]) {
  int n, y;
  cin >> n >> y;
  
  for(int i = 0; i <= n; ++i) {
    for(int j = 0; j <= n - i; ++j) {
      int k = n - i - j;
      int sum = 10000 * i + 5000 * j + 1000 * k;
      if(sum == y) {
        cout << i << " " << j << " " << k;
        return 0;
      }
    }
  }

  cout << "-1 -1 -1";
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    string a, b;
    cin >> a >> b;
    int ab;
    ab = stoi(a+b);

    for (int i=1;i<=1000;i++) {
        if (i*i==ab){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

ll R(int i, int S, int A, int C) {
  if(i == 0) {
    return S;
  } else {
    return (A * R(i-1, S, A, C) + C) % 256;
  }
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int n; cin >> n;
    if(n == 0) break;
    vi I(n);
    REP(i, n) {
      cin >> I[i];
    }

    double mi = 10000000000;
    ll miS = 0;
    int miA = 0, miC = 0;
    bool endloop = false;
    REP(S, 16) {
      if(endloop) break;
      REP(A, 16) {
        if(endloop) break;
        REP(C, 16) {
          map<ll, int> O;
          REP(i, n) {
            ll tmp = (I[i] + R(i+1, S, A, C)) % 256;
            O[tmp]++;
          }

          double H = 0;
          MFOR(i, O) {
            H -= (((double)(i->second)) / n) * log(((double)(i->second)) / n);
          }
          if(H < mi-eps) {
            miS = S;
            miA = A;
            miC = C;
            mi = H;
          }
          if(H == 0) {
            cout << miS << " " << miA << " " << miC << endl;
            endloop = true;
            break;
          }
        }
      }
    }
    if(!endloop) cout << miS << " " << miA << " " << miC << endl;
  }
}



Measured memory_bytes: 3264
from  heapq import heappush, heappop, heapify

n,m,s,t=map(int,raw_input().split())

nl=[ [ ] for j in range(n+1) ] 

for i in range(m):
	u,v,a,b=map(int,raw_input().split())
	nl[u].append( (v,a,b) )
	nl[v].append( (u,a,b) )


def dij(v,type):
	d=[ float("inf") for i  in range(n+1)]
	d[v]=0

	Q=[]
	heappush(Q, (0,v ) )

	while len(Q)>0:
		base, u=heappop(Q)
		for v,yen,snuuk in nl[u]:
			if type=="y":alt=base+yen
			elif type=="s":alt=base+snuuk

			if d[v]> alt:
				d[v]=alt
				heappush(Q,( d[v], v ) )
	return d

d_y=dij(s,"y")
d_s=dij(t,"s")

val=float("inf")

A=[]
for i in range(n,0,-1):
	tmp=d_y[i]+d_s[i]
	val=min(val, tmp)
	A.append(val)

for i in reversed(A):
	print 10**15-i

Measured memory_bytes: 89116
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll n;
vector<vector<pair<ll,ll>>> A(16);
ll ans=0;
ll cnt=0;
bool used[BITLE(17)];
void dfs(ll dep,ll bit){
  if(dep==n){
    //   cnt++;
    bool hoge=true;
    for(ll i=0;i<n;i++){
      if(BITLE(i)&bit){
	//if(bit==4)
	  //cout<<bit<<" "<<i<<"!"<<endl;
	for(int j=0;j<A[i].size();j++){
	  //if(bit==4)
	    //	  cout<<i<<" "<<A[i][j].F<<" "<<A[i][j].S<<endl;
	  if(A[i][j].S == 1){
	    if(!(bit&BITLE(A[i][j].F)))hoge=false;
	  }else{
	    if(bit&BITLE(A[i][j].F))hoge=false;
	  }
	}
      }
    }
    //if(hoge)cout<<bit<<" "<<BITCNT(bit)<<endl;
    if(hoge)ans=max(ans,(ll)BITCNT(bit));
    return;
  }
  for(ll i=0;i<n;i++){
    if(used[bit|BITLE(i)])continue;
    if(BITLE(i)&bit)continue;
    used[bit|BITLE(i)]=true;
    dfs(dep+1,bit|BITLE(i));
    dfs(dep+1,bit);
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  for(int i=0;i<n;i++){
    ll a;cin>>a;
    for(int j=0;j<a;j++){
      ll x,y;cin>>x>>y;
      A[i].pb(mp(x-1,y));
    }
  }
  dfs(0,0);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[1000001],N,k,h[1000000];
int main(){

    int t;
    cin>>N>>k;
    for(int i=0; i<N; i++){
        cin>>h[i];
    }
    dp[0] = 0, dp[1] = abs(h[0] - h[1]);


    for(int i=2; i<N; i++){
            dp[i] = dp[i-1]+abs(h[i-1] - h[i]);
            for(int j=2; j<=min(i,k); j++)  {
                dp[i] =min(dp[i],dp[i-j]+abs(h[i-j] - h[i]));
                //cout<<dp[i]<<" ";
            }
            //cout<<"\n";
        }
    cout<<dp[N-1]<<"\n";



}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
    string S;
    cin >> S;
    int ans = 0;
    int cnt = 0;
    REP(i,S.size()){
        if('R' == S[i])cnt++;
        else cnt = 0;
        ans = max(ans,cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include<stdio.h>

int main(){
	int L,n;
	scanf("%d%d",&L,&n);
	int ans=0;
	for(int i=0;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		ans-=a*b;
	}
	if(ans>0)printf("1\n1 %d\n",ans);
	else if(ans<0)printf("1\n-1 %d\n",-ans);
	else puts("0");
}


Measured memory_bytes: 2148
#include<stdio.h>
int main()
{
	int a[120],t;
	for(int i = 0;i<3;i++)
		scanf("%d",&a[i]);
	for(int i = 0;i<3;i++)
	{
		if(a[i]>a[i+1])
		{
			t=a[i] + a[i+1];
			a[i]=t - a[i];
			a[i+1]=t - a[i];
		}
	}
	printf("%d",a[0]*a[1]/2);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
  long long int a[n];
    for(int i=0;i<n;i++)
      {
          cin>>a[i];
      }
    long long int s=0;
    sort(a,a+n);
    for(int i=0;i<(n-k);i++)
      {
          s+=a[i];
      }
      cout<<s;
      return 0;
}

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

using namespace std;

typedef long long ll;

const int MX = 155;

ll work_odd(int n, int k, ll mod)
{
	auto add = [=](ll &x, const ll &y){x = (x+y) % mod;};
	static ll f[2][MX][MX];
	int now = 0;
	memset(f[now], 0, sizeof(f[now]));
	f[now][0][0] = 1;
	for(int i=2-k; i<=n+2; i+=2)
	{
		int l = i, r = i+k;
		memset(f[now^1], 0, sizeof(f[now^1]));
		//l=0, r=0:
		for(int a=0; a<=k+1; a++)
			for(int b=0; b<=n; b++)
				add(f[now^1][0][0], f[now][a][b]);

		//l=1, r=0:
		if(1<=l && l<=n)
			for(int a=0; a<k+1; a++)
				for(int b=0; b<=n; b++)
					add(f[now^1][a+(a>0)][0], f[now][a][b]);
		
		//l=0, r=1:
		if(r <= n)
			for(int a=0; a<=k+1; a++)
				for(int b=0; b<=n; b++)
					add(f[now^1][0][b+1], f[now][a][b]);
		
		//l=1, r=1:
		if(1<=l && l<=n && r<=n)
			for(int a=0; a+1<=k+1; a++)
				for(int b=0; b+2<=k+1; b++)
					add(f[now^1][max(a+1, b+2)][b+1], f[now][a][b]);
		
		now ^= 1;
	}
	return f[now][0][0];
}

ll work_even(int n, int k, ll mod)
{
	auto add = [=](ll &x, const ll &y){x = (x+y) % mod;};
	static ll f[MX][MX];
	memset(f, 0, sizeof(f));
	f[0][0] = 1;
	for(int i=1; i<=n+1; i++)
	{
		for(int j=0; j<=k; j++) add(f[i][0], f[i-1][j]);
		for(int j=1; j<=k; j++) add(f[i][j], f[i-1][j-1]);
	}
	return f[n+1][0];
}

int main()
{
	int n, k;
	ll mod;
	scanf("%d%d%lld", &n, &k, &mod);
	if(k&1) printf("%lld\n", work_odd(n, k, mod));
	else printf("%lld\n", work_even(n/2, k/2, mod) * work_even(n-n/2, k/2, mod) % mod);
	return 0;
}

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

int limit=101;

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  int time[limit];

  for(int i=0; i<limit; i++){
    time[i] = 0;
    if(a<=i && i<b)time[i]++;
    if(c<=i && i<d)time[i]++;
  }

  int ans=0;
  for(int i=0; i<limit; i++){
    if(time[i]==2) ans++;
  }

  cout << ans << 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++)
int main(){
    string str;
    getline(cin, str);
    for(int i=0; i<str.size(); i++){
        char s = str[i];
        if (str[i] >= 'a' && str[i] <= 'z') str[i] += 'A' - 'a';
        else if (str[i] >= 'A' && str[i] <= 'Z') str[i] += 'a' - 'A';
    }
    cout << str << endl;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

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

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	string S;
	cin >> S;
	int ans = 0;
	rep(i, 2, SZ(S) - 1)
	{
		if (i % 2 == 1)continue;
		string ts = S.substr(0, SZ(S) - i);
		bool ok = true;
		rep(i, 0, SZ(ts) / 2)
		{
			if (ts[i] != ts[i + SZ(ts) / 2])
			{
				ok = false;
				break;
			}
		}
		if (ok)
		{
			ans = SZ(ts);
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;
string s;
int number(){
 if(s[0]-'0'==0||s[1]-'0'==0||s[2]-'0'==0){
   c =s[0]-'0'+s[1]-'0'+s[2]-'0';
   return c;

 }
 if(s[0]-'0'==1||s[1]-'0'==1||s[2]-'0'==1){
   c=s[0]-'0'+s[1]-'0'+s[2]-'0';
   return c;
 }
}




int main(){
 
 cin>>s;
 cout<<number()<<endl;
 return 0;
 

}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)1e5
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	ll n,k,i,s=0,c=0;cin>>k>>n;vi v(n);for(i=0;i<n;i++) cin>>v[i];
	for(i=1;i<n;i++) s=max(s,v[i]-v[i-1]),c+=s;s=max(s,v[0]+k-v[n-1]);
	cout<<k-s<<endl;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

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

    string s;
    cin >> s;

    int count = 0;
    rep (i, s.size()) {
        if (s[i] == 'x') {
            count++;
        }
    }

    if (count >= 8) {
        NO
    } else {
        YES
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef unsigned long long ull;
typedef vector<ull> vull;
int main() {
  ull n;
  cin >> n;
  vull a(n);
  rep(i, n) { cin >> a[i]; }
  ull count = 0;
  if (a[0] > 1) {
    count += a[0] - 1;
  }
  ull index = 2;
  REP(i, 1, n) {
    if (a[i] > index) {
      count += (a[i] - 1) / index;
    }
    if (a[i] == index) {
      index += 1;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 1656
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

// https://melheaven.hatenadiary.jp/entry/atcoder144
///約数の配列を返す
func makeDivisors(_ n:Int) -> [Int] {
    var divisors = [Int]()
    for i in 1..<Int(pow(Double(n), 0.5)) + 1 {
        if n % i == 0{
            divisors.append(i + n / i)
        }
    }
    
    return divisors
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}

func main() {
    let (s, k) = (readLine()!.map { Int(String($0))! }, readInt())
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    var f = 1
    var count = 0
    while f <= 1 && count < k {
        f = s[count]
        count += 1
    }
    print(f)
}

main()


Measured memory_bytes: 13224
fn main() {
    let _ = read::<u32>();
    let v = read_vec::<u32>();

    let mut mi = u32::max_value();
    let mut ma = 0;
    for i in v {
        if i < mi {
            mi = i;
        }
        if i > ma {
            ma = i;
        }
    }

    println!("{}", ma - mi);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let hw: Vec<usize> = read_vec();
    let h = hw[0];
    let w = hw[1];
    let mut m: Vec<Vec<char>> = vec![];
    for _ in 0..h {
        let s: String = read();
        let cv: Vec<char> = s.chars().collect();
        m.push(cv);
    }

    let mut hm: Vec<Vec<u32>> = vec![vec![0; w]; h];
    let mut vm: Vec<Vec<u32>> = vec![vec![0; w]; h];

    let mut tmp: usize;

    for i in 0..h {
        let mut j: usize = 0;
        while j < w {
            tmp = j;
            while j < w && m[i][j] == '.' {
                j += 1;
            }
            for k in tmp..j {
                hm[i][k] = (j - tmp) as u32;
            }

            tmp = j;
            while j < w && m[i][j] == '#' {
                j += 1;
            }
            for k in tmp..j {
                hm[i][k] = 0;
            }
        }
    }

    for j in 0..w {
        let mut i: usize = 0;
        while i < h {
            tmp = i;
            while i < h && m[i][j] == '.' {
                i += 1;
            }
            for k in tmp..i {
                vm[k][j] = (i - tmp) as u32;
            }

            tmp = i;
            while i < h && m[i][j] == '#' {
                i += 1;
            }
            for k in tmp..i {
                vm[k][j] = 0;
            }
        }
    }

    let mut ans: u32 = 0;
    for i in 0..h {
        for j in 0..w {
            let t1 = hm[i][j];
            let t2 = vm[i][j];
            if t1 > 0 && t2 > 0 {
                if t1 + t2 - 1 > ans {
                    ans = t1 + t2 - 1;
                }
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 53500
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
f = [1 << 31] * n 

f[0] = 0
for i in range(0, n):
    lim = max(i - k, 0)
    for j in range(lim, i):
        f[i] = min(f[i], abs(h[j] - h[i]) + f[j])

print(f[n - 1])

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){
    
    int n; scanf("%d", &n);    
    vector<ll> t(n), a(n);
    rep(i, n) scanf("%lld", &t[i]);
    rep(i, n) scanf("%lld", &a[i]);
    if( *max_element(a.begin(), a.end()) != *max_element(t.begin(), t.end()) ) {cout << 0 << endl; return 0;}
    ll ans = 1;
    set<int> cfd = {0, n-1};
    for(int i = 1; i < n; ++i){
        if(t[i-1] != t[i]){
            cfd.insert(i);
            if(t[i] > a[i]){
                ans = 0;
                break;        
            }
        }
    }
    for(int i = n-2; i >= 0; --i){
        if(a[i] != a[i+1]){
            cfd.insert(i);
            if(a[i] > t[i]){
                ans = 0;
                break;
            }
        }
    }
    rep(i, n) if(cfd.find(i) == cfd.end()) (ans *= min(a[i], t[i])) %= MOD;

    ppp(ans);

    return 0;
}


Measured memory_bytes: 6528
#include<stdio.h>

int a[3000];
long long dp[3005][3005][3];

#define MODNUM 998244353

int main(){
	int n, s;
	int i, j;

	scanf("%d %d", &n, &s);
	for(i=0; i<n; i++){
		scanf("%d", a+i);
	}

	for(i=0; i<n; i++){
		for(j=0; j<s; j++){
			dp[i][j][0] = 0;
			dp[i][j][1] = 0;
			dp[i][j][2] = 0;
		}
	}

	dp[0][0][0] = 1;
	for(i=0; i<n; i++){
		for(j=0; j<=s; j++){
			dp[i+1][j][0] += dp[i][j][0];
			dp[i+1][j][0] %= MODNUM;
			dp[i+1][j][1] += dp[i][j][0] + dp[i][j][1];
			dp[i+1][j][1] %= MODNUM;
			dp[i+1][j][2] += dp[i][j][0] + dp[i][j][1] + dp[i][j][2];
			dp[i+1][j][2] %= MODNUM;
			if(j + a[i] <= s){
				dp[i+1][j+a[i]][1] += dp[i][j][0] + dp[i][j][1];
				dp[i+1][j+a[i]][1] %= MODNUM;
				dp[i+1][j+a[i]][2] += dp[i][j][0] + dp[i][j][1];
				dp[i+1][j+a[i]][2] %= MODNUM;
			}
		}
	}

	printf("%lld", dp[n][s][2]);
	return 0;
}


Measured memory_bytes: 211584
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,s,g) for(int i = s;i < g;i++)
int main() {
    ll n, ans = 0, s = 0; cin >> n; vector<ll> a(n);
    map<ll, ll> L, R;
    rep(i, 0, n) {
        cin >> a[i];
        L[i - a[i]]++;
        R[i + a[i]]++;
        s = max(s, i - a[i]);
    }
    rep(i, 1, s+1) ans += L[i] * R[i];
    cout << ans << endl;
}

Measured memory_bytes: 47528
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll k;
    cin >> k;
    vector<ll> a(k+1, 0);
    for(ll i = 1; i <= k; i++){
        for(ll j = 1; j <= k; j++){
            ll c = __gcd(i,j);
            a[c]++;
        }
    }
    ll ans = 0;
    for(ll i = 1; i <= k; i++){
        if(a[i]==0) continue;
        for(ll j = 1; j <= k; j++){
            ans+=__gcd(i,j)*a[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
n = int(input())
p = list(map(int, input().split()))
q = [0] * (n + 2)
c = 0
ans = 0
for i in range(n):
    if p[i] == i + 1:
        q[i + 1] = 1
for i in range(1, n + 2):
    if q[i] == 1 and q[i - 1] == 0:
        c = 1
    elif q[i] == 1 and q[i - 1] == 1:
        c += 1
    elif q[i] == 0 and q[i - 1] == 1:
        ans += (c + 1) // 2
print(ans)

Measured memory_bytes: 13880
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define int long long
#define endl "\n"
using namespace std;
int n  , m, x  , c , k ;
const int N = 1000000;
int z ;
int inf = 1e14;
int dp[N][5];
int a[N];

int r , g , b;

int BA = 0;
int A = 0;
int B = 0;

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    cin >> n ;
    int cnt = 0;

    for (int i=1;i<=n;i++){
        bool f1 = 0;
        bool f2 = 0;
        string s;
        cin >> s;
        if (s[0] == 'B'){
            f1 = 1;
        }
        if (s[s.size()-1] == 'A'){
            f2 = 1;
        }
        for (int i=1;i<s.size();i++){
            if (s[i-1] == 'A' && s[i] == 'B'){
                cnt++;
            }
        }
        if (f1 && f2){
            BA++;
        }
        else
        if (f1){
            B++;
        }
        else
        if (f2){
            A++;
        }
    }

    if (BA != 0)
        cnt = cnt + BA - 1;

    if (B+A == 0){
        cout << cnt << endl;
        return 0;
    }

    if (BA != 0)
        B++ , A++;


    cnt = cnt + min(B , A) ;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int K; cin >> K;
    int X; cin >> X;
    if (K * 500 >= X) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 256
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define wl(n) while(n--)
#define fl(i,a,b) for(i=a; i<b; i++)
#define rev(i,a,b) for(i=a; i>=b; i--)

#define si(n) scanf("%d", &n)
#define sll(l) scanf("%lld",&l)
#define ss(s) scanf("%s", s)
#define sc(c) scanf("%c", &c)
#define sd(f) scanf("%lf", &f)

#define pi(n) printf("%d\n", n)
#define pll(l) printf("%lld\n", l)
#define ps(s) printf("%s\n", s)
#define pc(c) printf("%c\n", c)
#define pd(f) printf("%lf\n", f)

#define debug(x) cout<<"\n#("<<x<<")#\n"
#define nline printf("\n")

#define mem(a,i) memset(a,i,sizeof(a))

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define PB push_back
#define SZ size
#define MP make_pair

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const int MAX_LIMIT = 1003;

int arr[MAX_LIMIT], vis[MAX_LIMIT];
std::vector<int> toTake;
int nodes;

const string NOT = "Impossible";
const string GOT =  "Possible";

int main()
{
	int i, j;

	cin >> nodes;

	fl(i,0,nodes)
	{
		cin >> arr[i];
	}

	sort(arr, arr + nodes);

	if(nodes == 1)
	{
		if(arr[0] == 0 )
			cout << GOT;
		else
			cout << NOT;
		return 0;
	}
	if(nodes == 2)
	{
		if(arr[0] == 1 && arr[1] == 1)
			cout << GOT;
		else
			cout << NOT;
		return 0;
	}

	int highest = arr[nodes - 1];
	int lowest = arr[nodes - 1] / 2;
	if(highest % 2 == 1)
		lowest += 1;

	int offset = 2;
	if(highest % 2 == 0)
		offset = 1;

	if(highest == lowest)
	{
		cout << NOT;
		return 0;
	}

	fl(i,lowest + 1,highest + 1)
	{
		toTake.PB(i);
	}

	// fl(i,0,toTake.SZ())
	// 	cout << toTake[i] << " ";
	// nline;

	if(arr[0] < lowest)
	{
		cout << NOT;
		return 0;
	}

	int left = 0;
	while(1)
	{
		left = 0;
		fl(i,0,nodes)
			if(!vis[i])	left++;
		if(left <= offset)
			break;

		// fl(i,0,nodes)
		// 	cout << vis[i] << " ";
		// nline;

		fl(i,0,toTake.SZ())
		{
			bool taken = 0;
			fl(j,0,nodes)
			{
				if(!vis[j] && arr[j] == toTake[i])
				{
					vis[j] = 1;
					taken = 1;
					break;
				}
			}
			if(!taken)
			{
				cout << NOT;
				return 0;
			}
		}
		break;
	}

	// cout << "here";
	// fl(i,0,nodes)
	// 	if(!vis[i] &&)

	if ( ( (offset == 2 && highest%2==1 && arr[0] == lowest && arr[1] == lowest && arr[2] != lowest) || (offset == 1 && highest%2 == 0 && arr[0] == lowest && arr[1] != lowest) ) )
		cout << GOT;
	else
		cout << NOT;


	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;
int main(){ 
   int a,b,c,x;
   cin>>a>>b>>c;
   cin>>x;
   int ans=0;
   rep(i,a+1){
      rep(j,b+1){
         rep(k,c+1){
            if(500*i+100*j+50*k==x) ans++;
         }
      }
   }
   cout<<ans;


   
   return 0;
}

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

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

  if(S.size() < 4){
    cout << "No" << endl;
  }
  else{
    if(S.at(0) == 'Y' && S.at(1) == 'A' && S.at(2) == 'K' && S.at(3) == 'I'){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }  
}

Measured memory_bytes: 256
n = int(input())
s = input()
if len(s)%2 ==1:
  print("No")
  exit()

s_h = s[:int((len(s)/2))]

s_h_2 = s[int((len(s)/2)):]


if s_h == s_h_2:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9112
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  string F[N];
  string BK[N];
  string BN[N];
  string SK[N];
  string SN[N];
  for(int i=0;i<N;i++){
    cin >> F[i];
    BK[i] = F[i].at(0);
    SK[i] = F[i].at(0);
    BN[i] = F[i].at(1);
    SN[i] = F[i].at(1);
  }
  for(int i=0;i<N;i++){
    for(int j=N-1;j>0;j--){
      if(BN[j]<BN[j-1]){
        swap(BN[j],BN[j-1]);
        swap(BK[j],BK[j-1]);
      }
    }
  }
  for(int i=0;i<N;i++){
    if(i<N-1){
    cout << BK[i] << BN[i] << " ";
    }
    else if(i==N-1){
      cout << BK[i] << BN[i] << endl << "Stable" << endl;
    }
  }
  for(int i=0;i<N-1;i++){
    int min=i;
    for(int j=i;j<N;j++){
      if(SN[j]<SN[min]){
        min =j;
      }
    }    
    swap(SN[i],SN[min]);
    swap(SK[i],SK[min]);
  }
  for(int i=0;i<N;i++){
    if(i<N-1){
      cout << SK[i] << SN[i] << " ";
    }
    else if(i==N-1){
      cout << SK[i] << SN[i] << endl;
    }
  }
  for(int i=0;i<N;i++){
    if(BK[i]!=SK[i]){
      cout << "Not stable" << endl;
      break;
    }
    if(i==N-1){
      cout << "Stable" << endl;
    }
  }
}  


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

int main(){
    int h,a;
    cin >> h >> a;
    int ans=0;
    while(h>0){
        h -= a;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include <map>
#include <iostream>
using namespace std;
void no() { cout << "No\n"; exit(0); }
void yes() { cout << "Yes\n"; exit(0); }


int main() {
    int n; cin >> n;
    map<int, int> c;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        c[x]++;
    }
    if (c.size() > 3) no();
    if (c.size() == 1) { if (c.begin()->first == 0) yes(); else no(); }
    if (c.size() == 2) {
        if (c.begin()->first == 0 && c.rbegin()->second == 2*n/3 && n%3==0) yes(); else no();
    }
    auto it = c.begin();
    int x = it->first, y = next(it)->first, z = next(next(it))->first;
    if (n%3==0 && x == (y^z) && c[x] == n/3 && c[y] == n/3) yes(); else no();
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+1;

int main()
{
	string s;
	cin >> s;
	int ans = s.size();
	for(int i=0; i+1<s.size(); i++) if(s[i] == s[i+1]) ans--, i+=2;
	cout << ans << endl;
}	


Measured memory_bytes: 640
#include <bits/stdc++.h>
# define N 105
using namespace std;
typedef long long LL;
char s[N];
int ans[30];
int main(){
  scanf ("%s", s + 1);
  int len = strlen(s + 1);
   for (int i = 1; i <= len; ++i)
      ans[s[i] - 'a' + 1] ++;
   for (int i = 1; i <= 26; ++i)
      if (ans[i] % 2 == 1){
         printf("No\n");
          return 0;
       }
   printf("Yes\n");
   return 0;
}


Measured memory_bytes: 256
def resolve():
    H, W = map(int, input().split())
    s = [input() for _ in range(H)]
    from collections import defaultdict
    cnt = defaultdict(int)
    for item in s:
        for c in item:
            cnt[c] += 1
    if '#' not in cnt:
        print(H+W-2)
        quit()

    def bfs(row, col, R, C, s):
        from collections import deque
        q = deque()
        q.append([(row, col), 0])
        seen = set()
        ans = 0
        while q:
            (r, c), dist = q.popleft()
            ans = max(dist, ans)
            seen.add((r, c))
            for (next_r, next_c) in ((r+1, c), (r-1, c), (r, c+1), (r, c-1)):
                if (next_r, next_c) not in seen and \
                    0 <= next_r < R and 0 <= next_c < C and \
                   s[next_r][next_c] == '.':
                    q.append([(next_r, next_c), dist + 1])
        return ans

    max_v = 0
    for h in range(H):
        for w in range(W):
            if s[h][w] == '.':
                max_v = max(max_v, bfs(h, w, H, W, s))
    print(max_v)
resolve()

Measured memory_bytes: 43372
//#include <bits/stdc++.h> // header file includes every Standard library
#include<iostream>
using namespace std;

int main() {
	float d,t,s;
	cin>>d>>t>>s;
	float k=d/s;
	if(k<=(float)t){
		cout<<"Yes";
	}
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3200