akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
#define int long long int
#define double long double
using namespace std;
#define INT_MAX 1000000005
#define INF 1000000005
const int MAX_N = 1 << 17;
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

signed main()
{
int h,w;
std::cin >> h >> w;
std::vector<std::vector<char>> map;
std::vector<std::vector<int>> check;
int wsum = 0;
for(int i = 0; i < h; i++){
   std::vector<char> tempm; 
   std::vector<int> tempc;
   for(int j = 0; j < w; j++){
       char temp;
       std::cin >> temp;
       if(temp == '.'){
           wsum++;
       }
       tempm.push_back(temp);
       tempc.push_back(INF);
   }
   map.push_back(tempm);
   check.push_back(tempc);
}

std::queue<pair<int,int>> tr;
pair<int,int> start = make_pair(0,0);
tr.push(start);
check[0][0] = 0;
while(!tr.empty()){
    pair<int,int> now = tr.front();
    tr.pop();
    if(now.first + 1 >= h){
    } else if(map[now.first + 1][now.second] == '#'){
    } else {
        if(check[now.first+1][now.second] > check[now.first][now.second] + 1){
           check[now.first+1][now.second] = check[now.first][now.second] + 1;
           pair<int,int> down = make_pair(now.first + 1,now.second);
           tr.push(down);
        }
    }
    if(now.first - 1 < 0){
    } else if(map[now.first - 1][now.second] == '#'){
    } else {
        if(check[now.first-1][now.second] > check[now.first][now.second] + 1){
           check[now.first-1][now.second] = check[now.first][now.second] + 1;
           pair<int,int> up = make_pair(now.first - 1,now.second);
           tr.push(up);
        }
    }
    if(now.second + 1 >= w){
    } else if(map[now.first][now.second + 1] == '#'){
    } else {
        if(check[now.first][now.second + 1] > check[now.first][now.second] + 1){
           check[now.first][now.second + 1] = check[now.first][now.second] + 1;
           pair<int,int> right = make_pair(now.first,now.second + 1);
           tr.push(right);
        }
    }
    if(now.second - 1 < 0){
    } else if(map[now.first][now.second - 1] == '#'){
    } else {
        if(check[now.first][now.second - 1] > check[now.first][now.second] + 1){
           check[now.first][now.second - 1] = check[now.first][now.second] + 1;
           pair<int,int> left = make_pair(now.first,now.second - 1);
           tr.push(left);
        }
    }
}
if(wsum - check[h - 1][w - 1] - 1 < 0){
    std::cout << -1 << std::endl;
} else {
    std::cout << wsum - check[h - 1][w - 1] - 1 << std::endl;
}


return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <cmath>
#include <iostream>
#include <cstdio>
using namespace std;

const double EPS = 1e-8;
typedef vector<double> vec;
typedef vector<vec> mat;

//Ax = b を解く
//O(n^3)
vec gauss_jordan(const mat &A, const vec &b){
  int n = A.size();
  mat B(n, vec(n+1));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      B[i][j] = A[i][j];
  for(int i=0;i<n;i++) B[i][n] = b[i];

  for(int i=0;i<n;i++){
    int pivot = i;
    for(int j=i+1;j<n;j++) if(fabs(B[j][i]) > fabs(B[pivot][i])) pivot = j;
    swap(B[i],B[pivot]);

    //解がないか、あっても一意ではない。
    if(fabs(B[i][i]) < EPS) return vec();
    
    for(int j=i+1;j<=n;j++) B[i][j] /= B[i][i];
    for(int j=0;j<n;j++)
      if(i != j)
	for(int k=i+1;k<=n;k++)
	  B[j][k] -= B[j][i] * B[i][k];
  }
  vec x(n);
  for(int i=0;i<n;i++) x[i] = B[i][n];
  return x;
}

int main(){
  mat A(2,vec(2));
  vec b(2);
  while(cin >> A[0][0] >> A[0][1]){
    cin >> b[0];
    for(int i=0;i<2;i++) cin >> A[1][i];
    cin >> b[1];
    vec ans = gauss_jordan(A, b);
    printf("%.3f %.3f\n",ans[0],ans[1]);
  }
}

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

#define endl '\n'
#define ll long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
const db pi = acos(-1);
const long long infl = LLONG_MAX;

#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

	ll c[10][10];
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll i,x,j=0,y,z=0,k,n;
	cin>>n;
	vector<ll>v;
	string s,t;
	rep(i,1,n+1,1){
		s=to_string(i);
		y=s.size();
		c[s[0]-'0'][s[y-1]-'0']++;		
	}
		// ce(j)
		// cout<<'z';
		
	rep(i,0,10,1){
		rep(j,0,10,1){
			z+=c[i][j]*c[j][i];
		}
	}
	ce(z)
	// for(auto zx:v)	cout<<zx<<" ";
}
/*

56 

65
56

*/


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>

using namespace std;

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	if (A* N < B) cout << A * N << endl;
	else cout << B << endl;;
	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()


def main():
    n, a, b = map(int, input().split())
    ans = 0
    for i in range(1, n + 1):
        s = str(i)
        val = 0
        for c in s:
            val += int(c)
        if a <= val <= b:
            ans += i
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 70660
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    vector<string>  blue(n);
    for (int i = 0; i < n; i++) {
        cin >> blue.at(i);
    }
    int m;
    cin >> m;
    vector<string> red(m);
    for (int i = 0; i < m; i++) {
        cin >> red.at(i);
    }
  	int counta = 0;
  	for (int i = 0; i < n; i++) {
      int countb = 0;
      for (int j = 0; j < n; j++) {
        if (blue.at(i)==blue.at(j))
          countb++;
      }
        for (int k = 0; k < m; k++) {
          if (blue.at(i)==red.at(k))
            countb--;
        }
      if (counta < countb)
        counta=countb;
    }
  	if (counta>0)
      cout << counta <<endl;
    else cout << 0 << endl;
}
      

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    int N;
    int M;
    cin>>N>>M;


int arr[N];
    double totalsum=0;
    for(int i=0;i<N;++i){
        cin>>arr[i];
        totalsum+=arr[i];
    }
  
  int count=0;
     for(int i=0;i<N;i++){
      if( (totalsum/(4*M))<=arr[i])
        count++;
    }

    if(count >= M)
    cout<<"Yes";
    else 
    cout<<"No";

}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double A,B,H,M;
  cin >> A >> B >> H >> M;
  double pi = 3.14159265358979323846264338327950288419716939937510;
  //min 2 * pi * M / 60 rad.
  //ex-hour Hex := H + (M / 60)
  //ex-hour 2 * pi * Hex / 60 rad. 
  H += M / 60;
  cout << fixed << setprecision(20);
  cout << sqrt(A * A + B * B - 2 * A * B * cos( abs( 2 * pi * ( H / 12 - M / 60 ) ) ) ); 
}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






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







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n,k,count,ans=0;
  cin>>n>>k;
  vector<int> v(n);
  rep(i,n){
    int a;
    cin>>a;
    v[a-1]++;
  }
  rep(i,n){
    if(v[i]==0){
      v[i]=200001;
    }else{
      count++;
    }
  }
  sort(v.begin(),v.end());
  if(count<=k){
    cout<<0<<endl;
  }else{
    for(int i=0;i<count-k;i++){
      ans+=v[i];
    }
    cout<<ans<<endl;
  }
  
  
  
}
///////////////////////////

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
bool red[101010];
int main() {
  int N,M;
  cin >> N >> M;
  int box[N];
  for (int i = 0; i < N; i++) box[i] = 1;
  red[0] = true;
  
  for (int i = 0; i < M; i++) {
    int x,y;
    cin >> x >> y;
    x--; y--;
    if (red[x]) {
      red[y] = true;
    }
    box[x]--;
    box[y]++;
    if (box[x] == 0) {
      red[x] = false;
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (red[i]) ans++;
  } 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4040
def main():
    N = int(input())
    #a,b,c = map(int, input().split())
    #S = input()
    if N % 1000 == 0:
        return 0
    return(1000 - (N % 1000))
print(main())
#if main():
#    print('Yes')
#else:
#    print('No')


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

int main(){
    string S,T,U;
    int A,B;
    cin >> S >> T >> A >> B >> U;
    
    if(S == U){
        A--;
    }
    if(T == U){
        B--;
    }
    cout << A << " " << B;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
string s[2];
const long long MOD=1000000007LL;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>s[0]>>s[1];
	long long res=1;
	int back=0;
	for(int i=0;i<n;i++){
		if(s[0][i]==s[1][i]){
			if(back==0){
				res*=3LL;
			}
			else if(back==1){
				res*=2LL;
			}
			else{
				res*=1LL;
			}
			back=1;
		}
		else{
			if(back==0){
				res*=6LL;
			}
			else if(back==1){
				res*=2LL;
			}
			else{
				res*=3LL;
			}
			back=2;
			i++;
		}
	}
	cout<<res%MOD<<endl;
	return 0;
}
/*
52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn
*/

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

rank = [0]*9

for i in range(N):
    if a[i] < 400:
        rank[0] += 1
    elif a[i] < 800:
        rank[1] += 1
    elif a[i] < 1200:
        rank[2] += 1
    elif a[i] < 1600:
        rank[3] += 1
    elif a[i] < 2000:
        rank[4] += 1
    elif a[i] < 2400:
        rank[5] += 1
    elif a[i] < 2800:
        rank[6] += 1
    elif a[i] < 3200:
        rank[7] += 1
    else:
        rank[8] += 1

sum = 0

for i in range(8):
    if rank[i] > 0:
        sum += 1

min = sum
max = sum + rank[8]

if min == 0:
  min = 1

print(min,max)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n], b[n]; for (int &x : a) cin >> x;
    copy(a, a+n, b);
    sort(b, b+n);
    int ans = 0;
    for (int i = 0; i < n; i++) if ((i - (lower_bound(b, b+n, a[i]) - b)) % 2 != 0) ans++;
    cout << ans/2 << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  string S, T;
  cin >> S >> T;
  
  //hash
  vvi posS(26, vi());
  
  for(int i=0; i<S.size(); i++) {
    posS[S[i]-'a'].push_back(i);
  }
  
  vi oks(26);
  //すべて同じ & 2回目出てこない
  for(int s=0; s<posS.size(); s++) {
    vi &v = posS[s];
    if(v.size() > 0) {
      char c = T[v[0]] - 'a';
      if(oks[c]) {
        fin("No");
        return 0;
      }
      for(int ss = 1; ss < v.size(); ss++) {
        if(T[v[ss]] - 'a' != c) {
          fin("No");
          return 0;
        }
      }
      oks[c] = 1;
    }
  }
  fin("Yes");
}

Measured memory_bytes: 1812
#include <bits/stdc++.h>
using namespace std;
 
int main()
  {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
    #endif

  map<int, int> mt;
  int n;
  cin >> n;
  int a;
  mt[0] = 0;
  for (int i = 1; i < n; i++)
    mt[i] = 0;


  for (int i = 1; i < n; i++){
    cin >> a;
    mt[a-1]++;
    // cout << a << " " << mt[a] << endl;
  }
  vector<pair<int,int>> ans;
  for (auto x: mt) {
    ans.push_back({x.first, x.second});
  }

  sort(ans.begin(), ans.end());

  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].second << endl;

  return 0;

}

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


void swap(ll &a , ll &b){
    ll t = a;
    a = b;
    b = t;
}

ll min(ll a, ll b){
    if(a<b)return a;
    return b;
}

ll max(ll a, ll b){
    if(a>b)return a;
    return b;
}
 ll pow(ll a, ll b) {
    a %= mod;
    ll ans = 1;
    while (b > 0) {
        if (b & 1)
            ans = ans * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return ans;
}


int main(){

   //  #ifndef ONLINE_JUDGE
    //    freopen("input.txt", "r", stdin);
   // #endif
    ll n;
cin>>n;
  ll a[n];
    ll flg = 0 ;
  for(int i = 0; i < n;i++){
    cin>>a[i];
    if(a[i]%2 == 0){
        if(a[i]%3!=0 && a[i]%5!=0 ){
            flg =1;
        }
    }
  }

  (flg == 1)?cout<<"DENIED":cout<<"APPROVED ";

}


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

// #define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
const int MOD=1e9+7;
int powmod(int a,int l, int md){a%=md; int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
int invmod(int a, int md){return powmod(a,md-2,md);}
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
typedef vector<int> vi; typedef pair<int, int> ii; typedef vector< ii > vii;
#define pb push_back
int __set(int b, int i) {return b|(1LL<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return (((a%md)*(b%md))%md+md)%md;}
int addmod(int a, int b, int md) {return ((a%md+b%md)%md+md)%md;}
int submod(int a, int b, int md) {return (((a%md-b%md)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
signed main(void)
{
	IOS;
	int n; cin>>n;
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	a--;b--;c--;d--;
	string s; cin>>s;
	int visa[n]={},visb[n]={};
	visa[a]=1; visb[b]=1;
	queue<int> q;
	q.push(a);
	while(!q.empty()) {
		int u=q.front(); q.pop();
		for(int i = 1; i <= 2; i++) {
			if(u+i<n && !visa[u+i] && s[u+i]!='#') {
				visa[u+i]=1;
				q.push(u+i);
			}
		}
	}
	q.push(b);
	while(!q.empty()) {
		int u=q.front(); q.pop();
		for(int i = 1; i <= 2; i++) {
			if(u+i<n && !visb[u+i] && s[u+i]!='#') {
				visb[u+i]=1;
				q.push(u+i);
			}
		}
	}
	if(!visa[c] || !visb[d]) {
		cout<<"No"<<endl;
		return 0;
	}
	if(c<d) {
		cout<<"Yes"<<endl;
	} else {
		for(int i = 0; i<=d; i++) {
			if(visa[i-1] && visb[i] && visa[i+1]) {
				cout<<"Yes"<<endl;
				return 0;
			}
		}
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 2128
# -*- coding: utf-8 -*-
l, r = map(int,input().split()) 

ans = 2018
for i in range(l, min(l + 2019, r)):
    for j in range(i + 1, min(r + 1, i + 2020)):
        if (i * j) % 2019 < ans:
            ans = (i * j) % 2019
print(ans)


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

int main(){
    
    int N,K,minv; cin >> N >> K;
    int data[N];
    for(int i=0;i<N;i++) cin >> data[i];
    sort(data,data+N);
    
    for(int i=0;i<N-K+1;i++){
        if(i == 0){ minv = data[i+K-1] - data[i]; }
        else {if(minv > data[i+K-1] - data[i]){ minv = data[i+K-1] - data[i];}}
    }
    
    cout << minv << endl;
} 

Measured memory_bytes: 3904
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;


int main(){
    int n,m;
    cin >> n >> m;
    vector<ll> A(n);
    rep(i,n) cin >> A[i];
    sort(ALL(A));

    vector< pair<ll, ll>> V(m, make_pair(0LL, 0LL));
    rep(i,m) cin >> V[i].second >> V[i].first;
    sort(ALL(V));
    reverse(ALL(V));

    // rep(i,n) cout << A[i] << " ";cout << endl;
    // rep(i,m) cout << V[i].second << "|" <<V[i].first <<endl;

    auto left = A.begin();
    auto right = A.end();

    ll ans = 0LL;
    rep(i,m){
        auto R = lower_bound(left, right, V[i].first);
        // cout << "R:" << R-A.begin()<< endl;
        R-=1;
        // cout << "left|right " << left - A.begin() << "|" << right-A.begin()  << endl;
        // cout << "R:" << R-A.begin()<< endl;
        if(R-left+1 > V[i].second){
            left = left + V[i].second;
            ans+= V[i].second * V[i].first;
        }
        else{
            // cout << "R-left " <<(R-left+1) << endl;
            ans+= (R-left+1) * V[i].first;
            left = left + (R-left+1);
            // cout << "add "<<(R-left+1)  << endl;
            break;
        }
        // cout << "ans " << ans << endl;
    }
    for(auto iter = left; iter!=right; iter++){
        ans+=*iter;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <array>
#include <algorithm>
#include <tuple>

constexpr int N = 2e5;
std::array<std::pair<int, int>, N> A;
std::array<long long int, N + 1> S; 

int readInt(void){
    char c;
    do{c = getchar_unlocked();} while(c < '0');
    int res = 0;
    do{res = 10 * res + c - '0'; c = getchar_unlocked();} while(c >= '0');
    return res;
}

int main(void){
    int n, d, a; n = readInt(); d = readInt(); a = readInt(); d <<= 1;
    for(int i = 0; i < n; ++i){
        A[i].first = readInt();
        A[i].second = readInt();
    }
    std::sort(A.begin(), A.begin() + n);
    long long int res = 0, dec = 0;
    int r = 0;
    for(int l = 0; l < n; ++l){
        while(r < n and A[r].first - A[l].first <= d) r++;
        dec -= S[l]; A[l].second -= dec;
        if(A[l].second <= 0) continue;
        long long int p = (A[l].second / a) + (!!(A[l].second % a));
        dec += p * a; S[r] += p * a; res += p;
    }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000 + 10;
const int M = 1000000007;
const double PI = atan(1) * 4;
const int oo = 2100000000;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define pb push_back 
#define all(c) (c).begin(),(c).end()
int n,k,l,cmp[2*N],cmp2[2*N];
vvi v,g;
bool vis[2*N];
map<pair<int,int>,int> mp;

void dfs(int u, vector<vector<int> >&v, bool f, int p){
	if(!f)cmp[u]=p;
	else {
		cmp2[u]=p;
		++mp[make_pair(p,cmp[u])];
	}
	vis[u]=true;
	for(int i=0; i<v[u].size(); ++i)
		if(!vis[v[u][i]])
			dfs(v[u][i], v, f, p);
}
int main(){
	cin>>n>>k>>l;
	v.resize(n);
	g.resize(n);
	for(int a,b,i=0; i<k; ++i){
		scanf("%d%d",&a,&b);
		--a;--b;
		v[a].pb(b);
		v[b].pb(a);
	}
	for(int a,b,i=0; i<l; ++i){
		scanf("%d%d",&a,&b);
		--a;--b;
		g[a].pb(b);
		g[b].pb(a);
	}
	for(int i=0; i<n; ++i)
		if(!vis[i])
			dfs(i,v,0,i);
	memset(vis, 0, sizeof(vis));
	for(int i=0; i<n; ++i)
		if(!vis[i])
			dfs(i,g,1,i);
	for(int i=0; i<n; ++i){
		printf("%d",mp[make_pair(cmp2[i],cmp[i])]);
		if(i<n-1)printf(" ");
	}
}




Measured memory_bytes: 28160
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

n = int(input())
c = list(map(lambda x: int(x) - 1, input().split()))

graph = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

ans = [n * (n + 1) // 2] * n
n_subtree = [1] * n  # n_st[i] = (頂点iの部分木の頂点数)
cnt = [0] * n  # cnt[i] = (訪問済み頂点のうち、色iを通過しないとたどり着けない頂点数)
n_visited = 0


def dfs(v, v_p):
    global n_visited
    cnt_v_before = cnt[c[v]]
    for v_next in graph[v]:
        if v_next == v_p:
            continue

        m_prev = n_visited - cnt[c[v]]
        dfs(v_next, v)
        n_subtree[v] += n_subtree[v_next]
        m_next = n_visited - cnt[c[v]]

        m = m_next - m_prev
        ans[c[v]] -= m * (m + 1) // 2

    cnt[c[v]] = cnt_v_before + n_subtree[v]
    n_visited += 1


dfs(0, -1)

for i in range(n):
    m = n - cnt[i]
    ans[i] -= m * (m + 1) // 2

print(*ans, sep='\n')


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

int main(){
  double a,b,h,m;
  const double PI=3.14159265358979;
  cin >> a >> b >> h >> m;
  double hrad = 30*(h+(m/60));
  double mrad = 6*m;
  double length = min(fabs(hrad-mrad),hrad+(360-mrad));
  double ans = (a*a)+(b*b)-2*a*b*cos(length*(PI/180));
 cout << fixed << setprecision(20) << sqrt(ans);
}


Measured memory_bytes: 4196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sf(n) scanf("%lld",&n)
#define sff(n,m) scanf("%lld %lld",&n,&m)
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PLL pair<ll,ll>
#define mod 1000000007
#define mx 200002
#define FILE freopen("input.txt","r",stdin)

ll n;
string s;
ll a[mx];
ll dp[mx][3];

ll F(ll i,ll last)
{
  if(i>=n) return 0;

  if(dp[i][last]!=-1) return dp[i][last];

  ll ret;

  ret = (a[i]!=1)+F(i+1,1);

  if(last!=1){
     ret = min(ret,(a[i]!=0)+F(i+1,0));
  }

  return dp[i][last] = ret;
}

int main()
{
fastio
cin>>n;
cin>>s;

for(ll i = 0;i<n;i++)
{
  if(s[i]=='.') a[i] = 0;
  else a[i] = 1;
}

memset(dp,-1,sizeof dp);

cout<<F(0,2)<<endl;

return 0;
}


Measured memory_bytes: 16148
a,b,c = map(int, raw_input().split())
cnt = 0
l = [(a,b,c)]
while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    cnt += 1
    na = (b+c) / 2
    nb = (a+c) / 2
    nc = (a+b) / 2
    if (na,nb,nc) in l:
        cnt = -1
        break
    else:
        l.append((na,nb,nc))
    a = na
    b = nb
    c = nc
print cnt


Measured memory_bytes: 2568
#include<iostream>
using namespace std;
int main(){
  int n,a,b;
  while(cin>>n,n){
    int asum=0,bsum=0;
    for(int i=0;i<n;i++){
      cin>>a>>b;
      if(a>b)asum+=a+b;
      else if(a<b)bsum+=a+b;
      else {asum+=a; bsum+=a;}
    }
    cout<<asum<<' '<<bsum<<endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

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

char s[2001], t[2001];
int n, m;
int dp[2001][2001][2];

int dfs(int is, int it, bool I) {
	if (dp[is][it][I] != INF) return dp[is][it][I];
	
	int res = 0;
	if (is < m) {
		if (s[is] == 'I' && !I) res = max(res, dfs(is + 1, it, true) + 1);
		if (s[is] == 'O' && I) res = max(res, dfs(is + 1, it, false) + 1);
	}
	
	if (it < n) {
		if (t[it] == 'I' && !I) res = max(res, dfs(is, it + 1, true) + 1);
		if (t[it] == 'O' && I) res = max(res, dfs(is, it + 1, false) + 1);
	}
	
	return dp[is][it][I?1:0] = res;
}

int main() {
	cin >> m >> n;
	cin >> s >> t;
	
	fill(dp[0][0], dp[m + 1][0], INF);
	
	int ans = 0;
	REP(i, m) REP(j, n) {
		int res = dfs(i, j, false);
		ans = max(ans, res - (res + 1) % 2);
	}
	
	cout << ans << endl;
	return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    static char S[200020];

    Scs(S);

    int N = strlen(S);
    int abc = 0;
    int cnt = 0;
    ll ans = 0;
    Rep(i,N){
        if( S[i] == 'A' ){
            if( abc == 1 ) cnt = 0;
            cnt++;
            abc = 0;
        }
        if( S[i] == 'B' ){
            if( abc != 0 ){
                cnt = 0;
            }else{
                abc = 1;
            }
        }
        if( S[i] == 'C' ){
            if( abc == 1 ){
                ans += cnt;
            }else{
                cnt = 0;
            }
                abc = 0;
        }
    }
    printf ("%llu\n", ans );



    return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    rep(i,n-2){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
n = int(input())
L = [int(i) for i in input().split()]
LL = [0 for i in range(pow(10,5)+1)]
 
for i in range(n):
  LL[L[i]] += 1
  
MOD = 998244353
out = 1
maximum = max(L)
for i in range(maximum):
  out = (out * pow(LL[i], LL[i+1], MOD)) % MOD
 
if L[0] != 0 or LL[0] != 1:
  out = 0

for i in range(maximum):
  if L[i+1] == 0:
    out = 0
  
print(out)

Measured memory_bytes: 14396
#author : dokueki

import sys


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    s = input()
    n = len(s)
    if s == s[::-1]:
        if s[0:(n - 1) // 2] == s[0:(n - 1) // 2][::-1] and s[(n + 3) // 2 - 1:] == s[(n + 3) // 2 - 1:][::-1]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")


if __name__ == "__main__":
    #IOE()
    main()


Measured memory_bytes: 38384
import java.util.*;

class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int A = Integer.parseInt(sc.next());
        final int B = Integer.parseInt(sc.next());
        sc.close();

        int ans = 0;
        if (A+B==3) {
            ans = 3;
        } else if (A+B==4) {
            ans = 2;
        } else {
            ans = 1;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
using namespace std;

int n,i,j,k,l,r,u,v,pre,val;
int tmp[200005],T;
int q[200005],p[200005],init[200005];
int col[200005];
vector<int> V[200005];

void fail(){printf("IMPOSSIBLE\n");exit(0);}

int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",&p[i]),++init[p[i]];
	for(i=1;i<=n;++i)if(!init[i])q[++r]=i;
	for(l=1;l<=r;++l)
	{
		u=q[l];
		++T;
		for(i=0;i<V[u].size();++i)tmp[V[u][i]]=T;
		for(i=0;tmp[i]==T;++i);
		col[u]=i;
		V[p[u]].push_back(i);
		if(!(--init[p[u]]))q[++r]=p[u];
	}
	
	for(i=1;i<=n;++i)if(init[i]){u=i;break;}
	
	++T;
	for(i=0;i<V[u].size();++i)tmp[V[u][i]]=T;
	for(k=0;tmp[k]==T;++k);
	pre=val=k;
	for(i=p[u];i!=u;i=p[i])
	{
		++T;
		tmp[pre]=T;
		for(j=0;j<V[i].size();++j)tmp[V[i][j]]=T;
		for(j=0;tmp[j]==T;++j);
		pre=j;
	}
	if(pre!=val)
	{
		printf("POSSIBLE\n");
		return 0;
	}
	
	++T;
	for(i=0;i<V[u].size();++i)tmp[V[u][i]]=T;
	for(k=0;tmp[k]==T;++k);
	val=k;
	for(++k;tmp[k]==T;++k);
	pre=k;
	for(i=p[u];i!=u;i=p[i])
	{
		++T;
		tmp[pre]=T;
		for(j=0;j<V[i].size();++j)tmp[V[i][j]]=T;
		for(j=0;tmp[j]==T;++j);
		pre=j;
	}
	if(pre==val)printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
}

Measured memory_bytes: 11648
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

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

int main() {
	int n=read();
	if (n%1000==0) puts("0");
	else printf("%d\n",1000-n%1000);
	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
int main(){
    int k, a, b, i;
    cin >> k >> a >> b;
    for(i=a;i<=b;i++){
        if(i%k==0){
            cout << "OK" <<endl;
            return 0;
        }
    }
    cout << "NG" <<endl;
    
    return 0;
}

Measured memory_bytes: 3636
from __future__ import print_function

from functools import reduce
from operator import mul
from collections import Counter
from collections import deque
from itertools import accumulate
from queue import Queue
from queue import PriorityQueue as pq
from heapq import heapreplace
from heapq import heapify
from heapq import heappushpop
from heapq import heappop
from heapq import heappush
import heapq
import time
import random
import bisect
import itertools
import collections
from fractions import Fraction
import fractions
import string
import math
import operator
import functools
import copy
import array
import re
import sys
sys.setrecursionlimit(500000)


input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    #
    S = input().strip()
    n = len(S)

    #
    temp = 0
    cnt = 0
    for i in range(n):
        if S[i] == 'R':
            temp += 1
        else:
            cnt = max(cnt, temp)
            temp = 0
    for i in range(n):
        if S[i] == 'L':
            temp += 1
        else:
            cnt = max(cnt, temp)
            temp = 0

    #
    T = [0 for _ in range(n)]
    #
    stack = 0
    ### 0 <= i < n
    for i in range(0, n):
        if S[i] == 'L':
            # if cnt % 2 == 1:    # 移動回数が奇数の場合
                T[i-1] += - (-stack//2)
                T[i] += stack//2
                stack = 0
            # else:               # 移動回数が偶数の場合
                # T[i-1] += stack//2
                # T[i] += -(-stack//2)
                # stack = 0
        else:
            stack += 1
    eprint(T)
    #
    stack = 0
    TT=[0 for _ in range(n)]
    for i in range(0, n)[::-1]:
        if S[i] == 'R':
            # if cnt % 2 == 1:    # 移動回数が奇数の場合
                TT[i] += stack//2
                TT[i+1] += - (-stack//2)
                stack = 0
            # else:               # 移動回数が偶数の場合
                # TT[i] += -(-stack//2)
                # TT[i+1] += stack//2
                # stack = 0
        else:
            stack += 1
    eprint(TT)

    for x in [(T[i] + TT[i]) for i in range(n)]:
        print(x,end=" ")

if __name__ == '__main__':
    main()


Measured memory_bytes: 83612
//Problem Web:
#include<bits/stdc++.h>
#include<ext/rope>
//using namespace __gnu_cxx;
#include<iostream>
#include<stack>
#include<vector>
#include<queue>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;

#define int long long
#define ll long long
#define lowbit(x) ((x)&(-(x)))
#define gcd(x,y) __gcd(x,y)
#define mem(x,y) memset(x,y,sizeof(x))
#define pr pair
#define pb push_back
#define mp make_pair
#define fi first
#define se second
//#define use_t 1
const double pi=acos(-1.0);
const double eps=1e-8;
const ll inf = 0x3f3f3f3f;
const ll maxn=1e5+7;
const ll mod=1e9+7;
ll ksm(ll a,ll b)
{
    ll ans=1LL;
    while(b>0)
    {
        if(b&1LL)
            ans=ans*a%mod;
        a=a*a%mod;
        b/=2LL;
    }
    return ans;
}
int n;
int ans=0;
void sol(int n1,int a,int b,int c){
	if(n1>n) return ;
	if(a&&b&&c) ++ans;
	sol(n1*10+3,1,b,c);
	sol(n1*10+5,a,1,c);
	sol(n1*10+7,a,b,1);
}

signed main ()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef yyhao
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif
#ifdef use_t
ll t;
ll tt=1;
cin>>t;
for(tt=1;tt<=t;tt++)
{
#endif // use_t

//int n;
cin>>n;
sol(0,0,0,0);

cout<<ans<<endl;














#ifdef use_t
}
#endif // use_t
    return 0;
}


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

using namespace std;

#define ll long long
#define rep(i,n) for(int i=1;i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)

const ll INF=1e9+7;
int n,maxf=-1,g,h;
int a[100001];
int main()
{
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	cin>>n;
	rep(i,n){
		int t;
		cin>>t;
		a[t]++;
		maxf=max(maxf,t); 
	}
	rep(i,maxf){
		if(a[i]){
			g++;
			if(a[i]>=2){
				h+=a[i]-1;
			}
		}
	}
	if(h&1){
		cout<<g-1;
	}
	else{
		cout<<g;
	}
	return 0;
}

Measured memory_bytes: 640
implicit none
integer :: n
integer :: i,t,x,y,nt,nx,ny,dt,dxy

read *,n
t = 0
x = 0
y = 0

do i = 1, n
   read *,nt,nx,ny
   dt = nt - t
   dxy = abs(nx - x) + abs(ny - y)
   if (dxy > dt .or. mod(dxy,2) /= mod(dt,2)) then
      print '(a)','No'
      stop
   endif
   t = nt
   x = nx
   y = ny
enddo
print '(a)','Yes'
end

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios_base::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

short nails[5050][5050];

int main()
{
  int N, M;
  N = in(), M = in();
  for (int i = 0; i < M; i++){
    int a, b, x;
    a = in(), b = in(), x = in();
    nails[a][b] = x + 1;
  }
  for (int i = 1; i <= N; i++){
    for (int j = 1; j <= i; j++){
      nails[i][j] = max<short>(nails[i][j], max(nails[i - 1][j], nails[i - 1][j - 1]) - 1);
    }
  }
  int cnt = 0;
  for (int i = 1; i <= N; i++){
    for (int j = 1; j <= i; j++){
      if (nails[i][j]) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 49352
H, W = map(int, input().split())

if H == 1 or W == 1:
  print(1)

elif W % 2 == 0:
  print(int(W/2*H))

else:
  x1 = W//2 + 1
  x2 = W//2
  if H % 2 == 0:
    result = int((x1+x2)*H/2)
    print(int(result))
  
  else:
    result = int((x1+x2)*(H//2) + x1)
    print(int(result))


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

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> a(n),b(n),c(n-1);

    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 0; i < n-1; i++) cin >> c[i];

    int sum = 0;
    for(int i = 0; i < n; i++){
        sum += b[a[i]-1];
        if( i!=0 && a[i] - a[i-1] == 1){
            sum += c[a[i-1]-1];
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#ABC135B
num = 0
tmp = [0,0,0,0]
N = int(input())
p = list(map(int,input().split()))
m = list(int(i) for i in range(1,N+1))
l = 0
if p == m:
  print("YES")
else:
  for k in range(N):
    if num >= 2:
      break
    if p[k] == m[k]:
      continue
    else:
      tmp[l] = p[k]
      tmp[l+1] = int(k+1)
      num+=1
      l+=2
  if tmp[1] == tmp[2]:
    print("YES")
  else:
    print("NO")


  

Measured memory_bytes: 3064
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

const double EPS=1e-8;
const double PI=acos(-1);

double solve(const vector<double> &r){
	int n=r.size();
	vector<double> theta(n);

	double lo=0,hi=PI;
	rep(i,n-1){
		double a=(r[n-1]*r[0])/(r[i]*r[(i+1)%n]);
		if(a>1-EPS){
			lo=max(lo,acos( 1/a));
			hi=min(hi,acos(-1/a));
		}
	}
	rep(_,20){
		double mi=(lo+hi)/2;
		theta[n-1]=mi;
		rep(i,n-1){
			double a=(r[n-1]*r[0])/(r[i]*r[(i+1)%n]);
			theta[i]=acos(a*cos(theta[n-1]));
		}

		double sum=0;
		rep(i,n) sum+=theta[i];

		if(sum<2*PI) lo=mi; else hi=mi;
	}

	double area=0;
	rep(i,n) area+=r[i]*r[(i+1)%n]*sin(theta[i]);
	area/=2;
	return area;
}

int main(){
	int n; scanf("%d",&n);
	int r[8];
	rep(i,n) scanf("%d",r+i);

	double ans=0;
	rep(S,1<<n){
		vector<double> a;
		rep(i,n) if(S>>i&1) a.push_back(r[i]);
		if(a.size()<3) continue;

		sort(a.begin(),a.end());
		do{
			ans=max(ans,solve(a));
		}while(next_permutation(a.begin(),a.end()));
	}
	printf("%.9f\n",ans);

	return 0;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define M 1000000007
int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, i, j, wt, m;
	
	cin >> n >> m;
	vector<string> v(n);
	vector<vector<int>> dp(n, vector<int> (m));
	for(i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	dp[0][0] = 1;
	for(i = 0; i < n; i++)
	{
		for(j = 0; j < m; j++)
		{
			if(i == 0 && j == 0)
				continue;
			if(i == 0)
			{
				if(v[i][j] == '#')
					dp[i][j] = 0;
				else
					dp[i][j] = dp[i][j-1] ;
			}
			else if(j == 0)
			{
				if(v[i][j] == '#')
					dp[i][j] = 0;
				else
					dp[i][j] = dp[i-1][j] ;
			}
		}
	}

	for(i = 1; i < n; i++)
	{
		for(j = 1; j < m; j++)
		{
			if(v[i][j] == '#')
				dp[i][j] = 0;
			else
				dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % M;
		}
	}
	
	cout << dp[n-1][m-1] << endl;
	
}


Measured memory_bytes: 9448
from itertools import product
S = input().strip()
N = len(S)
cnt = 0
for x in product((0,1),repeat=N-1):
    y = S[:]
    for i in range(N-2,-1,-1):
        if x[i]==1:
            y = y[:i+1]+"+"+y[i+1:]
    cnt += eval(y)
print(cnt)

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

const int inf = 1e9;
const int MAXN = 1e6 + 5;
 
int arr[MAXN], dp[MAXN];

int main()
{
	int n,k;
	cin>>n>> k;	
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
		dp[i] = inf;
	}
	
		dp[1] = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= k; j++) {
				if (i + j > n) break;
				dp[i + j] = min(dp[i + j], dp[i] + abs(arr[i] - arr[i + j]));
			}        	
	}
	
	cout<< dp[n];
	return 0;
	
}

Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int n, l;
  cin >> n >> l;

  int total = 0;
  for (int i = 0; i < n; i++) total += i + l;

  int ans = 1000000007;
  for (int i = 0; i < n; i++) {
    int p = total - (i + l);
    if (abs(p - total) < abs(ans - total)) ans = p;
  }

  cout << ans << endl;

  return 0;
}


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

#define ll long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    priority_queue<double,vector<double>,greater<double>> pq;
    ll n;
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        double d;
        cin>>d;
        pq.push(d);
    }
    while(pq.size()>1)
    {
        //cout<<pq.top()<<" ";
        double x = pq.top();
        pq.pop();
        double y = pq.top();
        pq.pop();
        pq.push((x+y)/2);
    }
    cout<<setprecision(5)<<pq.top();
    
	return 0;
}

Measured memory_bytes: 256
x,y = map(int,input().split())
A = [1,3,5,7,8,10,12]
B = [4,6,9,11]
C = [2]

if x in A and y in A: print("Yes")
elif x in B and y in B : print("Yes")
elif x in C and y in C : print("Yes")
else: print("No")


Measured memory_bytes: 3060
<?php
list($K) = ints();
$sum = 0;
for($i = 1; $i <= $K; $i++)
for($j = 1; $j <= $K; $j++)
$memo[$i][$j] = $memo[$j][$i] = gcd($i, $j);

for($i = 1; $i <= $K; $i++)
for($j = 1; $j <= $K; $j++)
for($k = 1; $k <= $K; $k++)
    $sum+=$memo[$memo[$i][$j]][$k];

echo $sum;


function str(){return trim(fgets(STDIN));}
function ints(){return array_map('intval',explode(' ',trim(fgets(STDIN))));}
function int(){return intval(trim(fgets(STDIN)));}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){$c=0;while($x){$x&=$x-1;++$c;}return$c;}
function o(...$val){
    if(count($val)==1)$val=array_shift($val);
    echo debug_backtrace()[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0)echo "empty array";
        elseif(!is_array(current($val)))echo "array: ",implode(" ", addIndex($val)),"\n";
        else{
            echo "array:array\n";
            if(isCleanArray($val))foreach($val as $row)echo implode(" ", addIndex($row)),"\n";
            else foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row)),"\n";
        }
    }else echo $val."\n";
}
function addIndex($val){if(!isCleanArray($val)){$val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);}return $val;}
function isCleanArray($array){$clean=true;$i = 0;foreach($array as $k=>$v){if($k != $i++)$clean = false;}return $clean;}
// 座圧対象の配列 -> [圧縮された配列,復元用のMap,圧縮用のMap]
function atsu($array){$a = array_flip($array);$fuku=array_flip($a);sort($fuku);$atsu = array_flip($fuku);foreach($array as $i=>$val)$array[$i]=$atsu[$val];return [$array, $fuku, $atsu];}
function gcdAll($array){$gcd=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$gcd=gcd($gcd,$array[$i]);}return $gcd;}
function gcd($m, $n){if(!$n)return $m;return gcd($n, $m % $n);}
function lcmAll($array){$lcm=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$lcm=lcm($lcm,$array[$i]);}return $lcm;}
function lcm($a, $b) {return $a / gcd($a, $b) * $b;}

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}

function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  return loadGraph($N, $N-1);
}
function loadGraph($N = false, $M = false, $both = true){
  if($N === false)$N = $GLOBALS['N'];
  if($M === false)$N = $GLOBALS['M'];
  $G = array_fill(1, $N, []);
  for($i = 0; $i < $M; $i++){
    $values = ints();
    if(count($values) == 2){
      list($a, $b) = $values;
      $G[$a][] = $b;
      if($both)$G[$b][] = $a;
    }else{
      list($a, $b, $d) = $values;
      $G[$a][] = [$b, $d];
      if($both)$G[$b][] = [$a, $d];
    }
  }
  return $G;
}


Measured memory_bytes: 18536
MOD = 10**9 + 7

x, y = list(map(int, input().split()))

a3 = 2 * y - x
b3 = 2 * x - y
if not (a3 % 3 == 0 and b3 % 3 == 0):
  print(0)
  exit()

a = a3 // 3
b = b3 // 3

n = a + b

# https://qiita.com/derodero24/items/91b6468e66923a87f39f


def cmb(n, r):
  if (r < 0 or r > n):
    return 0
  r = min(r, n - r)
  return g1[n] * g2[r] * g2[n - r] % MOD


g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, n + 1):
  g1.append((g1[-1] * i) % MOD)
  inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)
  g2.append((g2[-1] * inverse[-1]) % MOD)

print(cmb(a + b, a))


Measured memory_bytes: 82448
#include<stdio.h>
#include<string.h>
int main(void){
    int n,i,j,b,f,r,v;
    char house[4][3][32] = {0};
    for (i = 0; i < 4; i++){
        for (j = 0; j < 3; j++){
            strcpy(house[i][j], " 0 0 0 0 0 0 0 0 0 0");
        }
    }
    scanf("%d",&n);
    while (n-->0){
        scanf("%d %d %d %d", &b, &f, &r, &v);
        house[b-1][f-1][r*2-1]+=v;
    }
    for (i=0;i<4;i++){
        for (j=0;j<3;j++){
            puts(house[i][j]);
        }
        if (i < 3){
            printf("####################\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2108