akhauriyash/Code-Regression huggingface dataset:
N = int(input())
dic = {}
ans = 0

for i, j in enumerate(input().split()):
    ind = int(i) + 1
    tall = int(j)

    delta = ind - tall

    ans += dic.get(delta, 0)  # default value 0

    addKey = ind + tall

    dic[addKey] = dic.get(addKey, 0) + 1

print(ans)


Measured memory_bytes: 46408
# CODE FESTIVAL 2016 予選 A: B – 仲良しうさぎ / Friendly Rabbits
N = int(input()) - 1
a = [int(s) - 1 for s in input().split()]

pairs = 0

for i in range(N):
    if a[i] != 0 and a[a[i]] == i:
        pairs += 1
        a[i] = 0
        a[a[i]] = 0

print(pairs)

Measured memory_bytes: 13880
//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(x) cout<<#x<<' '<<'='<<' '<<x<<'\n'
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
void solveforthiscase(const int & test)
{//deb(test);
cin>>a>>b>>m;
vll v(a);
vll vv(b);
read(v);
read(vv);
vector<ll> costs;
while(m--)
{
    cin>>x>>y;
    x--;
    y--;
    cin>>c;
    costs.pb(v[x]+vv[y]-c);
}
sor(vv);
for(int i=0;i<a;i++)
{
    costs.pb(v[i]+vv[0]);
}
sor(costs);
cout<<costs[0];







return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 3956
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif

string f(string s){
    vector<pair<char,int>> v;
    rep(i,s.size()){
        if(v.size()){
            if(v.back().first == s[i]){
                v.back().second ++;
            } else {
                v.eb(s[i],1);
            }
        } else {
            v.eb(s[i],1);
        }
    }

    stringstream ss;
    rep(i,v.size()){
        ss << v[i].second << v[i].first;
    }
    return ss.str();
}

int main(){
    string s;
    int k;
    while(cin >> k >> s && s!="0"){
        rep(i,k) s = f(s);
        cout << s << endl;
    }
}

Measured memory_bytes: 1668
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    map<int,int> p;
    rep(i,n){
        cin>>a[i];
        p[a[i]]++;
    }
    vector<int64_t> b;
    for(auto c:p){
        int v = c.first;
        int count = c.second;
        if(count>=4){
            b.push_back(v);
        }
        if(count>=2){
            b.push_back(v);
        }
    }
    if(b.size()<=1){
        cout<<0<<endl;
        return 0;
    }
    all(b);
    reverse(b.begin(),b.end());
    /*
    rep(i,b.size()){
        cout<<b[i]<<" ";
    }
    cout<<endl;
    */
    cout<<b[0]*b[1]<<endl;
}

Measured memory_bytes: 5376
import java.util.*;

class Main {
    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        long res = 1;
        for (int i = 1; i <= n; i++) {
            res *= i;
        }

        System.out.println(res);
    }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
vector<vector<int>> v;
vector<int> val;

void dfs(int p, int x) {
    val[p] += x;
    for (int i : v[p])
        dfs(i, val[p]);
}

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

    int n, q;
    cin >> n >> q;
    v.resize(n);
    val.resize(n, 0);
    for (int i = 0, x, y; i < n-1; i++) {
        cin >> x >> y;
        v[--x].push_back(--y);
    }
    while (q--) {
        int p, x;
        cin >> p >> x;
        val[--p] += x;
    }
    dfs(0, 0);
    for (int i : val)
        cout << i << ' ';
    cout << endl;
}


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

void solve(){
  int n; cin >> n;
  vector<int> l(n);
  int maxi = 0, sum = 0;
  cin >> l[0];
  for(int i = 1; i < n; i++){
    cin >> l[i];
    if(l[i] > l[maxi]){
      sum += l[maxi];
      maxi = i;
    }
    else sum += l[i];
  }
  //cout << sum << " " << l[maxi] << endl;
  if(l[maxi] < sum) cout << "Yes\n";
  else cout << "No\n";
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
// https://ynucpc.github.io/blog/2018/04/15/cp_vscode/
// http://www.atmarkit.co.jp/ait/articles/1509/08/news019.html

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;

// 配列の総和
// greater


ll big(ll n){
    return (1ll << n) * 4 - 3;
}
ll pa(ll n){
    return (1ll << n+1) - 1;
}
int main(){
    ll N, X;
    cin >> N >> X;
    ll ans = 0;
    for(int i=N; i>=0; i--){
        ll bg = big(i);
        //show(bg);
        //show(ans);
        if (bg>>1 < X){
            ans += pa(i-1) + 1;
            X -= (bg>>1) + 1;
        }else if (bg>>1 == X){
            ans += pa(i-1);
            break;
        }else{
            X -= 1;
        }

    }
    cout << ans << endl;

}




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

int main(){
  int N; cin >> N;
  //i番目の人間がj番目に言うコメント
  //-1なら言ってない、0なら不親切、1なら正直
  int comment[15][15];
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      comment[i][j]=-1;
    }
  }
  
  for(int i=0; i<N; i++){
    int A; cin >> A;
    for(int j=0; j<A; j++){
      int x,y; cin >> x >> y;
      x--;
      comment[i][x]=y;
    }
  }
  
  int maxhonest=0;
  for(int i=0; i<(1<<N); i++){
    int honest=0;
    bool t=true;
    for(int j=0; j<N; j++){
      //正直者のコメントについて正誤チェックすればよい
      if((i&(1<<j))>0){
        honest++;
        for(int k=0; k<N; k++){
          if((comment[j][k]==1)&&((i&(1<<k))==0)||((comment[j][k]==0)&&((i&(1<<k))>0))){
            t=false;
          }
        }
      }
    }
    if(t) maxhonest=max(maxhonest,honest);
  }
  cout << maxhonest << endl;
}


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

using namespace std;


int main()
{
	int n;
	vector<int> prime;
	
	for(int i=0;i<1000000;i++)
		prime.push_back(1);
	
	prime[0]=prime[1]=0;
	
	for(int i=0;i<1000000;i++)
	{
		if(prime[i]==1)
		{
//			cout << i << endl;
			
			for(int j=2;i*j<1000000;j++)
			{
				prime[i*j]=0;
//				cout << i*j <<endl;
			}
		}
	}
	
	
	for(;cin >> n;)
	{
		int ans=0;
		
		for(int i=0;i<=n;i++)
			if(prime[i]==1)
				ans++;
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <climits>
#include <math.h>
#define rep(i,s,n) for (int i = s; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;

int main() {
    int x;
    cin>>x;
    cout<<1-x<<endl;
}

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

using namespace std;

int main()
{
	int n;
	vector<int> v;
	scanf("%d", &n);
	
	for(int i = 3; i <= n; i++)
		if(i % 3 == 0 || i % 10 == 3
			|| i % 100 / 10 == 3 || i % 1000 / 100 == 3
			|| i % 10000 / 1000 == 3 || i % 100000 / 10000 == 3)
			v.push_back(i);
	
	vector<int>::iterator it;
	
	for(it = v.begin(); it != v.end(); it++)
			printf(" %d", *it);	
    printf("\n");
	
	return 0;
}


Measured memory_bytes: 3284
#include <iostream>
#include <vector>
using namespace std;

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

bool owari(vector<int> v, int c) {
    rep(i,v.size()) {
        if(i == c) continue;
        if(v[i] > 0) return false;
    }
    return true;
}

void solve(int n, int p) {
    int cup = p;
    vector<int> per(n,0);
    
    int i;
    while(1) {
        for(i=0; i<n; i++) {
            if(cup == 0) {
                if(owari(per, i)) goto out;
                cup += per[i]; per[i] = 0;
            }
            else {
                ++per[i]; --cup;
            }
        }
    }
out:
    cout << i << "\n";
    return ;
}

int main() {
    int n,p;
    while(cin>>n>>p && n) solve(n,p);
    return 0;
}

Measured memory_bytes: 2984
#include <iostream>
int main(){
    int n,i,x;
    std::cin >> n;
    for(i=1;i<n+1;i++){
        if(i%3 == 0){
            std::cout <<" " << i ;
            continue;
        }
        x = i;
        while(x>0){
            if(x%10 == 3){
                std::cout <<" " << i ;
                break;
            } 
            x /=10;
        }
    }
    std::cout << std::endl;
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int cnt=0;
    string s;
    cin>>s;
    for(int i=0;i<SZ(s);i++)
    {
        if(s[i]=='1')
        {
            cnt++;
        }
    }
    cout<<cnt<<NL;
    return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; i + 3 <= s.size(); i++) {
    if (s.substr(i, 3) == "ABC") cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

struct Coordinate {
	int x, y;
	std::vector<Coordinate> neighbors() const { return std::vector<Coordinate>{ Coordinate{x + 1, y}, Coordinate{x - 1, y}, Coordinate{x, y + 1}, Coordinate{x, y - 1} }; }
};
constexpr std::array<char, 3> Colors = { 'R', 'G', 'B' };
int min_step(std::vector<std::vector<char>>& state, const int current_step = 0, int current_min = 30) {
	if (current_step >= current_min) return current_min;
	if (std::all_of(state.begin(), state.end(), [&state](const std::vector<char>& line) {return std::all_of(line.begin(), line.end(), [&state](const char c) {return c == state[0][0]; }); })) return current_step;
	auto initial = state[0][0];
	std::vector<std::vector<bool>> is_join(state.size(), std::vector<bool>(state.front().size(), false));
	is_join[0][0] = true;
	std::queue<Coordinate> queue; queue.push(Coordinate{ 0, 0 });
	while (!queue.empty()) {
		auto top = queue.front(); queue.pop();
		for (auto next : top.neighbors()) if (0 <= next.y && next.y < state.size() && 0 <= next.x && next.x < state.front().size() && !is_join[next.y][next.x]) {
			if (state[next.y][next.x] == initial) {
				is_join[next.y][next.x] = true;
				queue.push(next);
			}
		}
	}
	auto diff = std::distance(Colors.begin(), std::find(Colors.begin(), Colors.end(), initial));
	for (auto c = 1; c < 3; ++c) {
		for (auto i = 0; i < state.size(); ++i) for (auto j = 0; j < state[i].size(); ++j) {
			if (is_join[i][j]) state[i][j] = Colors[(c + diff) % 3];
		}
		current_min = min_step(state, current_step + 1, current_min);
	}
	for (auto i = 0; i < state.size(); ++i) for (auto j = 0; j < state[i].size(); ++j) if (is_join[i][j]) state[i][j] = initial;
	return current_min;
}
int main() {
	std::cin.tie(0); std::cin.sync_with_stdio(false);
	while (true) {
		int x, y; std::cin >> x >> y; if (x == 0 && y == 0) break;
		std::vector<std::vector<char>> state(y, std::vector<char>(x)); for (auto& line : state) for (auto& cell : line) std::cin >> cell;
		std::cout << min_step(state) << '\n';
	}
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int d, t, s;
    cin >> d >> t >> s;
    if(s*t >= d) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 3652
import numpy as np
gen_input = list(map(int, input().split()))
H = gen_input[0]
W = gen_input[1]
K = gen_input[2]
string = [list(input()) for n in range(H)]

for i in range(len(string)):
    for j in range(len(string[0])):
        if string[i][j] == '.':
            string[i][j] = 100
        else:
            string[i][j] = 1000
            
string = np.array(string)

count = 0

if (string == 1000).sum() == K:
    count += 1
for i in range(2**H):
    for j in range(2**W):
        temp = string.copy()
        I = list(bin(i)[2:].zfill(H))
        J = list(bin(j)[2:].zfill(W))
        fill_h = np.where(np.array(list(map(int, list(I)))) == 1)[0]
        fill_w = np.where(np.array(list(map(int, list(J)))) == 1)[0]

        if len(fill_h) > 0 and len(fill_w) == 0:
            for f in fill_h:
                temp[f, :] = 0
            if (temp == 1000).sum() == K:
                count += 1
        elif len(fill_h) == 0 and len(fill_w) > 0:
            for f in fill_w:
                temp[:, f] = 0
            if (temp == 1000).sum() == K:
                count += 1
        elif len(fill_h) > 0 and len(fill_w) > 0:
            for f in fill_h:
                temp[f, :] = 0
            for f in fill_w:
                temp[:, f] = 0
            if (temp == 1000).sum() == K:
                count += 1

print(count)

Measured memory_bytes: 27276
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main() {
    int N; cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; ++i) cin >> a[i];
    
    vector<long long> s(N+1, 0);
    map<long long, long long> nums;
    for(int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];
    for(int i = 0; i < N+1; ++i) ++nums[s[i]];
    long long res = 0;
    for(auto i : nums) {
        long long num = i.second;
        res += num * (num - 1) / 2;
    }
    
    cout << res << endl;
}


Measured memory_bytes: 15104
from itertools import permutations
n, c = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(c)]
C = [list(map(int, input().split())) for _ in range(n)]

colors = [[0]*c for _ in range(3)]
for i in range(n):
    for j in range(n):
        c_ij = C[i][j]-1
        index = (i+j)%3
        for col in range(c):
            colors[index][col] += D[c_ij][col]

ans = 1000*500**2
for c0, c1, c2 in permutations(range(c), 3):
    diff = colors[0][c0] + colors[1][c1] + colors[2][c2]
    ans = min(ans, diff)
print(ans)


Measured memory_bytes: 7668
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
using namespace std;

int main()
{
  int n;
  cin>>n;
  long long int ans=1;
  map<int, int> mp;
  for(int i=2;i<=n;i++){
    int tmp=i;
    for(int j=2;j<=i;j++){
      while(tmp%j==0){
        tmp/=j;
	mp[j]++;
      }
    }
  }
  for (auto x : mp){
    ans = ans*(x.second+1);
    ans = ans%(1000000007);
  }
  cout<< ans <<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int s_time;
    scanf("%d", &s_time);
    if(!s_time){
        printf("0:0:0\n");
        return 0;
    }else{
        int h = s_time / 3600;
        int m = (s_time - h * 3600) / 60;
        int s = s_time - h * 3600 - m * 60;
        printf("%d:%d:%d\n", h, m, s);
        return 0;
    }
}

Measured memory_bytes: 592
n, k = [int(i) for i in input().split()]

ans = [0, 0]
d = k // 2

for i in range(1, n+1):
    if k % 2 == 0 and i % k == d:
        ans[0] += 1
    if i % k == 0:
        ans[1] += 1

print(ans[0] ** 3 + ans[1] ** 3)

Measured memory_bytes: 3060
let solve (mt, ma) (t, a) =
    let tm = (mt + t - 1UL) / t
    let am = (ma + a - 1UL) / a
    let m = max tm am
    (t * m, a * m)
     
let () =
    let n = stdin.ReadLine  () |> int
     
    let taSeq =
        seq { for i in 1..n do
                let t, a =
                    stdin.ReadLine () |>
                    (fun line -> line.Split()) |>
                    (fun arr -> (uint64 arr.[0], uint64 arr.[1]))
                yield (t, a) }
     
    Seq.fold solve (1UL, 1UL) taSeq |>
    (fun (t, a) -> t + a) |>
    printfn "%d"

Measured memory_bytes: 4180
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}

int cnt[M+3];
int a[M+3];

 main()

{
    fast
    int n,k,q;
    cin>>n>>k>>q;
    f(i,1,n)cnt[i]=k-q;
    f(i,1,q)
    {
        cin>>a[i];
        cnt[a[i]]++;
    }
   f(i,1,n)
   {
       //cout<<cnt[i]<<" "<<endl;
       if(cnt[i]>0)
       {
           cout<<"Yes"<<endl;
       }
       else
       {
           cout<<"No"<<endl;
       }
   }
    return 0;

}













Measured memory_bytes: 2176
import heapq
 
N, M = map(int, input().split(" "))
As = [-i for i in map(int, input().split(" "))]
As.sort()
heapq.heapify(As)

for _ in range(M):
  i = - heapq.heappop(As)
  i = i >> 1
  heapq.heappush(As,-i)

print(-sum(As))

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

long long gcd(long long x, long long y) {
    if(y == 0) return x;
    return gcd(y,x%y);
}

long long lcm(long long x, long long y) {
    if(x == 0 || y == 0) return 0;
    return x / gcd(x,y) * y;
}

int main(){
    int n;
    cin >> n;
    int l,r;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        cin >> l >> r;
        cnt += r - l + 1;
    }
    cout << cnt << endl;    
}

Measured memory_bytes: 256
s2 = input()
t = input()
c1=1
c2=0
c3=0

for i in range(len(s2)-len(t)+1):
    if s2[i]==t[0] or s2[i]=='?':
        for j in range(1,len(t)):
            if s2[i+j]==t[j] or s2[i+j]=='?':
                c1+=1
        if c1 == len(t):
            c2=1
            c3=i
        c1=1
if c2==1:
    s=list(s2)
    for i in range(len(t)):
        s[c3+i]=t[i]
    for i in range(len(s2)):
        if s[i]=='?':
            s[i]='a'
    print("".join(s))
else:
    print('UNRESTORABLE')


Measured memory_bytes: 3064
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

long long P = 1000000007;
void mul(vector<vector<long long>> &a, vector<vector<long long>> &b,
         vector<vector<long long>> &c) {
  int n = a.size();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      c[i][j] = 0;
      for (int k = 0; k < n; k++) {
        c[i][j] += (a[i][k] * b[k][j]) % P;
        c[i][j] %= P;
      }
    }
  }
}

int main() {
  int n;
  long long k;
  cin >> n >> k;
  vector<vector<long long>> a, b, ans;
  a.resize(n);
  b.resize(n);
  ans.resize(n);
  for (int i = 0; i < n; i++) {
    a[i].resize(n);
    b[i].resize(n);
    ans[i].resize(n);
    ans[i][i] = 1;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      cin >> a[i][j];

  while (k > 0) {
    if (k % 2 == 0) {
      mul(a, a, b);
      swap(a, b);
    } else {
      mul(a, ans, b);
      swap(ans, b);
      mul(a, a, b);
      swap(a, b);
    }
    k >>= 1;
  }
  long long ret = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      ret += ans[i][j];
      ret %= P;
    }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long ll;
#define print(x) cout<<(x)<<endl


#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


// DONT USE "int", USE "ll" !!!!!!!!!!!!
int main() {

	int N;
	cin >> N;
	int out = (N - 2) * 180;
	print(out);




	return 0;
}

Measured memory_bytes: 384
int main(void) {
    int n, x, i, j, k, count, sum = 0;
    count = 0;
    while (1) {
 
        scanf("%d %d", &n, &x);
 
        if (n == 0 && x == 0) break;
 
        for (i = 1; i <= n; i++) {
            for (j = i + 1; j <= n; j++) {
                for (k = j + 1; k <= n; k++) {
                    sum = i + j + k;
                    if (sum == x) {
                        count++;
                    }
                }
            }
        }
        printf("%d\n", count);
        count = 0;
    }
    return 0;
}

Measured memory_bytes: 1756
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;

#define NMAX 100001
#define INF (1 << 30)

int v[NMAX], a[NMAX], b[NMAX];
vector <int> aux[NMAX];
vector <pair <int, int> > s;

int solve_single(int x[]) {
    int non_zero = 0;
    int m = 0;
    for (int i = 1; i < NMAX; i++) {
        if (x[i] == 0)
            continue;
        non_zero += x[i];
        m = max(m, x[i]);
    }
    return non_zero - m;
}

void build_second_best(int x[]) {
    int non_zero = 0;
    for (int i = 1; i < NMAX; i++) {
        non_zero += x[i];
    }
    for (int i = 1; i < NMAX; i++) {
        if (x[i]) {
            aux[non_zero - x[i]].push_back(i);
        }
    }
    for (int i = 0; i < NMAX; i++) {
        for (const int z : aux[i]) {
            s.emplace_back(i, z);
        }
    }
}

bool get_second_best(int nr, int& cnt) {
    if (s.size() == 1u) {
        if (s[0].second == nr)
            return false;
        cnt += s[0].first;
    } else {
        if (s[0].second == nr) {
            cnt += s[1].first;
        } else {
            cnt += s[0].first;
        }
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);

    int n;
    // ifstream cin("code.in");
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
    }
    for (int i = 1; i < n; i += 2) {
        a[v[i]]++;
        b[v[i + 1]]++;
    }
    int sol = (n >> 1) + solve_single(b);
    build_second_best(b);
    for (int i = 1; i < NMAX; i++) {
        if (a[i] == 0)
            continue;
        int cnt = (n >> 1) - a[i];

        if (!get_second_best(i, cnt)) {
            cnt += (n >> 1);
        }

        sol = min(sol, cnt);

    }
    cout << sol << '\n';
    return 0;
}


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

int main(void){
    string n;

    cin>>n;
    for(int i=0;i<n.size();i++){
        if(n[i]=='1')
            n[i]='9';
        else if(n[i]=='9')
            n[i]='1';
    }
    cout<<n<<endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <algorithm>
#include <limits.h>
#include <cmath>
#include <time.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define SQR(X) ((X)*(X))


int test = 0;
/* ここからが本編 */
int f(int x) {
  return x*x;
}
int main(void)
{
  int i,j,k,l;
  int d;


  while(cin >> d) {
    int rep = 0;
    for(i=d; i<600; i+=d){
      rep += f(i)*d;
    }
    cout << rep << endl;
  }
  return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
using ll = long long;
const ll MOD = 1000000007;

ll dp[42][131072];
ll d10[42];

int main() {
	d10[0] = 1;
	for (int i = 1;i < 42;i++)d10[i] = d10[i - 1] * 10 % MOD;

	int N, X, Y, Z;
	cin >> N >> X >> Y >> Z;

	ll pat = (1LL << (X + Y + Z - 1)) + (1LL << (Y + Z - 1)) + (1LL << (Z - 1));
	ll ans = 0;

	dp[0][0] = 1;

	for (int i = 0;i < N;i++) {
		for (ll j = 0;j < 131072;j++) {
			dp[i][j] %= MOD;
			if ((j & pat) == pat) {
				ans += d10[N - i] * dp[i][j];
				ans %= MOD;
				dp[i][j] = 0;
			}
			else {
				for (int k = 1;k < 11;k++) {
					dp[i + 1][((j << k) + (1LL << (k - 1))) % 131072] += dp[i][j];
				}
			}
		}
	}
	for (ll j = 0;j < 131072;j++) {
		if ((j & pat) == pat) {
			ans += dp[N][j];
		}
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 43264
#include<stdio.h>
int main()
{
	 int num1,num2,n1,n2,rem,LCM,temp;
	 printf("");
	 scanf("%d %d",&num1,&num2);

	 n1=num1;
	 n2=num2;

	 while(n2!=0)
	 {
	 	rem=n1%n2;
	 	n1=n2;
	 	n2=rem;
	 }
	 printf("%d\n",n1);

	return 0;
}



Measured memory_bytes: 2124
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();
		int K = sc.nextInt();
		
		long[] A = new long[X];
		long[] B = new long[Y];
		long[] C = new long[Z];
		
		for(int i = 0; i < X; i++) {
			A[i] = sc.nextLong();
		}
		
		for(int i = 0; i < Y; i++) {
			B[i] = sc.nextLong();
		}
		
		for(int i = 0; i < Z; i++) {
			C[i] = sc.nextLong();
		}
		
		long[] del = new long[X * Y];
		int p = 0;
		for(int i = 0; i < X; i++) {
			for(int j = 0; j < Y; j++) {
				del[p] = A[i] + B[j];
				p++;
			}
		}
		Arrays.sort(del);
		long[] del2 = new long[Z * K];
		int x = Math.max(del.length - 1 - K, -1);
		int q = 0;
		for(int i = del.length - 1; i > x; i--) {
			for(int j = 0; j < Z; j++) {
				del2[q] = del[i] + C[j];
				q++;
			}
		}
		Arrays.sort(del2);
		for(int i = del2.length - 1; i > del2.length - 1 - K; i--) {
			System.out.println(del2[i]);
		}
	}
}


Measured memory_bytes: 59840
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int K;
    cin >> K;
    K = K - 1;
    vector <int> vec{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << vec.at(K) << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def read():
    S = input().strip()
    T = input().strip()
    return S, T


def solve(S, T):
    N = len(S)
    for i in range(N):
        is_matched = True
        for j1 in range(N):
            j2 = (i + j1) % N
            if S[j1] != T[j2]:
                is_matched = False
                break
        if is_matched:
            return "Yes"
    return "No"


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 9124
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <cmath>
#include <list>
#include <set>
#include <map>

#define MaxInt 2e9
#define LF '\n';
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main(void)
{
	ios::sync_with_stdio(false);
	int a, b, t;
	cin >> a >> b >> t;
	cout << (t / a) * b;

	return 0;
}

//https://codeforces.com/problemset/problem/500/B

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

typedef long long ll;

const ll mod = 1e9+7;
const ll maxn = 1000 * 1001;
const ll INF = 1e18;

ll x[maxn];
bool mark[maxn];

vector<ll> v[maxn];

ll n , k;

int main()
{
	cin>> n;

	ll a[n];

	for(ll i = 0; i < n; i++)
		cin >> a[i];
		
	sort(a , a + n);
	
	cout<<a[n/2] - a[n/2-1];
}


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

struct pq{
	int p;
	int q;
};

int main(){
	int n , m , a;
	while(cin >> n >> m >> a , n|m|a){
		int* tate = new int [n];
		for(int i=0;i<n;++i){
			tate[i]=i+1;
		}
		multimap<int , pq > yoko;
		for(int i=0;i<m;++i){
			int h;
			pq tmp;
			cin >> h >> tmp.p >> tmp.q;
			yoko.insert(make_pair(h , tmp));
		}
		multimap<int , pq>::iterator it;
		for(it=yoko.begin();it!=yoko.end();++it){
			pq tmp=(*it).second;
			swap(tate[tmp.p-1] , tate[tmp.q-1]);
		}
		cout << tate[a-1] << endl;
		yoko.clear();
		delete [] tate;
	}
	return 0;
}

Measured memory_bytes: 1252
def is_space(iterable):
    return all(map(lambda x: x == ".", iterable))


H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]

remove_row_idx = []
for idx, row in enumerate(A):
    if is_space(row):
        remove_row_idx.append(idx)
# print(remove_row_idx)
for count, idx in enumerate(remove_row_idx):
    del A[idx - count]

remove_column_idx = []
for i in range(W):
    column = [r[i] for r in A]
    if is_space(column):
        remove_column_idx.append(i)

for count, idx in enumerate(remove_column_idx):
    for row in A:
        del row[idx - count]

for row in A:
    print("".join(row))


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int a, b, c, d = 0, e;
	cin >> a >> b >> c;
	int test[101] = { 0 };
	for (int h = 1; h <= min(a, b); h++) {
		if (a % h == 0 && b % h == 0) {
			test[h] = h;
		}
	}
	for (int j = 0; j < 100; j++) {
		for (int k = j + 1; k < 101; k++) {
			if (test[k] > test[j]) {
				int uio = test[k];
				test[k] = test[j];
				test[j] = uio;
			}
		}
	}
	cout << test[c - 1] << endl;
	cin >> e;
}

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

int main()
{
    long N;
    std::vector<long> L;
    std::cin >> N;
    for(long i=0; i<2*N; i++){
        long temp;
        std::cin >> temp;
        L.push_back(temp);
    }
    std::sort(L.begin(),L.end());
    long sum=0;
    for(long i=0; i<2*N; i+=2){
        sum+=L[i];
    }
    std::cout << sum << std::endl;
    return 0;
}

Measured memory_bytes: 256
/*
   Author: Shivam Shukla
*/
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;
 
const int MOD=1e9+7;
const int MAX=1e5+5;
const double PI= acos(-1.0);
const long double EPS=1e-10;
const int64_t INF=1e18+10;
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<str>
#define vc(x) vector<x>
#define mapll map<ll,ll>
#define mapib map<int,bool>
#define mapiv map<int,vector>
#define mapsi map<string,int>
#define rep(i,j,k) for(ll i=j;i<k;i++)
#define down(i,j,k) for(ll i=j;i>=k;i--)
#define repa(i,n) for(ll i=0;i<n;i++)
#define dowa(i,n) for(ll i=n;i>=0;i--)
#define reps(i,j,k,s) for(ll i=j;i<k;i+=s)
#define downs(i,j,k,s) for(ll i=j;i>=k;i-=s)
#define trv(i,x) for(auto i:x)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define str string 
#define dub double
#define pqmax priority_queue<ll>
#define pqmin priority_queue<ll,vl,greater<ll> >
 
template<typename t> t lcm(t a, t b) {return (a*b)/__gcd(a,b);}
template<typename t> t gcd(t a, t b) {return __gcd(a,b);}
template<typename t> t mul_mod(t a, t b, t m){t res=((a%m)*(b%m)%m); return res;}
template<typename t> t add_mod(t a, t b, t m){t res=((a%m)+(b%m))%m; return res;}
template<typename t> t pow_mod(t a,t b,t m) {t res=1;while(b){if(b&1) res=mul_mod(res,a,m);a=mul_mod(a,a,m), b>>=1;} return res%m;}
template<typename t> vc(t) num_vec(t num) {t res; while (num) res.pb(num%10), num/=10; return res;}
template<typename t> t vec_num(t vec) {t res=0; ll mul=1; repa(i,sz(vec)) res=vec[i]*mul, mul*=10; return res;}
 

int32_t main(int argc,char** argv){
	fastio();
	auto tstart= clock();
 
    double n, s; cin >> n;
    s = (n / 3.0);
    
    cout << fixed << setprecision(6) << (s * s * s) << endl;

    cerr<<setprecision(2)<<fixed<<"Time elapsed: "<<(double)(clock() - tstart)/CLOCKS_PER_SEC<<endl; 
    return 0; 
}

Measured memory_bytes: 256
def q3():
    N, M = (int(i) for i in input().split())
    H = [int(i) for i in input().split()]
    ans = [True]*N

    for i in range(M):
        A, B = (int(i) for i in input().split())

        if H[A-1] <= H[B-1]:
            ans[A-1] = False
        if H[B-1] <= H[A-1]:
            ans[B-1] = False

    print(ans.count(True))


if __name__ == '__main__':
    q3()


Measured memory_bytes: 20080
#include<stdio.h>
#include<string.h>
char hira[1<<21],sawa[256];
int main(int argc,char *argv[]){
    int hata;
    int fu,s,t;
    char c;
    sawa['T'] = 1;
    sawa['G'] = 2;
    sawa['C'] = 3;
    sawa['A'] = 4;
     
    scanf("%d", &fu);
    getchar();
    while (fu--) {
        s = 0;
        t = 1;
        hata = ( c = getchar() ) == 'i';
        while ( ( c = getchar() ) != ' ' );
        while ( ( c = sawa[getchar()] ) != 0 ) {
            s += c * t;
            t *= 4;
        }
        if (hata) hira[s] = 1; else puts( hira[s] ? "yes" : "no" );
    }
    return 0;
}

Measured memory_bytes: 1952
a,b,c=gets.chomp.split("")
d, e, f=gets.chomp.split("")

unchi = 0

if a == d
  unchi = unchi + 1
end
 
if b == e
  unchi = unchi + 1
end
if c == f
  unchi = unchi + 1
end
 
 
print unchi

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){
    int n;
    cin >> n;
    cout << n/3 << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    string s1,s2;
    cin>>s1>>s2;
    if(s1.size()!=s2.size())
        std::cout << "No" << std::endl;
    else{
        bool f= false;
        for(int i=0;i<s1.size();i++){
            int j,t=i;
            for(j=0;j<s2.size();j++,t++){
                if(s1[t]!=s2[j])
                    break;
                if(t==s1.size()-1)
                    t=-1;
            }
            if(j>=s2.size())
                f= true;
        }
        if(f)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
s = input()

def komoji(L):
    if L == "A":
        return "a"
    elif L == "B":
        return "b"
    else:
        return "c"

kotae = s[:k-1] + komoji(s[k-1]) + s[k:]
print(kotae)

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

int main() {
    int N, Q; cin >> N >> Q;
    char S[100100]; for (int i = 0; i < N; i++) cin >> S[i];
    int l[100100], r[100100], AC[100100] = {0};
    for (int i = 0; i < Q; i++) cin >> l[i] >> r[i];

    int ac = 0;
    for (int i = 1; i < N; i++) {
        if (S[i - 1] == 'A' && S[i] == 'C') {
            ac ++;
        }
        AC[i] = ac;
    }

    for (int i = 0; i < Q; i++) {
        if (l[i] == r[i]) printf("%d\n", 0);
        else {
            int ans;
            ans = AC[r[i] - 1] - AC[l[i] - 1];
            printf("%d\n", ans);
        }
    }

}

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

using namespace std;

#define ll long long

const int N = 402;
int a[N];
ll dp[N][N], sum[N];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		sum[i] = sum[i-1] + a[i];
	}
	for (int i = 2; i <= n; i++) {
		for (int l = 1, r = i; r <= n; l++, r++) {
			dp[l][r] = 2e18;
			for (int j = l + 1; j <= r; j++) {
				dp[l][r] = min(dp[l][r], dp[l][j-1] + dp[j][r] + sum[r] - sum[l-1]);
			}
		}
	}
	printf("%lld", dp[1][n]);
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);

    string s;
    cin >> s;
    int a = INT_MAX;
    int z = -1;
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'A') a = min(a, i);
        if(s[i] == 'Z') z = max(z, i);
    }
    cout << z - a + 1 << endl;
    
    return 0;
}

Measured memory_bytes: 720
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
class pair{
	int cost;
	int val;
	
	pair(int a,int b)
	{
		cost=a;
		val=b;
	}
}
class compare implements Comparator<pair>{

	@Override
	public int compare(pair o1, pair o2) {
		if(o1.cost>o2.cost)
		{
			return 1;
			
		}
		else if(o1.cost<o2.cost){
			return -1;
			
		}
		else {
			return 0;
		}
	}
	
}
public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		long m=scan.nextInt();
		pair[] x=new pair[n];
		for(int i=0;i<n;i++)
		{
			x[i]=new pair(scan.nextInt(),scan.nextInt());
		}
		Arrays.sort(x,new compare());
		long cur=0;
		long total=0;
		int index=0;
		while(cur<m)
		{
			total+=(x[index].cost*Math.min(m-cur,x[index].val));
			cur+=x[index].val;
			index++;
		}
		System.out.println(total);
	}
}


Measured memory_bytes: 91536
#include<stdio.h>
#include<limits.h>
#define MAX 2000000

int size=0;
int heap[MAX];

void maxHeapInsert(int);
void heapIncreaseKey(int ,int);
void maxHeapify(int);
int heapExtractMax();
int parent(int);
int left(int);
int right(int);

int main(){

  int n,i,tmp,x;
  char com[20];

  while(1){
    scanf("%s",com);
    if(com[0] == 'i'){
      scanf("%d",&x);
      maxHeapInsert(x);
    }
    else if(com[0] == 'e' && com[1] == 'x'){
      printf("%d\n",heapExtractMax());
    }
    else if(com[0] == 'e' && com[1] == 'n')
      break;
  }
  

  return 0;
}

void maxHeapInsert(int key){

  size++;
  heap[size] = INT_MIN;
  heapIncreaseKey(size,key);
}

void heapIncreaseKey(int i, int key){

  int tmp;

  if(key < heap[i])
    printf("error\n");
  heap[i] = key;
  while(i > 1 && heap[parent(i)] < heap[i]){
    tmp = heap[i];
    heap[i] = heap[parent(i)];
    heap[parent(i)] = tmp;
    i = parent(i);
  }
}

int heapExtractMax(){

  int max;

  max = heap[1];
  heap[1] = heap[size];
  size--;
  maxHeapify(1);
  return max;
}

int parent(int i){
  return i / 2;
  }

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

void maxHeapify(int i){
    int l,r,largest,tmp;
 
    l = left(i);
    r = right(i);
    if(l <= size && heap[l] > heap[i])
        largest = l;
    else
        largest = i;
    if(r <= size && heap[r] > heap[largest])
        largest = r;
    if(largest != i){
        tmp = heap[i];
        heap[i] = heap[largest];
        heap[largest] = tmp;
        maxHeapify(largest);
    }
}

Measured memory_bytes: 4696
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
using namespace std;

#define ll long long

int main(){
    int N,ans = 0;
    cin >> N;
    for(int i = 0; i < 9; i++){
        if((N - 1) / (111 * (i + 1)))ans = i + 1;
        else break;
    }
    ans = 111 * (ans + 1);
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 100000002;

vector<int> a, b;
vector<bool> c(4005, false);

int main(){
	int n; cin >> n;
	vector<char> s(n); 
	rep(i,n){
		cin >> s[i];
		if (s[i]=='R') a.push_back(i);
		else if(s[i]=='G') b.push_back(i);
		else c[i] = true;
	} 
	int c_size = count(c.begin(), c.end(), true);
	ll ans = 0;
	for(auto x:a){
		for(auto y:b){
			int tmp = abs(x-y);
			int add = c_size;
			if(x-y>0){
				if(y-tmp>=0){
					if(c.at(y-tmp)) add --;
				}
				if(x+tmp<4003){
					if(c.at(x+tmp)) add --;
				}
			}else{
				if(x-tmp>=0){
					if(c.at(x-tmp)) add --;
			}
				if(y+tmp<4003){
					if(c.at(y+tmp)) add --;
				}
			}
			if((x+y)%2==0){
				if(c.at((x+y)/2)) add --;
			}
			ans += add;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);


int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];

ll n;
ll ans = 0;

void dfs(ll x, int a, int b, int c) {
	if (x > n)return;
	if (a && b && c)ans++;
	dfs(10 * x + 3, 1, b, c);
	dfs(10 * x + 5, a, 1, c);
	dfs(10 * x + 7, a, b, 1);
}

int main() {
	string  s;
	cin >> s;
	int q;
	cin >> q;
	string t;
	rep(qi, q) {
		int ty;
		cin >> ty;
		if (ty == 1) {
			swap(s, t);
		}
		else {
			int f;
			char c;
			cin >> f >> c;
			if (f == 1) {
				t += c;
			}
			else {
				s += c;
			}
		}
	}
	reverse(t.begin(), t.end());
	t += s;
	cout << t << endl;
	return 0;
}


Measured memory_bytes: 1128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

void no(){
  cout<<"NO"<<ENDL;
  exit(0);
}

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  ll sum=0,num;
  V<ll> v(n),dif(n);
  rep(i,0,n){
    cin>>v[i];
    sum+=v[i];
  }
  rep(i,0,n)dif[i]=v[(i+1)%n]-v[i];

  if(sum%((n*(n+1))/2ll)!=0){
    no();
  }else{
    num=sum/((n*(n+1))/2ll);
  }

  ll x,cnt=0;
  rep(i,0,n){
    x=(num-dif[i]);
    if(dif[i]>num)no();

    if((x+n*INF)%n!=0)no();
    else {
      cnt+=x/n;
    }
  }

  if(num==cnt)cout<<"YES"<<ENDL;
  else cout<<"NO"<<ENDL;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 1792
#include<stdio.h>

int main(){
   int X,Y;
   scanf("%d %d",&X,&Y);
   if(Y<2*X||4*X<Y){
      printf("No\n");
   }else if(Y%2==1){
      printf("No\n");
   }else{
      printf("Yes\n");
   }
   return 0;
}
   

Measured memory_bytes: 1584
from collections import deque
N=int(input())
color=["w"]*(N+1)
start=[None]*(N+1)
finish=[0]*(N+1)
rinsetu=[[] for i in range(N+1)]
for i in range(1,N+1):
    a=list(map(int,input().split()))
    a=a[2:]
    rinsetu[i]=a
def dfs(i,t):
    if color[i]=="w":
        t+=1
        start[i]=t
        color[i]="g"
        for j in rinsetu[i]:
            t=dfs(j,t)
        t+=1
        finish[i]=t
        return t
    else:return t
t=dfs(1,0)
while(None in start[1:]):
    a=start[1:].index(None)
    t=dfs(a+1,t)

for i in range(1,N+1):
    print("%d %d %d" %(i,start[i],finish[i]))



Measured memory_bytes: 6032
import java.util.*;
public class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] d = new int[n];
	int cout = 1;
	for(int i = 0; i < n; i++) {
		d[i] = sc.nextInt();
	}
	Arrays.sort(d);
	for(int i = 1; i < n; i++) {
		if(d[i] > d[i - 1]) {
			cout++;
		}
	}
	System.out.println(cout);
}
}

Measured memory_bytes: 23764
def q3():
    N = int(input())
    B = [int(i) for i in input().split()]
    A = [10**5]*N
    for i in range(N-1):
        if A[i] > B[i]:
            A[i] = B[i]
        if A[i+1] > B[i]:
            A[i+1] = B[i]
    print(sum(A))

if __name__ == '__main__':
    q3()


Measured memory_bytes: 3060