akhauriyash/Code-Regression huggingface dataset:
import os
import sys

import numpy as np


def solve(inp):
    n = inp[0]
    xxx = inp[1::3]
    yyy = inp[2::3]
    ppp = inp[3::3]

    ans = np.full(n + 1, 10 ** 18, dtype=np.int64)

    default_dist = np.zeros(n, dtype=np.int64)
    for i in range(n):
        default_dist[i] = min(abs(xxx[i]), abs(yyy[i]))

    for bit in range(1 << n):
        k = (bit & 0x5555) + (bit >> 1 & 0x5555)
        k = (k & 0x3333) + (k >> 2 & 0x3333)
        k = (k & 0x0f0f) + (k >> 4 & 0x0f0f)
        k = (k & 0x00ff) + (k >> 8 & 0x00ff)

        i = 0
        cur = 0
        t = bit
        selected = np.zeros(k, dtype=np.int64)
        is_selected = np.zeros(n, dtype=np.int8)
        while t:
            if t & 1:
                selected[cur] = i
                is_selected[i] = 1
                cur += 1
            t >>= 1
            i += 1

        for bit2 in range(1 << k):
            cost = 0
            for i in range(n):
                if is_selected[i]:
                    continue
                town_dist = default_dist[i]
                t = bit2
                for j in range(k):
                    if t & 1:
                        town_dist = min(town_dist, abs(yyy[selected[j]] - yyy[i]))
                    else:
                        town_dist = min(town_dist, abs(xxx[selected[j]] - xxx[i]))
                    t >>= 1
                cost += town_dist * ppp[i]
            kk = len(selected)
            ans[kk] = min(ans[kk], cost)

    return ans


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print('\n'.join(map(str, ans)))


Measured memory_bytes: 27208
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits>
#include <cmath>

using namespace std;

template<class T>
class Input {
public:
    auto operator()() const {
        T v;
        cin >> v;
        return v;
    }
};

template<class L, class R>
class Input<pair<L, R>> {
public:
    auto operator()() const {
        L l;
        R r;
        cin >> l >> r;
        return make_pair(l, r);
    }
};

template<class U>
class Input<vector<U>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        return (*this)(n);
    }
    auto operator()(size_t n) const {
        vector<U> v;
        v.reserve(n);
        Input<U> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in();
            v.emplace_back(move(u));
        }
        return v;
    }
};

template<class U>
class Input<vector<vector<U>>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        auto m = in();
        return (*this)(n, m);
    }
    auto operator()(size_t n, size_t m) const {
        vector<vector<U>> v;
        v.reserve(n);
        Input<vector<U>> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in(m);
            v.emplace_back(move(u));
        }
        return v;
    }
};

template<class T>
T input() {
    Input<T> i{};
    return i();
}

using ll = long long;
using ull = unsigned long long;

int main() {
    Input<size_t> in1{};
    auto n = in1();
    auto m = in1();
    Input<vector<size_t>> in2{};
    vector<vector<size_t>> ss{};
    ss.reserve(m);
    for (size_t i = 0; i < m; ++i)
        ss.emplace_back(in2());
    vector<size_t> p{};
    p.reserve(m);
    for (size_t i = 0; i < m; ++i)
        p.emplace_back(in1());
    size_t res = 0;
    for (size_t i = 0; i < (1ull << n); ++i) {
        size_t b = 0;
        for (size_t j = 0; j < m; ++j) {
            size_t c = 0;
            for (auto s : ss[j]) {
                if ((i & (1ull << (s - 1))))
                    ++c;
            }
            if (p[j] == c % 2)
                ++b;
        }
        if (b == m)
            ++res;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111

	bool dp[31000][4][1000];

	void solve(){

		ini(n);
		ins(morty);
		dp[0][0][0] = 1;
		FOR(i,0,n){
			FOR(i1,0,4){
				FOR(i2,0,1000){
					if(!dp[i][i1][i2])continue;
					dp[i+1][i1][i2] = 1;
					if(i1<=2){
						dp[i+1][i1+1][i2*10+(morty[i]-'0')] = 1;
					}
				}
			}
		}
		int rick = 0;
		FOR(i,0,1000){
			rick+=dp[n][3][i];
		}
		out(rick);








	}	























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 119168
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n, m = MAP()
L = [LIST() for i in range(m)]

R = [[0] * n for i in range(n)]

for a, b in L:
    R[a-1][b-1] += 1
    R[b-1][a-1] += 1

for r in R:
    print(sum(r))
    


Measured memory_bytes: 5144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

bool is_palindrome(string s)
{
	string t = s;
	reverse(t.begin(), t.end());
	return s == t;
}

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	bool flag = true;
	if (!is_palindrome(s)) flag = false;
	if (!is_palindrome(s.substr(0, (n - 1) / 2))) flag = false;
	cout << (flag ? "Yes" : "No") << endl;
}

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

now=h[0]
cnt=0
A=[]
for i in range(n-1):
  nxt=h[i+1]
  if nxt<=now:
    cnt+=1
  else:
    A.append(cnt)
    cnt=0
  now=nxt
A.append(cnt)
print(max(A))

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

using namespace std;

int main(void){

  int N;
  string S;
  int ac, wa, tle, re;

  ac = wa = tle = re = 0;

  cin >> N;

  for(int i=0; i<N; i++){
    cin >> S;
    if(S=="AC") ac++;
    else if(S=="WA") wa++;
    else if(S=="TLE") tle++;
    else if(S=="RE") re++;
  }

  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define MAX 200010
using namespace std;

char str[MAX];

int main(void)
{
	int N;
	cin >> str;
	N = strlen(str);
	int ans = 0;
	int idx = 0;
	int flag = 0;
	while (idx < N)
	{
		ans++;
		if (idx && str[idx] == str[idx - 1] && !flag)
		{
			flag = 1;
			idx += 2;
		}
		else
		{
			flag = 0;
			idx++;
		}
	}
	if (idx > N) ans--;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>//復習必須
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
const int mod=1e9+7;
int main (){ 
    int n,p=1;
  cin>>n;
  map<int,int> m;
  for(int i=0,a;i<n;++i){
    cin>>a;
    if(++m[a]>2 || (m[a]==2 && a==0) || (n%2 == a%2))return cout<<0,0;
    if(m[a]==2)p=p*2%mod;
  }
  cout<<p << endl;;

}

 


Measured memory_bytes: 2560
#include <iostream>
using namespace std;
#define MAX 300000

int a[MAX];
long long s[MAX];
int main(){
	fill(a, a+MAX, 1);
	for(int i = 2;i < MAX;i++){
		if(a[i]){
			for(int j = 2;i*j < MAX;j++)a[i*j] = 0;
		}
	}
	s[1] = 0;
	for(int i = 2;i < MAX;i++)s[i] = s[i-1]+a[i];
	int n, ans;
	while(cin >> n, n){
		ans = s[2*n]-s[n+1];
		if(s[n] != s[n+1])cout << ans+1 << endl;
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 6596
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>


using namespace std;

const int MAX	= 1e5 + 5;
const int LIM	= 3e5 + 5;
const int MOD	= 1e9 + 7;
const long double  EPS	= 1e-10;
const double PI = acos(-1.0);

typedef long long LL; 
typedef long double LD;


#define uint64 unsigned long long
#define int64 long long


#define IOS  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

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

int main()
{
    LL n,k;
	scanf("%lld%lld",&n,&k);
	n%=k;
	if(n>k-n)printf("%lld\n",k-n);
	else printf("%lld\n",n);
}




Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


int main(){
  
  int n;
  cin>>n;
  long long a[n];
  long long index[n+1];//1~nの配列中のインデックスを格納する配列
  REP(i,n){
    cin>>a[i];
    index[a[i]] = i;
  }
  
  set<long long> s;
  s.insert(-1);
  s.insert(n);
  long long l,r;
  long long ans = 0;
  for(long long i=1;i<=n;i++){//最小値としてiをとる区間の個数を数える
    auto itr_r = s.lower_bound(index[i]);
    r = *itr_r;
    auto itr_l = --itr_r;
    l = *itr_l;
    ans += i*(index[i]-l)*(r-index[i]);
    s.insert(index[i]);
  }
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 12800
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    int n;
    bool ok;
    int count=0;
    cin >> n;
    if(n==1){
        ok=true;
    }else if(n==2){
        ok=false;
    }else if(n==3){
        ok=true;
    }else{
        int tmp=3;
        int incl=3;
        count=1;
        ok=false;
        while(tmp<n){
            tmp+=incl;
            if(tmp==n){
                ok=true;
                break;
            }
            incl++;
            count++;
        }
    }

    vector<vector<int>> box(3+count, vector<int>(2+count));
    box[0][0] = 1;
    box[0][1] = 2;
    box[1][0] = 3;
    box[1][1] = 1;
    box[2][0] = 2;
    box[2][1] = 3;    

    if(ok==false){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
        if(n==1){
            cout << 2 << endl;
            cout << 1 << " " << 1 << endl;
            cout << 1 << " " << 1 << endl;
        }else if(n==3){
            cout << 3 << endl;
            cout << 2 << " " << box[0][0] << " " << box[0][1] << endl;
            cout << 2 << " " << box[1][0] << " " << box[1][1] << endl;
            cout << 2 << " " << box[2][0] << " " << box[2][1] << endl;
        }else{
            int tmp=4;
            int tmp2=3;
            //cout << 3+count << " " << 2+count << endl;
            for(int i=0; i<count; i++){
                int tmp3=3+i;
                for(int j=0; j<tmp3; j++){
                    box[3+i][j] = tmp+j;
                }
                //cout << "test" << endl;
                for(int j=0; j<tmp3; j++){
                    box[j][tmp3-1] = tmp+j;
                }
                //cout << "test2" << endl;
                tmp+=tmp2;
                tmp2++;
            }
            cout << 3+count << endl;
            for(int i=0; i<3+count; i++){
                cout << 2+count << " ";
                for(int j=0; j<2+count; j++){
                    cout << box[i][j] << " ";
                }
                cout << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 2176
while True:
    t, p, r = map(int, input().split())
    if t == 0 and p == 0 and r == 0: break
    logs = [input().split() for _ in range(r)]
    score = [[0, 0, -i, [0] * p] for i in range(t)]
    c_n, pen, w_n = 0, 1, 3
    for tid, pid, time, msg in logs:
        tid, pid, time = int(tid) - 1, int(pid) - 1, int(time)
        if msg == 'WRONG':
            score[tid][w_n][pid] += 1
        elif msg == 'CORRECT':
            score[tid][c_n] += 1
            score[tid][pen] -= (score[tid][w_n][pid] * 1200 + time)
            score[tid][w_n][pid] = 0
    score = sorted(score, reverse=True)
    for c_n, pen, t, _ in score:
        print(abs(t) + 1 , c_n, abs(pen))

Measured memory_bytes: 7028
import java.util.Scanner

fun main(args: Array<String>){
    val scn = Scanner(System.`in`)
    val list = scn.nextLine().split(" ")
    val N = list[0].toInt()
    val M = list[1].toInt()

    val result = (M*(M-1)/2) + (N*(N-1)/2)
    print("$result")


}

Measured memory_bytes: 35828
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        boolean b = false;
        for (int i=0;i<=x&&!b;i++){
            if (2*i+4*(x-i)==y)b=true;
        }
        if (b){
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35780
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.Collections;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ESequenceDecomposing solver = new ESequenceDecomposing();
        solver.solve(1, in, out);
        out.close();
    }

    static class ESequenceDecomposing {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            ArrayList<Integer> a = new ArrayList<>();
            for (int i = 0; i < n; i++) a.add(in.nextInt());
            Collections.reverse(a);
            out.println(CustomList.longestIncreasingSubsequence(a));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }

    static class CustomList {
        public static int upperBound(List<Integer> a, int low, int high, int element) {
            while (low < high) {
                int middle = low + (high - low) / 2;
                if (a.get(middle) > element)
                    high = middle;
                else
                    low = middle + 1;
            }
            return low;
        }

        public static int longestIncreasingSubsequence(List<Integer> a) {

            ArrayList<Integer> ans = new ArrayList<>();
            for (int i = 0; i < a.size(); i++) {
                int x = upperBound(ans, 0, ans.size(), a.get(i));
                if (x + 1 > ans.size()) {
                    ans.add(a.get(i));
                } else
                    ans.set(x, a.get(i));
            }
            return ans.size();
        }

    }
}



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

int main(){
  int W,H,x,y,r;
  cin>>W>>H>>x>>y>>r;
    
  if(x-r>=0&&x+r<=W&&y-r>=0&&y+r<=H)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}



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

int main(){
    int n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll MX = -1e18;
    rep(i,n) MX = max(MX, a[i]);
    vector<bool> add(n,false);
    if(MX<0){ //要素全てが負の場合
        rep(i,n){
            if(a[i]==MX){
                add[i] = true;
                break;
            }
        }
    }else{ //偶奇で分けて答えを求める
        ll p=0,q=0;
        rep(i,n){
            if(a[i]>0){
                if(i&1) p+=a[i];
                else q+=a[i];
            }
        }
        for(int i=(p>q);i<n;i+=2)if(a[i]>0) add[i] = true;
    }

    vector<int> ans; //答え用の配列
    while(a.size()>1){
        int la = a.size();
        if(!add.front()){ //前がいらない
            a.erase(a.begin());
            add.erase(add.begin());
            ans.push_back(1);
        }else if(!add.back()){ //後ろがいらない
            a.erase(prev(a.end()));
            add.erase(prev(add.end()));
            ans.push_back(la);
        }else{ //間
            int pos=0;
            for(int i=1;i<la-1;i++){
                if(add[i-1]&&!add[i]&&add[i+1]) pos=i; //1&&0&&1
                if(!add[i-1]&&!add[i]&&!add[i+1]) pos=i; //0&&0&&0
            }
            ll sum = a[pos-1] + a[pos+1];
            a.erase(a.begin() + pos);
            add.erase(add.begin() + pos);
            a.erase(a.begin() + pos);
            add.erase(add.begin() + pos);
            a[pos-1] = sum;
            ans.push_back(pos+1);
        }
    }

    cout << a[0] << endl;
    n = ans.size();
    cout << n << endl;
    rep(i,n) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 3648
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools
import math


def main():
  coods = [tuple(map(int, input().split())) for _ in range(int(input()))]
  dists = [[0] * len(coods) for _ in range(len(coods))]

  for i, j in itertools.product(range(len(coods)), repeat=2):
    d = math.sqrt((coods[i][0] - coods[j][0]) ** 2 + (coods[i][1] - coods[j][1]) ** 2)
    dists[i][j] = d
    dists[j][i] = d

  dist = sum(sum(v) / (len(v) - 1) for v in dists)

  print('{:.14f}'.format(dist - dist / len(coods)))


if __name__ == '__main__':
  main()


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
typedef long long ll;

using namespace std;

int main(){
  int H, W, h, w;
  cin >> H  >> W >> h >> w;
  int ans = H * W - (H * w + h * W - h * w);
  cout << ans << endl;
}


Measured memory_bytes: 256
//start of jonathanirvings' template v3.0.3 (BETA)

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

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
}

//end of jonathanirvings' template v3.0.3 (BETA)

LL dp[100005][3];
int angka[100005];
string op[100005];
int n;

LL jahja(int now,int open)
{
  if (now == n) return 0;
  LL &ret = dp[now][open];
  if (ret >= 0) return ret;
  ret = 0;
  int num = angka[now] * (op[now] == "+" ? 1 : -1);
  REP(i,open) num *= -1;
  ret = jahja(now + 1, open) + num;
  if (open > 0) MAX(ret,jahja(now,open-1));
  if (open < 2 && op[now] == "-") MAX(ret,jahja(now+1,open+1)+num);
  //debug("%d %d %lld\n",now,open,ret);
  return ret;
}

int main()
{
  scanf("%d",&n);
  op[0] = "+";
  scanf("%d",&angka[0]);
  FOR(i,1,n)
  {
    op[i] = GetString();
    scanf("%d",&angka[i]);
  }
  RESET(dp,-1);
  LL risan = jahja(0,0);
  printf("%lld\n",risan);
  return 0;
}










Measured memory_bytes: 16384
import java.util.ArrayList;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    ArrayList<Integer> A = new ArrayList<>();

	    for (int i = 0; i < N; i++) {
	    	int even = sc.nextInt();
	    	if (even % 2 == 0) {
	    		A.add(even);
	    	}
	    }

	    boolean flg = true;
	    for (int a : A) {
	    	if ((a % 3 !=0) && (a % 5 != 0)) {
	    		flg = false;
	    		break;
	    	}
	    }
	    
	    if (flg) {
	    	System.out.println("APPROVED");
	    } else {
		    System.out.println("DENIED");
	    }

	  }
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
int n,k,a[100010],ans=INT_MAX;
int main(){
	cin>>n>>k;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	if (a[n]<=0)
	{
		cout<<abs(a[n-k+1])<<"\n";
		return 0;
	}
	if (a[1]>=0)
	{
		cout<<abs(a[k])<<"\n";
		return 0;
	}
	int l=lower_bound(a+1,a+n+1,0)-a-1;
	int g=l;
	int r=l+k-1;
	//cout<<l<<" "<<r<<"\n";
	while (r>=g)
	{ //cout<<l<<" "<<r<<"\n";
		if (l<=0 || r>n || l>n || r<=0) 
		{
			l--,r--;
			continue;
		}	
		
		//cout<<ans<<"\n";
		if (a[r]>0 && a[l]<0) ans=min(ans,min(abs(a[r]),abs(a[l]))+a[r]-a[l]);
		else ans=min(ans,max(abs(a[r]),abs(a[l])));
		l--,r--;
	}
	cout<<ans<<"\n";
	return 0;
}



Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	string s; cin>>s;
	int n=s.size();
	for(int i=0; i<n; i++){
		if(i&1){
			if(s[i]=='R'){
				cout<<"No"<<endl;
				return 0;
			}
		}else{
			if(s[i]=='L'){
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
//Palindromic Matrix

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int h,w;cin>>h>>w;
    vecrep(h,a,string);
    map<int,int>m;
    rep(i,0,h)rep(j,0,w)m[a[i][j]-'a']++;
    bool ans=true;
    int o=0,t=0,s=0,f=0;
    for(auto i:m){
        if(i.second%4==1)o++;
        else if(i.second%4==2)t+=2;
        else if(i.second%4==3)s+=3;
    }
    bool flag=true;
    if(o>1||s!=0)flag=false;
    if((w&1)&&(h&1)){
        if(o!=1)flag=false;
        if(h+w-2<t)flag=false;
    }else if(w&1){
        if(h<t)flag=false;
    }else if(h&1){
        if(w<t)flag=false;
    }else{
        if(t!=0)flag=false;
    }
    if(flag)cout<<"Yes"<<nnn;
    else cout<<"No"<<nnn;
    return 0;
}

Measured memory_bytes: 3612
N, K = map(int, input().split())
A = list(map(int, input().split()))
D = {}
for i in A:
  if i in D:
    D[i] += 1
  else:
    D[i] = 1
B = [D[i] for i in D]
if len(B) <= K:
  print(0)
else:
  B.sort()
  print(sum(B[i] for i in range(len(B) - K)))

Measured memory_bytes: 32184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
ll res=0;
int main()
{
	cin>>s;
	int n=s.size()-1;
	for(int i=0;i<(1<<n);i++)
	{
		vector<ll> v;
		ll tmp=0; 
		for(int j=0;j<=n;j++)
		{
			tmp*=10;
			int x=s[j]-'0';
			tmp+=x; 
			if(1&(i>>j))
			{
				v.push_back(tmp);
				tmp=0;
			}
		}
		v.push_back(tmp);
		ll sum=0;
		for(int j=0;j<v.size();j++)
		{
			ll x=v[j];
			sum+=x;
		}
		res+=sum;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n;
    int p[50];
    int i;
    int flag = 0;
    
    scanf("%d",&n);
    for(i=0; i<n; i++){
    	scanf("%d",&p[i]);
    }
    
    for(i=0; i<n; i++){
    	if(p[i] != i+1){
        	flag++;
        }
    }
    
    if(flag == 2 || flag == 0){
   		printf("YES");
    }else{
        printf("NO");
    }

	return 0;
}

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

using namespace std;

int main(void) {
  int N; cin >> N;
  vector<int> P, Q;
  for (int i = 0; i < N; i++) {
    int j; cin >> j;
    P.push_back(j);
  }
  for (int i = 0; i < N; i++) {
    int j; cin >> j;
    Q.push_back(j);
  }
  int a = 0, b = 0;

  while (next_permutation(P.begin(), P.end())) a++;
  while (next_permutation(Q.begin(), Q.end())) b++;

  cout << abs(a-b) << endl;
  
  return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
	ll n, ans = 0;
	cin >> n;
	string s;
	map<string, ll> mp;
	for(int i = 0 ; i < n ; i++){
		cin >> s;
		sort(s.begin(), s.end());
		++mp[s];
	}
	for(auto it = mp.begin() ; it != mp.end() ; it++){
		ans += (it->second  * (it->second - 1)) >> 1;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 11136
#include<iostream>
using namespace std;
#define m int64_t
#define d(s,i,n) for(m i=s;i<n;i++)
#define z else
main(){m n,a,b,o=1e9+7,x=90,l[x][x],r[x][x];cin>>n;d(0,i,x){l[i][0]=r[i][0]=1;d(1,j,x){if(i==j)r[i][j]=r[i][j-1]*2+l[i][j-1];z r[i][j]=r[i][j-1]+l[i][j-1];l[i][j]=r[i][j-1];}}d(0,i,n){cin>>a>>b;if(b>a)swap(a,b);m k=0;d(0,j,x)if(a>=r[0][j]&&b>=l[0][j])k=j;m g;if(k==0)k=1,g=1;z if(k==1)if(b==1)g=a;z g=4;z{g=1;if(b>=r[0][k]&&a>=l[0][k]&&l[0][k]<r[0][k])g++;d(1,j,k+1)if(r[j][k]<=a&&l[j][k]<=b)g+=1+(a-r[j][k])/l[j][k];d(1,j,k+1)if(r[j][k]<=b)g+=1+(b-r[j][k])/l[j][k];}cout<<k<<" "<<g%o<<" ";}}

Measured memory_bytes: 4444
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define eps 1e-9

typedef long long ll;
typedef pair<int, int> pii;

const ll INF = 1e18;
const int maxn = 2e3 + 10;
int n, m, a, b, c, edge = 0;
int head[maxn], Next[maxn], to[maxn], cnt[maxn];
ll val[maxn], dis[maxn];
bool vis[maxn], vis1[maxn];
bool flag;

inline void add_edge(int u, int v, int _val) {
    to[edge] = v; val[edge] = _val; Next[edge] = head[u]; head[u] = edge++;
}
void dfs(int u) {
    if (u == n) { flag = true; return; }
    for (int i = head[u]; i != -1; i = Next[i]) {
        if (vis1[to[i]]) { continue; } vis1[to[i]] = true; dfs(to[i]);
    }
}
bool judge(int u) { memset(vis1, false, sizeof(vis1)); flag = false; dfs(u); return flag; }

bool spfa() {
    memset(vis, false, sizeof(vis)); memset(cnt, 0, sizeof(cnt)); int f;
    dis[1] = 0; for (int i = 2; i <= n; ++i) { dis[i] = INF; }
    queue<int> q; q.push(1);
    while (!q.empty()) {
        f = q.front(); q.pop(); vis[f] = false; ++cnt[f];
        if (cnt[f] > n + 1) {
            if (judge(f)) { return false; } vis[f] = true;
        }
        for (int i = head[f]; i != -1; i = Next[i]) {
            if (dis[to[i]] > dis[f] + val[i]) {
                dis[to[i]] = dis[f] + val[i];
                if (!vis[to[i]]) { vis[to[i]] = true; q.push(to[i]); }
            }
        }
    }
    return true;
}
int main() {
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // __AiR_H
    memset(head, -1, sizeof(head));
    scanf("%d %d", &n, &m);
    while (m--) {
        scanf("%d %d %d", &a, &b, &c); c = -c; add_edge(a, b, c);
    }
    if (spfa()) { printf("%lld\n", -dis[n]); } else { printf("inf\n"); }
#ifdef __AiR_H
    printf("Time used = %.2fs\n", (double)clock() / CLOCKS_PER_SEC);
#endif // __AiR_H
    return 0;
}


Measured memory_bytes: 384
use proconio::input;

fn main() {
    input! {
        n: i64,
    };

    let (l, m) = {
        let mut l = 0;
        let mut m = 0;
        while m < n {
            l += 1;
            m += 26_i64.pow(l);
        }
        (l, m - 26_i64.pow(l))
    };
    let ans = {
        let mut n = n - m - 1; // shadowing
        let mut s = vec![];
        for _ in 0..l {
            s.push(((n % 26) as u8 + b'a') as char);
            n /= 26;
        }
        s.iter().rev().collect::<String>()
    };
    println!("{}", ans);

    // let mut s = vec![];
    // while n > 0 {
    //     n -= 1;
    //     s.push(((n % 26) as u8 + b'a') as char);
    //     n /= 26;
    // }
    // println!("{}", s.iter().rev().collect::<String>());
}


Measured memory_bytes: 2160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n;
long long ans;
int main(){
	scanf("%d", &n);
	for(int i=1; i<=n; i++) if(i%3 && i%5) ans += i;
	printf("%lld\n", ans);
}

Measured memory_bytes: 3816
#include <iostream>
using namespace std;
int main(void){
    int x, y;
    while (1) {
        cin >> x >> y;
        if ( x == 0 && y == 0 ) { break; }
        if ( x < y ) {
            cout << x << " " << y << endl;
        }else{
            cout << y << " " << x << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3012
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin >> n;
    
    vector<int> a(n, 0);

    for (int i = 1; i < n; i++) {
        cin >> a.at(i);
    }

    vector<int> ans(n, 0);
    for (int i = 1; i < n; i++) {
        ans.at(a.at(i) - 1)++;
    }
    for (int i = 0; i < n; i++) {
        cout << ans.at(i) << endl;
    }
}



Measured memory_bytes: 4796
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
#define INF 1e9
using ll = int64_t;
template <class T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b)
{
  if (b < a)
  {
    a = b;
    return true;
  }
  return false;
}

//10^9 + 7
#define yojo 1000000007

std::int64_t gcd(std::int64_t a, std::int64_t b)
{
  // a >= b && b != 0
  std::int64_t c;
  do
  {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb)
{
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0)
  {
    return -1;
  }
  do
  {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
void rle(std::vector<std::pair<char, std::int64_t>> &data, std::string str)
{
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++)
  {
    if (i == str.size())
    {
      data.push_back(make_pair(str[i - 1], count));
      break;
    }
    else if (now != str[i])
    {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return;
}

#define MAX_NUM 200001

void Main()
{
  string s;
  cin >> s;
  for (int i = 1; i <= s.size(); i++)
  {
    char tmp = s[i - 1];
    if (i % 2 == 0)
    {
      if (tmp == 'R')
      {
        std::cout << "No" << std::endl;
        return;
      }
    }
    else
    {
      if (tmp == 'L')
      {
        std::cout << "No" << std::endl;
        return;
      }
    }
  }
  std::cout << "Yes" << std::endl;

  return;
}

int main()
{
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

// 無限大の値
const long long INF = 1LL << 60;


int main(){
    int N, K;
    vector< tuple<llong, llong, llong> > act;

    // i-1日目にある行動(a:0, b:1, c:2)を取った時のi日目までの幸福の最大値
    llong dp[100000][3]; 

    cin >> N;
    llong a,b,c;
    for(int i = 0; i < N; i++){
        cin >> a >> b >> c;
        act.push_back( make_tuple(a,b,c) );
    }

    for(int i = 0; i < N; i++){
        for(int j=0; j<3 ;j++){
            dp[i][j] = 0;
        }
    }

    dp[0][0] = get<0>(act[0]); // 0日目に行動aを取った
    dp[0][1] = get<1>(act[0]); // 0日目に行動bを取った
    dp[0][2] = get<2>(act[0]); // 0日目に行動cを取った
    
    for(int i=1; i<N; i++){
        dp[i][0] = max( dp[i-1][1], dp[i-1][2] ) + get<0>(act[i]);
        dp[i][1] = max( dp[i-1][0], dp[i-1][2] ) + get<1>(act[i]);
        dp[i][2] = max( dp[i-1][0], dp[i-1][1] ) + get<2>(act[i]);
    }

    llong res = 0;
    for(int j=0; j<3 ;j++){
        res = max(res, dp[N-1][j]);
    }

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

Measured memory_bytes: 5488
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

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

long long INF = 1LL<<60;
int main( ){
    ll a,b;
    cin>>a>>b;
    ll x;
    cin>>x;
    cout<<b/x-a/x+(a%x==0)<<endl;
    return 0;
}




Measured memory_bytes: 256
import numpy as np
[N,W]=[int(x) for x in input().split()]
wv=[[int(x) for x in input().split()] for i in range(N)]

dp=np.array([[10**10]*(10**5+1) for i in range(N)])

dp[0][wv[0][1]]=wv[0][0]
dp[0][0]=0

for i in range(1,N):
  last=10**5-wv[i][1]+2
  dp[i][wv[i][1]:]=np.minimum(dp[i-1][wv[i][1]:],dp[i-1][:last-1]+wv[i][0])
  dp[i][:wv[i][1]]=dp[i-1][:wv[i][1]]
ans=0
count=10**5
while(ans==0):
  if dp[N-1][count]<=W:
    ans=count
    break
  else:
    count=count-1
print(ans)

Measured memory_bytes: 183232
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;


void solve(long long N, std::string S){
  vl s(N+1);
  rep(i,N) s[i+1] = s[i]+ll(S[i]=='#');
  ll ans = LINF;
  rep(i,N+1){
    ll temp = (s[i])+N-i-(s[N]-s[i]);
    dump(i,temp);
    chmin(ans,temp);
  }
  cout << ans << endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::string S;
  std::cin >> S;
  solve(N, S);
  return 0;
}


Measured memory_bytes: 2308
import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc  = new Scanner(System.in);

    int n = sc.nextInt();
    int l = sc.nextInt();

    List<Integer> tastes = new ArrayList<>();
    for (int i = 1; i <= n; i++) {
      int taste = l + i - 1;
      tastes.add(taste);
    }

    List<Integer> tasteAbs = tastes
      .stream()
      .map(t -> Math.abs(t))
      .collect(Collectors.toList());

    Integer exclude = Collections.min(tasteAbs);
    Integer excludeIndex = tasteAbs.indexOf(exclude);

    tastes.remove(tastes.get(excludeIndex));

    int sum = tastes.stream().mapToInt(t -> t).sum();

    System.out.println(sum);
  }
}


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

using namespace std;
const int maxn = 1e5 + 4;


void _accepcted_by_one_hit_()
{
    #ifdef NTMA
        freopen("abc.inp", "r", stdin);
        freopen("abc.out", "w", stdout);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}
int Round(double x)
{
    int a = x, b = x + 1;
    if (a - x > b - x) return b;
    else return a;
}
int main()
{	
	_accepcted_by_one_hit_();
    int a, b; cin >> a >> b;
    for(int i=1; i<=maxn; ++i) {
        int x = Round(i*0.08); 
        int y = Round(i*0.1);
        if (x == a && y == b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1;
    return 0;
    
}

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

using namespace std;

const int N = 2005;
int u[N][N], d[N][N], l[N][N], r[N][N];
char s[N][N];

int main() {
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            u[i][j] = 0;
            d[i][j] = 0;
            l[i][j] = 0;
            r[i][j] = 0;
            s[i][j] = '#';
        }
    }

    int H, W;
    cin >> H >> W;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; ++j) {
            cin >> s[i][j];
        }
    }

    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (s[i][j] != '#') {
                u[i][j] = u[i - 1][j] + 1;
                l[i][j] = l[i][j - 1] + 1;
            }
        }
    }

    for (int i = H; i >= 1; i--) {
        for (int j = W; j >= 1; j--) {
            if (s[i][j] != '#') {
                d[i][j] = d[i + 1][j] + 1;
                r[i][j] = r[i][j + 1] + 1;
            }
        }
    }

    int ans = 0;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (s[i][j] != '#') {
                ans = max(ans, u[i][j] + d[i][j] + l[i][j] + r[i][j] - 3);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

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

int rui(int n,int x) {
  vector<int> vec(50);
  int64_t i,s,ans;
  i=0;
  ans=1;
  while(x>0){
  vec.at(i)=x%2;
    x=x/2;
  i++;    
  }
  s=n;
  for(int j=0;j<50;j++){
  if(vec.at(j)==1){ans=(ans*s)%2019;}  
   s=(s*s)%2019; 
  }
return ans;
}

int main() {
  int a=0;
  int n;
string s;
  cin>>s;
  n=s.size();
  vector<char> vec(n);
  vector<int> v(n);
  vector<int> ans(n);
  vector<int> cou(2019);
  for(int i=0;i<n;i++){
  vec.at(i)=s.at(i);
  }
  for(int i=0;i<n;i++){
  if(vec.at(i)=='1'){v.at(i)=1;}
    else if(vec.at(i)=='2'){v.at(i)=2;}
    else if(vec.at(i)=='3'){v.at(i)=3;}
    else if(vec.at(i)=='4'){v.at(i)=4;}
    else if(vec.at(i)=='5'){v.at(i)=5;}
    else if(vec.at(i)=='6'){v.at(i)=6;}
    else if(vec.at(i)=='7'){v.at(i)=7;}
    else if(vec.at(i)=='8'){v.at(i)=8;}
    else if(vec.at(i)=='9'){v.at(i)=9;}
  }
  reverse(v.begin(), v.end());
  ans.at(0)=v.at(0);
  for(int i=0;i<n-1;i++){
  ans.at(i+1)=(ans.at(i)+v.at(i+1)*rui(10,i+1))%2019;
  }
  cou.at(0)=1;
  for(int i=0;i<n;i++){
  cou.at(ans.at(i))++;
  }
  for(int i=0;i<2019;i++){
  a+=cou.at(i)*(cou.at(i)-1)/2;
  }
  cout<<a<<endl;
}


Measured memory_bytes: 5180
#include<stdio.h>
int main()
{
	int a,b,c,d,i,n;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a<c)
	{
		if(b<c)
		printf("0");
		else
		{
			if(b>d)
			printf("%d\n",d-c);
			else
			printf("%d\n",b-c);
		}
	}
	else
	{
		if(d<a)
		printf("0");
		else
		{
			if(d>b)
			printf("%d\n",b-a);
			else
			printf("%d\n",d-a);
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
typedef map<int, vector<int>> Graph;
typedef map<int, map<int, int>> WGraph;
typedef pair<int, int> Edge;
typedef pair<int, int> PII;
typedef pair<int, Edge> PIE;

vector<Edge> prim(WGraph &g)
{
    vector<Edge> ret;
    map<int, bool> mp;
    priority_queue<PIE, vector<PIE>, greater<PIE>> pq;
    mp[0] = true;
    for (auto x : g[0])
    {
        pq.push({x.second, {0, x.first}});
    }
    while (!pq.empty())
    {
        auto t = pq.top();
        auto next = t.second.second;
        pq.pop();
        if (mp[next] == true)
        {
            continue;
        }
        mp[next] = true;
        ret.push_back(t.second);
        for (auto x : g[next])
        {
            pq.push({x.second, {next, x.first}});
        }
    }
    return ret;
}

int main(int argc, char const *argv[])
{
    int v, e;
    cin >> v >> e;
    WGraph g;
    rep(i, e)
    {
        int s, t, w;
        cin >> s >> t >> w;
        g[s][t] = w;
        g[t][s] = w;
    }
    auto tree = prim(g);
    ll ans = 0;
    for (auto x : tree)
    {
        // cerr << x.first << " " << x.second << endl;
        ans += g[x.first][x.second];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 16592