akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=(ll)1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;
#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T> 
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string S;
    cin >> S;
    ll tow=0;
    ll tor=0;
    for(auto p: S){
        if(p=='R')tow++;
    }
    ll ans=tow;
    for(ll i=0;i<N;++i){
        if(S[i]=='R'){
            tow--;
        }
        else tor++;
        ll k=max(tor,tow);
        chmin(ans,k);
    }
    prt(ans);

    return 0;
}



Measured memory_bytes: 3776
import sys
from collections import Counter
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)


S = C(IS())
T = C(IS())
sv = sorted([v for v in S.values()])
tv = sorted([v for v in T.values()])
P('Yes') if sv == tv else P('No')  # これはうそ S = 'zazel' T = 'apple'でダメ


Measured memory_bytes: 3880
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    vector<pair<int, int>> work(n);
    REP(i, n) cin >> work[i].second >> work[i].first; // sortのしやすさのため逆にしていることに注意
    whole(sort, work);
    ll now = 0;
    bool ok = true;
    REP(i, n){
        now += work[i].second;
        if(now > work[i].first){
            ok = false;
            break;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int N, M, C;

	cin >> N >> M >> C;
	vector<int> B(M);

	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}

	int ans,num;

	ans = 0;
	for (int i = 0; i < N; i++) {
		num = 0;
		for (int j = 0; j < M; j++) {
			int A;
			cin >> A;
			num += A * B[j];
		}
		if (num + C > 0) ans++;
	}

	cout << ans << endl;

	return 0;
}

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

const int maxn = 100005;
const int inf = 1e9;
int a[maxn], c[16], f[1<<16], ins[1<<16];
int n, x, y, z, ans, now;

int solve(int s) {
	if (!(s >> 1)) return 0;
	if (ins[s]) return inf;
	if (f[s] != -1) return f[s];
	f[s] = inf; ins[s] = 1;
	rep (i, 1, 15) if (s >> i & 1)
		rep (j, 1, 15) if (i != j)
			f[s] = min(f[s], solve(s ^ (1 << i) ^ (1 << j)
			^ (1 << (i ^ j)) | 1) + 1 + ((s >> (i ^ j)) & 1));
	ins[s] = 0;
	//printf("%d %d\n", s, f[s]);
	return f[s];
}

int main() {
	scanf("%d", &n);
	rep (i, 2, n) {
		scanf("%d%d%d", &x, &y, &z);
		a[x+1] ^= z; a[y+1] ^= z;
	}
	rep (i, 1, n) c[a[i]]++;
	rep (i, 1, 15) {
		ans += c[i] / 2;
		c[i] &= 1;
		now |= c[i] << i;
	}
	memset(f, -1, sizeof f);
	printf("%d\n", ans + solve(now | 1));
	return 0;
}


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

void factorize(ll n) {
  for (ll i = 2; i*i <= n; ++i) {
    if (n%i) continue;
    while (n%i == 0) {
      n /= i;
      res[i]++;
    }
  }
  if (n != 1)
      res[n]++;
}

int main(void){
    ll N;
    cin >> N;
    rep(i, N + 1){
        factorize(i);
    }

    ll c = 1;
    rep(i, N + 1){
        if(res.count(i)){
            c *= res[i] + 1;
            c %= 1000000007;
        }
    }

    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
#define M 2000
bool ab[100000],ac[100000],bc[100000];
bool match(char c1,char c2){
  return(c1== '?' ||c2== '?' ||c1==c2);
}
int main(void){
	int i,j;string a,b,c;
	cin>>a>>b>>c;
	int A=a.length();
	int B=b.length();
	int C=c.length();
  
	for(int i=0;i<A;i++)
	{
		for(int j=0;j<B;j++)
		{
			if(!match(a[i],b[j]))
			{
				ab[i-j+40000] =true;
			}
		}
	}
	for(int i=0;i<A;i++)
	{
		for(int j=0;j<C;j++)
		{
			if(!match(a[i],c[j]))
			{
				ac[i-j+40000] =true;
			}
		}
	}
	for(int i=0;i<B;i++)
	{
		for(int j=0;j<C;j++)
		{
			if(!match(b[i],c[j]))
			{
				bc[i-j+40000] =true;
			}
		}
	}
	
	int ans=3*M;
	for(i=-2*M;i<=2*M;i++)
	{
    	for(j=-2*M;j<=2*M;j++)
    	{
    		if(!ab[i+40000] && !ac[j+40000] &&!bc[j-i+40000])
			{
        		int L=min(0,min(i,j));
        		int R=max(A,max(B+i,C+j));
				ans=min(ans,R-L);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    int a,b,c,count;
    count=0;
    cin>>a>>b>>c;
    rep(i,a){
        if(i<10){
            if(b<=i&&i<=c){
                //cout<<"A"<<i<<endl;
                count=count+i;
            }
        }
        if(10<=i&&i<100){
            int t=i/10+i%10;
            if(b<=t&&t<=c){
                //cout<<"B"<<i<<endl;
                count=count+i;
            }    
        }
        if(100<=i&&i<1000){
            int t=i/100+((i%100)/10)+((i%100)%10);
            if(b<=t&&t<=c){
                //cout<<"C"<<i<<endl;
                count+=i;
            }
        }
        if(1000<=i&&i<10000){
            int t=i/1000+(i%1000)/100+(i%100)/10+(i%100)%10;
            if(b<=t&&t<=c){
                //cout<<"D"<<i<<endl;
                count+=i;
            }
        }
        if(i==10000)
            if(b<=1&&1<=c)
                count+=i;
        //cout<<count<<endl;
    }
    cout<<count<<endl;
   
}



Measured memory_bytes: 256
#include <iostream>

int main(void)

{
    int n;
    int count;
    float ans = 0;
    int a;
    //整数の数を入力
    std::cin>>n;
    //整数を入力
    for(int i = 0; i < n; i++)
    {
        std::cin>>a;
        ans = ans + 1 / (float)a;
    }
    ans = 1 / ans;
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

bool check(int n1, int n2 , int n3){
	int a,b;
	a = n1*n1;
	b = n2*n2 + n3*n3;
	return (a==b)? true : false ;
}

int main(){
	int N,n1,n2,n3;

	scanf("%d", &N);
	for(int i=0 ; i<N ; i++){
		scanf("%d %d %d", &n1 , &n2 , &n3);
		if( check(n1,n2,n3) || check(n2,n1,n3) || check(n3,n2,n1) ){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f3f3f3f
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define pb push_back
#define ms(a, x) memset(a, x, sizeof(a))
#define forn(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i) 
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int mod = 1e9 + 7;
const int N = 3e3+10;
/*=======================================================================*/

int n;
db p[N];
db dp[N][N];
db ans;

int main() {
   dp[0][0] = 1;
   scanf("%d", &n);
   for1(i, n) {
      scanf("%lf", &p[i]);
   }
   for1(i, n) {
      // debug1
      for(int j = 0; j <= i; ++j) {
         if(j == 0) {
            dp[i][j] = dp[i-1][j] * (1.0 - p[i]);
         } else {
            dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1- p[i]);
         }
      }
   }
   for(int j = n/2+1; j <= n; ++j) {
      // debug1
      ans += dp[n][j];
   }
   printf("%.9lf\n", ans);
   return 0;
}

Measured memory_bytes: 69120
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,PS[li];
int cev;
string s;
vector<int> v;

main(void){
	scanf("%lld %lld %lld",&n,&m,&k);
	FOR scanf("%lld",&a[i]);
	for(int i=1;i<=m;i++){
		scanf("%lld",&b[i]);
		PS[i]=PS[i-1]+b[i];
	}
	int bas=1;
	int son=m;
	while(bas<=son){
		if(PS[ort]<=k)bas=ort+1;
		else son=ort-1;
	}
	cev=max(cev,son);
	FOR{
		k-=a[i];
		if(k<0)break;
		bas=1;
		son=m;
		while(bas<=son){
			if(PS[ort]<=k)bas=ort+1;
			else son=ort-1;
		}
		cev=max(cev,son+i);
	}
	printf("%lld\n",cev);
	return 0;
}



Measured memory_bytes: 8520
#include<bits/stdc++.h>
using namespace std ;
#define Fors(n) for(int i=1;i<=n;i++)
#define For(n) for(i=0;i<n;i++)
#define ll long long
#define vint(s) vector<int> s
#define pb(x)  push_back(x)
#define mpair(x,y) make_pair(x,y)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll s=0,n=0,i=0;

int main(){
    IOS;
    double x, y =0;
    cin >> n;
    ll a[n+1];
    For(n){
    	cin>> a[i];
    }
    sort(a,a+n);
    x = a[0];
    for (i=1;i<n;i++){
    	x = (x+double(a[i]));
    	x /= (2.0);
    }
    printf("%0.5f",x);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
#define f first
#define s second
#define pb push_back
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll INF = (ll) -1e10;
ll n, arr[1005];
ll mo, me;
pi no = pi(INF, 0), ne = pi(INF, 0);
vector<ll> o, e, v, ans;

int main() {
	fastio; cin >> n;
	FOR(i, 1, n) {
		cin >> arr[i];
		if (i & 1) {
			if (arr[i] > 0) {
				mo += arr[i];
				o.pb(i);
			} else no = max(no, pi(arr[i], i));
		} else {
			if (arr[i] > 0) {
				me += arr[i];
				e.pb(i);
			} else ne = max(ne, pi(arr[i], i));
		}
	}
	if (mo == 0) {mo = no.f, o.pb(no.s);}
	if (me == 0) {me = ne.f, e.pb(ne.s);}
	ll m = max(mo, me); v = (mo > me ? o : e);
	FOR(i, 1, v[0]-1) ans.pb(1);
	FOR(i, 0, v.size()-2) {
		DEC(j, (v[i] + v[i+1])/2 - v[i] + 1, 2) ans.pb(j);
	}
	DEC(i, n - v.back() + 1, 2) ans.pb(i);
	cout << m << "\n" << ans.size() << "\n";
	for(auto it:ans) cout << it << "\n";
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>

template <class T> void read(T &x) {
	int f = 1;
	char c = getchar();
	x = 0;
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	x *= f;
}

template <class T> void write(T x) {
	int len = 0;
	char s[30];
	if(x < 0) putchar('-'), x = -x;
	do {
		s[++len] = x % 10;
		x /= 10;
	}while(x);
	while(len) putchar(s[len--] + '0');
}

template <class T> inline bool gmin(T &a, T b) { return a > b ? a = b, true : false; }
template <class T> inline bool gmax(T &a, T b) { return a < b ? a = b, true : false; }

int h, w, h0, w0;

int main() {
		read(h); read(w); read(h0); read(w0);
		if(!(h % h0) && !(w % w0)) puts("No");
		else {
			puts("Yes");
			for(int i = 1; i <= h; i++) {
				for(int j = 1; j <= w; j++) {
					if(!(h % h0)) {
						if(!(j % w0)) write(-1000 * (w0 - 1) - 1), putchar(' ');
						else write(1000), putchar(' ');
					} else {
						if(!(i % h0)) write(-1000 * (h0 - 1) - 1), putchar(' ');
						else write(1000), putchar(' ');
					}
				}
				putchar('\n');
			}
		}
	return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>
#include<stdlib.h>
void printHeap(int*,int);
int parent(int);
int left(int);
int right(int);
int main(void)
{
  int i;//counter
  int n;//the size of binary heap
  int *arr;//heap array
  scanf("%d",&n);
  arr=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++) scanf("%d",&arr[i]);
  printHeap(arr,n);
  return 0;
}
void printHeap(int *arr,int n)
{
  int i;//counter
  for(i=0;i<n;i++)
    {
      printf("node %d: ",i+1);
      printf("key = %d, ",arr[i]);
      if(parent(i)>=0) printf("parent key = %d, ",arr[parent(i)]);
      if(left(i)<n) printf("left key = %d, ",arr[left(i)]);
      if(right(i)<n) printf("right key = %d, ",arr[right(i)]);
      printf("\n");
    }

}
int parent(int i)
{
  return (i+1)/2-1;
}
int left(int i)
{
  return 2*(i+1)-1;
}
int right(int i)
{
  return (2*(i+1)+1)-1;
}


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

int main() {
  int n; 
  cin >> n;
  vector<int> h(n);
  for(int i = 0; i < n; i++) cin >> h.at(i);
  
  bool ok = true;
  int now = h.at(0) - 1;
  for(int i = 1; i < n; i++){
    if(h.at(i) < now) ok = false;
    now = max(now, h.at(i) - 1);
  }
  
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(int argc, char const* argv[])
{
	int n;

	cin >> n;

	int money = 100000;
	for( int i = 0;i < n;i++ ){
		money *= 1.05;
		int hoge = 1000 - money % 1000;
		money += ( hoge != 1000 ) ? hoge : 0;
	}
	cout << money << endl;
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
using si = int;

int main(){

	si n;
	std::cin >> n;

	std::vector<si>tab(n,0);

	for( si i{ 0 }; i < n-1; ++i )
	{
		si x;
		std::cin >> x;
		++tab[x-1];
	}

	for( si i{}; i<n; ++i )
		std::cout << tab[i] << "\n";

	return 0;
}

Measured memory_bytes: 3616
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=200000,maxt=maxn<<2,MOD=998244353,INV9=443664157;

int n,te,pw[maxn+5],INV[10];
int l[maxt+5],r[maxt+5],val[maxt+5],tag[maxt+5];

#define EOLN(x) ((x)==10 || (x)==13 || (x)==EOF)
inline char readc(){
	static char buf[100000],*l=buf,*r=buf;
	return l==r && (r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<typename T> int readi(T &x){
	T tot=0;char ch=readc(),lst='+';
	while (!isdigit(ch)) {if (ch==EOF) return EOF;lst=ch;ch=readc();}
	while (isdigit(ch)) tot=(tot<<1)+(tot<<3)+(ch^48),ch=readc();
	lst=='-'?x=-tot:x=tot;return EOLN(ch);
}
void Pushup(int p) {val[p]=((LL)val[p<<1]*pw[(r[p]-l[p]+1)>>1]%MOD+val[p<<1|1])%MOD;}
void Build(int L,int R,int p=1){
	l[p]=L;r[p]=R;if (L==R) {val[p]=1;return;} int mid=L+(R-L>>1);
	Build(L,mid,p<<1);Build(mid+1,R,p<<1|1);Pushup(p);
}
void Addtag(int p,int K) {val[p]=(LL)(pw[r[p]-l[p]+1]-1)*INV9%MOD*K%MOD;tag[p]=K;}
void Pushdown(int p) {if (tag[p]) Addtag(p<<1,tag[p]),Addtag(p<<1|1,tag[p]),tag[p]=0;}
void Insert(int L,int R,int K,int p=1){
	if (L==l[p] && r[p]==R) return Addtag(p,K);
	Pushdown(p);int mid=l[p]+(r[p]-l[p]>>1);
	if (R<=mid) Insert(L,R,K,p<<1); else if (L>mid) Insert(L,R,K,p<<1|1);
	else Insert(L,mid,K,p<<1),Insert(mid+1,R,K,p<<1|1);
	Pushup(p);
}
int main(){
	readi(n);pw[0]=1;for (int i=1;i<=n;i++) pw[i]=(LL)pw[i-1]*10%MOD;Build(1,n);
	for (readi(te);te;te--){
		int L,R,K;readi(L);readi(R);readi(K);
		Insert(L,R,K);printf("%d\n",val[1]);
	}
	return 0;
}

Measured memory_bytes: 11416
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,i,k,cnt;
string s,a,b;
int main(){
  cin>>s;
  if(s.size()%2==0)s=s.substr(0,s.size()-2);
  else s=s.substr(0,s.size()-1);
  for(;;s=s.substr(0,s.size()-2),i++){
    a=s.substr(0,s.size()/2);
    b=s.substr(s.size()/2,s.size()/2);
    if(a.compare(b)==0)break;
  }
  cout<<s.size()<<endl;
}

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

int main(){
  string s;
  string t;
  cin >> s >> t;
  for(int i=0; i<s.size(); i++){
    if(s[i] != t[i]){
      cout << "No" << endl;
      return 0;
    }
    if(i+1 == s.size()){
      cout << "Yes" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3616
n = list(input())
n.insert(0, 0)
if n.count("U") + n.count("D") == len(n):
    print("Yes")
else:
    count_l = 0
    count_r = 0
    for i in range(1, len(n)):
        if i % 2 == 0:
            if n[i] == 'R':
                count_r += 1
        if i % 2 != 0:
            if n[i] == 'L':
                count_l += 1
    print("No") if count_r > 0 or count_l > 0 else print("Yes")



Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
  double max,min,input;
  scanf("%lf",&input);
  min=input;max=input;

  while(scanf("%lf",&input)!=EOF){
    if(max<input)max=input;
    else if(input<min)min=input;
  }
  printf("%lf\n",max-min);
  return 0;
}

Measured memory_bytes: 648
import java.util.*;

public class Main {

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

        String s = sc.next();
        int q = sc.nextInt();

        StringBuilder sbL = new StringBuilder();
        StringBuilder sbR = new StringBuilder();

        boolean flag = false;

        int cnt = 0;

        for (int i=0; i<q; i++){
            int tmp = sc.nextInt();
            if (tmp==1){
                cnt++;
                flag = !flag;
            }else if (tmp==2){
                int tmpI = sc.nextInt();
                String tmpS = sc.next();
                if (tmpI==1){
                    if (flag){
                        sbR.append(tmpS);
                    }else {
                        sbL.append(tmpS);
                    }
                }else if (tmpI==2){
                    if (flag){
                        sbL.append(tmpS);
                    }else {
                        sbR.append(tmpS);
                    }
                }
            }
        }

        if (cnt%2==0){
            System.out.print(sbL.reverse().append(s).append(sbR).toString());
        }else {
            StringBuffer str = new StringBuffer(s);
            s = str.reverse().toString();
            System.out.print(sbR.reverse().append(s).append(sbL).toString());
        }

    }

}



Measured memory_bytes: 121520
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        new Main().start();
    }

    void start() throws Exception {
        start(new Scanner(System.in));
    }

    boolean isMatch(String sd, String t, int offset) {
        for (int i = offset; i < offset + t.length(); ++i) {
            char c = sd.charAt(i);
            if (c != '?') {
                if (c != t.charAt(i - offset)) return false;
            }
        }
        return true;
    }

    void start(Scanner sc) throws Exception{
        String sd = sc.next();
        String t = sc.next();
        List<String> candidates = new ArrayList<>();

        if (sd.length() < t.length()) {
            System.out.println("UNRESTORABLE");
        }
        else {
            for (int offset = 0; offset <= (sd.length() - t.length()); ++offset) {
                if (isMatch(sd, t, offset)) {
                    candidates.add((sd.substring(0, offset) + t + sd.substring(offset + t.length())).replace('?', 'a'));
                }
            }
            Collections.sort(candidates);
            if (candidates.isEmpty())
                System.out.println("UNRESTORABLE");
            else
                System.out.println(candidates.get(0));
        }
    }
}

Measured memory_bytes: 22740
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int ps[10][10];

int main() {
	int n,d;
	cin >> n>>d;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < d; j++) {
			cin >> ps[i][j];
		}
	}
	int ans = 0;
	for(int i = 0; i < n; i++) {
		for(int j = i+1; j < n; j++) {
			int sm = 0;
			for(int k = 0; k < d; k++) {
				int temp = ps[i][k]-ps[j][k];
				sm += temp*temp;
			}
			for(int k = 0; k*k <= sm; k++) {
				if(sm==k*k) ans++;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N, K = LI()

k = list(range(N+1))
ans = 1
l = sum(k[0:K-1])
r = sum(k[N-K+2:])
# print(l,r)
for i in range(K-1, N):
    l += k[i]
    r += k[N-i]
    
    if  r-l < 0:
        break
    # print(l,r)
    ans = (ans + (r-l) + 1) % MOD

print(ans)

Measured memory_bytes: 72632
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 8/21/2018
 
 15:25-15:27 analysis
 16:10 give up
 
 17:20- read editorials and add solution
 
 I've never come up with dp. Also I couldn't make formula of number of '?' and 'c' separately. sigh 😞
 The reason that I could not make formula is that handling '?' and 'c' are mixed.
 
 Editorials:
  - https://img.atcoder.jp/abc104/editorial.pdf
 
 Summary:
  - I tried to solve by cumulative sum. However it was waste of time 😡😡😡😡😡😡😡😡😡😡
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
const int MAX_N=1e5+1;
int N;
string S;
LL A[MAX_N],C[MAX_N],Q[MAX_N];
LL P3[MAX_N];
const LL MOD=1e9+7;
void solve() {
  ZERO(A),ZERO(C),ZERO(Q);
  P3[0]=1;
  REP(i,N) P3[i+1]=P3[i]*3LL%MOD;
  REP(i,N) {
    A[i+1]=A[i]+(S[i]=='A');
    C[i+1]=C[i]+(S[i]=='C');
    Q[i+1]=Q[i]+(S[i]=='?');
  }
  LL res=0;
  FOR(i,1,N-1) if(S[i]=='B'||S[i]=='?') {
    LL a=A[i]*P3[Q[i]]%MOD;
    if(Q[i]>0)a=(a+Q[i]*P3[Q[i]-1]%MOD)%MOD;
    LL q=Q[N]-Q[i+1];
    LL c=(C[N]-C[i+1])*P3[q]%MOD;
    if(q>0) c=(c+q*P3[q-1]%MOD)%MOD;
//    dump3(i,C[N]-C[i+1],q);
//    dump3(i,a,c);
    (res+=a*c%MOD)%=MOD;
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>S;
  N=SZ(S);
  solve();
  return 0;
}


Measured memory_bytes: 3648
# -*- coding: utf-8 -*-
import math
from operator import mul
from functools import reduce
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = S()
sum_ = 0
for n in N:
    sum_ += int(n)
if (sum_ % 9 == 0):
    print('Yes')
else:
    print('No')


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

int main(){
  while(1){
    int n,m;
    cin>>n>>m;
    if(n==0&& m==0) break;
    int a[1000];
    lp(i,n){
      cin>>a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    int ans=0;
    lp(i,n){
      if((i+1)%m==0) continue;
      else ans+=a[i];
    }
    cout<<ans<<endl;
  }
  return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end



int main(){
    int a,b,c; scanf("%d%d%d",&a,&b,&c);
    printf(a+b+c<=21?"win":"bust");
    return 0;
}

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

const int INF = 1e9;

int main() {
  long long n,m;
  cin>>n>>m;

  if (n>1&&m>1){
    cout<<(n-2)*(m-2)<<endl;
    return 0;
  }
  if(n==1&&m==1){
    cout<<1<<endl;
    return 0;
  }
  if (n==1){
    cout<<m-2<<endl;
    return 0;
  }
  if (m==1){
    cout<<n-2<<endl;
    return 0;
  }
}

Measured memory_bytes: 256
#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define ran(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(13);
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
	do {\
		std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
		debug_impl(__VA_ARGS__);\
		std::cerr << std::noboolalpha;\
	} while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
	{ for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
	for (auto it = v.begin(); it != v.end(); it++)
		{os << (it != v.begin() ? "," : "") << *it;}
	return os << "}";
}

int main() {
	std::cin.tie(0); std::cin.sync_with_stdio(false);
	int n; std::cin >> n;
	std::vector<lint> a(n); std::cin>>a;

	auto solve = [&] (auto&& a) {
		auto pivot = [&] {
			int ans = 0;
			lint val = a.at(0);
			if (val < 0) val = -val;
			rep(i,1,n) {
				lint x = a.at(i);
				if (x < 0) x = -x;
				if (val < x) {
					ans = i;
					val = x;
				}
			}
			return ans;
		}();
		debug(pivot);

		int sign = a.at(pivot) < 0 ? -1 : 1;

		std::vector<std::pair<int,int>> ans;
		auto move = [&] (int i, int j) {
			a.at(j) += a.at(i);
			ans.emplace_back(i,j);
		};
		rep(i,0,n) {
			if (i == pivot) continue;
			move(pivot,i);
			debug(a);
		}
		if (0 < sign) {
			rep(i,0,n-1) {
				move(i,i+1);
				debug(a);
			}
		} else {
			for (int i = n - 2; i >= 0; i--) {
				move(i+1, i);
				debug(a);
			}
		}

		assert(std::is_sorted(all(a)));
		assert((int)ans.size() <= 2 * n);
		return ans;
	};

	auto ans = solve(a);
	std::cout << ans.size() << std::endl;
	for (auto&& pair : ans) {
		int i,j; std::tie(i,j) = pair;
		i++,j++;
		std::cout << i << " " << j << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx,avx2")
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define pb push_back
#define X first
#define Y second
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
const ll INF = 1e18+1;
const ll MOD = 1000000007L;
#ifdef umang99m
    #include "/home/umang/Desktop/folder/home/.templates/header.h"
#else
    #define dbg(args...)
    #define timer()
#endif
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    ll n,k;
    cin>>n>>k;
    vi w(n+1), v(n+1);
    repA(i,1,n) cin>>w[i]>>v[i];
    ll vsum=0;
    rep(i,n) vsum+=v[i+1];


    ll dp[n+1][vsum+1];
    repA(i,1,vsum) dp[0][i] = INF;
    rep(i,n+1) dp[i][0] = 0;
    repA(i,1,n){
        repA(j,0,vsum){
            dp[i][j] = dp[i-1][j];
            if(j >= v[i]) dp[i][j] = min(dp[i][j] , dp[i-1][j-v[i]] + w[i]);
        }
    }
    
    for(int i=vsum; i>=0; i--){
        if(dp[n][i] <= k) {
            cout<<i<<endl;
            break;
        }
    }

    timer();
    return 0;
}

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

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

    vector<int> B(M);
    for(int i=0; i<M; i++){
        cin >> B.at(i);
    }

    vector<vector<int>> A(N, vector<int>(M));
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            cin >> A.at(i).at(j);
        }
    }

    int ans=0;
    for(int i=0; i<N; i++){
        int fi = C;
        for(int j=0; j<M; j++){
            fi += A.at(i).at(j) * B.at(j);
        }
        if(fi > 0){
            ans ++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

void merge(int *,int ,int,int);
void mergeSort(int *,int,int);

int num=0;

int main(){
  int *A;
  int n;
  int i;

  scanf("%d",&n);
  A=(int *)malloc(n*sizeof(int));
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  mergeSort(A,0,n);
  for(i=0;i<n-1;i++)printf("%d ",A[i]);
  printf("%d\n",A[i]);
  printf("%d\n",num);
  
  return 0;
}

void merge(int *A,int left,int mid,int right){
  int n1,n2;
  int *L;
  int *R;
  int i,j,k;
  n1=mid-left;
  n2=right-mid;
  L=(int *)malloc((n1+1)*sizeof(int));
  R=(int *)malloc((n2+1)*sizeof(int));
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];
  L[n1]=1000000001;
  R[n2]=1000000001;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
    }
    else{
      A[k]=R[j];
      j++;
    }
    num++;
  }
  free(L);
  free(R);
}
void mergeSort(int *A,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}



Measured memory_bytes: 5472
N = int(input())
eat_list = list(map(int, input().split()))
manzok_list = list(map(int, input().split()))
add_manzok_list = list(map(int, input().split()))

manzok = 0

for i in range(N):
 manzok += manzok_list[eat_list[i]-1]
 if(i > 0 and (eat_list[i] - eat_list[i-1]) == 1):
   manzok += add_manzok_list[eat_list[i-1]-1]

print(manzok)

Measured memory_bytes: 3064
#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>;


int main (){
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  sort(l.begin(), l.end());
  int ans = 0;
  for (int i = 0; i < n; i++){
    for (int j = i+1; j < n; j++){
      for (int k = j+1; k < n; k++){
        if(l[i] == l[j] || l[j] == l[k]) continue;
        if(l[i] + l[j] > l[k]) ans++;
          /*
          cout << "i:" << i << "j:" << j 
          << "k:" << k << ", i+j=" << l[i] + l[j] 
          <<", k=" << l[k] << endl;
          */
      }
    }
  }
  
  cout << ans << endl; 
  return 0;
}

Measured memory_bytes: 3628
/*
	  Author : @evenbao
	  Created : 2020 / 07 / 12
*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

#define pii pair<int , int>
#define mp make_pair
#define fi first
#define se second

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

const int N = 1000 + 10;
const int mod = (int) 1e9 + 7;

int n , K;
int a[N] , binom[N][N] , dp[N][N];

inline void inc(int &x , int y) { x = x + y < mod ? x + y : x + y - mod; }
inline void dec(int &x , int y) { x = x - y >= 0 ? x - y : x - y + mod; }
inline int quickpow(int a , int n) {
		int b = a , res = 1;
		for (; n >>= 1; a = (LL) a * a % mod)
				if (n & 1) res = (LL) res * a % mod;
		return res;
} 

int main() {
		
		read(n); read(K);
		for (int i = 1; i <= K; ++i) read(a[i]);
		for (int i = 0; i <= n; ++i) {	
				binom[i][0] = binom[i][i] = 1;
				for (int j = 1; j < i; ++j)
						binom[i][j] = (binom[i - 1][j] + binom[i - 1][j - 1]) % mod;
		}		
		dp[0][0] = 1;
		for (int i = 1; i <= K; ++i)
		for (int j = 0; j <= n; ++j)
		for (int k = 0; k <= j; ++k)
				if (a[i] >= j - k)
						inc(dp[i][j] , (LL) dp[i - 1][k] * binom[n - k][j - k] % mod * binom[n - j + k][a[i] - j + k] % mod);
		printf("%d\n" , dp[K][n]);
	  return 0;
}


Measured memory_bytes: 7692
#include <cstdio>
#include <cctype>
#include <utility>
#include <string>
#include <vector>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
inline bool scan(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
void scan(string &s) {for (char c; !isspace(c = gcu()); s += c);}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

int main() {
	int n = in();
	while (n--) {
		int OUT = 0, score = 0, runner = 0;
		while (OUT < 3) {
			string s;
			scan(s);
			switch (s[1]) {
			case 'I' :
				runner++;
				if (runner == 4) {
					score++;
					runner = 3;
				}
				break;
			case 'O' :
				score += runner + 1;
				runner = 0;
				break;
			default :
				OUT++;
			}
		}
		out(score, '\n');
	}
}


Measured memory_bytes: 2640
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int c;
  if(b < 10) c = a * 10 + b;
  else if(b < 100) c = a * 100 + b;
  else c = a * 1000 + b;
  for(int i = 1; i < 400; i++) {
    if(i * i == c) {
      cout << "Yes" << endl;
      break;
    }
    if(i == 399) {
      cout << "No" << endl;
    }
  }
}

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

typedef pair<int, int> P;

int main() {
    int w, a, b;
    cin >> w >> a >> b;
    int ans = INT_MAX;
    
    if (
        ((a <= b) && ((a + w) >= b)) ||
        ((a <= (b + w)) && ((a + w) >= (b + w)))
    ) {
        cout << 0 << endl;
        return 0;
    }
    
    ans = min(ans, abs((a + w) - b));
    ans = min(ans, abs(a - (b + w)));
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))
ans=sum(b)
for i in range(n-1):
    if a[i]+1 == a[i+1]:
        ans+=c[a[i]-1]
print(ans)

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

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

    for(int i = 0; i < n; i++){
        int b,c;
        cin >> b >> c;
        a[i] = make_pair(b,c);        
    }

    int cnt = 0;
    int sum = 0;
    for(int i = n - 1; 0 <= i; i--){
        if((a[i].first + cnt) % a[i].second != 0)
        cnt += a[i].second - ((a[i].first + cnt) % a[i].second);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int n, k;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    vector<int> a(n), cs(n + 1);
    cs[0] = 0;
    rep(i, 0, n){
        cin >> a[i];
        cs[i + 1] = cs[i] + a[i];
    }
    if(k == 1){
        cout << 0 << endl;
        return 0;
    }
    rep(i, 1, n + 1){
        cs[i] = (cs[i] - i % k + k) % k; 
        // cout << cs[i] << " ";
    }
    // cout << endl;
    int ans = 0;
    map<int, int> mp;
    mp[0] = 1;
    rep(i, 0, n){
        int tmp = mp[cs[i + 1]];
        ans += tmp;
        // cout << i << " " << tmp << endl;
        mp[cs[i + 1]]++;
        if(i + 2 - k >= 0) mp[cs[i + 2 - k]]--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	int c[4]={0,0,0,0};
	string s;
	for(int i=1;i<=n;i++){
			cin>>s;
			if(s=="AC")c[0]++;
			if(s=="WA")c[1]++;
			if(s=="TLE")c[2]++;
			if(s=="RE")c[3]++;
		}	
	cout<<"AC"<<" x "<<c[0]<<endl;
	cout<<"WA"<<" x "<<c[1]<<endl;
	cout<<"TLE"<<" x "<<c[2]<<endl;
	cout<<"RE"<<" x "<<c[3]<<endl;	
	return 0;
	} 


Measured memory_bytes: 3640
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk

using namespace std;

inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    /*int n, m;
    cin >> n >> m;
    if (m % 2 != 0) {
        cout << -1 << "\n";
        return 0;
    }
    rep(i, 0, m) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        if (u > v) {
            swap(u, v);
        }
        c[u] ^= 1;
        ans.insert({u, v});
    }
    dfs(0, -1);*/

    int n;
    cin >> n;
    if ((n & (n - 1)) == 0) {
        cout << "No\n";
        return 0;
    }
    cout << "Yes\n";
    bool need = false;
    int M = n;
    if (n % 2 == 0) {
        need = true;
        n--;
    }
    for (int i = 2; i <= n; i += 2) {
        if (i == 2) {
            cout << M + 1 << " " << i << "\n";
        }
        cout << i << " " << i + 1 << "\n";
        cout << i + 1 << " " << 1 << "\n";
        cout << 1 << " " << M + i << "\n";
        cout << M + i << " " << M + i + 1 << "\n";
    }
    if (need) {
        n++;
        int x = 1;
        while (x * 2 <= n) {
            x *= 2;
        }
        cout << n + n << " " << n + x << "\n";
        cout << n << " " << (n ^ x ^ 1) << "\n";
    }
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<ll, ll> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}


 
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	const ll mod = 1e9 + 7;
	int n;
	cin >> n;

	vector<ll> none(n + 1), both(n + 1), zero(n + 1), nine(n + 1);
	
	none[1] = 8;
	both[1] = 0;
	zero[1] = 1;
	nine[1] = 1;

	for(int i = 2; i <= n; i++){
		//add 1-8
		none[i] = (none[i - 1] * 8ll) % mod;
		nine[i] = (nine[i - 1] * 8ll) % mod;
		zero[i] = (zero[i - 1] * 8ll) % mod;
		both[i] = (both[i - 1] * 8ll) % mod;

		//add 0
		zero[i] = (zero[i] + zero[i - 1] + none[i - 1]) % mod;
		both[i] = (both[i] + both[i - 1] + nine[i - 1]) % mod;

		//add 9
		nine[i] = (nine[i] + nine[i - 1] + none[i - 1]) % mod;
		both[i] = (both[i] + both[i - 1] + zero[i - 1]) % mod;
	}
	
	cout << both[n] << endl;

	return 0;
}


Measured memory_bytes: 34524
#include <iostream>
#include <vector>
#include <array>

int main()
{
    std::vector<std::array<int, 4>> moves;
    int h, w;
    std::cin >> h >> w;
    std::vector<std::vector<int>> board;
    for (int i = 0; i < h; i++) {
        std::vector<int> row;
        std::vector<bool> row_used;
        for (int j = 0; j < w; j++) {
            int p;
            std::cin >> p;
            row.emplace_back(p % 2);
        }
        board.emplace_back(row);
    }

    // $B>e$+$i96$a$k(B
    for (int i = 0; i < h - 1; i++) {
        for (int j = 0; j < w; j++) {
            if (board.at(i).at(j) == 1) {
                moves.emplace_back(std::array<int, 4>({i + 1, j + 1, i + 2, j + 1}));
                board.at(i).at(j) = 0;
                board.at(i + 1).at(j) = (board.at(i + 1).at(j) + 1) % 2;
            }
        }
    }
    // $B:G=*CJ$r:8$+$i96$a$k(B
    int buf;
    bool rest = false; // 1$B$,M>$C$F$$$k$+(B
    for (int j = 0; j < w; j++) {
        if (board.at(h - 1).at(j) == 1) {
            if (rest) {
                for (int k = buf; k < j; k++) {
                    moves.emplace_back(std::array<int, 4>({h, k + 1, h, k + 2}));
                    board.at(h - 1).at(k) = 0;
                }
                board.at(h - 1).at(j) = 0;
                buf = -1; // error check
                rest = false;
            } else {
                buf = j;
                rest = true;
            }
        }
    }
    std::cout << moves.size() << std::endl;
    for (const auto& move : moves) {
        std::cout << move[0] << " " << move[1] << " " << move[2] << " " << move[3] << std::endl;
    }
    return 0;
}

Measured memory_bytes: 5232
#include <iostream>

using namespace std;

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

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

	return 0;
}

Measured memory_bytes: 1160
S = input()
T = input()
S_a, S_b = [0], [0]
T_a, T_b = [0], [0]

for s in S:
    if s == "A":
        S_a.append(S_a[-1] + 1)
        S_b.append(S_b[-1])
    if s == "B":
        S_a.append(S_a[-1])
        S_b.append(S_b[-1] + 1)

for t in T:
    if t == "A":
        T_a.append(T_a[-1] + 1)
        T_b.append(T_b[-1])
    if t == "B":
        T_a.append(T_a[-1])
        T_b.append(T_b[-1] + 1)


def calc(na, nb):
    if na > nb:
        diff = na- nb
        if diff % 3 == 0:
            return ""
        elif (diff % 3) % 2 == 0:
            return "B"
        else:
            return "A"
    else:
        diff = nb - na
        if diff % 3 == 0:
            return ""
        elif (diff % 3) % 2 == 0:
            return "A"
        else:
            return "B"


Q = int(input())
for q in range(Q):
    a, b, c, d = map(int, input().split())
    sa = S_a[b] - S_a[a - 1]
    sb = S_b[b] - S_b[a - 1]
    ta = T_a[d] - T_a[c - 1]
    tb = T_b[d] - T_b[c - 1]

    SQ = calc(sa, sb)
    TQ = calc(ta, tb)

    print("YES" if SQ == TQ else "NO")


Measured memory_bytes: 13132
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String str = sc.next();
		String[] ar = str.split("");
		List<String> list=Arrays.asList(ar);
		boolean flg = false;
		
//		for(int i=0; i<list.size()-1; i++){
//			System.out.println("true");
//			String tmp = list.get(i);
//			list.remove(i);
//			flg = list.contains(tmp);
//			if(flg){
//				break;
//			}
//		}
//		
		
		
		
		
		for(int i=0; i<ar.length; i++){
			for (int j=i+1; j<ar.length; j++){
//				System.out.println("ar["+i+"]="+ar[i]);
//				System.out.println("ar["+j+"]="+ar[j]);
				if(ar[i].equals(ar[j])){
//					System.out.println("true");
					flg = true;
					break;
				}
			}
		}
		
		if(flg){
			System.out.println("no");
		}
		else {
			System.out.println("yes");
		}
		
		
	}

}


Measured memory_bytes: 21844