akhauriyash/Code-Regression huggingface dataset:
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_6-B: Partition

#include <algorithm>
#include <cstdio>

using uint = unsigned int;

static void print_partition_ints(const int as[], const uint q, const uint n)
{
  auto out_sep = "";
  for (auto i = 0u; i < n; ++i) {
    auto format = (i != q ? "%s%d" : "%s[%d]");
    std::printf(format, out_sep, as[i]);
    out_sep = " ";
  }
  std::printf("\n");
}

static uint partition(int as[], const uint first, const uint last)
{
  // as[last] is pivot
  auto ge = first;
  for (auto i = first; i < last; ++i) {
    if (as[i] <= as[last]) {
      std::swap(as[ge++], as[i]);
    }
  }
  std::swap(as[ge], as[last]);
  return ge;
}

int main()
{
  uint n;
  std::scanf("%u", &n);
  int as[n];
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%d", &as[i]);
  }

  auto q = partition(as, 0, n-1);
  print_partition_ints(as, q, n);
}

// eof

Measured memory_bytes: 2956
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;



int main() {
  int n; cin >> n;
  vector<int> A(n);
  rep(i,n) cin >> A[i];
  vector<int> ans(n);
  rep(i,n){
    ans[A[i] -1] = i+1;
  }

  rep(i,n) cout << ans[i] << endl;

	return 0;
}



Measured memory_bytes: 4036
n = int(input())
s = input()
e = [0] * (n + 1)
w = [0] * (n + 1)

for i in range(len(s)):
    if s[i] == "E":
        e[i+1] = e[i] + 1
        w[i+1] = w[i]
    else:
        w[i+1] = w[i] + 1
        e[i+1] = e[i]

ans = 10 ** 9
for i in range(0, n+1):
    t = w[i] + e[n] - e[i]
    ans = min(ans, t)

print(ans)


Measured memory_bytes: 19580
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

  cout << (char) toupper(a[0]) << (char) toupper(b[0]) << (char) toupper(c[0]) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000000
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<pair<int,int>,int> &a, const pair<pair<int,int>,int> &b)
{
    return (a.first.second<b.first.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
void vok()
{
    FAST
    FO
    FI
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    // #endif
}
int main()
{
    vok();
    int n;
    IN n;
    vector<int> a(n-1);
    map<int,int> m;
    loop(i,0,n-1)
    {
        IN a[i];
        m[a[i]]++;
    }
    loop(i,1,n+1)
    {
        OUT m[i]<<endl
    }
    return 0;
}

Measured memory_bytes: 13540
A,B = map(int,input().split())
grid_b = [["#"]*100 for i in range(50)]
grid_w = [["."]*100 for i in range(50)]
for i in range(A-1):
    grid_b[(i//50)*2][(i%50)*2] = "."
for i in range(B-1):
    grid_w[49-(i//50)*2][(i%50)*2] = "#"
grid = grid_b+grid_w
print(100,100)
for y in grid:
    for x in y:
        print(x,end="")
    print()

Measured memory_bytes: 4468
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
count = 0
for key, value in d.items():
    if key < value:
        count += value - key
    elif key > value:
        count += value
print (count)


Measured memory_bytes: 18168
n = int(input())
a = list(map(int,input().split()))
cnt = 0
s = 'on'
while True:
    for i in range(n):
        if a[i] % 2 == 0:
            a[i] //= 2
        else:
            s = 'off'
            break
    else:
        cnt += 1
    
    if s == 'off':
        break
    
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}


int main(void) {
  ll a, b;
  cin >> a >> b;
  
  if(a<b) {
    pt(b+b-1);
  }else if(a>b) {
    pt(a+a-1);
  }else {
    pt(a+b);
  }
}












Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void) {
	int n, a;
	cin >> n;
	int odd = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		if (a % 2 == 1) ++odd;
	}
	if (odd % 2 == 0) cout << "YES\n";
	else cout << "NO\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


bool prime[100000];
vector<ll> primes;
void sieve() {
    fill(prime, prime + 100000, 1);
    prime[0] = prime[1] = 0;

    for (int i = 2; i < 100000; i++) {
        if (prime[i]) {
            primes.pb(i);
            for (int j = i * 2; j < 100000; j += i) {
                prime[j] = 0;
            }
        }
    }
}



int main() {
    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int a, b;
    cin >> a >> b;
    int m = max(a, b);
    cout << max(a + b, m + m - 1);


}






Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<list>
#include<set>
#include<math.h>
using namespace std;

int main(){

  double a,b,x;

  cin >> x >> a >> b;

  a=fabs(x-a);
  b=fabs(x-b);

  if(a > b){
    cout << "B" << endl;
  }else{
    cout << "A" << endl;
  }


  return 0;
}


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

#define mp make_pair
#define X first
#define Y second
#define FOE(x, a) for(auto x : a)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FOD(i, a, b) for(int i = a; i >= b; i--)

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ii, int> iii;

const int N = 21;

int n, val[N], l;
vector <iii> edge;

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

    cin >> l;
    while (l > 0){
        n++;
        val[n] = l;
        l /= 2;
    }
    reverse(val + 1, val + 1 + n);
    assert(val[1] = 1);

    FOR(i, 2, n){
        edge.push_back(mp(mp(i - 1, i), 0));
        edge.push_back(mp(mp(i - 1, i), val[i - 1]));
        if (val[i - 1] * 2 < val[i])
            edge.push_back(mp(mp(1, i), val[i] - 1));
    }

    cout << n << ' ' << (int) edge.size() << endl;
    for(iii p : edge)
        cout << p.X.X << ' ' << p.X.Y << ' ' << p.Y << endl;

    return 0;
}



Measured memory_bytes: 3652
N=int(input())
h=list(map(int,input().split()))
ans=0
flag=True
for i in range(N):
  for j in range(h[i]):
    for k in range(i,N):
      if h[k]==0:
        if k==i:
          flag=False
        break
      h[k]-=1
    if flag:
      ans+=1
    flag=True
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define loop(i, sta, end, inc) for(int i = sta; i <= end; i += inc)
#define itr(it, l)             for(auto it = l.begin(); it != l.end(); it ++)
#define in(a, b, c)            assert( b <= a && a <= c)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define what_is(x) cerr<<#x<<" ="<<x<<" ";
#define error(args...)  { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define LINT_MAX  9223372036854775807
#define LINT_MIN -9223372036854775808
#define EPS 1e-9
#define MOD 1000000007
#define DEBUG 0

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
void err(istream_iterator<string> it) { cerr<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    if(DEBUG == 0)return;
	cerr << *it << " = " << a <<" ";
	err(++it, args...);
}

long long A[400];
long long dp[400][400];
long long sum[400][400];
int main(){
   // freopen("test.txt", "r", stdin);
    int n;cin>>n;
    forn(i,n)cin>>A[i];
   	int k=0;
   	forn(i,n){
   		for(int j=i;j<n;j++){
   			if(i==j)sum[i][j]=A[i];
   			sum[i][j]=sum[i][j-1]+A[j];
   		}
   	}
   	while(k<n){
   		forn(i,n-k){
   			long long temp=LINT_MAX;
   			if(k==0){dp[i][i]=0;continue;}
   			for(int j=i;j<i+k;j++){
   				temp=min(temp,sum[i][j]+sum[j+1][i+k]+dp[i][j]+dp[j+1][i+k]);
   			}
   			dp[i][i+k]=temp;
   		}
   		k++;
   	}
   	
   	cout<<dp[0][n-1]<<endl;
    

    
    return 0;
}



Measured memory_bytes: 2688
/* long long or int */
/* xx 396*/

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

typedef long long ll;

const int MAX_N=1e5+10;

int n;
ll ans=0;
int a[MAX_N],b[MAX_N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin>>n;
	for(int i=0;i<n+1;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	for(int i=0;i<n+1;i++) ans+=a[i];
	for(int i=0;i<n;i++){
		if(b[i]>a[i]){
			 b[i]-=a[i]; a[i]=0;
		}
		else{
			a[i]-=b[i];
			b[i]=0;
		}
		if(b[i]>a[i+1]){
			b[i]-=a[i+1]; a[i+1]=0; 
		}
		else{
			a[i+1]-=b[i];
			b[i]=0;
		}
	}
	ll sum=0;
	for(int i=0;i<n+1;i++){
		sum+=a[i];
	}
	ans=ans-sum;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	x := getNextInt64(scanner)
	ans := x / 500 * 1000
	x %= 500
	ans += x / 5 * 5
	fmt.Fprintln(writer, ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define NFOR(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); --i)
#define rep(i, a) for (ll i = 0; i < a; i++)
#define endl "\n"
#define fi first
#define se second
#define MOD 1000000007
#define inf 1e12
#define pb push_back
#define Case cout<<"Case #"<<++cas<<": ";
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;

#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}

ll dp[12][2][12][12][12];

ll solver(string &s, ll ind = 0, bool tight = true, ll cnt3=0, ll cnt5=0,ll cnt7=0)
{
	if (ind == s.size())
		return cnt5>0 and cnt3>0 and cnt7>0;

	if (dp[ind][tight][cnt3][cnt5][cnt7] != -1)
		return dp[ind][tight][cnt3][cnt5][cnt7];

	ll ans = 0;
	if (cnt3+cnt5+cnt7 == 0)
		ans += solver(s, ind+1,false,cnt3,cnt5,cnt7);

	if (not tight or (s[ind]-'0')>=3)
	ans+=solver(s, ind + 1, tight and s[ind]=='3', cnt3+1,cnt5,cnt7);
	
	if (not tight or (s[ind]-'0')>=5)
	ans+=solver(s, ind + 1, tight and s[ind]=='5', cnt3,cnt5+1,cnt7);
	
	if (not tight or (s[ind]-'0')>=7)
	ans+=solver(s, ind + 1, tight and s[ind]=='7', cnt3,cnt5,cnt7+1);
	
	dp[ind][tight][cnt3][cnt5][cnt7] = ans;
	return ans;
}

void solve() {
	memset(dp, -1,sizeof(dp));
	string s;
	cin>>s;
	cout<<solver(s)<<endl;
}

int main()
{
    fastio;
    ll t  = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

const int MAX_N = 300010;

// 1baseでs1,...,snの和を計算
class BIT{
private:
  ll bit[MAX_N];
  int n;
public:
    BIT(){}

    void init(int sz){
        n=sz;
        for(int i=0;i<=n;i++)
            bit[i]=0;
    }

  ll sum(int i){
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
  // from-to間の総和を求める
  ll rangeSum(int from,int to){
    ll res=0;
    res=(sum(to)-sum(from-1));
    return res;
  }
  void add(int i,ll x){
    while(i<=n){
      bit[i]+=x;
      i+=i&-i;
    }
  }
  // sumとaddを組み合わせて、iの場所にxの値を代入
  void insert(int i,ll x){
    add(i,-(sum(i)-sum(i-1))+x);
  }
};


int N;
string S;
int cnts[2][1001];

BIT bit[2];

int main(){

    cin >> N;
    cin >> S;
    bit[0].init(N);
    bit[1].init(N);

    for(int i = 0; i < N; i++){
        bit[S[i]=='W'].add(i+1, 1);
    }
    ll ans = 1 << 29;
    for(int i = 0; i < N; i++){
        ll c = 0;
        if(i + 2 <= N) c += bit[0].rangeSum(i+2, N);
        if(i >= 1) c+= bit[1].rangeSum(1, i);
        ans = min(ans, c);
    }

    cout << ans << endl;


    return 0;
}


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


int main() {
  int N,K;
  cin >> N >> K;
  int ans = 0;
  while(N/K != 0) {
    ans++;
    N = N/K;
  }
  cout << ans + 1 << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
  std::string to_string(char val) {
    return std::string(1, val);
    // return std::string{val};
  }
}

using namespace std;

int main(void) {
  int n;
  cin >> n;
  
  vector<int> array(n);
  int max = INT_MIN;
  int total = 0;

  for(int i = 0; i < n; i++){
    cin >> array[i];
    total += array[i];
    max = (max > array[i]) ? max : array[i];
  }

  total -= max;
  
  cout << ( max < total ? "Yes" : "No") << endl;


  return 0;
}

Measured memory_bytes: 764
N = int(input())
A = list(map(int, input().split()))

import collections

A_count = collections.Counter(A)


ans = 0
for x, x_count in A_count.items():
    if x == x_count:
        continue
    elif x < x_count:
        ans += x_count-x
    else:
        ans += x_count
print(ans)

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

int main()
{
  int n, k, d, aind;
  int res = 0;
  cin >> n >> k;
  bool a[n];
  for (int i = 0; i < n; i++) {
    a[i] = true;
  }

  for (int i = 0; i < k; i++) {
    cin >> d;
    for (int j = 0; j < d; j++) {
      cin >> aind;
      a[aind - 1] = false;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i]) res++;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3640
from bisect import bisect_left
from itertools import accumulate
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
bs = [0]*N
for i in range(N):
    b = B[i]
    ai = bisect_left(A, b)
    bs[i] = ai
bs = [0]+list(accumulate(bs, lambda x,y:x+y))
ans = 0
for i in range(N):
    c = C[i]
    bi = bisect_left(B, c)
    ans += bs[bi]
print(ans)

Measured memory_bytes: 31036
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int a,p;
  cin >> a >> p;
  cout << ((a*3)+p)/2 << endl;
}


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

typedef long long ll;

const int Maxn = 200005;
const int nil = 100001;

int n;
int par[Maxn], siz[Maxn];
int mya[Maxn], myb[Maxn];
ll res;

int getPar(int x) { return par[x] == x? x: par[x] = getPar(par[x]); }

void unionSet(int a, int b)
{
    a = getPar(a), b = getPar(b);
    if (a == b) return;
    if (siz[a] < siz[b]) swap(a, b);
    siz[a] += siz[b]; par[b] = a;
    mya[a] += mya[b]; myb[a] += myb[b];
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < nil; i++) {
        par[i] = i; siz[i] = 1;
        mya[i] = 1;
    }
    for (int i = nil; i < Maxn; i++) {
        par[i] = i; siz[i] = 1;
        myb[i] = 1;
    }
    for (int i = 0; i < n; i++) {
        int x, y; scanf("%d %d", &x, &y);
        unionSet(x, nil + y);
    }
    for (int i = 0; i < Maxn; i++) if (getPar(i) == i)
        res += ll(mya[i]) * myb[i];
    res -= n;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2944
n = gets.to_i
a = n.times.map{gets.to_i}

max_num = a.max
max_2_num = a.reject{|e| e == max_num}.max.to_i

max_indexes = a.map.with_index{|e, i| e == max_num ? i : nil}.compact

a.each_with_index do |e, i|
  if max_indexes.size == 1 && max_indexes[0] == i
    puts max_2_num
  else
    puts max_num
  end
end

Measured memory_bytes: 8500
#include <bits/stdc++.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> PP;

struct edge {
	int to,cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

int n;
int a[100000];
int used[100000];

void dfs(int idx,int cnt) {
	if(idx==1) {
		cout<<cnt<<endl;
		return;
	}
	if(used[idx]) {
		cout<<-1<<endl;
		return;
	}
	used[idx]=1;
	dfs(a[idx],cnt+1);
}

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

	cin>>n;
	REP(i,n) {
		cin>>a[i];
		a[i]--;
	}

	dfs(0,0);

	return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			for (int i = n; i < 1000; i++) {
				if (check(i)) {
					out.println(i);
					return;
				}
			}

		}

		boolean check(int n) {
			char[] s = String.valueOf(n).toCharArray();
			return s[0] == s[1] && s[1] == s[2];
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 22228
#include<stdio.h>

int main(){

  int n, data[100], i, j, stock, sum, newdata[100];

  while(scanf("%d",&n) != EOF){

    sum = 0;

    for(i = 0; i < n; i++){
      newdata[i] = 0;
    }
    for(i = 0; i < n; i++){
      scanf("%d",&data[i]);
    }

    for(i = 0; i < n-1; i++){
      for(j = i; j < n; j++){
	if(data[i] > data[j]){
	  stock = data[i];
	  data[i] = data[j];
	  data[j] = stock;
	}
      }
    }

    for(i = 0; i < n; i++){
      for(j = 0; j <= i; j++){
	newdata[i] += data[j];
      }
      //printf("%d\n",data[i]);
    }

    for(i = 0; i < n; i++){
      sum += newdata[i];
    }

    printf("%d\n",sum);
  }

  return 0;
}

Measured memory_bytes: 0
IN=input()
M=int(IN.split(" ")[0])
N=int(IN.split(" ")[1])

count=0

if M >= 2:
    x=M*(M-1)
    count=x/2

if N >= 2:
    x=N*(N-1)
    count=x/2 + count

print(int(count))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for(int i=m; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <typename T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0; }
template <typename T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1;} return 0; }
const int INF = 1000000000;

struct UnionFind
{
    vi par;
    vi sizes;
    UnionFind(int n) : par(n), sizes(n,1){
        rep(i,0,n) par[i] = i;
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x==y) return;
        if(sizes[x]<sizes[y]) swap(x,y);
        par[y] = x;
        sizes[x] += sizes[y];
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sizes[find(x)];
    }
};

int main(){
    ll N,M; cin>>N>>M;
    UnionFind uf(N);
    ll a[M],b[M];
    rep(i,0,M){
        cin>>a[i]>>b[i];
        a[i]--,b[i]--;
    } 
    ll ans[M+1];
    ll rec=N*(N-1)/2;
    ans[M] = rec;
    for(int i=M-1;i>=0;i--){
        if(uf.same(a[i],b[i])) ans[i]=rec;
        else{
            rec-=uf.size(a[i])*uf.size(b[i]);
            ans[i]=rec;
            uf.unite(a[i],b[i]);
        }
    }
    rep(i,1,M+1) cout<<ans[i]<<endl;

}

Measured memory_bytes: 4480
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
char str[1100][1100];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%s",str[i]);
	bool ok=false;
	for(int i=0;i<a;i++)for(int j=0;j<a;j++)if(str[i][j]=='#')ok=true;
	if(!ok){
		printf("-1\n");return 0;
	}
	int ad=0;
	int ret=114514;
	for(int i=0;i<a;i++){
		bool dd=false;
		for(int j=0;j<a;j++)if(str[j][i]=='.')dd=true;
		if(dd)ad++;
	}
	for(int i=0;i<a;i++){
		bool OK=false;
		for(int j=0;j<a;j++)if(str[j][i]=='#')OK=true;
		
		int cnt=0;
		for(int j=0;j<a;j++){
			if(str[i][j]=='.')cnt++;
		}
		if(!OK)cnt++;
		ret=min(ret,cnt);
		//printf("%d\n",cnt);
	}
	printf("%d\n",ret+ad);
}

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;
int main(){
	string m;
	cin >> m;
	int a = m[0]-'0', b = m[1]-'0', c = m[2]-'0', d = m[3]-'0';
	if (a -b -c - d ==7) printf("%d-%d-%d-%d=7\n",a ,b ,c , d);
	else if (a -b - c + d ==7) printf("%d-%d-%d+%d=7\n",a, b , c, d);
	else if (a - b +c - d ==7) printf("%d-%d+%d-%d=7\n",a, b, c, d);
	else if (a - b + c + d ==7) printf("%d-%d+%d+%d=7\n", a, b, c, d);
	else if ( a +b -c - d ==7) printf("%d+%d-%d-%d=7\n", a, b, c, d);
	else if ( a +b - c + d ==7) printf("%d+%d-%d+%d=7\n", a, b, c, d);
	else if ( a + b +c - d ==7) printf("%d+%d+%d-%d=7\n", a, b, c, d);
	else if ( a + b + c + d ==7) printf("%d+%d+%d+%d=7\n", a, b, c, d);
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<*it.F<<' '<<*it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m;
    cin>>n;
    ll ans = 0;
    for(int i=1;i<=n;i++){
            if((i%3) && (i%5)){
                ans+=i;
            }
        }
            
cout<<ans;
    return 0;
}







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

using namespace std;
using ll = long long;

int main() {
	int a, b, K;
	cin >> a >> b >> K;

	vector<int> v;
	for (int i = 1; i <= min(a, b); ++i) {
		if ((a % i == 0) && (b % i == 0)) {
			v.push_back(i);
		}
	}
	sort(v.rbegin(), v.rend());

	int idx = max(0, K - 1);
	cout << v[idx] << endl;

	return 0;
}


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

public class Main {

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

	static int w,h,si,sj,n;
	static int[] di = {0,1,0,-1};
	static int[] dj = {1,0,-1,0};
	static int[][] table;
	static BitSet visited;

	static boolean solve() {
		w = in.nextInt();
		h = in.nextInt();
		if (w == 0 && h == 0) return false;
		table = new int[h][w];
		si = -1; sj = -1;
		n = 0;

		for (int i=0; i<h; i++) {
			for (int j=0; j<w; j++) {
				table[i][j] = in.nextInt();
				if (table[i][j] == 1) {
					n++;
				} else if (table[i][j] == 2) {
					si = i; sj = j;
					table[i][j] = 0;
				}
			}
		}

		visited = new BitSet();
		out.println(rec(si,sj));
		out.flush();
		return true;
	}

	static int rec(int ci, int cj) {

		if (visited.cardinality() == n) {
			return ci == si || cj == sj ? 1 : 0;
		}

		int res = 0;

		for (int k=0; k<4; k++) {
			int ni = ci + di[k];
			int nj = cj + dj[k];
			while (0 <= ni && 0 <= nj && ni < h && nj < w) {
				if (table[ni][nj] > 0 && !visited.get(ni*w+nj)) {
					visited.set(ni*w+nj);
					res += rec(ni, nj);
					visited.set(ni*w+nj, false);
					break;
				}
				ni += di[k];
				nj += dj[k];
			}
		}

		return res;
	}

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

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

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

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

Measured memory_bytes: 29020
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;
using P=pair<int,int>;//01,len

int main(){
    int N,K;
    string S;
    cin>>N>>K;
    cin>>S;
    vector<P> V;
    V.emplace_back(S[0]-'0',1);
    for(int i=1;i<S.size();i++){
        if(S[i]-'0'==V.back().first){
            V.back().second++;
        }else{
            V.emplace_back(S[i]-'0',1);
        }
    }
    int ans=0;
    for(int k=0,l=0,r=0,sum=0;r<V.size();r++){//[l,r]
        if(V[r].first==0){
            k++;
            sum+=V[r].second;
            while(k>K){
                if(V[l].first==0) k--;
                sum-=V[l].second;
                l++;
            }
        }else{
            sum+=V[r].second;
        }
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1528
#include <stdio.h>
int main(){
	int N;
	scanf("%d",&N);
	N = N % 10;
	if(N==2||N==4||N==5||N==7||N==9)
		printf("hon");
	else if(N==0||N==1||N==6||N==8)
		printf("pon");
	else
		printf("bon");
}

Measured memory_bytes: 1720
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>

typedef long long int LL;
using namespace std;

int main(int argc, char const *argv[]) {
    int N, W;
    cin >> N >> W;
    vector<int> weight(N), value(N);
    for (int i = 0; i < N; i++) {
        cin >> weight[i] >> value[i];
    }
    int V = accumulate(value.begin(), value.end(), 0);
    LL WINF = (LL) (W + 1);
    vector<vector<LL>> sum_weight(N + 1, vector<LL>(V + 1));

    for (int i = 0; i <= N; i++) {
        for (int v = 0; v <= V; v++) {
            if (v == 0) {
                sum_weight[i][v] = 0LL;
                continue;
            }
            if (i == 0) {
                sum_weight[i][v] = WINF;
            }
            else {
                if (v - value[i - 1] >= 0) {
                    sum_weight[i][v] = min(sum_weight[i - 1][v], sum_weight[i - 1][v - value[i - 1]] + (LL) weight[i - 1]);
                } else {
                    sum_weight[i][v] = sum_weight[i - 1][v];
                }
            }
        }
    }
    // cout << sum_weight[N][V] << endl;
    int ans;
    for (int v = V; v >= 0; v--) {
        if (sum_weight[N][v] <= W) {
            ans = v;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0;cin>>n;
  for(ll i=1;i<=n;i+=2) {
    ll num=0;
    for(ll div=1;div<=i;++div) if(i%div==0) num++;
    if(num==8) ans++;
  }
  print(ans);
  return 0;
}

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

b = []
bn = 0
for i in range(n):
    bn += a[i]
    b.append(bn)
b.append(0)

b.sort()
num = []
i = 0
count = 0
for j in range(1, n+1):
    if b[i] == b[j]:
        count += 1
        if j == n:
            num.append(count)
    else:
        i = j
        num.append(count)
        count = 0

ans = 0
for i in num:
    ans += ((i+1) * i // 2)
print(ans)

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

int main() {
  int a;
  cin >> a ;
  int b,c,d;
  
  b = a / 100;
  c = (a % 100) / 10;
  d = a % 10;
  
  cout << b+c+d << endl;
}

Measured memory_bytes: 3608
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int N, K, A[5000];

char dp[5001];

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A, A+N);
    for (int n = 0; n < N; ++n) if (A[n] >= K) { N = n; break; }

    int l = 0, r = N;
    while (l < r) {
        int m = (l + r) / 2;

        fill(dp, dp+K+1, 0); dp[0] = 1;

        for (int i = 0; i < N; ++i) {
            if (i == m) continue;
            for (int j = K; j >= A[i]; --j) {
                dp[j] |= dp[j-A[i]];
            }
        }

        bool ok = false;
        for (int i = K-A[m]; i < K; ++i) {
            if (dp[i]) {
                ok = true;
            }
        }

        if (ok) r = m;
        else    l = m+1;
    }

    cout << r << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define per(i,a,b) for(ll i=(a);i>=(b);i--)
using namespace std;
typedef long long ll;
const ll maxn=1e5+100;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f3f3f3f3f;
ll t,b[300];
ll a[4];
map<ll,ll> mp;
int main(){
    //freopen("in.txt","r",stdin);
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    ll x,k,d,res;
    cin>>x>>k>>d;
    ll t=x>0?x:-x;
    ll tm=t/d;
    if(tm>k){
        res=x>0?x-k*d:x+k*d;
    }else{
        k-=tm;
        if(k%2==1) res=x>0?x-(tm+1)*d:x+(tm+1)*d;
        else res=x>0?x-tm*d:x+tm*d;
    }cout<<(res>0?res:-res)<<endl;
	return 0;
}

Measured memory_bytes: 3632
// AUTHOR - RUTVIK KOTHARI
// DAIICT , GANDHINAGAR

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

#define ll long long int
#define ull unsigned long long
#define pll pair<ll,ll>
#define MS(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define INFL LLONG_MAX
#define pb push_back
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const ll N = 1e6 + 5;
const ll M = 3e5 + 5;
const ll mod = 1e9 + 7;
const ll m1 = 1e9 + 7;
const ll m2 = 1e9 + 9;
const ll p1 = 402653189;
const ll p2 = 1610612741;
const int LN = 20;

ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

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

ll pw[LN],fact[N],invfact[N];

void pre()
{
    fact[0]=1;
    for(int i=0;i<LN;i++)pw[i]=power(2,i);
    for(int i=1;i<N;i++)fact[i]=(i*fact[i-1])%mod;
    for(int i=0;i<N;i++)invfact[i]=powermodm(fact[i],mod-2,mod);
}


int main()
{
    FIO;
    //pre();

    ll i,j;

    ll n;
    cin>>n;
    
    ll a[n+1],b[n+1],c[n];
    
    for(i=1;i<=n;i++)
        cin>>a[i];
    
    for(i=1;i<=n;i++)
        cin>>b[i];
    
    for(i=1;i<n;i++)
        cin>>c[i];
    
    ll ans = 0,last = -1;
    
    for(i=1;i<=n;i++)
    {
        ans += b[a[i]];
        
        if(a[i] == last + 1)
            ans += c[last];
        
        last = a[i];
    }
    cout<<ans;
    
    
    return 0;
}

Measured memory_bytes: 256
//Sinhov : "Hi stalker!"
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
int main() {
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    ll h,w,i,j,n,k,val;
    cin>>h>>w>>n;
    vector<vector<ll> >arr(h,vector<ll>(w));
    vector<ll>arr1(n);
    for(i=0;i<n;i++)
        cin>>arr1[i];
    k=0,val=0;
    for(i=0;i<h;i++){
        if(i%2==0){
            for(j=0;j<w;j++){
                arr[i][j]=k+1;
                val++;
                if(val==arr1[k]) {
                    val=0;
                    k++;
                }
            }
        }
        else{
            for(j=w-1;j>=0;j--){
                arr[i][j]=k+1;
                val++;
                if(val==arr1[k]) {
                    val=0;
                    k++;
                }
            }
        }
    }
    for(i=0;i<h;i++){
        for(j=0;j<w;j++)
            cout<<arr[i][j]<<" ";
        cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 512
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
           bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: String,
    };
    let patterns = ['A', 'C', 'G', 'T'];
    let mut cnts = vec![0];
    for s in s.chars() {
        if patterns.contains(&s) {
            let cl = cnts.len()-1;
            cnts[cl] += 1;
        } else {
            cnts.push(0);
        }
    };
    println!("{:?}", cnts.iter().max().unwrap());
}




Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }


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

    int n;
    cin >> n;;
    vi x(n);
    vi y(n);
    vi p(n);
    int kaizyo =0;
    rep(i,n){
        cin >> x[i] >> y[i];
        p[i]=i;
    }
    double total = 0;
    do{
        rep(i,n-1){
            double dx = x[p[i]] - x[p[i+1]];
            double dy = y[p[i]] - y[p[i+1]];
            total += sqrt(dx*dx + dy*dy);
        }
    kaizyo++;

    }while(next_permutation(all(p)));
    double ans = total / kaizyo;
    printf("%.10f\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 10000
#define NIL -1
 
typedef struct node{
    int p,l,r;
}Node;
Node T[MAX];
int n;
 
void preorder(int u){
    if(u==NIL) return;
    printf(" %d",u);
    preorder(T[u].l);
    preorder(T[u].r);
}
 
void inorder(int u){
    if(u==NIL) return;
    inorder(T[u].l);
    printf(" %d",u);
    inorder(T[u].r);
}
 
void postorder(int u){
    if(u == NIL) return;
    postorder(T[u].l);
    postorder(T[u].r);
    printf(" %d",u);
}
int main(void){
    int i,v,l,r,root;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        T[i].p=NIL;
    for(i=0;i<n;i++){
        scanf("%d %d %d",&v,&l,&r);
        T[v].l=l;
        T[v].r=r;
        if(l != NIL)
            T[l].p=v;
        if(r != NIL)
            T[r].p=v;
    }
    for(i=0;i<n;i++)
        if(T[i].p == NIL)
            root=i;
    printf("Preorder\n");
    preorder(root);
    printf("\n");
    printf("Inorder\n");
    inorder(root);
    printf("\n");
    printf("Postorder\n");
    postorder(root);
    printf("\n");
    return 0;
}



Measured memory_bytes: 2048
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 1000000007
#define eps 1e-8
int n,m;
char s[5050];
ll f[5050][5050];

int read()
{
    int x=0,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()
{
	n=read();scanf("%s",s+1);
	m=strlen(s+1);
	f[0][0]=1;
	rep(i,1,n) rep(j,0,n)
	{
		if (j)
			f[i][j]=(f[i-1][j-1]+f[i-1][j+1]*2)%maxd;
		else 
			f[i][j]=(f[i-1][j]+f[i-1][j+1]*2)%maxd;
	}
	printf("%lld",f[n][m]);
	return 0;
}


Measured memory_bytes: 198912
#include<bits/stdc++.h>
using namespace std;
const int mx=305;
double dp[mx][mx][mx];
int main()
{
	int n;
	scanf("%d",&n);
	vector<int>cnt(4,0);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		cnt[x]++;
	}
	for(int c=0;c<=n;c++){
		for(int b=0;b<=n;b++){
			for(int a=0;a<=n;a++){
				if(a+b+c>n)continue;
				if(a>0)dp[a][b][c]+=dp[a-1][b][c]*a;
				if(b>0)dp[a][b][c]+=dp[a+1][b-1][c]*b;
				if(c>0)dp[a][b][c]+=dp[a][b+1][c-1]*c;
				if(a+b+c>0)dp[a][b][c]=(dp[a][b][c]+n)/((a+b+c)*(1.0));
			}
		}
	}
	printf("%.10lf", dp[cnt[1]][cnt[2]][cnt[3]]);
}

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

int main(){
    string S;
    cin>>S;
    if(S=="RRS"||S=="SRR"){
        cout<<"2"<<endl;
    }else if(S=="RRR"){
        cout<<"3"<<endl;
    }else if(S=="SSS"){
        cout<<"0"<<endl;
    }else{
        cout<<"1"<<endl;
        
    }
 }

Measured memory_bytes: 3620