akhauriyash/Code-Regression huggingface dataset:
from typing import Optional, Sequence


class BinaryIndexedTree:
    """Binary Indexed Tree (Fenwick Tree): O(logN)

    References:
        http://hos.ac/slides/20140319_bit.pdf
    """

    __slots__ = ["_size", "_tree", "is_zero_origin"]

    def __init__(
        self,
        size: int,
        initial_values: Optional[Sequence[int]] = None,
        is_zero_origin: bool = True,
    ):
        self._size = size
        self._tree = [0] * (size + 1)
        self.is_zero_origin = is_zero_origin

        if initial_values:
            for i, a in enumerate(initial_values):
                self.add(i, a)

    def add(self, index: int, value: int) -> None:
        """Add value to tree[index], O(logN)."""
        if self.is_zero_origin:
            index += 1
        while index <= self._size:
            self._tree[index] += value
            index += index & -index

    def sum(self, index: int) -> int:
        """Return the sum of [1, index] in O(logN)."""
        ret = 0
        while index > 0:
            ret += self._tree[index]
            index -= index & -index
        return ret

    def range_sum(self, left: int, right: int) -> int:
        """Return the range sum of [left, right] in O(logN)."""
        if not self.is_zero_origin:
            left -= 1
        return self.sum(right) - self.sum(left)


def point_add_range_sum():
    # https://judge.yosupo.jp/problem/point_add_range_sum
    N, Q, *X = map(int, open(0).read().split())
    A, queries = X[:N], X[N:]
    tree = BinaryIndexedTree(N, A)
    res = []
    for com, x, y in zip(*[iter(queries)] * 3):
        if com:
            res.append(tree.range_sum(x, y))
        else:
            tree.add(x, y)
    print("\n".join(map(str, res)))


if __name__ == "__main__":
    point_add_range_sum()


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

int main(){
  int K;
  string S;
  cin >> K >> S;
  size_t size = S.length();
  if(size <= K){
    cout << S << endl;
  }else{
    cout << S.substr(0,K) + "..." << endl;
  }
}

Measured memory_bytes: 3604
from copy import copy

h, w, k = map(int, input().split(' '))
c = []
for i in range(h):
    c.append(input())

def draw_tate(c, i):
    #c = copy(c)
    for j in range(len(c)):
        c[j] = c[j][0:i] + "." + c[j][i+1:]
    #return c

def draw_yoko(c, i):
    #c = copy(c)
    c[i] = "." * w
        #return c

a = 0
b = 2 ** h # 横
e = 2 ** w # 縦
for i in range(b):
    for j in range(e):
        d = copy(c)
        for m in range(h):
            if ((1 << m) & i) != 0:
                draw_yoko(d, m)
        for l in range(w):
            if ((1 << l) & j) != 0:
                draw_tate(d, l)
        d = ''.join(d)
        if d.count("#") == k:
            a += 1
print(a)


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


bool check_prime(int val) {
    for (int i = 2; i <= std::sqrt(val); i++) {
        if (val % i == 0) {
            return false;
        }
    }
    return true;
}


int main() {
    int N;
    std::cin >> N;
    int count = 0;
    for (int i = 0; i < N; i++) {
        int val;
        std::cin >> val;
        if (check_prime(val)) {
            count++;
        }
    }
    std::cout << count << std::endl;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
  long long i,a[5],c=0;
  for(int i=0;i<5;i++)
  {
      cin>>a[i];
      if(a[i]==0)
      {
          c=i;
          break;
      }
  }
    cout<<c+1<<endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll,ll>> p(n);
  rep(i,n) {
    ll a, b;
    cin >> a >> b;
    p[i] = make_pair(a,b);
  }

  SORT(p);

  ll sum_k = 0;
  rep(i,n) {
    sum_k += p[i].se;
    if (sum_k >= k) {
      cout << p[i].fi << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 1792
#2020-05-03
n, k = map(int, input().split())
lst = []
cou = 0
for i in range(k):
    a = int(input())
    lst = lst + input().split()
    set(lst)
for j in range(1, n+1):
    if str(j) not in lst:
        cou += 1
print(cou)


Measured memory_bytes: 9632
#include<bits/stdc++.h>
using namespace std;
int main (){
  int N, A, B;
  cin >> N >> A >> B;
  
  int count = 0;
  for(int i = 1; i <= N; i ++){
    int sum = 0;
    int n = i;
    while(n > 0){
      sum += n % 10;
      n /= 10;
      if(n == 0) break;
    }
    if(A <= sum && sum <= B)count += i;
  }
  cout << count << endl;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.System.in;


public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        int N = Integer.parseInt(reader.readLine());
        int[] seat = new int[100000];
        for (int i = 0; i < N; i++) {
            String[] inputs = reader.readLine().split(" ");
            int left = Integer.parseInt(inputs[0]);
            int right = Integer.parseInt(inputs[1]);
            for (int j = left - 1; j < right; j++) {
                seat[j] = 1;
            }
        }

        int counter = 0;
        for (int i = 0; i < 100000; i++) {
            counter += seat[i];
        }

        System.out.println(counter);
    }
}

Measured memory_bytes: 23124
// AtCoder My Practice
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!(usize);
    let mut xs = vec![1];
    let mut nine = 1;
    for i in 0..100 {
    	nine *= 9;
        if nine > n {
        	break;
        }
        xs.push(nine);
    }
    let mut six = 1;
    for i in 0..100 {
    	six *= 6;
        if six > n {
        	break;
        }
        xs.push(six);
    }
    xs.sort();
    let mut dp = vec![n+1; n+1];
    dp[0] = 0;
    loop {
    	for i in 0..dp.len() {
        	let i = dp.len()-i-1;
            if dp[i] > n {
            	continue;
            }
            for &x in xs.iter() {
            	let p = i+x;
                if p > n {
                	break;
                }
                if dp[i]+1<dp[p] {
                	dp[p] = dp[i]+1;
                }
            }
        }
        if dp[n] <= n {
        	break;
        }
    }
    let ans = dp[n];
	println!("{}", ans);    
}

Measured memory_bytes: 4352
n = int(input())
flag=0
lst = [int(i) for i in input().split()][:n]
for i in lst:
    if i%2==0 and i%3!=0 and i%5!=0:
        flag=1 
    else:
        continue
if flag==1:
    print("DENIED")
else:
    print("APPROVED")

Measured memory_bytes: 2940
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
//~ #pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=507;
using bn=bitset<nax*nax>;
const int d=63;

int n;

struct bity
{
	vll wek;
	bity(){}
	bity(int v)
	{
		wek.resize((v/d)+2, 0);
	}
	void ustaw(int v)
	{
		wek[v/d]|=(1LL<<(v%d));
	}
	void zeruj()
	{
		fill(wek.begin(), wek.end(), 0);
	}
	int licz()
	{
		int ret=0;
		for (const ll &i : wek)
			ret+=__builtin_popcountll(i);
		return ret;
	}
};

void oruj(bity &a, const bity &b)
{
	int r=min(a.wek.size(), b.wek.size());
	for (int i=0; i<r; i++)
		a.wek[i]|=b.wek[i];
}

char wcz[nax];
int tab[nax][nax];

bity oso[nax][10];

ll wyn;

int ile[nax];
int num[nax][nax];

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
	{
		scanf("%s", wcz+1);
		for (int j=1; j<=n; j++)
		{
			if (wcz[j]=='#')
			{
				tab[i][j]=-1;
			}
			else
			{
				tab[i][j]=wcz[j]-'0';
				ile[tab[i][j]]++;
				num[i][j]=ile[tab[i][j]];
			}
		}
	}
	for (int i=1; i<=n; i++)
		for (int j=1; j<=9; j++)
			oso[i][j]=bity(ile[j]);
	for (int i=n; i; i--)
	{
		for (int j=n; j; j--)
		{
			if (tab[i][j]==-1)
			{
				for (int l=1; l<=9; l++)
					oso[j][l].zeruj();
				continue;
			}
			for (int l=1; l<10; l++)
				oruj(oso[j][l], oso[j+1][l]);
			//~ oso[j]|=oso[j+1];
			for (int l=1; l<10; l++)
			{
				//~ if (oso[j][l].licz())
					//~ debug() << i << " " << j << " to " << l << " " << oso[j][l].licz();
				wyn+=l*tab[i][j]*oso[j][l].licz();
			}
			//~ oso[j][num(i, j)]=1;
			oso[j][tab[i][j]].ustaw(num[i][j]);
		}
	}
	printf("%lld\n", wyn);
	return 0;
}


Measured memory_bytes: 17920
/* Author haleyk10198 */
/* 作者:  haleyk10198 */
/* CF handle: haleyk100198*/
#include <bits/stdc++.h>

#define MOD 1000000007
#define LINF (1LL<<60)
#define INF 2147483647
#define PI 3.1415926535897932384626433
#define ll long long
#define pii pair<int,int>
#define mp(x,y) make_pair((x),(y))
#define pb(x) push_back((x))
#define vi vector<int>
#define vvi vector<vi>

using namespace std;

string itos(int x){
	stringstream ss;
	ss << x;
	return ss.str();
}

string str;
int used[26], n, T[800010], d[200010], nxt[200010], ch[200010];

bool ask(int x, int y){
	return (d[x] < d[y] || (d[x] == d[y] && str[x] < str[y]));
}

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	
	cin >> str; n = str.length()+1; fill(used, used+26, n);
	str = '0'+str;
	for(int i = n-1, cnt = 0; i >= 0; i--){
		int best = 0;
		for(int i = 1; i < 26; i++)
			if(ask(used[i], used[best])) best = i;
		nxt[i] = used[best];
		ch[i] = best;
		d[i] = d[nxt[i]]+1;
		if(i) used[str[i]-97] = i;
	}
	
	string res; 
	for(int pos = 0; pos < n; pos = nxt[pos])
		res += 'a'+ch[pos];
	
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 4688
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	string n=s;	/*PS!!!将s的值赋给s2,为了后期的判断做一个参照*/
	reverse(s.begin(),s.end());	/*倒置字符串*/
	for(int i=0;i<s.size();++i)	/*遍历字符串（可用s.length()）*/
	{
		if(s[i]=='b') s[i]='d';
		else if(s[i]=='d') s[i]='b';
		else if(s[i]=='p') s[i]='q';
		else if(s[i]=='q') s[i]='p';
	}
	if(s==n) cout<<"Yes"; 	/*直接使用参照数据进行判断*/
	else  cout<<"No";  		
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    map<int, int> m;
    rep (i, n) {
        int a; cin >> a;
        m[a]++;
    }
    int ans = 0;
    for (auto p : m) ans += p.second % 2;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
    #include <ext/pb_ds/tree_policy.hpp> 
    #include <functional> // for less 
    using namespace __gnu_pbds; 
    using namespace std;
    //typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;    
    #define ll            long long
    #define pb            push_back
    #define ppb           pop_back
    #define si            set <ll>
    #define endl          '\n'
    #define fr            first
    #define sc            second
    #define mii           map<ll ,ll >
    #define msi           map<string,ll >
    #define mis           map<ll , string>
    #define rep(i,a,b)    for(ll  i=a;i<b;i++)
    #define all(v)        v.begin(),v.end()
    #define sort(v)       sort(all(v))
    #define pii           pair<ll ,ll >
    #define vi            vector<ll >
    #define vii           vector<pair<ll , ll >>
    #define vs            vector<string>
    #define sz(x)         (ll)x.size()
    #define M             1000000007
    #define bs            binary_search
    #define rev(a)        reverse(all(a));
    #define sp(n)         setprecision(n)
    #define spl           " "
    #define arr(a,n)      rep(i,0,n) cin>>a[i]
    #define mod           998244353
    #define print_vector(a)  for(auto t:a) cout<<t<<" ";cout<<endl;
    #define print_arr(a,n)   rep(i,0,n) cout<<a[i]<<" "; cout<<endl;        
    #define show(a,n)     for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
    #define N             100000000
    #define debug(x)      cout << #x << " is " << x << endl;
    #define time          cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    #define INF           1ll<<31
    #define M_PI 3.14159265358979323846
    using namespace std;
    ll min(ll a,ll b)
    {
        return a>b?b:a;
    }
    ll max(ll a,ll b)
    {
        return a>b?a:b;
    }
    const ll maxn=2e5+500;
    void solve()
    {
      ll n,m;
      cin>>n>>m;
      vi a(m);
      arr(a,m);
      ll s=0;
      rep(i,0,m) s+=a[i];
      if(s>n) cout<<-1<<endl;
      else cout<<n-s<<endl;

    }
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        ll t=1;
        //cin>>t;
        while(t--) solve();
    }


Measured memory_bytes: 3740
import re

def main():
    S = input()
    pattern = r'^(dream|dreamer|erase|eraser)+$'
    rep = re.compile(pattern)
    result = rep.match(S)
    if result:
        print("YES")
    else:
        print("NO")
    pass

if __name__ == "__main__":
    main()
    pass

Measured memory_bytes: 41968
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <utility>
using namespace std;
#define INF 100000005
#define MAX 200005

int c[10][10], a[210][210], d[10];

int solve(){
	int used[10];
	fill(used, used+10, 0);
	fill(d, d+10, INF);
	d[1] = 0;
	while(1){
		int v = -1;
		for(int i = 0;i < 10;i++){
			if(!used[i] && (v == -1 || d[v] > d[i]))v = i;
		}
		if(v == -1)break;
		used[v] = 1;
		for(int i = 0;i < 10;i++){
			d[i] = min(d[i], d[v] + c[i][v]);
		}
	}
	return 0;
}

int main(){
	int h, w;
	cin >> h >> w;
	for(int i = 0;i < 10;i++)
	for(int j = 0;j < 10;j++)cin >> c[i][j];
	for(int i = 0;i < h;i++)
	for(int j = 0;j < w;j++)cin >> a[i][j];
	solve();
	int ans = 0;
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			if(a[i][j] != -1 && a[i][j] != 1)ans += d[a[i][j]];
		}
	}
	cout << ans << endl;
	//for(int i = 0;i < 10;i++)cout << d[i] << " ";
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#define ll long long
#define rep(i,j,k) for (i=j;i<=k;i++)
#define down(i,j,k) for (i=j;i>=k;i--)
using namespace std;
const int N=1e5+5,K=70;
int n,m,i,d[N],p[N],a[N];
int lim,j,trans[N][K];
ll sum,x[N];
int main()
{
//	freopen("rabbit.in","r",stdin);
//	freopen("rabbit.out","w",stdout);
	scanf("%d",&n);
	rep(i,1,n) scanf("%lld",&x[i]),d[i]=x[i]-x[i-1];
	scanf("%d%lld",&m,&sum);
	rep(i,1,m) scanf("%d",&a[i]);
	rep(i,1,n) trans[i][0]=p[i]=i;
	rep(i,1,m) swap(trans[a[i]][0],trans[a[i]+1][0]);
	for (lim=0;(1ll<<lim)<sum;lim++);
	rep(j,1,lim)
		rep(i,1,n) trans[i][j]=trans[ trans[i][j-1] ] [j-1];
	down(j,lim,0)
	{
		if ((1ll<<j)>sum) continue;
		rep(i,1,n) p[i]=trans[p[i]][j];
		sum-=(1ll<<j);
	}
	rep(i,1,n) x[i]=x[i-1]+d[p[i]];
	rep(i,1,n) printf("%lld\n",x[i]);
	return 0;
}

Measured memory_bytes: 30464
import numpy as np
 
[N, M] = list(map(int, input().split()))
A = list(map(int, input().split()))
threshold = np.sum(A) / (4 * M)
#print(threshold)
Th = [a for a in A if threshold <= a]
#print(Th)
if len(Th) < M:
  ans = 'No'
else:
  ans = 'Yes'
print(ans)

Measured memory_bytes: 12500
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
typedef long long ll;
int main(void)
{
    ll a,b;
    while(cin>>a>>b)
    {
        if(b>=a) cout<<0<<endl;
        else cout<<a-b<<endl;
    }
    return 0;
}


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

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;

#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)

int main(){
    char c;
    cin >> c;
    c++;
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N = int(sys.stdin.readline())
list_a = list(map(int, sys.stdin.readline().split()))
list_b = list(map(int, sys.stdin.readline().split()))
list_c = list(map(int, sys.stdin.readline().split()))

# print(list_a)
# print(list_b)
# print(list_c)

sum_b = 0

for i in range(N):
    sum_b += list_b[i]
    if(i < N-1 and (list_a[i]+1) == list_a[i+1]):
        sum_b += list_c[list_a[i]-1]

print(sum_b)


Measured memory_bytes: 5716
import collections
h, w = map(int, input().split())
grid = []
for i in range(h):
    grid.append(input())

ans = 0
for i in range(h):
    for j in range(w):
        if grid[i][j] == "#":
            continue

        dist = [[-1 for a in range(w)] for b in range(h)]
        dist[i][j] = 0

        q = collections.deque()
        q.append((i, j))
        while q:
            now = q.popleft()
            for x, y in [[0, 1], [0, -1], [-1, 0], [1, 0]]:
                if 0 <= now[0] + x <= h-1 and 0 <= now[1] + y <= w-1:
                    if grid[now[0]+x][now[1]+y] == "." and dist[now[0]+x][now[1]+y] == -1:
                        dist[now[0]+x][now[1]+y] = dist[now[0]][now[1]] + 1
                        q.append((now[0]+x, now[1]+y))

        temp = 0
        for k in range(h):
            temp = max(temp, max(dist[k]))
        ans = max(ans, temp)

print(ans)


Measured memory_bytes: 3316
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


long long N, A, B, h[111111];


bool check(int c)
{
  int cc = 0;

  for (int i = 0; i < N; i ++) {
    if (h[i] < c * B)
        break;

    if (A == B) {
      if (h[i] > c * B)
        return false;
    }
    else {
      cc += (h[i] - c * B + A - B - 1) / (A - B);
    
      if (cc > c)
        return false;
    }
  }

  return true;
}


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  std::cin >> N >> A >> B;

  for (int i = 0; i < N; i ++)
    std::cin >> h[i];

  std::sort(h, h + N, std::greater<int>());

  long long l = -1, u = 1000000000;

  while (u - l > 1) {
    long long m = (l + u) / 2;

    (check(m) ? u : l) = m;
  }

  std::cout << u << std::endl;

  return 0;
}


Measured memory_bytes: 1024
# https://atcoder.jp/contests/abc158/tasks/abc158_d

S = input()
Q = int(input())
T = ""

for _ in range(Q):
    query = input()
    ty = query[0]
    if ty == '1':
        S, T = T, S
    else:
        if query[2] == '1':
            T += query[4]
        else:
            S += query[4]

T = T[::-1]
print(T + S)


Measured memory_bytes: 4316
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
string s;
vector<string>a;
vector<int>b,c;
while(cin>>s){
int no=-1;
rep(j,a.size())if(a[j]==s)no=j;
if(no+1)b[no]++;
else{
pb(a,s);
pb(b,0);
pb(c,s.size());
}
}
int m=0,mi=0;
rep(i,b.size())if(m<b[i]){m=b[i];mi=i;}
cout<<a[mi]<<" ";
m=mi=0;
rep(i,c.size())if(m<c[i]){m=c[i];mi=i;}
cout<<a[mi]<<endl;
}

Measured memory_bytes: 1212
# https://atcoder.jp/contests/agc017/tasks/agc017_a
# dpっぽくね？

'''
dp[i][p] ... 袋の選び方の通りの総数 [0,i)まで見たとき、余りがpになる場合


if A[i]が偶数
選ぶときの通りの数
    dp[i+1][0] += dp[i][0]*2
    dp[i+1][1] += dp[i][1]*2
    ∵偶+偶→偶、奇+偶→奇 でもともとの通りの数に影響を与えない
if A[i]が奇数
    dp[i+1][0] += dp[i][1]+dp[i][0]
    dp[i+1][1] += dp[i][0]+dp[i][1]
    ∵偶+奇→奇、奇+奇→偶 で遷移するので選ぶときと選ばないときで遷移先が異なる
'''
N, P = map(int, input().split())
A = list(map(int, input().split()))
dp0 = 1
dp1 = 0

for a in A:
    if a & 1:
        new0 = dp0 + dp1
        new1 = new0
    else:
        new0 = dp0 * 2
        new1 = dp1 * 2
    dp0 = new0
    dp1 = new1

print(dp1 if P & 1 else dp0)


Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int C = sc.nextInt();
		int A[] = new int[M];
		int cnt = 0;

		int[] B = new int[M];
		for (int i = 0; i < M; i++) {
			B[i] = sc.nextInt();
		}

		for (int i = 0; i < N; i++) {
			int det = 0;
			for (int j = 0; j < M; j++) {
				det += B[j] * sc.nextInt();
			}
			det += C;

			if (det > 0) {
				cnt++;
			}
		}

		System.out.println(cnt);

	}
}

Measured memory_bytes: 22612
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long gcd = getGcd(a, b);
        System.out.println(getPf(gcd) + 1);
    }

    static long getGcd(long x, long y) {
        return y == 0 ? x : getGcd(y, x % y);
    }

    static long getPf (long n) {
        int cnt = 0;
        for (long i = 2; i * i <= n; i++) {
            boolean isFirst = true;
            if (n % i != 0) {
                continue;
            }
            while (n % i == 0) {
                n /= i;
                if (isFirst) {
                    cnt++;
                    isFirst = false;
                }
            }
        }
        if (n != 1) {
            cnt++;
        }
        return cnt;
    }
}

Measured memory_bytes: 23252
#include <stdio.h>
 
int main(int argc, const char * argv[]) {
     
    while (1) {
         
     
     
    int h,w;
    scanf("%d %d",&h,&w);
     
        if(h==0 && w==0){
            break;
        }
         
    int i,j;
    for (i=0; i<h; i++) {
        for(j=0;j<w;j++){
            printf("#");
        }
        printf("\n");
    }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case(){
	int n; cin >> n;
	vector<int> a(n);
	ll ans=1;
	string s; cin >> s;
	for(int i = 0 ; i < n ; i++){
		if(s[i] == 'R')
			a[i] = 0;
		if(s[i] == 'G')
			a[i] = 1;
		if(s[i] == 'B')
			a[i] = 2;
	}
	vector<ll> cnt(3);
	for(int i = 0 ; i < n ; i++)
		cnt[a[i]]++;
	for(int i = 0 ; i < 3 ; i++)
		ans *= cnt[i];
	for(int j = 0 ; j < n ; j++){
		for(int i = 0 ; i < j ; i++){
			int k = j + (j-i);
			if(k < n){
				if(a[i] == a[j])
					continue;
				if(a[i] == a[k])
					continue;
				if(a[k] == a[j])
					continue;
				ans--;
			}
		}
	}
	cout<<ans<<"\n";
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

vector<vector<P> > d;

signed main(){
    int n, m;
    cin >> n >> m;
    d.resize(n, vector<P>());
    while(1){
        int s, t, e;
        cin >> s >> t >> e;
        if(s + t + e == 0) break;
        d[s - 1]. push_back(make_pair(t - 1, e));
    }
    int l;
    cin >> l;
    rep(i, 0, l){
        vector<int> b(m);
        rep(j, 0, m) cin >> b[j];
        rep(j, 0, n){
            int sum = 0;
            rep(k, 0, d[j].size()){
                sum += d[j][k].second * b[d[j][k].first];
            }
            if(j != 0) cout << ' ';
            cout << sum; 
        }
        cout << endl;
    }
}

Measured memory_bytes: 2824
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

int main() {
	int n, a, b, ans = 0;
	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) {
		string str = to_string(i);
		int sum = 0;
		for (int j = 0; j < str.size(); j++) {
			sum += str[j]-'0';
		}
		if (sum >= a&&sum <= b) {
			ans += i;
		}
	}
	cout << ans << endl;
}


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

void dfs(int d,ll val){
    all.push_back(val);
    if (d == 10) return;
    //cout << val << endl; 
    for (int i = -1;i < 2;i++){
        if (val%10 == 0 && i == -1) continue;
        else if (val%10 == 9 && i == 1) continue;
        dfs(d+1,val*10+val%10+i);
    }    
}

int main(){
    cin >> n;
    for (int i = 1;i < 10;i++){
        dfs(1,i);
    }
    sort(all.begin(),all.end());
    //rep(i,n) {
    //    cout << all[i] << endl;
    //    if (all[i] == 0) {
    //        cout << i << endl;
    //        break;
    //    }
    //}
    cout << all[n-1] << endl;
    return 0;
    
}

Measured memory_bytes: 5296
#include<iostream>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#define P pair<long long, long long>


using namespace std;
const long long int MOD=1e9+7;

int main(){
  int n, m, s, tmpc, c[5];
  cin >> n >> m;
  bool ans=true;
  for(int i=1;i<=n;i++){
    c[i]=-1;
  }
  for(int i=0;i<m;i++){
    cin >> s >> tmpc;
    if(c[s]!=-1 && c[s] != tmpc){
      ans=false;
    }
    c[s] = tmpc;
  }
  if(n!=1 && c[1]==0){
    ans = false;
  }
  if(!ans){
    cout << -1 << endl;
    return 0;
  }
  for(int i=1;i<=n;i++){
    if(c[i] == -1 && (i!=1 || n==1)){
      cout << 0;
    }
    else if(c[i] == -1 && i==1){
      cout << 1;
    }
    else{
      cout << c[i];
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int q = sc.nextInt();
        int[] k = new int[q];
        for(int i=0; i<q; i++){
            k[i] = sc.nextInt();
        }
        sc.close();

        boolean[] pd = new boolean[n];
        boolean[] pm = new boolean[n];
        boolean[] pc = new boolean[n];
        int[] sumd = new int[n+1];
        int[] summ = new int[n+1];
        int[] sumc = new int[n+1];
        for(int i=0; i<n; i++){
            sumd[i+1] = sumd[i];
            summ[i+1] = summ[i];
            sumc[i+1] = sumc[i];
            if(s.charAt(i) == 'D'){
                pd[i] = true;
                sumd[i+1]++;
            }else if(s.charAt(i) == 'M'){
                pm[i] = true;
                summ[i+1]++;
            }else if(s.charAt(i) == 'C'){
                pc[i] = true;
                sumc[i+1]++;
            }
        }

        long[] score = new long[n+1];
        for(int i=n-2; i>=0; i--){
            score[i] = score[i+1];
            if(pm[i]){
                score[i] += sumc[n] - sumc[i];
            }
        }

        for(int i=0; i<q; i++){
            long ans = 0;
            for(int j=0; j<n; j++){
                if(!pd[j]) continue;
                int end = Math.min(j+k[i]-1, n-1);
                ans += score[j];
                ans -= score[end+1];
                ans -= (long)(summ[end+1]-summ[j]) * (long)(sumc[n] - sumc[end+1]);
            }
            System.out.println(ans);
        }
    }

}

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

using namespace std;

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

	int n, k, i;
	cin >> n >> k;
	long long h[n], minn = LLONG_MAX;

	for(i = 0; i < n; ++i)
		cin >> h[i];
	sort(h, h + n);

	for(i = 0; i <= n-k ; ++i)
		minn = min(minn, h[i + k - 1] - h[i]);
	cout << minn;
	
	return 0;
}

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

using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    map<int,int> mp;
    int mx=0;
    for(int i=0;i<n;i+=2)
    {
        mp[a[i]]++;
        mx=max(mx,mp[a[i]]);
    }

    map<int,int>::iterator it;
    vector<pair<int,int> > A1;
    A1.push_back({0,0});
    it=mp.begin();
    while(it!=mp.end())
    {
        A1.push_back({it->second,it->first});
        it++;

    }
    sort(A1.rbegin(),A1.rend());

    map<int,int> m1;
    int m2=0;
    for(int i=1;i<n;i+=2)
    {
        m1[a[i]]++;
        m2=max(m2,m1[a[i]]);
    }
    vector<pair<int,int> > A2;
    A2.push_back({0,0});
    it=m1.begin();
    while(it!=m1.end())
    {
        A2.push_back({it->second,it->first});
        it++;

    }
    sort(A2.rbegin(),A2.rend());
    if(A1[0].second==A2[0].second)
    {
        int mn=n-A1[1].first-A2[0].first;
        int mn2=n-A1[0].first-A2[1].first;
        cout<<min(mn,mn2)<<endl;
    }
    else
    {
        cout<<n-A1[0].first-A2[0].first<<endl;
    }
    return 0;
}


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

using namespace std;

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

  vector<vector<int>> vv;
  for (int i=0; i < M; i++) {
    int k;
    cin >> k;
    vector<int> v;
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      v.push_back(s - 1);
    }
    vv.push_back(v);
  }

  vector<int> pv;
  for (int i=0; i < M; i++) {
    int p;
    cin >> p;
    pv.push_back(p);
  }

  // スイッチパターンを列挙
  int ans = 0;
  for (int i = 0; i < (1 << N); i++) {
    bool isOk = true;
    for (int j = 0; j < M; j++) {
      int c = 0;
      for (int s : vv.at(j)) {
        if ((i >> s) & 1) c++;
      }
      if (c % 2 == pv.at(j)) continue;
      isOk = false;
    }

    if (isOk) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

typedef long long int ll;

std::vector<ll> enum_div(ll n);
long long comb(int n, int r);
bool IsPrime(int num);
bool dp[110][10010];
class UnionFind;
using Graph = vector<vector<int>>;

//自作関数一覧---------------------------
ll gcd(ll a, ll b); //最小公倍数の導出
ll lcm(ll x, ll y); //最大公約数の導出
ll bur(ll N, ll X); //??
//---------------------------------------

//UF木
class UnionFind {
public:
	//親
	vector<int> Parent;

	//初期状態
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//サイズ確認
	int size(int A) {
		return -Parent[root(A)];
	}

	int connect(int A, int B) {
		//root同氏をくっつける
		A = root(A);
		B = root(B);

		//結合済み
		if (A == B) {
			return false;
		}
		//大きいほうに小さいほうをくっつける
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズ更新
		Parent[A] += Parent[B];
		//Bの親をAに
		Parent[B] = A;

		return true;
	}

};

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;


	string S, T;
	char fi[50], fv[50];
	char board[4][4];
	bool start = false;
	ll left = 0, right = 0;
	ll all = 0;
	all++;
	cin >> N;
	cin >> S;

	rep(i, 0, N - 1) {
		if (S[i] != S[i + 1]) {
			all++;
		}
	}
	
	cout << all << endl;

	return 0;
}


std::vector<ll> enum_div(ll n)//nの約数を列挙
{
	vector<ll> res;
	for (int i = 1; i*i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}








bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}



//combination
long long comb(int n, int r) {
	std::vector<std::vector<long long>> v(n + 1, std::vector<long long>(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v[n][r];
}


ll gcd(ll a, ll b) {

	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y / b*x;
}

// 最大公約数を求める関数
ll lcm(ll x, ll y)
{
	if (x == 0 || y == 0)  // 引数チェック
	{
		//fprintf(stderr, "引数エラーです。\n");
		return 0;
	}

	return (x * y / gcd(x, y));
}

ll bur(ll N, ll X) {
	ll pan = 1;
	ll pat = 1;
	ll burg = 0;



	if (X > burg) {
		if (N == 0)
			return pat;


		burg += pan;
		burg += bur(N - 1, X);
		burg += pat;
		burg += bur(N - 1, X);
		burg += pan;


	}

	return burg;

}

Measured memory_bytes: 512
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define msg(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define pri(a) cout << a << endl;

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

  ll a,b,ans=-1;
  cin >> a >> b;

  for(float i=1;i<=1250;i++){
    if(int(i*0.08)==a && int(i*0.1)==b){
      ans = i;
      break;
    }
  }

  pri(ans);

}

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


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define nl "\n"
#define pb push_back
#define sp " "
typedef long long ll;
#define len(x) x.length()
#define vsort(x) sort(x.begin(), x.end();
using namespace std;
ll inf=2e18;

int main()

{

    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
   // freopen("bruh.txt","r",stdin);
    #endif
    ll a , b;
    cin >> a >> b;
    cout<<(a*b)/__gcd(a,b);
    }


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

#define NUM_MAX 100000

int main(void) {
    int num;
    static int64_t map[NUM_MAX+1];
    int64_t k;
    scanf("%d %lld", &num, &k);
    int i;
    for(i = 0; i < num; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        map[a] += b;
    }

    int64_t sum = 0;
    for(i = 1; i <= NUM_MAX; i++) {
        sum += map[i];
        if(sum >= k) {
            printf("%d\n", i);
            return 0;
        }
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  bool a = false;
  
  for (int i = 0; i < N; i++){
    string S;
    cin >> S;
    
    if ( S == "Y" ){
      a = true;
    }
  }
  
  if (a){
    cout << "Four" << endl;
  }
  
  else {
    cout << "Three" << endl;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
#define rep(i,a,b) for(re int i=a,i##end=b; i<=i##end; i++)
#define drep(i,a,b) for(re int i=a,i##end=b; i>=i##end; i--)
#define repp(i,a,b) for(re int i=a,i##end=b; i<i##end; i++)
#define drepp(i,a,b) for(re int i=a,i##end=b; i>i##end; i--)
#define Erep(i,x) for(int i=head[x]; ~i; i=Edge[i].nxt)
#define ms(x,a) memset(x,a,sizeof x)
#define se second
#define fi first
#define lowbit(x) (x&-x)
#define debug(x) cerr<<#x<<" = "<<x<<endl
#define coint const int
typedef long long ll;
using namespace std;
template<class T>inline T rd(){
	static char ch;static bool neg;static T x;
	for(neg=0,ch=0; ch>'9'||ch<'0'; neg|=(ch=='-'),ch=getchar());
	for(x=0; ch<='9'&&ch>='0'; x=(x<<1)+(x<<3)+(ch-'0'),ch=getchar());
	return neg?-x:x;
}
template<class T>inline T Max(const T &x, const T &y){
	return x>y?x:y;
}
template<class T>inline T Min(const T &x, const T &y){
	return x<y?x:y;
}
coint N=1e5+5;
int A[N];


int main(){
	int n=rd<int>(),m=rd<int>();
	printf("%d\n",(n+m-3)/(n-1));
	return 0;
}



Measured memory_bytes: 256
//##MohK
// 9/2/2020 ..... 2,00
#include <bits/stdc++.h>
using namespace std ;
using ll = long long ;
using ld = long double;
int main(){
    string a;
    cin>>a;
    for(ll i=0;i<a.size();i++){
        cout<<'x';
    }


    return 0 ;
}



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

int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    int M;
    int p,b;
    cin >> M;
    for(int i=0;i<M;i++){
        int sum=0;
        cin >> p >> b;
        for(int j=0;j<N;j++){
            if(p-1!=j) sum+=a[j];
            else sum+=b;
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
using namespace std;

void printNumArray(int *numArray,int N){
	cout << numArray[0];
	for(int i = 1; i < N; i++){
		cout << " " <<numArray[i];
	}
	cout<< endl;
}


int main()
{
	int n;
	cin >> n;
	int *numArray = new int[n+1];
	for(int i = 0; i < n; i++){
		cin>>numArray[i];
	}
	for(int i = 0; i < n; i++){
		int j = i - 1;
		int key = numArray[i];
		while( j >= 0 && numArray[j] > key){
			numArray[j + 1] = numArray[j];
			j--;
		}
		numArray[j+1] = key;
		printNumArray(numArray,n);
	}
	
	return 0;
}




Measured memory_bytes: 3128
#include <iostream>

using namespace std;

int main() {
  int n;
  int building[4][3][10] = {0};
  int b,f,r,v;
  cin >> n;
  for(int i=0; i < n; ++i){
    cin >> b >> f >> r >> v;
    building[b-1][f-1][r-1] += v;
  }
  for(int i=0; i < 4; ++i){
    if(i) cout << "####################" << endl;
    for(int j=0; j < 3; ++j){
      for(int k=0; k < 10; ++k){
        cout << ' ' << building[i][j][k];
      }
      cout << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


void solve(){
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i,N) cin >> a[i];
    vector<vector<int>> G(N);
    REP(i,N-1){
        int u, v;
        cin >> u >> v;
        --u, --v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    vector<int> ans(N, INF);
    vector<int> dp(N+1, INF);
    dp[0] = -INF;

    auto dfs = [&](auto && self, int cur, int par) -> void{
        int idx = lower_bound(dp.begin(), dp.end(), a[cur]) - dp.begin();
        int tmp = dp[idx];
        dp[idx] = a[cur];
        ans[cur] = lower_bound(dp.begin(), dp.end(), INF) - dp.begin() - 1;
        for(auto nv : G[cur]){
            if(nv == par) continue;
            self(self, nv, cur);
        }
        dp[idx] = tmp;
    };

    dfs(dfs, 0, -1);
    for(auto x : ans) cout << x << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}


Measured memory_bytes: 30856
N = int(input())
a = list(map(int,input().split()))

cum = [0]*(N+1)
ans = 10**12
total = sum(a)
for i in range(N):
  cum[i+1] = cum[i] + a[i]
  ans = min(ans,abs(cum[i+1]-(total-cum[i+1])))
print(ans)


Measured memory_bytes: 31448
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long idx=0;
    long N;
    cin >> N;
    map<long, long> A;
    long a;
    for(size_t i=2;i<=N; i++)
    {
        cin >> a;
        A[a]++;
        A[i];
    }
    for(size_t i=1;i<=N; i++)
    {
        cout << A[i] << endl;
    }
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};

int main()
{
  int H, W;
  cin >> H >> W;
  vector<vector<bool>> field(H, vector<bool>(W, false));
  int cnt = 0;
  rep(y, H)
  {
    rep(x, W)
    {
      char c;
      cin >> c;
      if (c == '.')
      {
        field.at(y).at(x) = true;
        cnt++;
      }
    }
  }

  vector<vector<int>> dist(H, vector<int>(W, -1));
  queue<pair<int, int>> que;
  dist.at(0).at(0) = 1;
  que.push(make_pair(0, 0));
  while (!que.empty())
  {
    int y, x;
    tie(y, x) = que.front();
    que.pop();
    rep(direction, 4)
    {
      int ny = y + dy.at(direction), nx = x + dx.at(direction);
      if (0 <= ny && ny < H && 0 <= nx && nx < W)
      {
        if (field.at(ny).at(nx))
        {
          if (dist.at(ny).at(nx) == -1)
          {
            dist.at(ny).at(nx) = dist.at(y).at(x) + 1;
            que.push(make_pair(ny, nx));
          }
        }
      }
    }
  }
  if (dist.at(H - 1).at(W - 1) == -1)
  {
    cout << -1 << endl;
  }
  else
  {
    cout << cnt - dist.at(H - 1).at(W - 1) << endl;
  }
}

Measured memory_bytes: 256