akhauriyash/Code-Regression huggingface dataset:
/*
[ ( ^ _ ^ ) ]
*/

import java.io.*;
import java.util.*;


class Main {
    int INF = (int)1e9;
    long MOD = 1000000007;
    
    boolean go(int n) {
        String s = ""+n;
        String r = new StringBuilder(s).reverse().toString();
        return s.equals(r);
    }

    void solve(InputReader in, PrintWriter out) throws IOException {
        int a = in.nextInt();
        int b = in.nextInt();
        int rs = 0;
        for(int i=a; i<=b; i++) {
            if(go(i)) rs++;
        }
        out.println(rs);
    }
    
    
    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new Main().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }
    
    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
    
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 39036
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
int a,b,c;
cin>>a>>b>>c;
if(a==5&&b==5&&c==7){
    cout<<"YES";
}
else if(a==5&&b==7&&c==5){
    cout<<"YES";
}
else if(a==7&&b==5&&c==5){
    cout<<"YES";
}
else
    cout<<"NO";



    return 0;
}


Measured memory_bytes: 3612
N, P = map(int, input().split())
A = list(map(int, input().split()))
MAX_C = 100

def comb_dp():
    """
    dpテーブルを作ってnCkを計算.
    modのpは素数でなくてよい.
    1 <= k <= n <= 2000程度
    O(MAX_C ** 2).
    """
    Com = [[0]*MAX_C for _ in range(MAX_C)]
    Com[0][0] = 1
    for i in range(1, MAX_C):
        # iC0 = 1
        Com[i][0] = 1
        for j in range(1, MAX_C):
            # iCj = i-1_C_j-1 + i-1_C_j mod p
            Com[i][j] = (Com[i-1][j-1] + Com[i-1][j])
        
    return Com
Com = comb_dp()
if P == 0:
    is_even = [A[i]%2==0 for i in range(N)]
    num_e = is_even.count(True)
    num_o = N-num_e
    tmp1 = 0
    tmp2 = 0
    for i in range(0, num_e+1):
        tmp1 += Com[num_e][i]
    for i in range(0, num_o+1, 2):
        tmp2 += Com[num_o][i]
    print(tmp1*tmp2)
else:
    is_even = [A[i]%2==0 for i in range(N)]
    num_e = is_even.count(True)
    num_o = N-num_e
    tmp1 = 0
    tmp2 = 0
    for i in range(0, num_e+1):
        tmp1 += Com[num_e][i]
    for i in range(1, num_o+1, 2):
        tmp2 += Com[num_o][i]
    print(tmp1*tmp2)


Measured memory_bytes: 67500
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> order(n);
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        order.at(a - 1) = i + 1;
    }
    for (int i = 0; i < n; ++i) {
        cout << order.at(i) << " ";
    }
    cout << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string str; cin >> str;
	bool flag = true;
	if(str.length() % 2) flag = false;
	for(int i=0; i<str.length(); i++) {
		if(str[i] == 'h' && str[i+1] == 'i') {
			i++;
			continue;
		}
		flag = false;
	}
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--)
using namespace std;
int dp[3004][3004];
string s1,s2,res;
int rec(int i,int j){
	if(i==0 || j==0)
		return 0;
	if(dp[i][j] != -1)
		return dp[i][j];
	if(s1[i-1] == s2[j-1])
	{
		dp[i][j] = rec(i-1,j-1)+1;
	}
	else{
		dp[i][j] = max(rec(i,j-1),rec(i-1,j));
	}
	return dp[i][j];
}
void backtrack(int i,int j){
	if(i==0 || j==0)
		return;
	if(s1[i-1] == s2[j-1]){
		res.pb(s1[i-1]);
		backtrack(i-1,j-1);
	}
	else{
		if(dp[i-1][j] > dp[i][j-1]){
			backtrack(i-1,j);
		}
		else
			backtrack(i,j-1);
	}
}
int32_t main(){

	FASTIO;
	cin >> s1 >> s2;
	mem(dp,-1);
	int n = s1.length();
	int m = s2.length();
	int ans = rec(n,m);
	backtrack(n,m);
	reverse(all(res));
	cout << res << endl;
    return 0;

}

Measured memory_bytes: 71040
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))


int main() {
  int N;
  cin >> N;
  int K;
  cin >> K;
  int trees[100100];
  m0(trees);
  rep(i,N) {
    cin >> trees[i];
  }
  sort(trees, trees + N);
  int ans = INF;
  rep(i, N-(K-1)){
    if (ans > trees[i+K-1] - trees[i]) {
      ans = trees[i + K-1] - trees[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define pb push_back
#define fr first
#define se second
#define ll long long
using namespace std;
    const ll N = 1e3 + 7;
ll used[N];
ll n , x , y , m ,a,  mx, cnt , b , ans ;
string s , s1 , s2;
deque<int>v;
int main(){
    cin >> n >> m;
    while(n){
        cnt ++;
        n /= m;
    }
    cout << cnt;
}


Measured memory_bytes: 256
# ?§£??¬?????????

n = gets.to_i
a, b = gets.split.map(&:to_i)
c = gets.to_i
d = []
n.times { d << gets.to_i }
d.sort! { |a, b| b - a }

cospa = 0
n.times do |i|
  cospa = [cospa, (c + d[0..i].inject(:+)) / (a + b * (i+1))].max
end

puts cospa.floor

Measured memory_bytes: 8564
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
MOD = 10 ** 9 + 7
dp = [[0] * (M + 1) for i in range(N + 1)]
s = [[0] * (M + 1) for i in range(N + 1)]
dp[0][0] = 1

for i in range(N):
    for j in range(M):
        if S[i] == T[j]:
            dp[i + 1][j + 1] = s[i][j] + 1
            dp[i + 1][j + 1] %= MOD
        s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + dp[i + 1][j + 1]
        s[i + 1][j + 1] %= MOD

ans = 0
for i in range(N + 1):
    for j in range(M + 1):
        ans += dp[i][j]
        ans %= MOD
print(ans)

Measured memory_bytes: 105180
function Main(input) {
    input = input.split('\n');
    var N = parseInt(input[0], 10);
    var hList = input[1].split(' ');
    var max = 0;
    var count = 0;
    for (var i = 0; i < N; i++) {
        var h = parseInt(hList[i], 10);
        if(h >= max) {
            count++
            max = h;
        }
    }
    console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

int main() {
  long long h;
  cin >> h;
  // vector<long long> nums;
  long long count = 0;
  while (true) {
    ++count;
    h /= 2;
    if (h == 0) break;
  }
  long long ans = 1; 
  for(int i=0; i<count; ++i){
    ans *= 2;
  }
  cout << ans -1 << endl;
}


Measured memory_bytes: 256
#include <bits//stdc++.h>
using namespace std;
#define int long long
#define rep(i,n,k) for(int i=n;i<k;i++)
#define P make_pair
#define F first
#define S second
#define M LLONG_MAX
signed main(void){
    int n,m,ans,p,q;
    ans=0;
    string s,s1,s2;
    vector<int> v;
    double w;
   cin>>w;
   cout<<2*w*3.141592<<endl;
   
}


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

int main()
{
	int a,b;
	int s,l;

	while(1){
		cin >> a >> b;
		if(a >= 1 && a <= 100 && b >= 1 && b<=100)
			break;
	}

	s = a*b;
	l = a*2+b*2;

	cout<< s << " " << l << endl;

	return 0;
}

Measured memory_bytes: 1164
N = (int)(input())
T = list(map(lambda x: int(x), input().split()))
V = list(map(lambda x: int(x), input().split()))

dp = [[-float('inf')]*(101) for _ in range(N+1)]
V.append(0)

dp[0][0] = 1

for i in range(N):
    for v in range(V[i]+1):
        for vv in range(V[i]+1):
            past_dist = dp[i][v]
            if 2*V[i]-v-vv <= T[i]:
                a = V[i]-v
                b = V[i]-vv
                c = (v+V[i])*a/2 + V[i]*(T[i] - a - b) + (vv+V[i])*b/2
                dp[i+1][vv] = max(dp[i+1][vv], c+past_dist)
            elif T[i] >= abs(vv-v):
                ta = (vv-v+T[i])/2
                tb = (T[i]+v-vv)/2
                c = (2*v+ta)*ta/2 + (vv+v+ta)*tb/2
                dp[i+1][vv] = max(dp[i+1][vv], c+past_dist)

print(dp[N][0]-1)


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<< "\n"


int main(){
    while(1){
        int x,y;
        cin >> x >> y;
        if(x==0&&y==0)break;
        if(y<x)swap(x,y);
        cout << x << " " << y << endl;
    }
    return 0;
}



Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
typedef tuple<unsigned, unsigned, unsigned> T;

template<unsigned mod>
struct RollingHash {
    vector<unsigned> hashed, power;

    inline unsigned mul(unsigned a, unsigned b) const {
        unsigned long long x = (unsigned long long) a * b;
        unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
        asm("divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (mod));
        return m;
    }

    RollingHash(const string &s, unsigned base = 10007) {
        int sz = (int) s.size();
        hashed.assign(sz + 1, 0);
        power.assign(sz + 1, 0);
        power[0] = 1;
        for (int i = 0; i < sz; i++) {
            power[i + 1] = mul(power[i], base);
            hashed[i + 1] = mul(hashed[i], base) + s[i];
            if (hashed[i + 1] >= mod) hashed[i + 1] -= mod;
        }
    }

    unsigned get(int l, int r) const {
        unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
        if (ret >= mod) ret -= mod;
        return ret;
    }

    unsigned connect(unsigned h1, int h2, int h2len) const {
        unsigned ret = mul(h1, power[h2len]) + h2;
        if (ret >= mod) ret -= mod;
        return ret;
    }

    int LCP(const RollingHash<mod> &b, int l1, int r1, int l2, int r2) {
        int len = min(r1 - l1, r2 - l2);
        int low = -1, high = len + 1;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid;
            else high = mid;
        }
        return (low);
    }
};

using RH1 = RollingHash<1000000007>;
using RH2 = RollingHash<998244353>;
using RH3 = RollingHash<10007>;

bool comp(const string &lh, const string &rh) {
    return lh.length() > rh.length();
}

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++)cin >> s[i];
    sort(s.begin(), s.end(), comp);

    long long ret = 0;
    map<T, vector<int>> ma;
    for (int i = 0; i < n; i++) {
        RH1 x(s[i]);
        RH2 y(s[i]);
        RH3 z(s[i]);

        T suffix = {x.get(1, s[i].size()), y.get(1, s[i].size()), z.get(1, s[i].size())};
        if (ma.find(suffix) != ma.end()) {
            ret += ma[suffix][s[i][0] - 'a'];
        }

        vector<bool> found(26);
        for (int j = 0; j <= s[i].size(); j++) {
            if (j > 0) {
                T now = {x.get(j, s[i].size()), y.get(j, s[i].size()), z.get(j, s[i].size())};
                if (ma.find(now) == ma.end())ma[now] = vector<int>(26);
                for (int k = 0; k < 26; k++) {
                    ma[now][k] += found[k] ? 1 : 0;
                }
            }
            if (j < s[i].size())found[s[i][j] - 'a'] = true;
        }
    }

    cout << ret << endl;
}

Measured memory_bytes: 209244
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
long long A;
long long B;
long long K;
long long t;
int main(){
  rd(A);
  rd(B);
  rd(K);
  t =min_L(A, K);
  A -= t;
  K -= t;
  t =min_L(B, K);
  B -= t;
  wt_L(A);
  wt_L(' ');
  wt_L(B);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200119-1

// --- original code ---
// ll A, B, K, t;
// {
//   rd(A,B,K);
//   t = min(A,K);
//   A -= t;
//   K -= t;
//   t = min(B,K);
//   B -= t;
//   wt(A,B);
// }


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main()
{
	ios_base::sync_with_stdio(false);   
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll n,p;
	cin>>n>>p;
	string s;
	cin>>s;
	//ll n = s.length();
	ll ans = 0;
	if(p==2||p==5)
	{
		for(ll i=0;i<n;i++)
		{
			if((s[i]-'0')%p == 0)
			{
				ans+= i+1;
			}
		}
		cout<<ans<<endl;
		return 0;
	}
	else
	{
		ll mod = p;
		map<ll,ll>mp;
		mp[0] = 1;
		ll curr = 0;
		for(ll i=0;i<n;i++)
		{
			curr*=10;
			curr += s[i]-'0';
			curr%=mod;
			ll temp = ((binpow(10,n-i-1,mod))*(curr))%mod;
			mp[temp]++;
			
		}
		for(ll i=0;i<p;i++)
		{
			ans += (mp[i])*(mp[i]-1)/2;
		}
		cout<<ans<<endl;
		
	}
}

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

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

    int A, B, C; cin >> A >> B >> C;
    if (B < C) swap(B, C);
    if (A < B) swap(A, B);
    cout << A * 10 + B + C << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

	int a,b;
	
	scanf ("%d %d",&a,&b);
	
	if(a>b){
	
		printf ("a > b\n");
		
	}else if(a<b){
	
		printf ("a < b\n");
		
	}else{
	
		printf ("a == b\n");
		
	}
	
	return 0;
	
}


Measured memory_bytes: 2044
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n+1) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

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

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for(double i = 1;i <= 50000;++i){
		if(int(i * 1.08) == n) return cout << i << '\n',0;
	}
	cout << ":(\n";
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

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

void die() {
  cout << "IMPOSSIBLE\n";
  exit(0);
}

int n;
pii dp[1005];
int desire[1005];
vector<int> children[1005];

void solve() {
  cin >> n;
  for(int i = 2; i <= n; i++) {
    int par;
    cin >> par;
    children[par].push_back(i);
  }
  for(int i = 1; i <= n; i++) {
    cin >> desire[i];
  }
  for(int i = n; i >= 1; i--) {
    set<int> valid;
    int total = 0;
    valid.insert(0);
    for(int out: children[i]) {
      set<int> nvalid;
      for(int out2: valid) {
        if(out2 + dp[out].first <= desire[i]) {
          nvalid.insert(out2 + dp[out].first);
        }
        if(out2 + dp[out].second <= desire[i]) {
          nvalid.insert(out2 + dp[out].second);
        }
      }
      total += dp[out].first;
      total += dp[out].second;
      valid = nvalid;
    }
    if(valid.empty()) die();
    int cand = *valid.rbegin();
    int other = total - cand;
    dp[i] = {desire[i], other};
  }
  cout << "POSSIBLE\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 640
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            var agg = CumulativeItems(A).ToArray();
            var answer = (long)2 * 1e9 + 1;
            for (var i = 1; i < agg.Length - 1; i++)
            {
                var x = agg[i] - agg[0];
                var y = agg[agg.Length - 1] - agg[i];
                answer = Math.Min(answer, Math.Abs(x - y));
            }
            Console.WriteLine(answer);
        }

        public static IEnumerable<long> CumulativeItems(IEnumerable<long> items)
        {
            var arr = items.ToArray();
            var ret = new long[arr.Length + 1];
            for (var i = 0; i < arr.Length; i++) ret[i + 1] = arr[i] + ret[i];
            return ret;
        }
    }
}


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

int main(){
  int n, m, x, y;
  std::cin >> n >> m;
  vector<bool> ans(n, 0);
  ans[0] = 1;
  vector<int> num(n, 1);
  for (int i = 0; i < m; i++) {
    std::cin >> x >> y;
    x--, y--;
    ans[y] = ans[y] or ans[x];
    num[x]--, num[y]++;
    if(num[x] == 0)ans[x] = false;
  }
  int hoge = 0;
  for (int i = 0; i < n; i++) {
    hoge += ans[i];
  }
  // for (int i = 0; i < n; i++) {
  //   std::cout << num[i] << std::endl;
  // }
  std::cout << hoge << std::endl;
  return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

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

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    double T, A;

    cin >> N;
    cin >> T >> A;

    vector<double> H(N);

    REP(i, N){
        cin >> H[i];
    }

    ll ans = 0;
    double minT = 1000.0;

    REP(i, N){
        double temp = T - H[i]*0.006;
        if(abs(temp-A) < minT){
            minT = abs(temp-A);
            ans = i + 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
//I have to work harder than anyone else to make it! I’ll never catch up otherwise…
//Don’t worry about what other people think. Hold your head up high and plunge forward.

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

#define P pair<int,int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define str std::string 
#define pb push_back
#define itrt(yo) for(auto x:yo){std::cout<<x<<nl;} 
#define vec(x) std::vector<x> 
#define nl '\n'
#define F first
#define S second
#define ll long long int
#define ALL(x) x.begin(),x.end() 
#define BN(x) x.begin()
#define ED(x) x.end()
#define MAP_traverse(it,x)  for(auto it = BN(x); it!= ED(x); it++)
#define PI 3.14159265358979323846264338327950L
const unsigned int M = 1000000007;




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

	if (a>8 || b>8)
	{
		cout<<":(";
	}else
	{
		cout<<"Yay!";
		
	}
	
	
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k;
    string s;
    cin >> k >> s;
    if (s.size()<=k) cout << s << "\n";
    else cout << s.substr(0,k) + "...\n";
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s1,s2;
	cin>>s1;
	ll k;
	cin>>k;
	s2=s1;
	s1='A'+s1;
	s2=s1[s1.size()-1]+s2;
	ll set1,set2;
	set1=set2=0;
	for(ll i=1;i<=s1.size();i++){
		if(s1[i]==s1[i-1]){
			set1++;
			s1[i]='A';
		}
	}
	for(ll i=1;i<=s2.size();i++){
		if(s2[i]==s2[i-1]){
			set2++;
			s2[i]='A';
		}
	}
	bool ch=false;
	bool ch2=false;
	if(s1[1]==s1[s1.size()-1]){
		ch=true;
		if(s2[s2.size()-1]!='A'){
			ch2=true;
		}
	}
	if(ch==false){
		cout<< k*set1;
	}
	else if(ch2!=true){
		cout << k/2*(set1+set2)+k%2*set1<<endl;
	}
	else{
		cout << 1*set1+(k-1)*set2;
	}
	//cout << set2;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (int argc, char **argv)
{
	int a,b;

	scanf("%d%d",&a,&b);

	if(a + b >= 10)
	{
		printf("error\n");
	}

	else
	{
		printf("%d\n",a + b);
	}

	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>

typedef struct node_{
    int key;
    int height;
    struct node_ *parent;
}node;

node *nd;

node* top(node* nd){
    while(true){
        if(nd->parent==NULL)break;
        nd = nd->parent;
    }
    return nd;
}

void unite(int x, int y){
    node* a = top(nd+x);
    node* b = top(nd+y);
    if(a==b)return;
    if(a->height < b->height){
        a->parent = b;
    }else{
        b->parent = a;
        if(a->height == b->height){
            a->height++;
        }
    }
    return;
}

int same(int x, int y){
    node* a = top(nd+x);
    node* b = top(nd+y);
    if(a==b)return 1;
    else return 0;
}

int main(){
    int i,n,q,x,y,com;
    scanf("%d %d",&n,&q);
    nd = (node *)malloc(sizeof(node)*n);

    for(i=0;i<n;i++){
        nd[i].key = i;
        nd[i].height = 1;
        nd[i].parent = NULL;
    }

    for(i=0;i<q;i++){
        scanf("%d %d %d",&com,&x,&y);
        switch(com){
        case 0://unite
            unite(x,y);
            break;
        case 1://same
            printf("%d\n",same(x,y));
            break;
        default:
            perror("error\n");
            return -1;
            break;
        }
    }
    return 0;
}



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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<pii, int> para;
const int inf = 1e9 + 7;
const int maxN = 1e6 + 5;

int n, arr[maxN];
map<int, int> pos;

int main() {
	scanf("%d",&n);
	REP(i, n) {
		scanf("%d",&arr[i]);
		pos[arr[i]] = i;
	}
	sort(arr, arr + n);
	int ans = 0;
	REP(i, n) {
		//printf("%d %d %d\n",arr[i], i, pos[arr[i]]);
		if (abs(pos[arr[i]] - i) % 2 == 1) {
			ans++;
			//printf("%d %d %d\n",arr[i], i, pos[arr[i]]);
		}
	}
	printf("%d",ans/2);
	return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  string s;
  int res=0;
  cin >> s;

  auto a=find(s.begin(), s.end(), 'A');
  auto z=find(a, s.end(), 'Z');
  auto prev_z=z;
  while(z!=s.end()){
    prev_z=z;
    z=find(prev_z+1, s.end(), 'Z');
  }

  res = (int)(prev_z-a)+1;

  cout << res << endl;
}



Measured memory_bytes: 640
#include<stdio.h>

int judgement(int);

int main(){

  int n,a[10000],i,c=0;

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

  for(i=0;i<n;i++){
    c=c+judgement(a[i]); //関数を用いる。素数であった場合、cに1が加算される。

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

  return 0;
}

int judgement(int an){ //値が素数であるかどうかを判断するための関数。

  int j;
  if(an==1) return 0;
  if(an==2) return 1;
  if(an%2==0)return 0;

  for(j=3;j*j<=an;j++){
    if(an%j==0) return 0;
  }
  return 1;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, ans = 0;
  cin >> N;
  vector<int>p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  sort(p.begin(),p.end());
  for (int i = 0; i < N-1; i++) {
    ans += p.at(i);
  }
  ans += p.at(N-1)/2;
  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


  
int main(){
  
  int n;
  cin>>n;
  string s;
  map<string,long long> mp;
  vector<char> temp;
  REP(i,n){
    cin>>s;
    temp.clear();
    REP(j,10){
      temp.push_back(s[j]);
    }
    sort(temp.begin(),temp.end());
    s = "";
    REP(j,10){
      s += temp[j];
    }
    mp[s]++;
  }
  long long ans=0;
  for(auto p:mp){
    ans += (p.second*(p.second-1))/2;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 12800
// In The Name Of Allah //
#include <bits/stdc++.h>
#define pb emplace_back
#define inf (int)1e9
#define ff first
#define ss second
#define ll long long
#define sp(n) cout << setprecision(n) << fixed
#define hellcat ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define give(x) cout << #x << " " << x << endl
#define debug cout << "dddd" << '\n'
#define debarr(a, n) for (int i = 0; i < n; ++i) cout << a[i] << ' '; cout << endl
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

#define int long long

template <class S, class T>
inline S smax(S &l, T r) {
  return l = max(l, (S)r);
}
template <class S, class T>
inline bool smin(S &l, T r) {
  return l = min(l, (S)r);
}

const int MAXN = 2e5 + 10;
int dp[MAXN], n, s, mx = 0;
pair<int, int> p[MAXN];

int32_t main () {
    hellcat;

  cin >> n >> s;
  for (int i = 1; i <= n; i++)
      cin >> p[i].first >> p[i].second;
  for (int i = 1; i <= n; i++)
        for (int j = s; j >= p[i].first; j--)
           dp[j] = max(dp[j] , dp[j - p[i].first] + p[i].second);
   
	cout << dp[s] << '\n';

	return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
	int n;
	string s;
	cin >> s;
	if(s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I'){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
	return 0;
}



Measured memory_bytes: 256
use strict;
use POSIX qw(floor ceil);
use Math::BigInt;
use Math::BigFloat;

my ($A, $B, $C, $D) = split(/ /, <>);
#my ($A, $B, $C, $D) = (10, 40, 6, 8);

if($B <= $A) {
    print "0";
    exit 0;
}

$A = Math::BigFloat->new($A);
$B = Math::BigFloat->new($B);

my $y = 1 + $B - $A;

my $Ca = ($A / $C)->bceil();
my $Cb = ($B / $C)->bfloor();
my $Da = ($A / $D)->bceil();
my $Db = ($B / $D)->bfloor();

my $CD = 0 + sprintf("%ld", Math::BigInt::blcm($C, $D));
my $CDa = ($A / $CD)->bceil();
my $CDb = ($B / $CD)->bfloor();

# print STDERR "$A $B $C $D\n";
# print STDERR "$y ($Ca $Cb) ($Da $Db) $CD ($CDa $CDb)\n";

$y = $y - (1 + $Cb -$Ca) - (1 + $Db - $Da) + (1 + $CDb - $CDa);
print $y;


Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
int a[1001],N;

bool check(int n){
  for(int i=0;i<N;i++){
    int sum=a[i],j=i+1;
    while(j<N&&sum<n)sum=sum*10+a[j++];
    if(sum==n) return 0;
  }
  return 1;
}

int main(){
  cin>>N;
  for(int i=0;i<N;i++) cin>>a[i];
  int i=0;
  while(!check(i++));
  cout <<i-1<<endl;
  return 0;
}

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  FAST();

  int n;
  cin >> n;
  vector<double> arr(n);
  REP(i, 0, n)  cin >> arr[i];

  double ans = 0;
  REP(i, 0, n)
  ans += 1/arr[i];

  ans = 1/ans;

  printf("%.6lf\n", ans);


  return 0;
}


Measured memory_bytes: 256
from collections import Counter 
N = int(input())
a = list(map(int, input().split()))
A = Counter(a)
Q = int(input())

ans = sum(a)
for _ in range(Q):
    B, C = map(int, input().split())
    if B in A.keys():
        if C in A.keys():
            A[C] += A[B]
        else:
            A[C] = A[B]
        ans += (C-B)*A[B]
        A[B] = 0
    print(ans)

Measured memory_bytes: 21440
// AtCoder Regular Contest 081
// D - Coloring Dominoes

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;


const int MAX_N = 52;
const ll MOD = 1000000007;

int N;
string s[2];
ll dp[2][MAX_N];

int main() {

    cin >> N;
    cin >> s[0];
    cin >> s[1];

    // init
    if (s[0][0] == s[1][0]) {
        dp[0][0] = 3;
        dp[1][0] = 0;
    } else {
        dp[0][0] = 3;
        dp[1][0] = 6;
    }

    for (int i = 1; i < N; i++) {
        if (s[0][i] == s[1][i]) {
            dp[0][i] = ((2 * dp[0][i - 1]) % MOD + dp[1][i - 1] % MOD) % MOD;
            dp[1][i] = 0;
        } else if (s[0][i] != s[0][i - 1] && s[1][i] != s[1][i - 1]) {
            dp[0][i] = 0;
            dp[1][i] = ((2 * dp[0][i - 1]) % MOD + (3 * dp[1][i - 1]) % MOD) % MOD;
        } else {
            dp[0][i] = 0;
            dp[1][i] = dp[1][i - 1];
        }
    }

    ll ans = (dp[0][N - 1] + dp[1][N - 1]) % MOD;
    cout << ans << endl;

    return 0;

}





Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)9e18;
int node[51] = {};


int root(int n){
	if (node[n] == n) return n;
	else return node[n] = root(node[n]);
}

void unite(int n ,int m){
	if (n > m) swap(n, m);
	n = root(n);
	m = root(m);
	if (n == m) return;
	else node[m] = n;
}

int main() {
	int N, M;
	cin >> N >> M;
	
	VP ab(M);
	REP(i,M){
		int a, b;
		cin >> a >> b;
		ab[i].first = a;
		ab[i].second = b;
	}

	int bridge = 0;
	REP(i, M) {
		FOR(j, 1, N + 1) node[j] = j;

		int a, b;
		REP(j, M) {
			if (j == i) {
				a = ab[j].first;
				b = ab[j].second;
				continue;
			}
			unite(ab[j].first, ab[j].second);
		}
		if (root(a) != root(b))bridge++;
	}
	cout << bridge << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()

if N%2==0: 
    ans = 2*sum(A[N//2+1:N]) + A[N//2]
    ans -= 2*sum(A[0:N//2-1]) + A[N//2-1]

    print(ans)
else :
    lsl = 2*sum(A[N//2+2:N]) + A[N//2+1] + A[N//2]
    lsl -= 2*sum(A[0:N//2])

    sls = 2*sum(A[N//2+1:N])
    sls -= 2*sum(A[0:N//2-1]) + A[N//2-1] + A[N//2]

    print(max(lsl, sls))

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define MOD 1000000007

int main()
{

    ll tc;
    cin >> tc;
    ll ans=1;
    for(ll i=1;i<=tc;i++)
    {

        ans=(ans*i)%MOD;
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	string s;
	cin >> s;
	bool a = false;
	if (s.size() >= 4) {
		if (s.substr(0, 4) == "YAKI") {
			a = true;
		}
	}
	cout << (a ? "Yes" : "No") << endl;
}	


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

int main() {
    int H, N;
    cin >> H >> N;
    int A[N], sum=0;
    for (int i=0; i<N; i++) cin >> A[i];
    for (int i=0; i<N; i++) sum+=A[i];
    if (sum >= H) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <algorithm>
 
using namespace std;
 
int main(){
 int A;
 int B;
 int C;
 cin >> A>>B>>C;
 if(A==B&&B==C){
 cout<<"No"<<endl;
 return 0;
 }
 else if(A==B){
 cout<<"Yes"<<endl;
 }
 else if(A==C) {
 cout<<"Yes"<<endl;
 }
 else if(B==C){
 cout<<"Yes"<<endl;
 }
 else{
 cout<<"No"<<endl;
 }
}


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

A = [0] * N

for i in range(N):
  if i == 0:
    A[i] = B[i]
  elif i == N-1:
    A[i] = B[i-1]
  else:
    A[i] = min(B[i-1], B[i])
    
print(sum(A))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool comp1(pair<int,int> &a,pair<int,int> &b)
{
    return a.second>b.second;
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    char a;
    cin>>a;
    if(a>=65 && a<=90) cout<<"A";
    else cout<<"a";
}

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

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i=0; i<n; i++){
        cin >> s.at(i);
    }
    int i=0;
    while(i<n){
        for(int j=i+1; j<n; j++){
         if(s.at(i) == s.at(j)){
             cout << "No" << endl;
             return 0;
         }
        }
        i += 1;
    }
    for(int k=1; k<n; k++){
        if(s.at(k).at(0) != s.at(k-1).at((int)s.at(k-1).size()-1)){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}



Measured memory_bytes: 3588
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		long a = parseLong(sc.next());
		long b = parseLong(sc.next());
		long c = parseLong(sc.next());
		sc.close();
		long cnt=0;
		while(a%2==0&&b%2==0&&c%2==0) {
			if(a==b&&b==c) {
				cnt=-1;
				break;
			}
			long a2 = a /2;
			long b2 = b /2;
			long c2 = c /2;
			a = b2 + c2;
			b = c2 + a2;
			c = a2 + b2;
			cnt++;
		}
		out.println(cnt);
	}
}


Measured memory_bytes: 22740
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int ans=0;
	int N;
	cin>>N;
	
	vint p(N);
	
	for (int i = 0; i < N; i++) {
		cin>>p[i];
	}
	
	for (int i = 1; i < N-1; i++) {
		if((p[i-1]<p[i]&&p[i]<p[i+1])||(p[i-1]>p[i]&&p[i]>p[i+1])){
			ans++;
		}
	}
	
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define INF (1<<29)
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=1e5;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int X;
bool table[1001]; //べきならtrue 1ori
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    
    cin>>X;
    table[1]=true;
    
    for(int i=2;i<40;i++){
        for(int j=2;pow(i,j)<=1000;j++){ //iをj乗する
            int x=pow(i,j);
            if(pow(i,j)>1000) break;
            table[x]=true;
        }
    }
    
    for(int i=X;i>=1;i--){
        if(table[i]) {
            cout<<i<<"\n";
            break;
        }
    }
    
    return 0;
}


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

public class Main {

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

	static void solve() {
		int cnt = 0;
		double sum = 0, sumc = 0;
		while (in.hasNext()) {
			cnt++;
			String[] s = in.next().split(",");
			sumc += Double.parseDouble(s[1]);
			sum += Double.parseDouble(s[0])*Double.parseDouble(s[1]);
		}
		out.println((int)sum);
		out.println((int)Math.round(sumc/cnt));
	}

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

		solve();
		out.flush();

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

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

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vi a(n);
    rep(i,n) cin>>a[i];
    sort(all(a));
    cout<<a[n-1]-a[0]<<endl;
    return 0;
}


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

#define MX_N 100000
#define MX   1000000000

int n;
int tab[MX_N+5][5];
long long dp[MX_N+5][3];

int main( )
{
    cin>>n;
    for( int i=0; i<n; i++ )
        cin>>tab[i][0]>>tab[i][1]>>tab[i][2];

    dp[0][0]=tab[0][0];
    dp[0][1]=tab[0][1];
    dp[0][2]=tab[0][2];
    for( int i=1; i<n; i++ )
    {
        dp[i][0]=max( dp[i-1][1], dp[i-1][2] )+tab[i][0];
        dp[i][1]=max( dp[i-1][0], dp[i-1][2] )+tab[i][1];
        dp[i][2]=max( dp[i-1][0], dp[i-1][1] )+tab[i][2];
    }
    cout<<max( dp[n-1][0], max( dp[n-1][1], dp[n-1][2] ) )<<"\n";


}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DEC(i, a, b) for (int i = (a); i > (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;
const ll LINF = (int) 1e18;
const double EPS = 1e-9;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;

  int ans = 0;
  int ans_ = 0;
  vector<int> v;
  REP(i, n) {
    int a_;
    cin >> a_;
    for (auto e: v) {
      if (e > a_) ++ans_;
    }
    v.pb(a_);
  }
  ans += (ans_ * k) % MOD;

  int rec = 0;
  for (auto e: v) {
    for (auto f: v) {
      if (f > e) ++rec;
    }
  }

  ans += rec * ((k - 1) * (k) / 2 % MOD) % MOD;

  ans %= MOD;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
k = gets.to_i
x = gets.chomp.split(" ").map(&:to_i)

ans = 0
x.each do |x_current|
    if x_current < (x_current - k).abs
        ans += x_current * 2
    else
        ans += (x_current - k).abs * 2
    end
end

puts ans

Measured memory_bytes: 1788
from collections import deque
import sys
#sys.setrecursionlimit(200000)
#input = sys.stdin.readline
#n = int(input())
n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 1
mod = 10**9+7
kitate = set()
kiyoko = set()
for i in range(n*m,-1,-1):
    tate = -1
    yoko = -1
    for j in range(n):
        if a[j] == i:
            tate = j
            break
    for j in range(m):
        if b[j] == i:
            yoko = j
            break
    if tate >=0 and yoko >=0:
        kitate.add(tate)
        kiyoko.add(yoko)
    elif tate == -1 and yoko>=0:
        ans *= len(kitate)
        ans %=mod
        kiyoko.add(yoko)
    elif yoko == -1 and tate >= 0:
        ans *= len(kiyoko)
        ans %= mod
        kitate.add(tate)
    else:
        stock = len(kitate)*len(kiyoko)-((n*m)-i)
        ans *= stock
        ans %= mod
        if stock<=0:
            print(0)
            exit()
    if len(kiyoko) == m and len(kitate) == n:
        break
for j in range(1,i):
    ans *= j
    ans %= mod
print(ans)

Measured memory_bytes: 44124
#vector    
def pushBack(a, x):
    a.append(x)
def randomAccess(a, p):
    print(a[p])
def popBack(a):
    a = a[:-1]
    return a
q = int(input())
a = []
for _ in range(q):
    b = list(map(int, input().split()))
    if b[0] == 0:
        pushBack(a, b[1])
    elif b[0] == 1:
        randomAccess(a, b[1])
    else:
        a = popBack(a)


Measured memory_bytes: 13368