akhauriyash/Code-Regression huggingface dataset:
def main():
    import sys
    input = sys.stdin.readline
    N, T = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(N)]
    ab.sort(key=lambda x: (x[0], x[1]))
    dp = [-1 for i in range(T*2 + 1)]
    dp[0] = 0
    for a, b in ab:
        for i in range(T*2, 0, -1):
            if i >= a:
                if dp[i-a] >= 0 and i - a < T:
                    dp[i] = max(dp[i], dp[i-a] + b)

    for i in range(1, T*2+1):
        dp[i] = max(dp[i], dp[i-1])
    ans = dp[-1]

    ab.sort(key=lambda x: x[1])
    tmp = ab.pop()
    dp = [-1 for i in range(T)]
    dp[0] = 0
    for a, b in ab:
        for i in range(T-1, 0, -1):
            if i >= a:
                if dp[i-a] >= 0:
                    dp[i] = max(dp[i], dp[i-a] + b)

    for i in range(1, T):
        dp[i] = max(dp[i], dp[i-1])
    ans = max(ans, tmp[1] + dp[-1])

    # print(dp)
    print(ans)


main()


Measured memory_bytes: 44656
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static class City {
        public City(int  n, int p, int y) {
            this.n = n;
            this.p = p;
            this.y = y;
        }
        int n;
        int p;
        int y;
        String id;
    }

    public static void main(String[] args) {
        
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        List<City> cities = new ArrayList<City>(m);

        for (int i = 0; i < m; i++) {
            cities.add(new City(i, scanner.nextInt(), scanner.nextInt()));
        }
        cities.sort(new Comparator<City>() {
            @Override
            public int compare(City o1, City o2) {
                if (o1.p < o2.p) {
                    return -1;
                } else if (o1.p > o2.p) {
                    return 1;
                } else {
                    if (o1.y < o2.y) {
                        return -1;
                    } else if (o1.y > o2.y) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
            }
        });
        int currentP = 0;
        int x = 0;
        for (City city : cities) {
            if (city.p != currentP) {
                currentP = city.p;
                x = 1;
            }
            city.id = String.format("%06d%06d", city.p, x);
            x++;
        }
        cities.sort(new Comparator<City>() {
            @Override
            public int compare(City o1, City o2) {
                return Integer.compare(o1.n, o2.n);
            }
        });
        for (City city : cities) {
            System.out.println(city.id);
        }
    }
}


Measured memory_bytes: 148528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
ll K,A[200000],L,R;
int main() 
{
	cin>>N>>K;
	for(int i=0;i<N;i++) 
	{
		cin>>A[i];
	}
	sort(A,A+N);
	L=-1e18;
	R=1e18;
	while(L+1!=R) 
	{
		ll M=(L+R)/2;
		ll cnt=0;
		for(int i=0;i<N;i++) 
		{
			if(A[i]<0) 
			{
				int l,r;
				l=i;
				r=N;
				while(l+1!=r) 
				{
					int m=(l+r)/2;
					if(A[i]*A[m]<=M) 
					{
						r=m;
					}
					else 
					{
						l=m;
					}
				}
				cnt+=N-r;
			}
			else 
			{
				int l,r;
				l=i;
				r=N;
				while(l+1!=r) 
				{
					int m=(l+r)/2;
					if(A[i]*A[m]<=M) 
					{
						l=m;
					}
					else 
					{
						r=m;
					}
				}
				cnt+=l-i;
			}
		}
		if(cnt<K)
		L=M;
		else 
		R=M;
	}
	cout<<R<<endl;
}



Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))
if max(a) - min(a) >= 2:
    print("No")

elif max(a) - min(a) == 0:
    if a[0] == n-1 or 2*a[0] <= n:
        print("Yes")
    else:
        print("No")

else:
    p = a.count(max(a))
    q = a.count(min(a))
    if q+1 <= max(a) <= q+p//2:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 83312
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vi c(k + 1);
    ll ans = 0;
    for (int i = 1; i <= k; i++)
    {
        c[i] = inq(k / i, n);
    }
    for (int i = k; i >= 1; i--)
    {
        for (int j = i + i; j <= k; j += i)
        {
            c[i] = (c[i] - c[j] + MOD) % MOD;
        }
    }
    for (int i = 1; i <= k; i++) ans = (ans + c[i] * i) % MOD;
    cout << ans;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (ll i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 
const int mod = 1e9 + 7, mxn = 1e5 + 1;

int solve(){
	int n;
	cin>> n;
	int t = (n + 999) / 1000;
	int ans = t*1000 - n;
	cout<< ans<< "\n";
	return 0;
}
 
int main()
{
    fast;
    int t = 1;
    //cin>> t;
    while(t--){  
        solve();
    }
    return 0;
}
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);
 
/*  inv[1] = 1; // inv is ll
    for(int i=2; i<=mxn; ++i)
        inv[i]=mod-mod/i*inv[mod%i]%mod;*/
        
// lower bound   >=  
// upper bound   >
// vector<int>().swap(vec); //free memory from vec


Measured memory_bytes: 3648
// Aizu 0580: Fish
// 2017.10.25 bal4u@uu
// ???????????????????????±?????¨?????????????¨????

#include <stdio.h>
#include <stdlib.h>

#define MAX  52
#define MAX2 104

typedef struct { int x1, y1, d1, x2, y2, d2; } PP;
PP p[MAX];
int x[MAX2], y[MAX2], d[MAX2], sz, xs, ys, ds;

int cmp(int *a, int *b) { return *a - *b; }

int uniq(int *a, int n)
{
	int i, j;
	for (i = 0, j = 1; j < n; j++) {
		while (j < n && a[j] == a[i]) j++;
		if (j < n) if (++i != j) a[i] = a[j];
	}
	return i+1;
}

int main()
{
	int n, k, i, xx, yy, dd, c;
	long long ans;

	scanf("%d%d", &n, &k);
	for (sz = 0, i = 0; i < n; i++) {
		scanf("%d%d%d%d%d%d", &p[i].x1, &p[i].y1, &p[i].d1, &p[i].x2, &p[i].y2, &p[i].d2);
		x[sz] = p[i].x1, x[sz+1] = p[i].x2;
		y[sz] = p[i].y1, y[sz+1] = p[i].y2;
		d[sz] = p[i].d1, d[sz+1] = p[i].d2;
		sz += 2;
	}
	qsort(x, sz, sizeof(int), cmp), xs = uniq(x, sz);
	qsort(y, sz, sizeof(int), cmp), ys = uniq(y, sz);
	qsort(d, sz, sizeof(int), cmp), ds = uniq(d, sz);

	ans = 0;
	for (xx = 1; xx < xs; xx++) for (yy = 1; yy < ys; yy++) for (dd = 1; dd < ds; dd++) {
		c = 0;
		for (i = 0; i < n; i++) {
          if (p[i].x1 <= x[xx-1] && x[xx] <= p[i].x2 &&
              p[i].y1 <= y[yy-1] && y[yy] <= p[i].y2 &&
              p[i].d1 <= d[dd-1] && d[dd] <= p[i].d2) c++;
        }
        if (c >= k) ans += (long long)(x[xx]-x[xx-1]) * (y[yy]-y[yy-1]) * (d[dd]-d[dd-1]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1812
s = input()

i = 0
ans = 0
while i < len(s)-1:
    # print(i, s[i], s[i+1], ans)
    if s[i] != s[i+1]:
        i += 1
        ans += 1
    else:
        if i == len(s)-2:
            i += 3
            ans += 1
        else:
            i += 3
            ans += 2
if i == len(s)-1:
    ans += 1
print(ans)


Measured memory_bytes: 9360
# D - Triangles

from bisect import bisect_left

N = int(input())
L = sorted([int(l) for l in input().split()])

cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        cnt += bisect_left(L, L[i] + L[j]) - (j + 1)

print(cnt)


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <cstdio>
#include <climits>
using namespace std;

#define DEB 0
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)

string in;
set<int> dp[200][200];

bool isope(char c){
  return (c=='+'||c=='-'||c=='*'||c=='/');
}
set<int> parse(int s, int t){
  int i;
  int x = 0;
  bool f = false;

  if( dp[s][t].size()>0 ) return dp[s][t];

  for(i=s; i<t; i++){
    if( in[i]=='(' )x++;
    if( in[i]==')' )x--;
    if( x==0 && isope(in[i]) ){
      f = true;
      set<int> left = parse(s,i-1);
      set<int> right = parse(i+1,t);
      set<int>::iterator j,k;
      for(j=left.begin(); j!=left.end(); j++){
        for(k=right.begin(); k!=right.end(); k++){
          if( in[i]=='+' ) dp[s][t].insert(*j + *k);
          if( in[i]=='-' ) dp[s][t].insert(*j - *k);
          if( in[i]=='*' ) dp[s][t].insert(*j * *k);
          if( in[i]=='/' && *k!=0 ) dp[s][t].insert(*j / *k);
#if DEB
          printf("s:%d, t:%d  i:%d  %d-%d\n",s,t,i,*j,*k);
#endif
        }
      }
    }
  }
  if( !f ){
    if( in[s]=='(' ) return dp[s][t]=parse(s+1, t-1);
    int d = atoi(in.substr(s,t-s+1).c_str());
    dp[s][t].insert(d);
  }
  return dp[s][t];
}

int main(){
  while(cin>>in,in!="#"){
    rep(i,200)rep(j,200)dp[i][j].clear();
    parse(0,in.size()-1);
    printf("%d\n",dp[0][in.size()-1].size());
  }
  return 0;
}

Measured memory_bytes: 1928
#include <iostream>
#include <string>
#define rp(i,n) for(int  i=0;i<n;i++)
using ll =long long;

using namespace std;

ll ab(ll a);

int main(void)
{
    ll N,X,Y;
    cin>>N>>X>>Y;
    ll A[N-1],s=0;
    rp(i,N-1) A[i]=0;
    for(ll i=1;i<N;i++)
    {
        for(ll j=0;j<i;j++)
        {
            s=min(ab(i-j),ab(j+1-X)+ab(i+1-Y)+1);
            A[s-1]+=1;

        }
    }
    rp(i,N-1)
    {
        cout<<A[i]<<endl;
    }
    return 0;

}

ll ab(ll a)
{
    if(a>0) 
    {
        return a;
    } else return -a;
}


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

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


fn main(){
    let n: u64 = read();
    let mut m = n;
    let mut ret = 0;

    for i in 2..n {
        if n < i * i {
            break;
        }

        let mut sum = 0;
        while m % i == 0 {
            sum += 1;
            m /= i;
        }

        if sum == 1 || sum == 2 {
            ret += 1;
            continue;
        }

        for j in 1..=sum {
            if sum < j * (j + 1) / 2 {
                ret += j - 1;
                //println!("{} {}", sum, i);
                break;
            }
        }
    }

    if m > 1 {
        ret += 1;
    }
    println!("{}", ret);
}


Measured memory_bytes: 2168
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    ll N,M;
    cin >> N >> M;
    if(N * 2 == M){
        cout << N << endl;
    }else if(N * 2 < M){
        ll ans = 0;
        ans += N;
        M -= N * 2;
        ans += (M/4);
        cout << ans << endl;
    }else{
        cout << M / 2 << endl;
    }


    return 0;
}


Measured memory_bytes: 256
l=list(input())
a=[list('dream'),list('erase')]
b=[list('eraser')]
c=[list('dreamer')]
n=len(l)
r=0
while n>=5:
    f=0
    if n>=7:
        if l[len(l)-5:] in a:
            l[len(l)-5:]=[]
            n-=5
            f+=1
        if l[len(l)-6:] in b:
            l[len(l)-6:]=[]
            n-=6
            f+=1
        if l[len(l)-7:] in c:
            l[len(l)-7:]=[]
            n-=7
            f+=1
    elif n>=6:
        if l[len(l)-5:] in a:
            l[len(l)-5:]=[]
            n-=5
            f+=1
        if l[len(l)-6:] in b:
            l[len(l)-6:]=[]
            n-=6
            f+=1
    elif n>=5:
        if l[len(l)-5:] in a:
            l[len(l)-5:]=[]
            n-=5
            f+=1
    if f==0:
        r=1
        break
if r==1 or n>0:
    print('NO')
else:
    print('YES')


Measured memory_bytes: 4084
/*Bismillahir Rahmanir Rahim*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,j,min,a[10];
    cin>>n;
    min=1000000000000009;
    for(i=0; i<5; i++)
    {
        cin>>a[i];
        if(a[i]<min)
            min=a[i];
    }
    if(n%min==0)
        cout<<(n/min)+4<<endl;
    else
       cout<<(n/min)+5<<endl;
    return 0;
}


Measured memory_bytes: 256
inp = gets.split.map!(&:to_i)
L = gets.split.map!(&:to_i)

dist = 0
count = 1
(inp[0]).times do |i|
  dist += L[i]
  if dist <= inp[1]  #まだ超えてなかったら
    count += 1
  else  #もうX地点を超えてたら
    break
  end
end

p count


Measured memory_bytes: 1788
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2e5+5;
int p[N],q[N],f[N],t[N],n;
int main(){
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&p[i]),q[p[i]]=i;
	t[n]=0;
	fd(i,n-1,1)
		if(!t[i+1])q[i]>q[i+1]?(t[i]=1,f[i]=i+1):t[i]=0;
		else{
			if((q[f[i+1]]<q[i])+(q[i]<q[i+1])+(q[i+1]<q[f[i+1]])==2)
				t[i]=t[i+1],f[i]=f[i+1];
			else t[i]=t[i+1]+1,f[i]=i+1;
		}
	printf("%d\n",t[1]);
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define rev(a,b){return a>b}
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
using namespace std;




int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    int p = a+b;
    int q = a+a-1;
    int r = b+b-1;
    cout<<max(p,max(q,r))<<endl;


}


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

//関数

int main() {
    //入力
    long N,K;
    cin>>N>>K;
    
    //計算
    double ans=0.0 , par=1.0/N;
    while(N>0){
        if(N>=K){
            ans+=par*(N-K+1);
            N=K-1;
        }
        
        par/=2;
        K=(K+1)/2;
    }
    
    //出力
    printf("%.12f\n",ans);
}

Measured memory_bytes: 256
import sys

def input():
    return sys.stdin.readline().rstrip('\n')

##### main

N,K = list(map(int, input().split()))
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse=True)
AxF = [A[i]*F[i] for i in range(N)]
AxFmax = max(AxF)

def is_possible(x):
    _sum = 0
    for i in range(N):
        _sum += max(0, A[i] - x//F[i])
    #print(x,_sum,K)
    return _sum <= K

left = 0
right = AxFmax

while(left != right):
    x = (left+right)//2
    if is_possible(x):
        right = x
    else:
        left = x+1
    #print('main', left, right, x)
            
print(left)


Measured memory_bytes: 116608
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define VIN(n,v) for(int64_t i=0;i<(n);i++){cin >> (v).at(i);}

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  string s;
  cin >> s;
  V v(s.size());
  REP(i,v.size()){
    v.at(i) = 0;
  }
  V t;
  REP(i,s.size()-1){
    if (s.at(i) == 'R' && s.at(i+1) == 'L'){
      t.push_back(i);
    }
  }
  I c = 0;
  REP(i,s.size()){
    if (t.at(c) > i && (t.at(c) - i) % 2 == 1){
      v.at(t.at(c)+1)++;
    }else if(t.at(c) > i && (t.at(c) - i) % 2 == 0){
      v.at(t.at(c))++;
    }else if(t.at(c) == i){
      v.at(t.at(c))++;
    }else if (t.at(c) < i && s.at(i) == 'L' && (i - t.at(c)) % 2 == 1){
      v.at(t.at(c)+1)++;
    }else if (t.at(c) < i && s.at(i) == 'L' && (i - t.at(c)) % 2 == 0){
      v.at(t.at(c))++;
    }

    if (t.at(c) < i && i < s.size()-1 && s.at(i+1) == 'R'){
      c++;
    }
  }
  REP(i,v.size()){
    if (i < v.size()-1){
      cout << v.at(i) << " ";
    }else{
      cout << v.at(i) << endl;
    }
  }
  return 0;
}



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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;

#define TT template<typename T>
#define ET(T) typename T::value_type
TT inline T sq(T x){return x*x;}
TT inline T In(){T x;cin>>x;return x;}
TT inline int ubnd(T&v,ET(T) x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT inline int lbnd(T&v,ET(T) x){return lower_bound(begin(v),end(v),x)-begin(v);}
TT inline void sort(T&v){sort(begin(v),end(v));}
TT inline void revs(T&v){reverse(begin(v),end(v));}
TT inline void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT inline void inpt(T&v,int n,function<ET(T)()>f=In<ET(T)>){for(v.reserve(n);n--;v.emplace_back(f()));}
TT inline void show(T&v,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),cout<<x;cout<<e;}
#undef TT
#undef ET

inline void fast_io(){ios::sync_with_stdio(0); cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline string instr(){string x;cin>>x;return x;}
inline ll pow_mod(ll a, ll k, ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a, ll p){return pow_mod(a,p-2,p);}

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

int main()
{
  string right = "yuiophjklnm";
  string s;
  while (cin >> s, s != "#"){
    int cnt = 0;
    bool is_r = right.find(s[0]) != -1;
    for (const auto& c : s){
      bool r = right.find(c) != -1;
      if (is_r != r){
        cnt++;
        is_r = r;
      }
    }
    cout << cnt << endl;
  }

  return (0);
}

// priority_queue queue deque front top push pop map set stringstream max_element min_element insert count find get tie make_tuple

Measured memory_bytes: 1192
a = int(input())
b = int(input())
c = int(input())
x = int(input())
answer = 0
for i in range(a+1):
	for j in range(b+1):
		for k in range(c+1):
			if x == 500*i+100*j+50*k:
				answer += 1
				break
print(answer)


Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Program
{
    public static Scanner cin;
    static void Main()
    {
        cin = new Scanner();
        long[] xyzk = cin.ArrayLong(4);
        long[][] abc = new long[3][];
        
        for(int a = 0; a < abc.Length; a++)
        {
            abc[a]= cin.ArrayLong((int)xyzk[a]);
        }
        Array.Sort(abc[0]);
        Array.Reverse(abc[0]);
        Array.Sort(abc[1]);
        Array.Reverse(abc[1]);
        Array.Sort(abc[2]);
        Array.Reverse(abc[2]);
        List<long> abc2 = new List<long>();
        for (int a = 0; a < xyzk[0]; a++)
        {
            for (int b = 0; b <xyzk[1]; b++)
            {
                for (int c = 0; c < xyzk[2]; c++)
                {
                    if ((a + 1) * (b + 1) * (c + 1) > xyzk[3]) break;
                    abc2.Add(abc[0][a] + abc[1][b] + abc[2][c]);
                }
            }
        }
        abc2.Sort();
        abc2.Reverse();
        for(int a = 0; a < xyzk[3]; a++)
        {
            Console.WriteLine(abc2[a]);
        }
        
        Console.ReadLine();

    }
}





class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 15200
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
    string s;
    string t;
    cin >> s >> t;
    int ans = 0;
    rep(i, 3)
    {
        if (s[i] == t[i])
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
template<typename T>
bool all_same(vector<T> v1,vector<T> v2)
{
    sort(ALL(v1));
    sort(ALL(v2),greater<T>());
    return v1 == v2;
}
   
// g++ -std=c++11 prac.cpp
ll Max=-1e9,Min=1e9+1;

int main(){
    ll a,b,d,x=0,y=0,z,n,m,k,lank=1,w,sum=0,sum2=0,ans=0;
    string s,t;
    bool ok=true;
    cin >> s;   
    char c = s[0];
    ans++;
    for(int i=1; i<s.size();i++){
        if(s[i]==c){
            i++;
            if(i>=s.size()){
                break;
            }
            ans++;
            c = ' ';
        }
        else{
            c = s[i];
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define pb push_back
#define ff first
#define ss second

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

const int MAXN = 1000 + 17, MAXM = 1000 * 10 + 17, inf = 1e9 + 17;

ll h, n, a[MAXN], b[MAXN], dp[MAXN][MAXM];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> h >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i] >> b[i];
	for (int i = 0; i < MAXN; i++)
		for (int j = 0; j < MAXM; j++)
			dp[i][j] = inf;
	for (int i = 0; i < MAXN; i++)
		dp[i][0] = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= h; j++)
			dp[i][j] = min(dp[i - 1][j], dp[i][max(j - a[i], 0LL)] + b[i]);
	cout << dp[n][h] << endl;
	return 0;
}


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

queue<int> s;
stack<int> a[MAX];
bool check[MAX][MAX];
int b[MAX];
int main(){
	int n, m, t1, t2;
	scanf("%d %d", &n, &m);
	fill(b, b+MAX, 0);
	rep(i,MAX)rep(j,MAX)check[i][j]=false;
	//fill((int*)check, (int*)(check+MAX), false);
	for(int i = 0;i < m;i++){
		scanf("%d %d", &t1, &t2);
		check[t1][t2] = 1;
		a[t1].push(t2);
		b[t2]++;
	}
	
	int ans[MAX], c = 0;
	for(int i = 1;i <= n;i++)if(!b[i])s.push(i);
	while(!s.empty()){
		int t = s.front();
		ans[c++] = s.front();
		while(!a[t].empty()){
			if(--b[a[t].top()] == 0)s.push(a[t].top());
			a[t].pop();
		}
		s.pop();
	}
	
	int f = 0;
	for(int i = 0;i < n-1;i++){
		if(check[ans[i]][ans[i+1]] != 1)f = 1;
	}
	for(int i = 0;i < n;i++)printf("%d\n", ans[i]);
	printf("%d\n", f);
	return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

class UnionFind {
    private :
        std::vector<int> par;
    public :
        UnionFind(int n) {
            par.resize(n);
            for (int i=0; i<n; i++) par.at(i) = i;
        }
        void unite(int x, int y) {
            int xPar = find(x);
            int yPar = find(y);
            if (xPar == yPar) return;

            par.at(xPar) = yPar;
        }
        int find(int x) {
            if (par.at(x) == x) return x;
            else return par.at(x) = find(par.at(x));
        }
        bool same(int x, int y) { return find(x) == find(y); }
};

void solve() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> a(n);
    for (int i=0; i<n; ++i) {
        cin >> a.at(i).first;
        a.at(i).second = i;
    }
    UnionFind uf(n);
    for (int i=0; i<m; ++i) {
        int a, b;
        cin >> a >> b;
        uf.unite(a, b);
    }

    int add = n - 1 - m;
    if (add > n / 2) {
        cout << "Impossible" << '\n';
        return;
    }
    if (add == 0) {
        cout << 0 << '\n';
        return;
    }

    ll res = 0;
    sort(a.rbegin(), a.rend());
    for (auto p : a) res += p.first;
    vector<int> cnt(n);
    for (int i=0; i<n; ++i) ++cnt.at(uf.find(i));
    int unused = n - 2 * add;
    for (auto p : a) {
        if (unused == 0) break;
        int par = uf.find(p.second);
        if (cnt.at(par) > 1) {
            res -= p.first;
            --cnt.at(par);
            --unused;
        }
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 1792
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var x = lines[0].split(' ');
 console.log(x.indexOf('0') + 1);
});

Measured memory_bytes: 30076
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())

    if N==0:
        print(0)
    else:
        nums=[]
        fugou=1  #+or-
        power=1  #2**0
        total=0
        while total!=N:
            m=N%(power*2)
            if m==total%(power*2):
                nums.append(0)
            else:
                nums.append(1)
            total+=nums[-1]*power*fugou
            fugou*=-1
            power*=2

        nums=nums[::-1]
        for i in range(len(nums)):
            print(nums[i],end="")
        print()
if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  int N;
  cin >> N;
  vector<vector<int>> G(N);
  vector<pair<int, int>> vp;
  map<pair<int, int>, int> I;
  vector<int> vc(N, 0);
  REP(i, N-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    vp.emplace_back(a, b);
  }
  int K = 0;
  vector<int> used(N, 0);
  queue<int> que;
  used[0] = 1;
  que.emplace(0);
  while(!que.empty()) {
    int v = que.front(); que.pop();
    if (K < (int)G[v].size()) K = G[v].size();
    int c = 1;
    for(int nv : G[v]) {
      if (used[nv] != 0) continue;
      if (c == vc[v]) c++;
      vc[nv] = c++;
      I[make_pair(nv, v)] = I[make_pair(v, nv)] = vc[nv];
      used[nv] = 1;
      que.emplace(nv);
    }
  }
  cout << K << endl;
  for (auto p:vp) cout << I[p] << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 20088
#include <stdio.h>

int main(void) {
    unsigned long long a, b, x;
    scanf("%llu %llu %llu", &a, &b, &x);

    unsigned long long ac = a / x;
    unsigned long long bc = b / x;

    long long ans = bc - ac;

    if (a % x == 0) {
        ans++;
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 128
fun main(args: Array<String>) = ABC163A.main()

object ABC163A {

    fun main() {
        val R = readLine()!!.toDouble()
        println(2 * R * Math.PI)
    }


    /*####################################################################################*/

    fun readString() = readLine()!!
    fun readStrings() = readLine()!!.split(" ")
    fun readInt() = readLine()!!.toInt()
    fun readInts() = readLine()!!.split(" ").map { it.toInt() }
    fun readMatrixRows(height: Int) = (1..height).map { readLine()!!.toList() }

    fun Boolean.yesOrNo() = if (this) "Yes" else "No"
    fun Double.toNaturalExpr() = println("%f".format(this))
}

Measured memory_bytes: 34708
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

A,B,H,M = parseMap(split(readline()))
Ax=A*cos(M/60*2*pi)
Ay=A*sin(M/60*2*pi)
Bx=B*cos((M/60*1/12)*2*pi+H/12*2*pi)
By=B*sin((M/60*1/12)*2*pi+H/12*2*pi)
println(sqrt((Ax-Bx)^2+(Ay-By)^2))


Measured memory_bytes: 209248
firstvar = input()
l = int(firstvar.split(" ")[0])
r = int(firstvar.split(" ")[1])
i = l
min = 2019
if (r/2019 - l/2019) >= 1:
    print(0)
else:
    for i in range(l,r + 1):
        for j in range(i + 1, r + 1):
            mod = (i*j)%2019
            if mod < min:
                min = mod
                if mod == 0:
                    break;
    print(min)

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

long long n, m;
vector<long long> a, sum;

long long solve();
long long check(long long x);

int main() {
  cin >> n >> m;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end(), greater<long long>());
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0, l = 0, r = a[0] * 3;
  while(r - l > 1) {
    long long now = (l + r) / 2;
    if(check(now) >= m)
      l = now;
    else
      r = now;
  }
  sum = a;
  for(int i = 1; i < n; ++i) sum[i] += sum[i - 1];
  for(int i = 0; i < n; ++i) {
    if(a[0] + a[i] < l) continue;
    long long now =
        upper_bound(a.begin(), a.end(), l - a[i],
                    greater<long long>()) -
        a.begin();

    res += now * a[i] + sum[now - 1];
  }
  res -= l * (check(l) - m);
  return res;
}

long long check(long long x) {
  long long cnt = 0;
  for(int i = 0; i < n; ++i) {
    if(a[0] + a[i] < x) continue;
    cnt += upper_bound(a.begin(), a.end(), x - a[i],
                       greater<long long>()) -
           a.begin();
  }
  return cnt;
}

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

int main()
{
  int n;
  scanf("%d",&n);
  char a[110],b[110],c[110];
  scanf("%s%s%s",a,b,c);
  int ans=0;
  for(int i=0;i<n;i++){
    if(a[i]==b[i]&&b[i]==c[i]){
    }
    else if(a[i]==b[i]||b[i]==c[i]||c[i]==a[i]){
      ans+=1;
    }
    else{
      ans+=2;
    }
  }
  printf("%d\n",ans);
  return 0;
}


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

res = 0
cnt = 1
mod = 10 ** 9 + 7
def f(n, r):
    X = 1
    Y = 1
    for i in range(r):
        X *= n - i    # nCr の分子
        X %= mod
        Y *= i + 1    # nCr の分母
        Y %= mod

    # フェルマーの小定理より (X/Y)%mod = X*Y^(mod - 2) % mod
    return X * pow(Y, mod - 2, mod) % mod

while S >= cnt * 3:
    tmp = S - (cnt * 3)
    res += f(tmp + cnt - 1, tmp)
    res %= mod
    cnt += 1

print(res)

Measured memory_bytes: 66008
function main(input) {
  var N = input[0]-0;
  var ans = 0;
  for(var i=111;i<=999;i+=111){
    if(N<=i){
      ans=i;
      break;
    }
  }
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    map<pair<int, int>, int> cnt;
    for (int i = 1; i <= n; ++i) {
        string s = to_string(i);
        int st = (s.front() - '0');
        int en = (s.back() - '0');
        ++cnt[{st, en}];
    }
    long long prs = 0;
    for (int i = 1; i <= n; ++i) {
        string s = to_string(i);
        int st = (s.front() - '0');
        int en = (s.back() - '0');
        prs += cnt[{en, st}];
    }
    cout << prs << "\n";
    return 0;
}



Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
typedef long long i64;
typedef vector<int> Vi;
typedef pair<int, int> Pii;
# define pb push_back
# define mp make_pair
# define MOD 1000000007
# define INF 1000000000
# define bug puts("H");

const int N = 10000 + 5;

inline int Scan() {
    int x=0;int f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

int main ()
{
    int n, d;
    scanf("%d%d", &n,&d);
    printf("%d\n",(n+2*d)/(2*d+1));
    return 0;
}


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

#define ll long long
#define s(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)

int main()
{
    int t, i, j, n,a[100005], p1=0, p2=n, k=0, v=0;
    cin >> n;
    for(i=0; i<n; i++){
        cin >> a[i];
    }
    for(i=0; i<n-1; i++){
        if(a[i]>=a[i+1]){
            v++;
        }
        else{

            v=0;
            //i--;
        }
        k = max(k, v);

    }
    cout << k << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <memory.h>
#include <algorithm>
#define case        printf("Case %d: ",++tc);
#define read        freopen("tst.txt","r",stdin)
#define write       freopen("out.txt","w",stdout)
typedef long long ll;
using namespace std;
#define pi acos(-1)

#define mx 100
int ar[mx],a[mx],b[mx];



main(){
int t,tc = 0;

int n;
cin>>n;
for(int i = 1; i<=n; i++)   cin>>ar[i];
for(int i = 1; i<=n; i++)   cin>>a[i];
for(int i = 1; i<n; i++)    cin>>b[i];
int tot = 0;
ar[0] = -1;
for(int i = 1; i<=n; i++){
    tot+=a[i];
    if(ar[i]==ar[i-1]+1)    tot+=b[ar[i-1]];

}
cout<<tot<<endl;

return 0;
}


Measured memory_bytes: 256
N = int(input())
L =  input().split()
sum_len = 0

L_i = [int(s) for s in L]
L_i.sort()

for i in range(N-1):
    sum_len = sum_len + int(L_i[i])

if sum_len > int(L_i[N-1]):
    print('Yes')
else :
    print('No')

Measured memory_bytes: 3060
//
// Created by wulang on 10/23/16.
//

#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

int a[10000+10];

int main(int argc, char *argv[]) {
    if (argc == 2) {
        freopen(argv[1], "r", stdin);
    }

    int n,m;
    while(cin>>n>>m) {
        for(int i=0;i<m;i++) cin>>a[i];
        sort(a,a+m);
        int x=a[m-1], y=n-x;

        int ans = x-y-1;
        ans=max(ans, 0);





        cout<<ans<<endl;

    }

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <bitset>
#include <string>
#include <array>
#include <random>
#include <chrono>
#include <algorithm>
#include <unordered_map>
int main(void){
	int a;
	std::string s;
	std::cin >> a >> s;
	if(a < 3200)s = "red";
	std::cout << s << std::endl;
}

Measured memory_bytes: 256
#include<stdio.h>

const int N=105;

int main(void)
{
     int a[N]={0};
     
     for(int i = 0 ; i < 10 ;i++)
     {
     	scanf("%d",&a[i]);
	 }
	 
	 for(int i = 0 ; i<10 ; i++)
	 {
	 	for(int j = i ; j<10 ;j++)
	 	{
	 		if(a[i]<a[j])
	 		{
	 			int tmp=a[i];
	 			a[i]=a[j];
	 			a[j]=tmp;
			 }
	 		
	 		
	 		
		 }
	 }
	 
	 for(int i=0 ; i<3 ;i++)
	 {
	 	printf("%d\n",a[i]);
	 }
	
	
	
}



Measured memory_bytes: 2708
public class Main {

  private static void solve() {
    int n = ni();
    int[] a = na(n);
    int v = 0;
    for (int x : a) {
      v ^= x;
    }

    System.out.println(v == 0 ? "Yes" : "No");
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

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

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 35728
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;

int main(){
  int a=1,b=1;
  while(b!=9||a!=9){
    cout<<a<<"x"<<b<<"="<<a*b<<endl;
    if(b==9){
      b=1,a++;
    }else{
      b++;}
  }
  cout<<"9x9=81"<<endl;

  return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<b?(a=b,1):0)
#define chmin(a,b) (a>b?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

vector<pii> g[100];
int dist[100];
int dist1[100];
double dp1[100];
double dp[100];
int c[100];

int main() {
  int n,m,p;
  while(cin>>n>>m>>p,n||m||p) {
    REP(i,n)g[i].clear();
    REP(i,m) {
      int a, b, d;
      cin>>a>>b>>d;
      g[a].push_back(pii(b,d));
      g[b].push_back(pii(a,d));
    }
    REP(i,p) cin >> c[i];
    priority_queue<pii> Q;
    Q.push(pii(0,0));
    memset(dist,0x3f,sizeof(dist));
    dist[0] = 0;
    vector<int> order;
    int minDist = INF;
    while(!Q.empty()) {
      pii p = Q.top(); Q.pop();
      int now = p.second;
      int dis = -p.first;
      if (dist[now] < dis) continue;
      if (now == n-1) {
        minDist = dis;
      }
      order.push_back(now);
      FOR(it, g[now]) {
        int e=it->first;
        if (dist[e] > dis + it->second) {
          dist[e] = dis + it->second;
          Q.push(pii(-dist[e],e));
        }
      }
    }
    
    memset(dist1,0x3f,sizeof(dist1));
    memset(dp1,0,sizeof(dp1));
    Q.push(pii(0,n-1));
    dist1[n-1] = 0;
    dp1[n-1] = 1;
    while(!Q.empty()) {
      pii p = Q.top(); Q.pop();
      int now = p.second;
      int dis = -p.first;
      if (dist1[now] < dis) continue;
      FOR(it, g[now]) {
        int e=it->first;
        if (dist1[e] > dis + it->second) {
          dist1[e] = dis + it->second;
          // cout << now << " " << e << " " << dist[e] << " " << dist1[e] << endl;
          if (dist[e] + dist1[e] == minDist) {
            dp1[e] = dp1[now];
          }
          Q.push(pii(-dist1[e],e));
        } else if (dist1[e] == dis + it->second) {
          if (dist[e] + dist1[e] == minDist) {
            dp1[e] += dp1[now];
          }
        }
      }
    }

    // REP(i,n) cout << dp1[i] << " "; cout << endl;

    memset(dp,0,sizeof(dp));
    dp[0] = 1;
    FOR(it, order) {
      int e = *it;
      FOR(jt, g[e]) {
        int f = jt->first;
        if (dist[e] + dist1[f] + jt->second == minDist) {
          dp[f] += dp[e] * dp1[f]/dp1[e];
        }
      }
    }

    REP(i,p) {
      printf("%.10f\n", dp[c[i]]);
    }
    puts("");
  }
}

Measured memory_bytes: 1356