akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long n, i, j, k, s;
	cin >> n;
	vector<long long> ct(n + 1, 0), a(n), ans(n);
	for (i = 0; i < n; i++) {
		cin >> a[i];
		ct[a[i]]++;
	}

	s = 0;
	for (i = 0; i <= n; i++)  s += ct[i] * (ct[i] - 1) / 2;

	for (i = 0; i < n; i++) {
		long long x;
		if (ct[a[i]] <= 1) x = 0;
		else x = ct[a[i]] * (ct[a[i]] - 1) / 2 - (ct[a[i]] - 2) * (ct[a[i]] - 1) / 2;
		ans[i] = s - x;
		cout << ans[i] << "\n";
	}

	return 0;
}


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

int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    
    int N,M;

    cin>>N>>M;

    if(N == M){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
    return 0;
}

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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int main() {
  ll n, m  ;
  cin >> n >> m ;
  if(n>m) swap(n,m) ;

  if(m == 1)cout << "1"<< endl ;
  else if(n == 1) cout << (m-2) << endl ;
  else cout << (n-2)*(m-2) <<endl ;
	
  return 0 ;
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

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

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N,K;
    cin >>N>>K;
    string S;
    cin >>S;
    
    //複数の矢の集合体と捉える。
    //rl　→←の数　一方(どちらでもよい)を戻して幸福+2
    //上をやれるだけやる。ただし最後の1つがどうしても外側にあぶれるのでmaxn-1
    int ans=0;
    //-----------------------------------
    rep(i,N-1){
        if(S[i]==S[i+1])ans++;
    }
    cout << min(N-1,ans+K*2)<<endl;
    return (0);
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>

using namespace std;

#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 REP(i,n) FOR(i,0,n)

double dp[301][301][301];
double N;

double solve(int i, int j, int k) {
  if (dp[i][j][k] != -1)
    return dp[i][j][k];
  double val = 0.0;
  double dx = N / (i + j + k);
  if (i != 0)
    val += (solve(i-1, j, k) + dx) * i / ((double)(i + j + k));
  if (j != 0)
    val += (solve(i+1, j-1, k) + dx) * j / ((double)(i + j + k));
  if (k != 0)
    val += (solve(i, j+1, k-1) + dx) * k / ((double)(i + j + k));
  dp[i][j][k] = val;
  return val;
}
int main() {
  cin >> N;

  int I = 0, J = 0, K = 0;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    if (a == 1)
      ++I;
    if (a == 2)
      ++J;
    if (a == 3)
      ++K;
  }
  REP(i, 301) {
    REP(j, 301) {
      REP(k, 301) {
        dp[i][j][k] = -1;
      }
    }
  }
  cout << fixed << setprecision(10) << solve(I, J, K) << endl;
}


Measured memory_bytes: 213376
#include<bits/stdc++.h>
using namespace std;
struct star{
    int star_x[1000];
    int star_y[1000];
};
int main()
{
    int n,m;
    while(cin>>n,n){
        struct star serch,picture,difference;
        for(int i=0;i<n;i++)cin>>serch.star_x[i]>>serch.star_y[i];
        cin>>m;
        for(int i=0;i<m;i++){
            cin>>picture.star_x[i]>>picture.star_y[i];
            difference.star_x[i]=picture.star_x[i]-serch.star_x[0];
            difference.star_y[i]=picture.star_y[i]-serch.star_y[0];
        }
        for(int i=0;i<m;i++){
            bool now=0;
            for(int j=0;j<n&&!now;j++){
                bool place=0;
                for(int k=0;k<m&&!place;k++)if(difference.star_x[i]==picture.star_x[k]-serch.star_x[j]&&difference.star_y[i]==picture.star_y[k]-serch.star_y[j])place=1;
                if(!place)now=1;
            }
            if(!now)cout<<difference.star_x[i]<<" "<<difference.star_y[i]<<endl;
        }
    }
}

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

const int INF = INT_MAX / 2;

int main()
{
    int n, m;
    cin >> n >> m;

    vector<vector<int> > d(m, vector<int>(m));
    for(int i=0; i<m; ++i){
        for(int j=0; j<m; ++j){
            cin >> d[i][j];
        }
    }

    vector<vector<int> > cnt(3, vector<int>(m));
    for(int i=0; i<n; ++i){
        for(int j=0; j<n; ++j){
            int c;
            cin >> c;
            ++ cnt[(i+j)%3][c-1];
        }
    }

    vector<vector<int> > v(3, vector<int>(m, 0));
    for(int i=0; i<3; ++i){
        for(int y=0; y<m; ++y){
            for(int x=0; x<m; ++x){
                v[i][y] += d[x][y] * cnt[i][x];
            }
        }
    }

    int ans = INF;
    for(int i=0; i<m; ++i){
        for(int j=0; j<m; ++j){
            for(int k=0; k<m; ++k){
                if(i != j && j != k && k != i)
                    ans = min(ans, v[0][i] + v[1][j] + v[2][k]);
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
N = int(input())
a = list(map(int,input().split()))
flg = 0
cnt = 1
brk = 0
for i in range(N):
    if a[i] == cnt:
        cnt += 1
        flg = 1
    else:
        brk += 1
if flg == 0:
    print(-1)
else: print(brk)

Measured memory_bytes: 26140
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

n,m,k = map(int,input().split())
Max = n*m
#二項係数とその逆元テーブルを作る前処理
fac = [0]*(Max)
finv = [0]*(Max)
inv = [0]*(Max)
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,Max):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
#O(1)でmod計算した組合せ数を計算
def C(n,r):
    if n < r:
        return 0
    if n < 0 or r < 0 :
        return 0
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod
#mod計算した順列の計算
def P(n,r):
    if n < r:
        return 0
    if n<0 or r<0:
        return 0
    return (fac[n]*finv[n-r])%mod


c = C(n*m-2,k-2)
res = 0

for i in range(1,n):
    res += i * (n-i) *(m**2)*c
    res %= mod

for i in range(1,m):
    res += i*(m-i)*(n**2)*c
    res %= mod
print(res)

Measured memory_bytes: 43760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
const ll NIL = (-1)*(pow(2, 63) - 1);
struct Node {
    ll key = NIL;
    int p = -1, l = -1, r = -1; // p, l, r is all id
};
Node u[500000];
int id, root;
void insert(int node){
    int y = u[node].p, x = root;
    while(x != -1 && u[x].key != NIL){
        y = x;
        if(u[node].key < u[x].key)x = u[x].l;
        else x = u[x].r;
    }
    u[node].p = y;

    if(y == -1)root = node;
    else if(u[node].key < u[y].key)u[y].l = node;
    else u[y].r  = node; 
}
void inorder(int node){
    if(u[node].l != -1)inorder(u[node].l);
    if(u[node].r != -1) {
        cout << " " << u[node].key;
        inorder(u[node].r);
        return;
    }
    cout << " " << u[node].key;
    return;
}
void preorder(int node){
    cout << " " << u[node].key;
    if(u[node].l == -1 && u[node].r == -1)return;
    if(u[node].l != -1)preorder(u[node].l);
    if(u[node].r != -1)preorder(u[node].r);
}
int find(ll v){
    int node = root;
    bool found = 0;
    while(node != -1 && !found){
        if(u[node].key == v)found = 1;
        else if(u[node].key  < v)node = u[node].r;
        else node = u[node].l;
    }
    if(found)return node;
    else return -1;
}
void del1(int node){
    int parent = u[node].p;
    if(parent == -1){
        root = id;
        return;
    }
    if(u[parent].key < u[node].key)u[parent].r = -1;
    else if(u[parent].key > u[node].key)u[parent].l = -1;
    else u[parent].r = -1;
}
void del2(int node){
    int parent = u[node].p;
    int chil = max(u[node].l, u[node].r);
    if(parent == -1){
        root = chil;
        return;
    }

    if(u[parent].key > u[node].key)u[parent].l = chil;
    else u[parent].r = chil;
    u[chil].p = parent;
}
void del(int node){
    int left = u[node].l, right = u[node].r;
    if(left == -1 && right == -1)del1(node);
    else if(left == -1 || right == -1)del2(node);
    else {
        int it = u[node].r;
        while(u[it].l != -1)it = u[it].l;
        u[node].key = u[it].key;
        del(it);
    }
}
int main(){
    root = -1;
    ll n; cin >> n;
    rep(i,n){
        string com;
        ll v;
        cin >> com;
        if(com == "insert" || com == "find" || com == "delete")cin >> v;
        if(com == "insert"){
            u[id].key = v;
            insert(id++);
        }
        else if(com == "print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
        else if(com == "find")cout << ((find(v) != -1)? "yes": "no") << endl;
        else del(find(v));
    }
    return 0;
}


Measured memory_bytes: 14884
/*
 * 5_20_B.cpp
 *
 *  Created on: 2017/05/20
 *      Author: 16k1117
 */

#include<iostream>

using namespace std;

int main(){

	int H , W;

	cin >> H;
	cin >> W;

	char **a = new char*[H];

	for(int i = 0; i < H; i++){
		a[i] = new char[W];
	}

	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin >> a[i][j];
		}
	}

	for(int i = 0; i < W + 2; i++){
		cout << "#";
	}
	cout << endl;
	for(int i = 0; i < H; i++){
		cout << "#";
		for(int j = 0; j < W; j++){
			cout << a[i][j];
		}
		cout << "#" << endl;
	}
	for(int i = 0; i < W + 2; i++){
			cout << "#";
		}
}


Measured memory_bytes: 256
s = input()
t = input()
n, m = len(s), len(t)
dp = [[0]*(m+1) for _ in range(n+1)]

for i in range(1, n+1):
    for j in range(1, m+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

i, j = n, m

ans = []

while i > 0 and j > 0:
    if dp[i][j] == dp[i][j-1]:
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    else:
        ans.append(s[i-1])
        i -= 1
        j -= 1

print("".join(reversed(ans)))

Measured memory_bytes: 144472
/**
 *    author:  FromDihPout
 *    created: 2020-07-27
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    bool maximize = n & 1;
    vector<long long> prev(n);
    for (int i = 0; i < n; i++) {
        if (maximize)
            prev[i] = a[i];
        else
            prev[i] = -a[i];
    }
    for (int size = 1; size < n; size++) {
        maximize = !maximize;
        vector<long long> curr(n - size);
        for (int i = 0; i < n - size; i++) {
            if (maximize) {
                curr[i] = max(prev[i + 1] + a[i], prev[i] + a[i + size]);
            }
            else {
                curr[i] = min(prev[i + 1] - a[i], prev[i] - a[i + size]);
            }
        }
        prev = curr;
    }
    cout << prev[0] << endl;
    return 0;
}

Measured memory_bytes: 3712
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main(){
	int n,a[M];
	ll ans=0;
	cin>>n;
	rep(i,0,n)cin>>a[i];
	rep(i,1,n)ans+=abs(a[i-1]-a[i]);
	ans=ans+abs(a[0])+abs(a[n-1]);
	rep(i,0,n){
		if(i==0)cout<<ans-abs(a[0])+abs(a[1])-abs(a[0]-a[1])<<endl;
		else if(i==n-1)cout<<ans-abs(a[n-1])+abs(a[n-2])-abs(a[n-1]-a[n-2])<<endl;
		else cout<<ans-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1])<<endl;
	}
	return 0;
}

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

int main() {
    int h,w;
    while (1) {
        cin>>h>>w;
        if(h==0 && w==0)break;

        for (int i = 1; i <= h; ++i) {
            for (int j = 1; j <= w; ++j) {
                cout<<'#';
                if(j==w)cout<<endl;
            }
        }
        cout<<endl;
    }
    return 0;

}


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

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

typedef long long ll;
typedef pair<int,int> pii;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<pii> v[16];
    REP(i, N) {
        int tmp; cin >> tmp;
        REP(j, tmp) {
            int x,y; cin >> x >> y;
            v[i].push_back(make_pair(x-1, y));
        }
    }
    int res = 0;
    REP(i, 1 << N) {
        bool flag = true;
        int cnt = 0;
        REP(j, N) {
            flag = true;
            if (i >> j & 1) { //j番目が正直者の場合
                for(auto x: v[j]) {
                    if((i >> x.first) % 2 == 1){ 
                        if (x.second == 1) continue;
                        else {
                            flag = false;
                            break;
                        }
                    }//この集合にたいして正しい証言になっている
                    else {
                        if (x.second == 0) continue;
                        else {
                            flag = false;
                            break;
                        }
                    }
                }
                if (flag) cnt++;
                else break;
            }
        }
        if (flag) {
            res = max(res, cnt);
            cerr << i <<":true:" << cnt << endl;
        }
        else {
            cerr << i << ":false" << endl;
        }

    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var ab = Console.ReadLine().Trim().Split(' ');
            var val = int.Parse(ab[0] + ab[1]);
            var tmp = (int)Math.Sqrt(val);
            Console.WriteLine(tmp * tmp == val ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13140
let explode s =
    let rec exp i l =
        if i < 0 then l else exp (i - 1) (s.[i] :: l) in
    exp (String.length s - 1) []


let count2 l =
    let is2 c = if c = '2' then 1 else 0 in
    let rec cnt2 l c =
        match l with
        | car::cdr -> cnt2 cdr (c + is2 car)
        | [] -> c in
    cnt2 l 0


let () =
    let n = read_line () in
    let l = explode n in
    begin
        print_int (count2 l);
        print_newline ()
    end


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    string s[N];
    int ans = 0;
    int a = 0, b = 0, c = 0;
    rep(i, N){
        cin >> s[i];
        if(s[i][0] == 'B' && s[i][sz(s[i])-1] == 'A') c++;
        if(s[i][0] == 'B') b++;
        if(s[i][sz(s[i])-1] == 'A') a++;
        rep(j, sz(s[i])-1){
            if(s[i][j] == 'A' && s[i][j+1] == 'B') ans++;
        }
    }
    if(a == c && b == c && c > 0) ans += c-1;
    else ans += min({a, b, N-1});
    cout << ans << endl;
}

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

#define TOT 2000001

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

    int k;

    vector<int> a;
    vector<int> b;
    vector<int> c;
    
    for (int i = 0; i < n; i++)
    {
        cin >> k;
        a.push_back(k);
    }
    for (int i = 0; i < n; i++)
    {
        cin >> k;
        b.push_back(k);
    }
    for (int i = 0; i < n; i++)
    {
        cin >> k;
        c.push_back(k);
    }

    int ai, ai_old = -1, total = 0;

    for (int i = 0; i < n; i++)
    {
        ai = a[i];
        total += b[ai-1];
        if (i != 0 && ai_old == (ai - 1))
        {
            total += c[ai_old-1];
        }
        ai_old = ai;
    }

    cout << total << endl;

}


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 3001
#define MOD 998244353

ll N,X,A[maxn];
ll dp[maxn][maxn];

int main(){
	fast;
	
	cin>>N>>X;
	FOR(i,1,N) cin>>A[i];
	
	dp[0][0] = 1;
	FOR(i,1,N){
		FOR(j,0,X){
			dp[i][j] = (2 * dp[i-1][j]) % MOD;
			if (j - A[i] >= 0){
				dp[i][j] += dp[i-1][j-A[i]];
				dp[i][j] %= MOD;
			}
		}
	}
	cout<<dp[N][X];
}



Measured memory_bytes: 73928
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int i,n,ans=0,gen=0;cin>>n;
	vector<int>a(n);
	vector<int>hi(n);
	for(i=0;i<n;i++){cin>>a[i];}
	for(i=0;i<n;i++){
		if(a[i]==0){gen=mod;}
		if(a[i]<0){mineq(gen,-a[i]);}
		maxeq(hi[i],gen);
		gen--;
	}
	REV(a);REV(hi);
	for(i=0;i<n;i++){
		if(a[i]==0){gen=mod;}
		if(a[i]<0){mineq(gen,-a[i]);}
		maxeq(hi[i],gen);
		gen--;
	}
	for(i=0;i<n;i++){
		if(a[i]>0){ans+=min(hi[i],a[i]);}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3600
n,m= map(int,input().split())
a = list(map(int,input().split()))[:n]

s = sum(a)
t = s * (1/(4*m))

r=0

for i in range(n):
    if a[i] >= t :r+=1


if r >= m:
    print('Yes')
else:print('No')

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

N, K=map(int, input().split())
A = list(map(int,input().split()))
now=0
rireki=[0]*N
isou=1
hazimete=0
for i in range(4*N):
    if rireki[now]==0:
        rireki[now]=1
        startnum=i
        start=now
    else:
        if hazimete==1:
            startnum=i
            start=now
        hazimte=1
        if rireki[now]==1:
            rireki[now]=2
        else:
            if rireki[now]==2:
                rireki[now]=3
                isou=i-startnum-1
                break
    #print("{}".format(now))
    now=A[now]-1

#print("{}".format(isou))
amari=(K-startnum-1)%isou

for i in range(amari):
    now=A[now]-1
#print("{}".format(amari))
if K>startnum:
    print("{}".format(now+1))
else:
    now=0
    for i in range(K):
        now=A[now]-1
    print("{}".format(now+1))


Measured memory_bytes: 32248
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pp() pop_back()
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 /*int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }*/
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int a){
	par= vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0)
      return a;
    else
      return par[a]=find(par[a]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
int gcm(int a,int b){
    if(b==0)
        return a;
    return gcm(b,a%b);
}
int lcm(int a,int b){
    return a/gcm(a,b)*b;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
/*struct dfs(){

}*/
signed main(){
	string a;
	cin>>a;
	int b=0;
	int c=0;
	fo(i,a.sz){
		if(a[i]=='W'){
			c+=i-b;
			b++;
		}
	}
	cout<<c<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> c(a.begin(), a.end());

    ll ans = inf;
    ll csum = 0;
    ll num = 0;
    bool is_positive = true;
    rep(i, n) {
        csum += c[i];
        if (is_positive) {
            if (csum <= 0) {
                num += abs(1 - csum);
                csum = 1;
            }
        } else {
            if (csum >= 0) {
                num += abs(csum + 1);
                csum = -1;
            }
        }

        is_positive = !is_positive;
    }
    ans = min(ans, num);

    csum = 0;
    num = 0;
    is_positive = false;
    rep(i, n) {
        csum += c[i];
        if (is_positive) {
            if (csum <= 0) {
                num += abs(1 - csum);
                csum = 1;
            }
        } else {
            if (csum >= 0) {
                num += abs(csum + 1);
                csum = -1;
            }
        }
        is_positive = !is_positive;
    }
    ans = min(ans, num);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
s = input()
t = input()
s = "".join(sorted(list(s)))
t = "".join(sorted(list(t),reverse=True))
import string
letter = list(string.ascii_lowercase)
for i in range(min(len(s), len(t))) :
    if letter.index(s[i]) == letter.index(t[i]) :
        continue
    elif letter.index(s[i]) < letter.index(t[i]) :
        ans = "Yes"
        break
    elif letter.index(s[i]) > letter.index(t[i]) :
        ans = "No"
        break
else :
    if len(s) < len(t) :
        ans = "Yes"
    elif len(s) >= len(t) :
        ans = "No"
print(ans)

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e10;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
typedef tuple<int, int, int> Q;


int main() {
    string s, t;
    cin >> s >> t;

    for (int i = 0; i < s.size(); i++) {
        string d = s.substr(i) + s.substr(0, i);
        if (d == t) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static boolean solve() {
		int h = in.nextInt();
		int m = in.nextInt();
		int s = in.nextInt();
		if (h + m + s == -3) return false;

		int x = h*3600 + m*60 + s;

		x = 7200 - x;

		out.println(toString(x));
		out.println(toString(x*3));

		return true;
	}

	static String toString(int t) {
		String res = "";
		res += String.valueOf(t/3600).length() == 1 ? "0" + String.valueOf(t/3600) : String.valueOf(t/3600);
		t %= 3600;
		res += ":";
		res += String.valueOf(t/60).length() == 1 ? "0" + String.valueOf(t/60) : String.valueOf(t/60);
		t %= 60;
		res += ":";
		res += String.valueOf(t).length() == 1 ? "0" + String.valueOf(t) : String.valueOf(t);

		return res;
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		while(solve());
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 26440
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int n,m;
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    vector<int>a(n);
    vector<int>x(m),y(m);
    vector<int>c(n+1,0);
    rep(i,n){
        cin >> a[i];
        c[a[i]]++;
    }
    int ans = 0;
    vector<int>k(n*2,0);
    for(int i = 1; i <= n; i++){
        for(int j = i-1+n; j >= i-c[i]+n ; j--){
            k[j]++;
        }
    }
    for(int i = n; i < n*2; i++){
        if(k[i] == 0){
            ans++;
        }
    }
    rep(i,m){
        cin >> x[i] >> y[i];
        x[i]--;
        int old = a[x[i]];
        int now = y[i];
        if(old == now){
            cout << ans << endl;
            continue;
        }
        k[n+now-c[now]-1]++;
        if(k[n+now-c[now]-1]==1 && now-c[now]-1>=0)ans--;
        k[n+old-c[old]]--;
        if(k[n+old-c[old]]==0 && old-c[old] >= 0)ans++;
        cout <<ans << endl;
        c[a[x[i]]]--;
        c[y[i]]++;
        a[x[i]] = y[i];
    }
    return 0;
}

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

using ll = long long;

#define mod 2019
#define INF 2<<30

int x[100010];

int main(void){
    // Your code here!
    ll n;
    cin >> n;
    
    for(int i=0;i<n;i++)cin>>x[i];
    
    int x1=x[0];
    for(int i=1;i<n;i+=2)
    {
        x1 += -x[i]+x[i+1];
    }
    
    int a=x1/2;
    cout << a*2;
    for(int i=0;i<n-1;i++)
    {
        int ans=x[i]-a;
        a=ans;
        cout<<" "<<ans*2;
        
    }
}



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

using namespace std;


int main() {

    string a,b;
    cin >> a >> b;
    if( a.size() == b.size() ) {
	if( a > b )
	    cout << "GREATER" << endl;
	else if( a < b )
	    cout << "LESS" << endl;
	else
	    cout << "EQUAL" << endl;
    }
    else if( a.size() > b.size() ) {
	cout << "GREATER" << endl;
    }
    else{
	    cout << "LESS" << endl;

    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end() 
using namespace std;
typedef long long ll;


int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   ll n, a, b;
   cin >> n >> a >> b;
   if((b-a)%2 == 0) {
       cout << (b - a)/2 << "\n";
   } else {
       ll res = min(a - 1, n - b);
       res += (b - a + 1)/2; 
       if(a == 1 || b == n)
           res = min({res, b-1, n-a});
       cout << res << "\n";
   }
   return 0;
} 


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

const int mod = 1000000007;
int R[200000];
int main() {
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i < 2 * n; ++i) {
    char c = i % 2 == 0 ? 'B' : 'W';
    R[i] = s[i] != c;
  }
  
  long sum = 1;
  int cnt = 0;
  for (int i = 0; i < 2 * n; ++i) {
    if (R[i]) {
      sum = sum * cnt % mod;
      --cnt;
    } else {
      ++cnt;
    }
  }
  if (cnt != 0) sum = 0;
  
  for (int i = 1; i <= n; ++i) {
    sum = sum * i % mod;
  }
  cout << sum << endl;
  
}

Measured memory_bytes: 1412
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M,K=map(int,input().split())
uf = UnionFind(N+1)
remove = [0]*(N+1)

for i in range(M):
    A,B=map(int,input().split())
    uf.union(A,B)
    remove[A] +=1
    remove[B] +=1

for i in range(K):
    A,B=map(int,input().split())
    if uf.same(A,B):
        remove[A] +=1
        remove[B] +=1

ANS = [0]*(N+1)

for i in range(0,N+1):
    ANS[i] = uf.size(i) - remove[i] - 1

ANS.pop(0)
print(*ANS)





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

int main(void){
  int N;
  int a, b, c;
  
  cin >> N;
  a = N / 100;
  b = (N - a * 100) / 10;
  c = N - a * 100 - b * 10;
  if(a == 7 || b == 7 || c == 7){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3616
H,W,N = gets.split.map(&:to_i)
sr,sc = gets.split.map(&:to_i)
S = gets.chomp
T = gets.chomp

i = 0
l = r = sc
u = d = sr
while i < N
  s = S[i]
  t = T[i]

  r += 1 if s == 'R'
  l -= 1 if s == 'L'
  u -= 1 if s == 'U'
  d += 1 if s == 'D'
  # p [l,r,d,u]
  if l < 1 || W < r || u < 1 || H < d
    puts 'NO'
    exit 0
  end
  r -= 1 if t == 'L' && 1 < r
  l += 1 if t == 'R' && l < W
  u += 1 if t == 'D' && u < H
  d -= 1 if t == 'U' && 1 < d
  i += 1
end

puts 'YES'


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

typedef pair<int, int> P;

const int N = 1e6+5;
string s,t = "Yes";
vector<int> v[N];
int n,result;
int a,b;

int main () {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin >> s >> t;
  cout << t << s << endl;
}


Measured memory_bytes: 23808
/*
 _  __    _   _   _ ____ _____ 
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |  
| . \  / ___ \ |_| |___) || |  
|_|\_\/_/   \_\___/|____/ |_|  
*/
#include <bits/stdc++.h>
#include <fstream>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb push_back
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
vi par;
vii v;
ll dp[100002][2];
void dfs(int x)
{
    for (int u : v[x])
    {
        if (par[x] != u)
        {
            par[u] = x;
            dfs(u);
        }
    }
}
vector<pair<int, int>> track;
int dpth(int x)
{
    int sum = 0;
    for (int u : v[x])
    {
        if (par[x] != u)
        {
            sum = max(sum, dpth(u) + 1);
        }
    }
    track.pb({sum, x});
    return sum;
}
// ll counto(int x, int turn)
// {
//     if (dp[x][turn] != -1)
//     {
//         return dp[x][turn];
//     }
//     ll sum = 1;
//     for (int u : v[x])
//     {
//         if (u != par[x])
//         {
//             if (turn)
//                 sum *= counto(u, turn) + counto(u, 1 - turn);
//             else
//                 sum *= counto(u, 1 - turn);
//             sum %= MOD;
//         }
//     }
//     return dp[x][turn] = sum;
// }
int main()
{
    CIN;
    int n;
    cin >> n;
    v.resize(n + 1);
    par.resize(n + 1, -1);
    rep(i, 0, 100002)
    {
        rep(j, 0, 2)
        {
            dp[i][j] = -1;
        }
    }
    rep(i, 0, n - 1)
    {
        int n1, n2;
        cin >> n1 >> n2;
        v[n1].pb(n2);
        v[n2].pb(n1);
    }
    dfs(1);
    dpth(1);
    rep(i,0,100002){
        rep(j,0,2){
            dp[i][j] = 1;
        }
    }
    rep(i,0,n-1){
        dp[par[track[i].ss]][1]*=dp[track[i].ss][1] + dp[track[i].ss][0];
        dp[par[track[i].ss]][0]*=dp[track[i].ss][1];
        dp[par[track[i].ss]][1]%=MOD;
        dp[par[track[i].ss]][0]%=MOD;
    }
    cout << (dp[1][0]+dp[1][1])%MOD;
    //cout << (counto(1, 0) + counto(1, 1)) % MOD;
}


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

using namespace std;

string s[10];

int n;

string decode(string str) {
    int pbt = 0;
    int cnt = 0;
    string res = "";
    for (char c : str) {
        int bt = c - '0';
        if (pbt != 0 && bt == 0) {
            res += s[pbt][(cnt - 1) % s[pbt].size()];
            pbt = 0;
            cnt = 0;
        } else if (bt != 0) {
            pbt = bt;
            cnt++;
        }
   }

   return res;
}

int main() {
    s[1] = ".,!? ";
    s[2] = "abc";
    s[3] = "def";
    s[4] = "ghi";
    s[5] = "jkl";
    s[6] = "mno";
    s[7] = "pqrs";
    s[8] = "tuv";
    s[9] = "wxyz";

    cin >> n;
    for (int i = 0; i < n; ++i) {
        string str;
        cin >> str;
        cout << decode(str) << endl;
    }
}

Measured memory_bytes: 3200
import scala.math._

// longでrangeの作り方

object Main extends App {

  val YES = "YES"
  val Yes = "Yes"
  val NO = "NO"
  val No = "No"
  ///////////////////////////////////////////

  val sc = new java.util.Scanner(System.in)
  val a, op, b = sc.next
//  val list = List.fill(3)(sc.next)

  val ans = if (op == "+") a.toInt + b.toInt else a.toInt - b.toInt

  println(ans)


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

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

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

const int maxN = 1005, mod = 1e9 + 7;

int N, K, a[maxN + 1];
int f[maxN + 1][maxN * 21 + 1];
int fac[maxN + 1], inv[maxN + 1];

inline int ADD(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }

inline int mpow(int a, int x)
{
	int ans = 1;
	while(x)
	{
		if(x & 1) ans = 1ll * ans * a % mod;
		a = 1ll * a * a % mod;
		x >>= 1;
	}
	return ans;
}

inline int C(int n, int m)
{
	if(n < m) return 0;
	return 1ll * fac[n] * inv[n - m] % mod * inv[m] % mod;
}

int main()
{
	scanf("%d %d", &N, &K);
	for(int i = 1; i <= K; i++) scanf("%d", &a[i]);
	
	fac[0] = 1;
	for(int i = 1; i <= N; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
	inv[N] = mpow(fac[N], mod - 2);
	for(int i = N - 1; i >= 0; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;

	f[0][0] = 1;
	for(int i = 1; i <= K; i++)
		for(int j = 0; j <= N; j++)
			for(int k = 0; k <= a[i]; k++)
				if(k <= j) 
					f[i][j] = ADD(f[i][j], 1ll * f[i - 1][j - k] * C(N - k, a[i] - k) % mod * inv[k] % mod);

	printf("%lld", 1ll * fac[N] * f[K][N] % mod);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
string s;
bool check[26];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s;
	int i = 0;
	while (i < s.length() && !check[s[i] - 'a']) {
		check[s[i] - 'a'] = 1;
		i++;
	}
	if (i == s.length()) cout << "yes";
	else cout << "no";
}

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

int main(){
  int N;
  cin >> N;
  int t[100010];
  int x[100010];
  int y[100010];
  t[0]=0;
  x[0]=0;
  y[0]=0;
  for(int i=1;i<=N;i++) cin>>t[i]>>x[i]>>y[i];
  
  bool flag=true;
  for(int i=1;i<=N;i++){
    int dt=t[i]-t[i-1];
    int dx=abs(x[i]-x[i-1]);
    int dy=abs(y[i]-y[i-1]);
    if(dt<dx+dy){
      flag=false;
      break;
    }
    if(abs(dt-(dx+dy))%2==1){
      flag=false;
      break;
    }
  }
  if(flag){
    cout << "Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }
  return 0;
}

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




int32_t main()
{

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


int n;
cin>>n;
int ans=0;

for(int i=1;i<=n;i++)
{
    for(int j=1;j<=n;j++)
    {
        for(int k=1;k<=n;k++)
        {
            int x=__gcd(i,j);
            ans+=__gcd(x,k);
        }
    }
}

cout<<ans<<"\n";


}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }


int n;
vector<vector<int>> g;
string s[200];
vector<int> dis;
vector<bool> checked;


int solve(int st){
    dis=vector<int>(n,INF);
    dis[st]=0;
    checked=vector<bool>(n,false);
    queue<pair<int,int>> q;
    q.push(make_pair(st,0));
    while(!q.empty()){
        auto now=q.front();q.pop();
        if(checked[now.first]) continue;
        checked[now.first]=true;
        for(auto x:g[now.first]){
            if(checked[x]) continue;
            dis[x]=now.second+1;
            q.push(make_pair(x,now.second+1));
        }
    }

    rep(i,n){
        for(int j=i+1;j<n;j++){
            if(s[i][j]=='1'){
                if(abs(dis[i]-dis[j])!=1)return -1;
            }
        }
    }

    int ret=0;
    rep(i,n){
        ret=max(ret,dis[i]);
    }
    return ret+1;
}


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

    cin>>n;
    g.resize(n);

    rep(i,n){
        cin>>s[i];
    }
    rep(i,n){
        for(int j=i+1;j<n;j++){
            if(s[i][j]=='1'){
                g[i].push_back(j);
                g[j].push_back(i);
            }
        }
    }

    int ans=-1;
    rep(i,n){
        ans=max(ans,solve(i));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 748
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
		a[i]--
	}
	b := make([]int, n)
	for i := range b {
		fmt.Scan(&b[i])
	}
	c := make([]int, n-1)
	for i := range c {
		fmt.Scan(&c[i])
	}

	old := -2
	ans := 0
	for _, v := range a {
		ans += b[v]
		if v-old == 1 {
			ans += c[old]
		}
		old = v
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int T; cin>>T; cin.ignore();
  map<string, int> conv;
  conv["yotta"] = 24;
  conv["zetta"] = 21;
  conv["exa"] = 18;
  conv["peta"] = 15;
  conv["tera"] = 12;
  conv["giga"] = 9;
  conv["mega"] = 6;
  conv["kilo"] = 3;
  conv["hecto"] = 2;
  conv["deca"] = 1;
  conv["deci"] = -1;
  conv["centi"] = -2;
  conv["milli"] = -3;
  conv["micro"] = -6;
  conv["nano"] = -9;
  conv["pico"] = -12;
  conv["femto"] = -15;
  conv["ato"] = -18;
  conv["zepto"] = -21;
  conv["yocto"] = -24;
  while(T--){
    string line;
    getline(cin, line);
    string num, prefix, unit;
    stringstream ss(line);
    ss>>num; ss>>prefix; ss>>unit;
    if(unit == "") swap(prefix, unit);
    int dot = num.size() - 1;
    REP(i, num.size())if(num[i] == '.'){
      dot = i - 1;
      num = num.substr(0, i) + num.substr(i+1);
    }
    int pow = INF;
    REP(i, num.size())if(num[i] != '0'){
      if(num.substr(i + 1) == "") num = num.substr(i, 1);
      else num = num.substr(i, 1) + "." + num.substr(i + 1);
      pow = dot - i;
      break;
    }
    pow += conv[prefix];
    printf("%s * 10^%d %s\n", num.c_str(), pow, unit.c_str());
  }
  return 0;
}

Measured memory_bytes: 0