akhauriyash/Code-Regression huggingface dataset:
Scanf.scanf "%d %d" (fun n c ->
    let d = Array.init c (fun _ ->
        Array.init c (fun _ -> Scanf.scanf " %d" (fun c -> c)))
    in
    let cc = Array.init n (fun _ ->
        Array.init n (fun _ -> Scanf.scanf " %d" (fun cc -> cc)))
    in

    let hist = Array.make_matrix 3 c 0 in
    for y = 0 to n - 1 do
        for x = 0 to n - 1 do
            let m = (x + y) mod 3 in
            let q = cc.(y).(x) - 1 in
            hist.(m).(q) <- hist.(m).(q) + 1
        done
    done;

    let calc c1 c2 c3 =
        let c4 = [| c1; c2; c3 |] in
        let rec loop i acc =
            let rec loop2 j acc =
                if j = c then acc else
                    let acc = acc + hist.(i).(j) * d.(j).(c4.(i)) in
                    loop2 (j + 1) acc
            in
            if i = 3 then acc else loop (i + 1) (loop2 0 acc)
        in
        loop 0 0
    in

    let rec loop_c1 c1 acc =
        let rec loop_c2 c2 acc =
            let rec loop_c3 c3 acc =
                if c3 = c then acc else
                    let acc = if c3 = c1 || c3 = c2 then acc else
                                min acc (calc c1 c2 c3)
                    in
                    loop_c3 (c3 + 1) acc
            in
            if c2 = c then acc else
                let acc = if c2 = c1 then acc else loop_c3 0 acc in
                loop_c2 (c2 + 1) acc
        in
        if c1 = c then acc else loop_c1 (c1 + 1) (loop_c2 0 acc)
    in
    loop_c1 0 max_int |> Printf.printf "%d\n"
)

Measured memory_bytes: 6144
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define N 2*10e5
#define precise cout<<fixed<<setprecision(10)
#pragma GCC optimize("O0")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#define rep(i,a,b) for(int i=a;i<b;i++)
#define min3(a,b,c) min(a,min(b,c))
#define nl cout<<"\n";
#define all(v) v.begin(),v.end()
#define F first
#define S second
typedef long long ll;
typedef vector<long long> vl;
typedef vector<pair<long,long>> vp;
void get(ll arr[],ll n){for(ll i=0;i<n;i++) cin>>arr[i];}
ll gcd(ll a,ll b);
ll binpow(ll a,ll b);
void solve()
{
    ll n;
    cin>>n;
    ll ans= 1000 - n%1000;
    if(ans==1000) ans=0;
    cout<< ans;
}
int main()
{
 	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
	 	solve();
	}
	//cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}
ll binpow(ll a, ll b) {
   ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

Measured memory_bytes: 3648
# -*- coding: utf-8 -*-
# A

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

a,b = map(int, input().split())
print(a*b)


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

int main() {
  int n;
  cin >> n;
  
  int h[n];
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }
  
  int cnt = 0;
  int max = 0;
  for(int i = 1; i < n; i++){
    if(h[i-1] >= h[i]){
      cnt++;
    }else if(max < cnt){
      max = cnt;
      cnt = 0;
    }else cnt = 0;
  }
  if(max < cnt){
      max = cnt;
  }

  cout << max << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
int main() {
  int n;
  cin >> n;
  vector<string> input(n);
  rep(i, n) cin >> input[i];
  string t;
  cin >> t;
  int top = 0;
  int middle = 1;
  int last = 0;
  rep(i, n) {
    string s;
    string ss;
    rep(j, input[i].size()) {
      if(input[i][j] == '?') {
        s += 'a';
        ss += 'z';
      }
      else {
        s += input[i][j];
        ss += input[i][j];
      }
    }

    if(ss < t) {
      top++;
    }
    else if(s <= t) {
      middle++;
    }
    else {
      last++;
    }
  }

  for(int i=top+1;i<=top+middle;i++) {
    cout << i;
    if(i != top+middle) cout << " ";
  }
  cout << endl;
}

Measured memory_bytes: 896
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = a; i <= b; i++)

#include <iostream>

using namespace std;

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

    cout << 0.5*N*(N+1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

void calc(vector<int> &dp, const vector<int> &mp, const vector<int> &dm){
  int m = dp.size();
  int n = mp.size();
  assert(mp.size() == dm.size());
  
  fill(ALL(dp), INF);
  dp[0] = 0;
  
  REP(i, n){
    REP(j, m){
      int p = min(m - 1, j + dm[i]);
      dp[p] = min(dp[p], dp[j] + mp[i]);
    }
    REP(j, m - 1){
      dp[m-j-2] = min(dp[m-j-2], dp[m-j-1]);
    }
  }
}

int main(){
  int n, m, mp, dm;
  string name, range;
  
  while(cin >> n && n){
    vector<int> enemy(n);
    REP(i, n) cin >> enemy[i];
  
    cin >> m;
    vector<int> mp_all, mp_single;
    vector<int> dm_all, dm_single;
  
    REP(i, m){
      cin >> name >> mp >> range >> dm;
      if(range == "All"){
        mp_all.push_back(mp);
        dm_all.push_back(dm);
      }else{
        mp_single.push_back(mp);
        dm_single.push_back(dm);
      }
    }

    int M = *max_element(ALL(enemy)) + 1;

    vector<int> dp_all(M);
    vector<int> dp_single(M);

    calc(dp_all, mp_all, dm_all);
    calc(dp_single, mp_single, dm_single);


    ll res = INF;
    REP(i, M){
      ll sum = dp_all[i];
      REP(j, n){
        int d = max(0, enemy[j] - i);
        sum += dp_single[d];
      }
      res = min(res, sum);
    }
  
    cout << res << endl;
  }
  return 0;
}

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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

const int INF = 0x3f3f3f3f;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
//int in() { int x; scanf("%d", &x); return x; }
//ll lin() { ll x; scanf("%lld", &x); return x; }
void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

int main(void){

	int a,b;
	cin >> a >> b;


	cout << max(a+b, max(a-b, a*b));

    return 0;
}


Measured memory_bytes: 256
n = int(input())

fives = [0]

if n % 2 == 1:
    print(0)
else:
    i = 0
    while 1:
        temp5 = (n // (5** (i +1))) //2
        if temp5 != 0:
            fives.append(temp5)
            i += 1
        else:
            break
    print(sum(fives))    

Measured memory_bytes: 9068
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,i;
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a;
    for(i=1; i<=a; i++){
        if(i%3!=0&&i%5!=0){
            c+=i;
        }
    }
    cout<<c;
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 ll n,m;
 sc(n);sc(m);
 
 pr(cei((n+m),2));
  
return 0;}

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

int main() {
  int x1,y1,x2,y2; cin >>x1>>y1>>x2>>y2;
  
  int a = x2 - x1;
  int b = y2 - y1;
  
  int x3 = x2 - b;
  int y3 = y2 + a;
  int x4 = x1 - b;
  int y4 = y1 + a;
  
  cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <new>

/*
#define FOR(i,m,n)    for(int i=m;i<n;i++)
#define FORB(i,m,n)    for(int i=m;i>=n;i--)
#define INF 999999999*/

#define ll long long
/*
#define PUSH(a) push_back(a)
#define POP() pop_back()
#define SORT(v,n) sort(v,v+n)
#define VSORT(v) sort(v.begin(),v.end())
*/

using namespace std;

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


int main() {
	int flag = 0;
	ll int N;
	cin >> N;
	ll int h = 1, n = 1, w = 1;
	for (ll int i = 1;i <= 3500;i++) {
		for (ll int j = 1;j <= 3500;j++) {
			if (4 * i*j > N*i + N*j) {
				if ((N*i*j >= (4 * i*j - N*i - N*j)) && ((N*i*j) % (4 * i*j - N*i - N*j) == 0)) {
					h = (i*N*j) / (4 * i*j - N*i - N*j);
					n = i;
					w = j;
					break;
				}
			}
		}
	}

	cout << h << ' ' << n << ' ' << w << endl;

}

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

static class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        var A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int count = 0;
        for (int i = 0; i < N; ++i)
        {
            if (i % 2 == 0 && A[i] % 2 != 0) { ++count; }
        }
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 17704
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

const string s="MARCH";
int n;
vi a(26);

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		string t;
		cin>>t;
		a[t[0]-'A']++;
	}
	ll res=0;
	for(int i=0;i<1<<5;i++){
		ll cnt=0,ans=1;
		for(int j=0;j<5;j++) if(i&1<<j) cnt++;
		if(cnt!=3) continue;
		for(int j=0;j<5;j++) if(i&1<<j) ans*=a[s[j]-'A'];
		res+=ans;
	}
	cout<<res<<endl;
}

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

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

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m, q;
	cin >>n >>m >>q;
	vector<VI> b(q, VI(4));
	rep(i, q){
		cin >>b[i][0] >>b[i][1] >>b[i][2] >>b[i][3];
		b[i][0]--; b[i][1]--;
	}
	
	VI v(n);
	auto f =[&](auto f, int c, int pi){
		ll rt = 0;
		if(c == n){
			ll sm = 0;
			for(auto& x: b){
				if(v[x[1]] - v[x[0]] == x[2]) sm += x[3];
			}
			return sm;
		}
		rep2(i, pi, m){
			v[c] = i;
			rt = max(rt, f(f, c+1, i));
		}
		return rt;
	};
	cout << f(f, 0, 0) <<"\n";
	return 0;
}


Measured memory_bytes: 3656
# 6199094

import sys
input = sys.stdin.readline

class UnionFind():
    def __init__(self,n):
        self.parent = [-1 for _ in range(n)]

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

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

    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if(x == y):
            return False
        if(self.size(x)<self.size(y)):
            self.parent[y]+=self.parent[x]
            self.parent[x]=y
        else:
            self.parent[x]+=self.parent[y]
            self.parent[y]=x
        return True

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

def main():
    N = int(input())
    xli = []
    yli = []
    x_app = xli.append
    y_app = yli.append


    for i in range(N):
        x,y = (int(x) for x in input().split())
        x_app([x-1,i])
        y_app([y-1,i])
    xli.sort()
    yli.sort()

    edges = []
    edges_app = edges.append
    for i in range(N-1):
        edges_app((xli[i][1],xli[i+1][1],xli[i+1][0]-xli[i][0]))
        edges_app((yli[i][1],yli[i+1][1],yli[i+1][0]-yli[i][0]))


    edges.sort(key=lambda edge: edge[2])
    uf = UnionFind(N)
    weight = 0

    for edge in edges:
        if not uf.same(edge[0], edge[1]):
            uf.unite(edge[0], edge[1])
            weight+=edge[2]
    print(weight)

if __name__ == '__main__':
    main()


Measured memory_bytes: 133980
n = int(input())
dat = []
for i in range(n):
    a,b = map(int, input().split())
    dat.append([a,b])
dat2 = []
if n == 1:
    print(1)
else:
    for i in range(n):
        x1, y1 = dat[i]
        for j in range(n):
            if i == j:
                continue
            x2, y2 = dat[j]
            dat2.append( (x1-x2, y1-y2) )
    import collections
    c = collections.Counter(dat2)
    #print(c)
    ta, tb = c.most_common(1)[0][0]
    res = 0
    for i in range(n):
        canwarp = False
        x1, y1 = dat[i]
        for j in range(n):
            if i == j:
                continue
            x2, y2 = dat[j]
            if x1-x2 == ta and  y1-y2 == tb:
                canwarp = True
        if canwarp:
            continue
        else:
            res += 1
    print(res)


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

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

    if(abs(a - c) <= d || ((abs(b - a) <= d && abs(c - b) <= d)))
    {
        cout << "Yes" << "\n";
    } else 
    {
        cout << "No" << "\n";
    }

    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int z_algorithm(string s) {
    int size = s.size(), A[5000] = { size }, i = 1, j = 0;
    while (i < size) {
        while (i + j < size && s[j] == s[i + j]) j++;
        A[i] = j;
        if (j == 0) {
            i++;
            continue;
        }
        int k = 1;
        while (i + k < size && k + A[k] < j) {
            A[i + k] = A[k];
            k++;
        }
        i += k;
        j -= k;
    }
    int ret = 0;
    FOR(i, 1, size) ret = max(min(A[i], i), ret);
    return ret;
}

int main() {
    int N, ans = 0;
    string S;
    cin >> N >> S;
    REP(i, N - 1) ans = max(z_algorithm(S.substr(i)), ans);
    cout << ans << endl;
    return 0;
}

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

int main(){
    map<int,int> m;
    int N,K;
    cin>>N>>K;

    for(int i=0;i<N;i++){
        m[i] = 0;
    }
    
    for(int i=0;i<K;i++){
        int d;
        cin>>d;
        for(int j=0;j<d;j++){
            int A;
            cin>>A;
            m[A-1] +=1;
        }
    }
    int count=0;
    for(int i=0;i<N;i++){
        if(m.at(i)==0){
            count++;
        }
    }
    cout<<count<<endl;
    
}

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

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<28;
void solve(int a){cout<<( a?"Yes":"No")<<endl;}
int main(){
	int n;
	cin >>n;
	vector<int>x(n,0);
	long long ans=INFLL;
	long long bef=0;
	for(int i=0;i<n;i++){
		cin >>x[i];
	}
	sort(x.begin(),x.end());
	for(int i=x[0];i<=x[n-1];i++){
		bef=0;
		for(int j=0;j<n;j++){
			bef += ((i - x[j]) * (i - x[j]));
		}
		chmin(ans,bef);
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
//测题解，请不要在意，我一会儿会再做的，谢谢！

#include<bits/stdc++.h>

using namespace std;

long long s=1;

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        s*=i;
        s%=1000000007;
    }
    cout<<s;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>
using namespace std;

int top, S[1000];

void push(int x) {
	S[++top] = x;
}

int pop(void) {
	top--;
	return S[top+1];
}

int main(void) {
	int a, b;
	top = 0;
	char s[10];

	while (cin >> s) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-') {
			a = pop();
			b = pop();
			push(b - a);
		}
		else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a * b);
		}
		else {
			push(atoi(s));
		}
	}
	
	cout << pop() << endl;

	return 0;
}

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

int main()
{
    int a, b, c, n;
    n = 0;
    cin >> a >> b >> c;

    for (int i = a; i <= b; i++)
    {
        if (c % i == 0)
            n++;
    }
    cout << n << endl;

    return 0;
}


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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  bool ok = true;
  while (n--) {
    int a;
    cin >> a;
    if (a % 2) continue;
    if (a % 3 && a % 5) {
      ok = false;
    }
  }
  cout << (ok ? "APPROVED" : "DENIED") << '\n';
  return 0;
}


Measured memory_bytes: 3652
from itertools import accumulate


class CoeffTable:
    def __init__(self, n):
        self.n = n
        if n == 2:
            (self.p2, self.p1, self.m1, self.m2) = (0, 1, 1, 0)
        if n % 2 == 0:
            self.p1 = self.m1 = 1
            self.p2 = self.m2 = (n - 1) // 2
        else:
            self.p1 = 0
            self.m1 = 2
            self.p2 = (n - 1) // 2
            self.m2 = (n - 2) // 2

    def reverse(self):
        (self.p2, self.p1, self.m1, self.m2) = (
            self.m2,
            self.m1,
            self.p1,
            self.p2,
        )

    def cumsum(self):
        return list(accumulate([self.p2, self.p1, self.m1, self.m2]))



def main(n, seq):
    seq = sorted(seq, reverse=True)
    coeff = CoeffTable(n)
    cm = coeff.cumsum()
    ans1 = (
        2 * sum(seq[0 : cm[0]])
        + 1 * sum(seq[cm[0] : cm[1]])
        - 1 * sum(seq[cm[1] : cm[2]])
        - 2 * sum(seq[cm[2] : cm[3]])
    )
    coeff.reverse()
    rcm = coeff.cumsum()
    ans2 = (
        2 * sum(seq[0 : rcm[0]])
        + 1 * sum(seq[rcm[0] : rcm[1]])
        - 1 * sum(seq[rcm[1] : rcm[2]])
        - 2 * sum(seq[rcm[2] : rcm[3]])
    )
    ans = max(ans1, ans2)
    print(ans)
    return


if __name__ == "__main__":
    n = int(input())
    sample = []
    for _ in range(n):
        sample.append(int(input()))
    main(n, sample)


Measured memory_bytes: 54104
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>


using namespace std;


int W, N;
int w[1001];
int v[1001];
int dp[1001][1001];

int main()
{
	for (int caseCount = 1; ; ++caseCount)
	{
		scanf("%d", &W);
		if (W == 0)
			break;
		scanf("%d", &N);
		for (int i = 0; i < N; ++i)
		{
			int a, b;
			scanf("%d,%d", &a, &b);
			v[i] = a;
			w[i] = b;
		}
		memset(dp, 0, sizeof(dp));

		for (int i = 0; i < N; ++i)
		{
			for (int j = 0; j <= W; ++j)
				dp[i+1][j] = max(dp[i][j], (w[i] <= j ? dp[i][j-w[i]]+v[i] : 0));
		}

		int mw, mv;
		mw = 9999;
		mv = -1;
		for (int i = 0; i <= W; ++i)
		{
			if (dp[N][i] > mv)
			{
				mv = dp[N][i];
				mw = i;
			}
		}
		printf("Case %d:\n%d\n%d\n", caseCount, mv, mw);
	}


	return 0;
}

Measured memory_bytes: 0
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
# input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    S = input()

    res = 'Yes'

    if (S == 'AAA') or (S == 'BBB'):
        res = 'No'

    print(res)



main()


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
main() {
    int A,B; cin>>A>>B;
    vector<int> xs({A,A-1,B,B-1});
    sort(xs.rbegin(), xs.rend());
    cout<< xs[0]+xs[1] <<endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()

{
   string a,b;
   cin>>a>>b;
   if(a[0]=='H')

   {
       if(b[0]=='H')
       {
           cout<<"H"<<endl;
       }
       else{
        cout<<"D"<<endl;
       }

   }
   else if(a[0]=='D')

   {
       if(b[0]=='H')
       {
           cout<<"D"<<endl;
       }
       else{
        cout<<"H"<<endl;
       }

   }
   return 0;
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(line);
            Console.WriteLine(Math.Abs(line[0] - line[1]) + Math.Abs(line[1] - line[2]));
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou((int)bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<int> hukasa;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
    }
    else{
      par.at(rx) = ry;
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
int main(){
  int n,m,k;
  cin >> n >> m >> k;
  vector<long long> a(n),b(m);
  for(int i=0;i<n;i++)cin >> a.at(i);
  for(int i=0;i<m;i++)cin >> b.at(i);
  vector<long long> as(n+1),bs(m+1);
  as.at(0) = 0;
  bs.at(0) = 0;
  for(int i=1;i<=n;i++)as.at(i) = as.at(i-1) + a.at(i-1);
  for(int i=1;i<=m;i++)bs.at(i) = bs.at(i-1) + b.at(i-1);
  int ans = 0;
  for(int i=0;i<=n;i++){
    int x=0,y=m;
    long long unko = k - as.at(i);
    if(unko < 0)break;
    if(bs.at(y) <= unko){
      ans = max(ans,y+i);
      continue;
    }
    while(y-x > 1){
      int z = (x + y)/2;
      if(bs.at(z) <= unko){
        x = z;
      }
      else y = z;
    }
    ans = max(ans,x + i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 9468
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let c = read::<i32>();
    let mut bs = vec![0; m];
    for i in 0..m {
        bs[i] = read::<i32>();
    }
    let mut ans = 0;
    for _i in 0..n {
        let mut sum = c;
        for j in 0..m {
            let a = read::<i32>();
            sum += a * bs[j];
        }
        if sum > 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define cs const int &
const int MOD=998244353,N=1e6+10;
inline int Add(cs a,cs b){return a+b>=MOD? a+b-MOD:a+b;}
inline int Sub(cs a,cs b){return a-b<0? a-b+MOD:a-b;}
inline int Mul(cs a,cs b){return int(1ll*a*b%MOD);}
inline int Pow(int a,int b){int r=1;while(b){if(b&1)r=Mul(a,r);a=Mul(a,a),b>>=1;}return r;}
inline int Div(cs a,cs b){return Mul(a,Pow(b,MOD-2));}

int fac[N],ifac[N];

inline int Comb(cs a,cs b){return a>b? 0:Mul(fac[b],Mul(ifac[a],ifac[b-a]));}

int main(){
	fac[0]=1;
	for(int i=1;i<N;i++) fac[i]=Mul(fac[i-1],i);
	ifac[N-1]=Pow(fac[N-1],MOD-2);
	for(int i=N-2;i>=0;i--) ifac[i]=Mul(ifac[i+1],i+1);
	const int inv2=Pow(2,MOD-2);
	int ans=0;
	int n,m;scanf("%d%d",&n,&m);
	if(n>m) swap(n,m);
	for(int i=1;i<=n;i++)
		ans=Add(ans,Div(Mul(Comb(i,i+i),Comb(n-i,n-i+m-i)),Comb(n,n+m)));
	ans=Mul(ans,inv2);
	printf("%d\n",Add(ans,m));
	return 0;
}

Measured memory_bytes: 9524
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int ans=0;
    for(char u:s){
        ans+=u-48;
    }
    if(ans%9==0)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> A(N);
  int all = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    all += A[i];
  }
  int c = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] * 4 * M >= all) {
      c++;
    }
  }
  if (c >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import heapq
N, M = map(int,input().split())
reward = [[] for _ in range(M)]
for i in range(N):
  A,B = map(int,input().split())
  if A <= M:
    reward[A-1].append(B)
q = []
ans = 0
for day in range(M):
  for r in reward[day]:
    heapq.heappush(q,-r)
  if len(q) >0:
    ans += -heapq.heappop(q)
print(ans)
  


  
  
  
  


Measured memory_bytes: 18400
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

#define MAX 400

template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
    if (a > b) a = b;
}

signed main() {
    int n, ma, mb;
    cin >> n >> ma >> mb;
    int a[n], b[n], c[n];
    rep(i, n) {
        cin >> a[i] >> b[i] >> c[i];
    }
    int dp[n + 1][MAX + 1][MAX + 1];
    fill(dp[0][0], dp[n + 1][0], INF);
    dp[0][0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= MAX; j++) {
            for (int k = 0; k <= MAX; k++) {
                chmin(dp[i + 1][j][k], dp[i][j][k]);
                if (j - a[i] < 0 || k - b[i] < 0) continue;
                chmin(dp[i + 1][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);
            }
        }
    }
    int ans = INF;
    for (int i = 1; ma * i <= MAX && mb * i <= MAX; i++){
        chmin(ans, dp[n][ma * i][mb * i]);
    }
    cout << (ans != INF ? ans : -1) << endl;
    return 0;
}

Measured memory_bytes: 29396
#include<stdio.h>
#include<string.h>
char s[100001];
int main()
{
    gets(s);
    int ans=0;
    for(int i=1;i<strlen(s);i++)
        if(s[i]!=s[i-1])
            ans++;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
		using namespace std;
		typedef long long ll;
		#define PI 3.14159265358979
		#define EPS 1e-8
		#define mod  998244353
		#define fi first
		#define se second
		#define mp make_pair
		#define pb push_back
		#define endl "\n"
			 
		const ll INF=1e15;	
		const int N=2e5+50;
		 

		 
		long long binpow(long long a, long long b, long long m) {
			a %= m;
			long long res = 1;
			while (b > 0) {
				if (b & 1)
					res = res * a % m;
				a = a * a % m;
				b >>= 1;
			}
			return res;
		}
		
		ll modinverse(ll a,ll m)
		{
			return binpow(a,m-2,m);
		}
		
		
		int main()
		{
			ios_base::sync_with_stdio(false);
			cin.tie(NULL);cout.tie(0);
			
			ll n,d,a;
			cin>>n>>d>>a;
			
			vector<ll> x(n),h(n);
			
			vector<pair<ll,ll> > v(n);
			for(ll i=0;i<n;i++)
			{
				cin>>x[i]>>h[i];
				v[i]={x[i],h[i]};
			}
			
			ll ans=0;
			sort(v.begin(),v.end());
			
			
			vector<pair<ll,ll> > v1;
			
			ll val=0;
			ll idx=0;
			for(auto i:v)
			{
				while(idx<v1.size() && v1[idx].fi<=i.fi)
				{
					val+=v1[idx].se;
					idx++;
				}
			
				if(val<i.se)
				{
					ll mov=(i.se-val+a-1)/a;
					ans+=mov;
					val+=mov*a;
					ll val1=mov*a;
					v1.pb({i.fi+2*d+1,-val1});
				}
				
			}
			cout<<ans;
			
			
			
			
		}
			
			
		


Measured memory_bytes: 13668
N,L=map(int,input().split())

Apple_List1=[]
Apple_List2=[]
for i in range(N):
    Apple_List1.append(L+i)
    Apple_List2.append(abs(L+i))

#Apple_List=abs(Apple_List)
Apple_List2.sort()

flag=0
if Apple_List2[0] in Apple_List1:
    flag=1
elif -Apple_List2[0] in Apple_List1:
    flag=-1
    
print(sum(Apple_List1)-flag*Apple_List2[0])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
    int n,m; cin>>n>>m;
    vector <int> a(n);
    vector <int> SUM(n+1);
    for(int i=0;i<n;i++){
        cin>>a[i];
        SUM[i+1] += (a[i]+SUM[i])%m;
    }
    map <int,int> data;
    ll ans=0;
    for(int i=0;i<n+1;i++){
        ans += data[SUM[i]];
        data[SUM[i]]++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
int main(){
char s1,s2,s3;
char t1,t2,t3;
 int n;
  cin>>s1>>s2>>s3;
  cin>>t1>>t2>>t3;
  if(s1==t1){
  n++;}
  if(s2==t2){
  n++;}
  if(s3==t3){
  n++;}
  cout<<n<<endl;
  return 0;
 }
    

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

#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007

int main(){
	fast;
	int n,ans=0;
	cin>>n;
	ll arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	sort(arr,arr+n);
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
			for(int k=j+1;k<n;k++)
				if(arr[i]+arr[j]>arr[k] and arr[i]!=arr[j] and arr[i]!=arr[k] and arr[j]!=arr[k])
					ans++;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

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

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

int A, B, C;
int N;
int ans;

string S;

int main(){
	
	cin>>N;
	//cin>>A>>B>>C;
	
	if( N % 10 == N /100 ) puts("Yes");
	else{				puts("No");}
	
	//cout<<ans<<endl;
	
	return 0;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
  int n,a,b;
  string s;
  cin>>n>>a>>b>>s;
  int ab=0,bo=0;
  for(auto&c:s){
    if(c=='a'){
      if(ab<a+b)puts("Yes");
      else puts("No");
      ab++;
    }
    else if(c=='b'){
      if(ab<a+b && bo<b)puts("Yes"),ab++;
      else puts("No");
      bo++;
    }
    else puts("No");
  }
}


Measured memory_bytes: 896
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

#define mp(x,y) make_pair(x,y)
const int MAXN=1e6+5;

int n,r1,r2,ecnt;
int ans[MAXN],siz[MAXN],ban[MAXN*4];
int head[MAXN],cnt;
struct node{
    int v,id,nxt;
}E[MAXN*4];

void addedge(int u,int v,int id){
    E[++cnt]=(node){v,id,head[u]};
    head[u]=cnt;
}

void dfs(int u,int fa=0){
    for(int i=head[u];i;i=E[i].nxt){
        int v=E[i].v;
        if(v==fa) continue;
        dfs(v,u);
        siz[u]++;
    }
}

void sol(int u){
    for(int &i=head[u];i;i=E[i].nxt){
        int v=E[i].v,id=E[i].id;
        if(ban[id]) continue;
        ban[id]=1;
        if(v==u-n) ans[v]=-1;
        else if(v==u+n) ans[u]=1;
        sol(v);
    }
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        if(x==-1) r1=i;
        else{
            addedge(x,i,++ecnt);
            addedge(i,x,ecnt);
        }
    }
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        if(x==-1) r2=i+n;
        else{
            addedge(x+n,i+n,++ecnt);
            addedge(i+n,x+n,ecnt);
        }
    }
    dfs(r1);
    dfs(r2);
    for(int i=1;i<=n;i++){
        if((siz[i]&1)!=(siz[i+n]&1)) return puts("IMPOSSIBLE"),0;
        if(!(siz[i]&1)){
            addedge(i,i+n,++ecnt);
            addedge(i+n,i,ecnt);
        }
    }
    addedge(r1,2*n+1,++ecnt),addedge(2*n+1,r1,ecnt);
    addedge(r2,2*n+1,++ecnt),addedge(2*n+1,r2,ecnt);
    sol(2*n+1);
    puts("POSSIBLE");
    for(int i=1;i<=n;i++)
        printf("%d ",ans[i]);
	return 0;
}

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

int N;
vector <int> A;


int main() {
  cin >> N;
  A.resize(N);
  int NN = N;
  
  for(int i = 0; i < N; i++){
      cin >> A.at(i); 
  }
  
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
       for(int i = 0; i < N - 1; i++){
         
    for(int j = 0; j < N - 1; j++){
      if(A[j] < A[j + 1]){
        int k = A[j];
        A[j] = A[j + 1];
        A[j + 1] = k;
      }
    }
  }
     
    }
  }
  
   for(int i = 0; i < N - 1; i++){
        if(A[i] == A[i + 1]){
          
          NN--;
        }
      }
  cout << NN << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<ll> h(N);
	REP(i, N) {
		cin >> h[i];
	}

	vector<ll> c(N);
	c[1] = abs(h[0] - h[1]);
	if (N == 2) {
		cout << c[1] << endl;
		return 0;
	}

	FOR(i, 2, N) {
		ll cost1 = abs(h[i] - h[i - 1]);
		ll cost2 = abs(h[i] - h[i - 2]);
		c[i] = min(c[i - 1] + cost1, c[i - 2] + cost2);
	}

	cout << c[N-1] << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,k;
string s;

int main(){
	cin>>n>>s>>k;
	for(int i=0;i<n;i++) if(s[i]!=s[k-1]) s[i]='*';
	cout<<s<<endl;
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) static_cast<int>((x).size())

using LL = long long;
template<class T, size_t D>
struct vec : vector<vec<T, D - 1>> {
  template<class... Args>
  vec(size_t n = 0, Args... args)
    : vector<vec<T, D - 1>>(n, vec<T, D - 1>(args...)) {}
};
template<class T>
struct vec<T, 1> : vector<T> {
  template<class... Args>
  vec(Args... args)
    : vector<T>(args...) {}
};

template<class T>
inline bool asMn(T& a, const T& b) { return a > b ? a = b, true : false; }
template<class T>
inline bool asMx(T& a, const T& b) { return a < b ? a = b, true : false; }
inline int nex(int i, int n) { return i == n - 1 ? 0 : i + 1; }
inline int pre(int i, int n) { return !i ? n - 1 : i - 1; }

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

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

  int n; cin >> n;
  vec<int, 1> a(n);
  for (auto& i : a) {
    cin >> i;
  }

  vec<int, 1> pref(n);
  pref[0] = abs(a[0]);
  for (int i = 1; i < n; ++i) {
    pref[i] = pref[i - 1] + abs(a[i] - a[i - 1]);
  }
  vec<int, 1> suff(n);
  suff[n - 1] = abs(a[n - 1]);
  for (int i = n - 2; ~i; --i) {
    suff[i] = suff[i + 1] + abs(a[i] - a[i + 1]);
  }

  for (int i = 0; i < n; ++i) {
    cout << (i ? pref[i - 1] : 0) + (i + 1 < n ? suff[i + 1] : 0) + abs((i ? a[i - 1] : 0) - (i + 1 < n ? a[i + 1] : 0)) << '\n';
  }

  return 0;
}

Measured memory_bytes: 4516
#include<iostream>
#include<vector>
#include<string>
using namespace std;
using ll = long long;
vector<string> splitwords(string s){
  vector<string> words;
  for(int i=0;i<s.size();i++){
    string w=s.substr(i,1);
    int j=i+1;
    while(j<s.size()&&s[i]==s[j]){
      w+=s[i];
      j++;
      i++;
    }
          words.push_back(w);
          }
          return words;
          }
          
int main(){
  string S;
  cin>>S;
  ll k;
  cin>>k;
  ll ans=0;
  vector<string> words;
  words=splitwords(S);
  if(words[0]==S){
    ans=(ll)S.size()*k/2;
  }else{
    for(int i=0;i<(int)words.size();i++){
      if(i==0||i==words.size()-1){
        continue;}else{
        ans+=((ll)words[i].size()/2)*k;
  }
    }
    
      ans+=(ll)words[0].size()/2;
      ans+=(ll)words[(int)words.size()-1].size()/2;
      string ab=words[0]+words[(int)words.size()-1];
    if(S[0]==S[(int)S.size()-1]){
      ans+=((ll)ab.size()/2)*(k-1);
    }else{
      ans+=((ll)words[0].size()/2)*(k-1);
      ans+=((ll)words[(int)words.size()-1].size()/2)*(k-1);
    }
  }
      cout<<ans<<endl;
      return 0;
    }
    

Measured memory_bytes: 256
import * as fs from 'fs';

export class Reader {
    lines: string[];
    currentLine: number;

    constructor() {
        this.lines = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        this.currentLine = 0;
    }

    readLine(): string {
        return this.lines[this.currentLine++];
    }

	readChars(): string[] {
		let S = this.readLine();
		return new Array(S.length).fill(null).map((_, i) => S.charAt(i));
	}

    readInt(): number {
        return Number(this.readLine());
    }

    readInts(): number[] {
        return this.readLine().split(" ").map(Number);
    }
}

let reader = new Reader();
let S = reader.readLine();
let A = new Array(S.length+1).fill(0);

for(let i=0; i<S.length; i++) {
	if (S.charAt(i) == '<') {
		A[i+1] = A[i]+1;
	}
}

for(let i=S.length-1; i>=0; i--) {
	if (S.charAt(i) == '>') {
		A[i] = Math.max(A[i], A[i+1]+1);
	}
}

console.log(A.reduce((a, b) => a+b, 0));


Measured memory_bytes: 42520
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    begin(v), end(v)
#define in        []{lint n; cin>>n; return n;}()

int main(){ cin.tie(0); ios::sync_with_stdio(false);
    int N = in, A = in, B = in;
    cout << min( N*A, B ) << "\n";
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
main()
{
	string s,t;
	cin>>s>>t;
	int ans=0;
	if(s[0]==t[0])
	{
		ans++;
	}
    if(s[1]==t[1])
	{
		ans++;
	}
	if(s[2]==t[2])
	{
		ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define MZ 1000000007
#define pq priority_queue
int main()
{
    int n;
    long long t,ans=0,now=-1,temp;
    cin>>n>>t;
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&temp);
        if(temp>=now)
            ans+=t;
        else
            ans+=temp+t-now;
        now=temp+t;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
klis=[]
for i in range(m):
  ababa=list(map(int,input().split()))
  ababa.pop(0)
  klis.append(ababa)
p=list(map(int,input().split()))

res=0
for i in range(0,2**n):
  keep=0
  jyotai=[]
  for j in range(0,n):
    j=n-j-1
    onezero=i//2**j
    jyotai.append(onezero)
    i-=onezero*(2**j)
  for k in range(0,m):
    count=0
    for l in range(0,len(klis[k])):
      if jyotai[klis[k][l]-1]==1:
        count+=1
    if count%2!=p[k]:
      keep=1
      break
  if keep==0:
    res+=1
print(res)

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

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

constexpr ll INF = 1ll<<60;
ll N, M;
ll C[20], X[20010];
ll dp[20010][270];

void init()
{
	for (ll i = 0; i < 20010; ++i)
		for (ll j = 0; j < 270; ++j)
			dp[i][j] = INF;
}

ll round(ll a)
{
	if (a < 0) return 0;
	else if (a > 255) return 255;
	else return a;
}

ll dist(ll a, ll b)
{
	return pow(a-b, 2);
}

int main(int argc, char **argv)
{
	while (true)
	{
		cin >> N >> M;
		if (N == 0 && M == 0) break;
		for (ll i = 0; i < M; ++i) cin >> C[i];
		for (ll i = 0; i < N; ++i) cin >> X[i];
		init();
		for (ll i = 0; i < M; ++i) dp[0][round(128+C[i])] = dist(round(128+C[i]), X[0]);

		for (ll n = 0; n < N; ++n)
		{
			for (ll a = 0; a <= 255; ++a)
			{
				for (ll m = 0; m < M; ++m)
				{
					ll tmp = round(a+C[m]);
					chmin(dp[n+1][tmp], dp[n][a]+dist(tmp, X[n+1]));
				}
			}
		}
		ll res{INF};
		for (ll i = 0; i <= 255; ++i) chmin(res, dp[N-1][i]);
		std::cout << res << std::endl;
		
	}
}



Measured memory_bytes: 45444
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define RREP1(x,n) for(int x = n-1; x >= 0; x--)
#define RREP2(x,s,e) for(int x = s; x >= e; x--)
#define BR printf("\n")
#define INF 2000000000

typedef long long ll;

int main(){
    string S;
    cin >> S;
    int len = S.size();
    int group = 1;
    REP2(i,1,len-1){
        if(S[i] != S[i-1]){
            group++;
        }
    }
    
    cout << group-1 << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

const int inf = 999999;

int n, m, d[501][501], t[501][501], a[501][501];
string s, p, g;
map<string, int> mpp;

int main()
{
  string s1, s2;
  int u, v, q;
  while(cin>>n>>m && (n+m)){
    cin >> s >> p >> g;
    fill(&d[0][0], &d[501][0], inf);

    for(int i = 0; i < n; i++) d[i][i] = 0;
    q = 0;

    while(m--){
      cin >> s1 >> s2 >> u >> v;
      if(mpp.find(s1) == mpp.end()) mpp[s1] = q++;
      if(mpp.find(s2) == mpp.end()) mpp[s2] = q++;

      d[mpp[s1]][mpp[s2]] = d[mpp[s2]][mpp[s1]] = u/40 + v;
    }

    for(int k = 0; k < n; k++)
      for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
          d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
    cout << (d[mpp[s]][mpp[p]]+d[mpp[p]][mpp[g]]) << endl;

    mpp.clear();
  }

  return 0;
}

Measured memory_bytes: 1948
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP2(i,m,n) for (int i=m;i<(n);i++)
typedef long long ll;
typedef long double ld;

const int HOGE = 1 << 20;
const ll INF = 1LL << 59;
const ll MOD = 1000000007;

int dr[8] = {-1, 1, 0, 0, HOGE, -HOGE};
int dc[8] = {0, 0, -1, 1, 0, 0, HOGE, -HOGE};

int H ,W, sr, sc, gr, gc;
ll dist[505][505];
ll dp[505][505];

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

    cin >> H >> W >> sr >> sc >> gr >> gc;

    REP(i, H) REP(j, W) dist[i][j] = INF;
    dp[504][504] = 1;

    priority_queue<tuple<int,int,int,int,int>> pq;
    pq.push(make_tuple(0, sr, sc, 504, 504));

    while (!pq.empty()) {
        auto t = pq.top();
        auto d = -get<0>(t);
        auto r = get<1>(t);
        auto c = get<2>(t);
        auto pr = get<3>(t);
        auto pc = get<4>(t);
        pq.pop();
        if (d > dist[r][c]) {
            continue;
        } else if (d == dist[r][c]) {
            (dp[r][c] += dp[pr][pc]) %= MOD;
            continue;
        } else {
            dp[r][c] = dp[pr][pc];
        }
        dist[r][c] = d;
        REP(i, 8) {
            int nr = r + dr[i];
            int nc = c + dc[i];
            if (nr < -10) nr = 0;
            if (nr > H+10) nr = H-1;
            if (nc < -10) nc = 0;
            if (nc > W+10) nc = W-1;
            if (nr < 0 || nr >= H || nc < 0 || nc >= W) continue;
            if (dist[nr][nc] < d + 1) continue;
            pq.push(make_tuple(-(d+1), nr, nc, r, c));
        }
    }

    cout << dist[gr][gc] << " " << dp[gr][gc] << endl;
}



Measured memory_bytes: 7052