akhauriyash/Code-Regression huggingface dataset:
N = int(input())
a = [int(i) for i in input().split()]
n = 0
for i in a:
    n ^= i
b = 1
ans = [0]*N
for _ in range(30):
    for i,v in enumerate(a):
        ans[i] += (v & b) ^ (n & b)
    b <<= 1
print(*ans)



Measured memory_bytes: 98404
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    int K; cin >> K;

    int h[100105];
    int dp[100105];
    rep(i,100105) dp[i] = INF;
    for (int i = 0; i < N; i++){
        cin >> h[i];
    }
    // dp[i]: 足場i(0-indexed)に到達するまでのコストの最小値
    dp[0] = 0;
    // dp[0]: コストの更新が以前のdp配列の値に依存しているのでこれは必要

    for (int i = 1; i < N; i++){
        for (int j = 1; j <= K; j++){
            if (i-j >= 0)
                dp[i] = min(dp[i],dp[i-j] + abs(h[i]-h[i-j]));
        }
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
n = int(input())
p_list = list(map(int, input().split()))
p_sorted = sorted(p_list)
count = 0
for i in range(n):
    if p_list[i] != p_sorted[i]:
        count += 1
if count in [0,2]:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>


using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

void dfs(int node, int end, int d, map<int, int> &open, const vector<int> E[]) {
    if (node == end) return;
    if (open.count(node) > 0) return;

    open[node] = d++;

    REP(i, E[node].size()) {
        dfs(E[node][i], end, d, open, E);
    }
}



int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    vector<int> E[int(1e5) + 10];

    int N;
    cin >> N;

    REP(i, N-1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        E[a].pb(b);
        E[b].pb(a);
    }

    map<int, int> o_f, o_s;
    dfs(0, N-1, 0, o_f, E);
    dfs(N-1, 0, 0, o_s, E);

    debug(o_f, o_s)

    int cnt = 0;
    int cf = o_f.size(), cs = o_s.size();
    REP(i, N) {
        if (o_f.count(i) == 0 || o_s.count(i) == 0) continue;
        ++cnt;
        if(o_f[i] <= o_s[i]) ++cf;
        else ++cs;
    }

    if (cf > cs) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl;
    }

}


Measured memory_bytes: 24448
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b;
lol i[500000];
bool ans[500000];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol c=1,d=1,e=0,f=0,g=0,h=0;
  cin >>a>>b;
  ans[1]=true;
  memset(i,0,sizeof(i));
  for(int n=0;n<b;n++){
      cin >>c>>d;
      if(ans[c]) ans[d]=true;
      i[c]--,i[d]++;
      if(i[c]==-1) ans[c]=false;
  }
  for(int n=1;n<=a;n++){
      if(ans[n]) g++;
  }
  cout <<g<<'\n';
  return (0);
}


Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
using namespace std;

int n;
string str[110];

int num[110][30];

int main() {
  while (cin >> n) {
	for (int i = 0; i < n; ++i) cin >> str[i];
	memset(num, 0, sizeof(num));
	for (int i = 0; i < n; ++i) {
	  for (int j = 0; j < str[i].size(); ++j) {
		num[i][(int)(str[i][j] - 'a')]++;
	  }
	}

	string res = "";
	for (int i = 0; i < 26; ++i) {
	  char c = 'a' + i;
	  int Min = 210;
	  for (int j = 0; j < n; ++j) {
		if (Min > num[j][i]) Min = num[j][i];
	  }
	  for (int j = 0; j < Min; ++j) res += c;
	}

	cout << res << endl;
  }
}




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


int main(){
    ll a, b;
    cin >> a >> b;
    if(a == 0 || b == 0){
        cout << "Zero" << endl;
    }
    else if(a < 0 && 0 < b){
        cout << "Zero" << endl;
    }
    else if(a < 0 && b < 0){
        ll dif = abs(b) - abs(a);
        if(dif%2 == 0){
            cout << "Negative" << endl;
        }
        else cout << "Positive" << endl;
    }
    else if(0 < a && 0 < b){
        cout << "Positive" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.* ;

public class Main
{
    public static void main(String [] args) throws Exception
    {
        Scanner sc = new Scanner(System.in) ;
        PrintWriter out = new PrintWriter(System.out) ;
        char c = sc.next().charAt(0);
        if(Character.isUpperCase(c))
            out.println('A');
        else
            out.println('a');

        out.flush();
        out.close();
    }
    static class Scanner
    {
        BufferedReader br ;
        StringTokenizer st ;

        Scanner(InputStream in)
        {
            br = new BufferedReader(new InputStreamReader(in)) ;
        }

        String next() throws Exception
        {
            while(st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine()) ;
            return st.nextToken() ;
        }

        int nextInt() throws Exception { return Integer.parseInt(next()) ; }

        long nextLong() throws Exception {return Long.parseLong(next()) ; }
    }
}

Measured memory_bytes: 25348
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long int ll;

int main(void) {
    vector<ll> b;
    vector<ll> a;
    ll t_a,t_b,n,h;
    cin >> n >> h;
    for(ll i = 0;i < n;i++) {
        cin >> t_a >> t_b;
        a.push_back(t_a);
        b.push_back(t_b);
    }
    sort(a.begin(),a.end(),std::greater<ll>());
    sort(b.begin(),b.end(),std::greater<ll>());
    auto itr = b.begin();
    ll sum = 0;
    ll count = 0;
    while(sum < h && *itr > a[0]) {
        sum = sum + *itr;
        itr++;
        count++;
    }
    if(sum < h) {
        if((h-sum)%a[0] == 0)
            count = count + ((h-sum)/a[0]);
        else
            count = count + ((h-sum)/a[0]) + 1;
    }
    cout << count << endl;
    return 0;
}

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

int main(){
    int N;
    int max, min;
    long long sum;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    max = vec[0];
    min = vec[0];
    for (int i = 0; i < N; i++) {
        if (max < vec[i]) max = vec[i];
        if (min > vec[i]) min = vec[i];
        sum += vec[i];
    }
    cout << min << ' ' << max << ' ' << sum << endl;
    return 0;
}



Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N, M;
vector<int> task[112345];

int main() {
	cin >> N >> M;
	REP(i, N) {
		int A, B;
		scanf("%d %d", &A, &B);
		if (M - A >= 0) task[M - A].push_back(B);
	}
	
	int ans = 0;
	priority_queue<int> pq;
	for (int i = M - 1; i >= 0; i--) {
		for (int cur : task[i]) pq.push(cur);
		
		if (!pq.empty()) {
			ans += pq.top();
			pq.pop();
		}
	}
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;
#define int int64_t
#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 gsort(x) sort((x).begin(), (x).end(), greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define pii pair<int, int>
#define re(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

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

   int n;
   string s;
   double a, cnt = 0;
   cin >> n;

   rep(i, n)
   {
      cin >> a >> s;

      if (s == "BTC")
      {
         a = a * 380000.0;
      }
      cnt += a;
   }

   cout << cnt << '\n';
}

Measured memory_bytes: 256
from collections import deque
H,W=map(int,input().split())
white=0
s=[]
for y in range(H):
    line=input()
    white+=line.count('.')
    s.append(list(line))

q = deque([(0,0,1)])
q_append=q.append
q_popleft=q.popleft
while q:
    x,y,l=q_popleft()
    if s[y][x]!='.':
        continue
    if x==W-1 and y==H-1:
        print(white-l)
        break
    s[y][x]='*'
    for d in [(1,0),(0,1),(-1,0),(0,-1)]:
        nx, ny=(x+d[0],y+d[1])
        if 0<=nx<W and 0<=ny<H:
            q_append((nx,ny,l+1))
else:
    print(-1)

Measured memory_bytes: 39664
k, n = map(int, input().split())
li = list(map(int, input().split()))

tmp = [0] * n
for i in range(n):
    tmp[i] = li[i] - k
li = li + tmp
li.sort()
ans = 10**9
for i in range(len(li) - n+1):
    ans = min(ans, abs(li[i] - li[i + n-1]))
print(ans)


Measured memory_bytes: 26436
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
    random_device seed_gen;
    mt19937_64 rnd(seed_gen());
    uniform_int_distribution<int> dist_d(0, 364), dist_q(0, 25);

    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26)cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d)rep(j, 26)cin >> s[i][j];

    vector<int> t(d);
    rep(i, d){
        t[i] = dist_q(rnd);
    }

    int m = 1000000;

    vector<set<int>> last(26);
    rep(i, 26){
        last[i].insert(-1);
        last[i].insert(d);
    }
    rep(i, d)last[t[i]].insert(i);
    int sum = 0;
    rep(i, d){
        sum += s[i][t[i]];
        rep(j, 26){
            if(last[j].find(i) == last[j].end()){
                auto itr = lower_bound(last[j].begin(), last[j].end(), i);
                itr--;
                int day = i - *itr;
                sum -= c[j] * day;
            }
        }
    }
    int cnt = 0;
    while(true){
        int day = dist_d(rnd);
        int que = dist_q(rnd);
        int diff = 0;
        
        int cont;
        rep(j, 26){
            if(last[j].find(day) != last[j].end()){
                cont = j;
                break;
            }
        }
        diff += s[day][que] - s[day][cont];
        auto itr1 = last[cont].find(day);
        auto itr2 = lower_bound(last[que].begin(), last[que].end(), day);
        int x = *itr1;
        int y = *itr2;
        int dx = day - *(--itr1);
        int dy = day - *(--itr2);
        itr1++; itr1++;
        itr2++;
        diff -= c[cont] * dx * (*itr1 - day);
        diff += c[que] * dy * (*itr2 - day);
        if(diff > 0){
            last[cont].erase(day);
            last[que].insert(day);
            t[day] = que;
            sum += diff;
        }else{
            int p = dist_d(rnd);
            if(p < 36){
                last[cont].erase(day);
                last[que].insert(day);
                t[day] = que;
                sum += diff;
            }
        }
        cnt++;
        end = chrono::system_clock::now();
        double time = static_cast<double>(chrono::duration_cast<chrono::milliseconds>(end - start).count());
        if(time > 1985)break;
    }
    
    rep(i, d){
        cout << t[i] + 1 << endl;
    }
    
    
}

Measured memory_bytes: 3708
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iomanip>
#include <cstring>
#include <climits>
#include <cstdio>
 
#define nl '\n'
 
using namespace std;
 
long long n, m, a, x, c, p;
string s;

int main(){

    cin >> n >> m;

    bool arr[n+5];
    long long w[n+5];

    memset(w, 0, sizeof(w));

    memset(arr, false, sizeof(arr));

    for(long long i = 0; i < m; i++){
        cin >> a >> s;
        if(s == "AC"){
            arr[a-1] = true;
        } else if(s == "WA"){
            if(!(arr[a-1])){
                w[a-1]++;
            }
        }
    } 

    for(long long i = 0; i < n; i++){
        if(arr[i]){
            c++;
        }
        if(w[i] > 0 && arr[i]){
            p += w[i];
        }
    }

    cout << c << " " << p;






}
 
//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out
 
//Surely this will AC

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);

    if(a == b) return false;

    if(a < b) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

int main(){
  int n,k,l; cin >> n >> k >> l;
  UnionFind road(n), rail(n);

  rep(i,k) {
    int p,q; cin >> p >> q;
    p--; q--;
    road.merge(p,q);
  }

  rep(i,l) {
    int r,s; cin >> r >> s;
    r--; s--;
    rail.merge(r,s);
  }

  map<pii,int> C;
  rep(i,n) C[mp(road.root(i), rail.root(i))]++;
  rep(i,n) {
    cout << C[mp(road.root(i), rail.root(i))] << endl;
  }
}

Measured memory_bytes: 13568
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x&&x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS*max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x*x + y*y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;


#if 0

int main()
{
	int n;
	scanf("%d", &n);

	int ret = n;
	printf("%d\n", ret);

	return 0;
}

#elif 1

int main()
{
	int n;
	scanf("%d", &n);

	int sum = 0;
	vector <int> a;
	a.push_back(0);
	for (int i = 0; i < n; ++i)
	{
		int tmp;
		scanf("%d", &tmp);
		a.push_back(tmp);
	}
	a.push_back(0);

	for (int i = 0; i < SZ(a)-1; ++i)
	{
		sum += abs(a[i + 1] - a[i]);
	}

	for (int i = 0; i < n; ++i)
	{
		int ret = 0;
		if (a[i] <= a[i + 2])
		{
			if (INRANGE(a[i + 1], a[i], a[i + 2]))
			{
				ret = sum;
			}
			else if (a[i] > a[i + 1])
			{
				ret = - 2 * abs(a[i + 1] - a[i]) + sum;
			}
			else
			{
				ret = -2 * abs(a[i + 1] - a[i+2]) + sum;
			}
		}
		else
		{
			if (INRANGE(a[i + 1], a[i+2], a[i]))
			{
				ret = sum;
			}
			else if (a[i] < a[i + 1])
			{
				ret = -2 * abs(a[i + 1] - a[i]) + sum;
			}
			else
			{
				ret = -2 * abs(a[i + 1] - a[i + 2]) + sum;
			}

		}

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




	return 0;
}

#endif

Measured memory_bytes: 1784
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>


/* ---------- Namespace ---------- */

using namespace std;


/* ---------- Type Abbreviation ---------- */

template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

using ll = long long;
using PL = P<ll, ll>;
using PS = P<string, ll>;

using VI = V<int>;
using VVI = V<VI>;
using VL = V<ll>;
using VVL = V<VL>;
using VS = V<string>;
using VB = V<bool>;
using VVB = V<VB>;
using VPL = V<PL>;
using VPS = V<PS>;

#define fst first
#define snd second


/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)


/* ---------- container ---------- */

#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define GSORT(c) sort(ALL(c), greater<decltype((c).front())>())
#define SZ(x) (LL((x).size()))


/* ---------- repetition ---------- */

#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)

#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// Usual REP runs from 0 to n-1 (R: n to 0)
// Natural REP runs from 1 to n (R: n to 1)


/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = 3.14159265358979;
// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};


/* ---------- Short Functions ---------- */

template <typename T>
T square(T a) {
    return a * a;
}


/* ---------- Debug ---------- */
#define GET_VAR_NAME(variable) #variable

#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;
#define testP(p) cout << GET_VAR_NAME(p) << " = (" << (p).fst << ", " << (p).snd << ")" << endl;


/* ^^^^^^^^^^^^^^^ Settting Part ^^^^^^^^^^^^^^^ */

/* ---------- Variances ---------- */


/* ---------- Functions ---------- */


/* ---------- Main Function ---------- */

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

  string S;
  cin >> S;
  S[3] = '8';
  cout << S << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  int i;
  vector<int> a(n+1);
  int cnt = 0;
  for(i=1;i<=n;i++) cin >> a[i];
  for(i=1;i<=n;i++){
    if(i==a[a[i]]) cnt++;
  }
  cout << cnt/2 << "\n";
  return 0;
}

Measured memory_bytes: 640
import sys
a = []
bingo = [[0 for _ in range(3)] for _ in range(3)]
for _ in range(3):
  a_dash = list(map(int,input().split()))
  a.append(a_dash)

n = int(input())
b = []
for _ in range(n):
  b.append(int(input()))

for i in range(n):
  for j in range(3):
    for k in range(3):
      if a[j][k] == b[i]:
        bingo[j][k] = 1

if bingo[0][0] == 1 and bingo[0][1] == 1 and bingo[0][2] == 1:
  print('Yes')
  sys.exit()
elif bingo[1][0] == 1 and bingo[1][1] == 1 and bingo[1][2] == 1:
  print('Yes')
  sys.exit()
elif bingo[2][0] == 1 and bingo[2][1] == 1 and bingo[2][2] == 1:
  print('Yes')
  sys.exit()
elif bingo[0][0] == 1 and bingo[1][0] == 1 and bingo[2][0] == 1:
  print('Yes')
  sys.exit()
elif bingo[0][1] == 1 and bingo[1][1] == 1 and bingo[2][1] == 1:
  print('Yes')
  sys.exit()
elif bingo[0][2] == 1 and bingo[1][2] == 1 and bingo[2][2] == 1:
  print('Yes')
  sys.exit()
elif bingo[0][0] == 1 and bingo[1][1] == 1 and bingo[2][2] == 1:
  print('Yes')
  sys.exit()
elif bingo[0][2] == 1 and bingo[1][1] == 1 and bingo[2][0] == 1:
  print('Yes')
  sys.exit()
else:
  print('No')

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

typedef long long int ll;




int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    string s;
    cin >> s;
    if (s[2]==s[3] && s[4]==s[5]) cout << "Yes" << endl;
    else cout << "No" << endl; 
	
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int n;
	while(scanf("%d",&n) != EOF)
	{
		int i = 0;
		int a,b,c;
		a = n%10;
		b = n/10%10;
		c = n/100;
		if(a == 1)i++;
		if(b == 1)i++;
		if(c == 1)i++;
		printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
	int w,h,n;
	cin>>w>>h>>n;
	int road=0;
	int x[3],y[3];
	cin>>x[0]>>y[0];
	for(int i=0;i<n-1;i++){
	    cin>>x[1]>>y[1];
	    x[2]=x[1]-x[0];
	    y[2]=y[1]-y[0];
	    if(x[2]>0&&y[2]>0){
	        while(x[2]!=0&&y[2]!=0){
	            x[2]-=1;
	            y[2]-=1;
	            road+=1;
	        }
	        while(x[2]>0){
	            x[2]-=1;
	            road+=1;
	        }
	        while(y[2]>0){
	            y[2]-=1;
	            road+=1;
	        }
	    }else if(x[2]<0&&y[2]<0){
	        while(x[2]!=0&&y[2]!=0){
	            x[2]+=1;
	            y[2]+=1;
	            road+=1;
	        }
	        while(x[2]<0){
	            x[2]+=1;
	            road+=1;
	        }
	        while(y[2]<0){
	            y[2]+=1;
	            road+=1;
	        }
	    }else if(x[2]<=0&&y[2]>=0){
	        while(x[2]!=0){
	            x[2]+=1;
	            road+=1;
	        }
	        while(y[2]!=0){
	            y[2]-=1;
	            road+=1;
	        }
	    }else if(x[2]>=0&&y[2]<=0){
	        while(x[2]!=0){
	            x[2]-=1;
	            road+=1;
	        }
	        while(y[2]!=0){
	            y[2]+=1;
	            road+=1;
	        }
	    }
	    x[0]=x[1];
	    y[0]=y[1];
	}
	cout<<road<<endl;
}

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

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    int N; cin >> N;
    vector <int> A(N+1);
    for (int i=1; i<N+1; i++) cin >> A[i];
    
    vector <int> cnt(N+1);
    for (int i=1; i<N+1; i++) cnt[A[i]]++;
    ll sum=0;
    rep(i,N) sum+=choose2(cnt[i]);
    rep(i,N){
        ll ans=sum;
        ans-=choose2(cnt[A[i]]);
        ans+=choose2(cnt[A[i]]-1);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define pb         push_back
#define mp         make_pair
#define F          first 
#define S          second
#define mod        998244353
#define all(x)     x.begin(),x.end()    
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
ll power(ll x, ll y){ll out = 1;while (y > 0){if (y & 1) out=(out*x)%mod;y = y>>1;x = (x*x)%mod;}return out%mod;}
ll inverse(ll a){return power(a,mod-2)%mod;}
void comp() {
	ll i,j,k,n,m;
	cin>>n;
	cout<<n+n*n+n*n*n<<"\n";
}
int main() {
    speedup;
    ll i=0,t;
    t=1;
    //cin>>t;
    while(t--) {
        comp();
    }
    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n;
char s[100010];

int main()
{
	scanf("%d", &n);
	scanf("%s", s);
	
	int count = 1;
	char lastCh = s[0];

	for (int i = 1 ; i < n ; i++)
	{
		if (lastCh == s[i])
			continue;
		
		lastCh = s[i];
		count++;
	}
	
	printf("%d\n", count);
	
	return 0;
}


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

int main(){
    ll k;
    cin >> k;
    ll a=7;
    ll ans=1;
    if(k%2==0){
        cout << -1 << endl;
        return 0;
    }
    while(1){
        if(a%k==0){
            cout << ans << endl;
            return 0;
        }
        if(ans>k){
            cout << -1 << endl;
            return 0;
        }
        a = (a*10+7)%k;
        ans++;
    }
}

Measured memory_bytes: 3672
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] A = new int[N];
    int[] B = new int[N];
    int[] C = new int[N - 1];
    for (int i = 0; i < N; i++) A[i] = scanner.nextInt() - 1;
    for (int i = 0; i < N; i++) B[i] = scanner.nextInt();
    for (int i = 0; i < N - 1; i++) C[i] = scanner.nextInt();

    int score = 0;
    int last = N;
    for (int i = 0; i < N; i++) {
      score += B[A[i]];
      if (last == A[i] - 1) score += C[last];
      last = A[i];
    }
    System.out.println(score);
  }
}


Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<cmath>
#include<stdio.h>

int ipow(int a, int b){
    if(b == 0) return 1;

    int temp = a;
    for(int i = 0;i < b-1;i++){
        temp *= a;
    }

    return temp;
}

using namespace std;

int main(void){

    int d, n;
    cin >> d >> n;

    if(n == 100){
         cout << ipow(100, d) * (n+1) << endl;
    }else{
        cout << ipow(100, d) * n << endl;
    }
    

    return 0;
}

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

using namespace std;

typedef long long ll;

ll n, x;

int main()
{
    cin>>n>>x;
    ll y = x - n;
    if(x == 1 || x == 2 * n - 1)
    {
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    for(ll i = 0; i < 2 * n - 1; i++)
    {
        printf("%lld\n", (i + y + 2 * n - 1) % (2 * n - 1) + 1);
    }
    return 0;
}


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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2>
inline void chmax(T1 &a, const T2 &b)
{
    if (a < b)
    {
        a = b;
    }
}
template <class T1, class T2>
inline void chmin(T1 &a, const T2 &b)
{
    if (a > b)
    {
        a = b;
    }
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;

int main()
{
    string S, T;
    cin >> S >> T;
    ll ans = 0;
    rep(i, S.size())
    {
        if (S[i] != T[i])
        {
            ++ans;
        }
    }
    cout << ans << endl;
}

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

string to_string(string s) {
    return '"' + s + '"';
}
string to_string(char ch) {
    string s(1, ch);
    return '\'' + s + '\'';
}
string to_string(const char *s) {
    return to_string((string)s);
}
string to_string(bool b) {
    return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
 
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long int ll;
#define int ll
#define pb          push_back
#define pll         pair<int,int>
#define mll	        map<int,int>
#define F           first
#define S           second
#define lbnd(v,val) lower_bound(v.begin(),v.end(),val)
#define ubnd(v,val) upper_bound(v.begin(),v.end(),val)
#define bs(v,val)   binary_search(v.begin(),v.end(),val)
#define mp          make_pair
#define f(i,x,n)    for(int i=x;i<n;i++)
#define isup		isupper
#define islow 		islower
#define max3(a,b,c)	max(a,max(b,c))
#define endl        "\n"
#define countbits(n)	 __builtin_popcountll(n)
#define all(ar) ar.begin(), ar.end()
#define rall(ar) (ar).rbegin(), (ar).rend()
const ll mod = 1e9 + 7;
const ll inf = LLONG_MAX;
const ll N = 2e5 + 10;

typedef vector<vector<ll>> matrix;
typedef vector<ll> vll;


void solve(){
	int r,c;
	cin>>r>>c;
	char v[r][c];
	int a[r][c],dp[r][c];
	f(i,0,r){
		f(j,0,c){
			cin>>v[i][j];
			if(v[i][j]=='.'){
				a[i][j]=0;
			}else{
				a[i][j]=1;
			}
		}
	}
	// f(i,0,r){
	// 	f(j,0,c){
	// 		cout<<a[i][j];
	// 	}
	// 	cout<<endl;
	// }
	dp[0][0]=1;
	f(i,0,r){
		f(j,0,c){
			if(i==0 and j==0){
				continue;
			}
			if(a[i][j]==1){
				dp[i][j]=0;
			}else{
				int val1=0,val2=0;
				if(i>=0 and j>=1){
					val1 = (dp[i][j-1]%mod);
				}
				if(i>=1 and j>=0){
					val2 = (dp[i-1][j]%mod);
				}
				dp[i][j] = (val1+val2)%mod;
			}
		}
	}
	// cout<<endl;
	// f(i,0,r){
	// 	f(j,0,c){
	// 		cout<<dp[i][j];
	// 	}
	// 	cout<<endl;
	// }
	cout<<(dp[r-1][c-1]%mod)<<endl;
}

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

    

    int t=1;
    // cin>>t;
    while(t--){
    	solve();
    }
    return 0;
}


Measured memory_bytes: 16896
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

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

    int A, B;
    cin >> A >> B;
    cout << max(0, A-2*B) << endl;
    return 0;
}

Measured memory_bytes: 384
int main(){

  int i;
  int N;
  scanf("%d",&N);

  int H[N];
  for (i=0; i<N; i++) {
    scanf("%d",&H[i]);
  }

  int ans = 1;
  int High = H[0];
  for (i=1; i<N; i++) {
    if (H[i] >= High) {
      High = H[i];
      ans +=1;
    }
  }

  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ExplodingFreeze
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define f(i,a,b) for(int i=(a);i<(b);i++)
const int MOD=1e9+7;
using pii=std::pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

using namespace std;

int n,a[10005];
class EFlatten {
public:
	void solve(std::istream& in, std::ostream& out) {
		in >> n;

		map<int,int> mppf;
		f(i,0,n)
		{
			in >> a[i];
			int x=a[i];
			map<int,int> lppf;
			for(int j=2;j*j<=x;j++)
				while(x%j==0)
				{
					if(!lppf.count(j))
						lppf[j]=0;
					lppf[j]++;
					x/=j;
				}
			if(x>0)
				lppf[x]=1;
			for(auto v : lppf)
			{
				//out << v.first << " " << v.second << "asdf\n";
				if(!mppf.count(v.first))
					mppf[v.first]=v.second;
				mppf[v.first]=max(mppf[v.first],v.second);
			}
		}
		int lcm=1;
		for(auto val : mppf)
		{
			//out << val.first << " " << val.second << "\n";
			lcm*=mod_exp(val.first,val.second);
			if(lcm>=MOD)
				lcm%=MOD;
		}
		//out << lcm << "\n";
		int ans=0;
		f(i,0,n)
		{
			ans+=(lcm*mod_inv(a[i]))%MOD;
			if(ans>=MOD)
				ans%=MOD;
		}
		out << ans << "\n";
	}
	int mod_inv(int x)
	{
		return mod_exp(x,MOD-2);
	}
	int mod_exp(int x,int p)
	{
		int result=1;
		while(p>0)
		{
			if(p&1)
			{
				result*=x;
				if(result>=MOD)
					result%=MOD;
			}
			x*=x;
			if(x>=MOD)
				x%=MOD;
			p/=2;
		}
		return result%MOD;
	}
};


int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	EFlatten solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

#define N 8
#define FREE -1
#define NOT_FREE 1

int board[N][N],row[N],col[N],dpos[2*N-1],dneg[2*N-1];

void initialize(){
  int i,j;
  for(i=0;i<N;i++){
	for(j=0;j<N;j++){
  	board[i][j]=FREE;
	}
  }
  for(i=0;i<N;i++)row[i]=col[i]=FREE;
  for(i=0;i<2*N-1;i++)dpos[i]=dneg[i]=FREE;
}

void print_board(){
  int i,j;

  for(i=0;i<N;i++){
	for(j=0;j<N;j++){
  	if(board[i][j]==NOT_FREE){
    if(row[i]!=j)return;
  	}
	}
  }

  for(i=0;i<N;i++){
	for(j=0;j<N;j++){
  	if(row[i]!=j)printf(".");
  	else printf("Q");
	}
	printf("\n");
  }
}

void put_queen(int i){
  if(i==N){
	print_board();
	return ;
  }

  int j;
  for(j=0;j<N;j++){
	if(col[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+N-1]==NOT_FREE)continue;

	row[i]=j;
	col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
	put_queen(i+1);

	row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
}

int main(){
  int n,k,i,j;
  initialize();
  scanf("%d",&n);

  for(k=0;k<n;k++){
	scanf("%d %d",&i,&j);
	board[i][j]=NOT_FREE;
  }
  put_queen(0);

  return 0;
}



Measured memory_bytes: 2108
import java.util.Scanner;

//AtCoder Beginner Contest 118
//A	B +/- A
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();
		System.out.println((B % A) == 0 ? B + A : B - A);
	}
}


Measured memory_bytes: 23124
#include <iostream>

typedef long long ll;

using namespace std;

int main() {
	int n;
	string s;
	
	cin >> n >> s;
	
	int nr = 0, ng = 0, nb = 0;
	for(int i = 0; i < n; i++) {
		if(s.at(i) == 'R') nr++; 
		if(s.at(i) == 'G') ng++; 
		if(s.at(i) == 'B') nb++; 
	}
	
	ll ans = nr * 1ll * ng * 1ll * nb;
	for(int i = 0; i < n; i++) {
		for(int d = 1; i + 2 * d < n; d++) {
			if(!(s[i] ^ s[i + d] ^ s[i + 2 * d] ^ 'R' ^ 'G' ^ 'B')) ans--;
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 3628
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace Atcoder_Answer
{
    class Program
    {
        const Int32 mod = 1000000007;

        static void Main(string[] args)
        {
            string[] Reader = ReadLine().Split(' ');
            int N = int.Parse(Reader[0]);
            int M = int.Parse(Reader[1]);
            int NeedDays = 0;
            Reader = ReadLine().Split(' ');
            foreach (string str in Reader) NeedDays += int.Parse(str);

            if (NeedDays > N) WriteLine("-1");
            else WriteLine(N - NeedDays);
        }
    }

    public static class Extension
    {
        #region 拡張:bool
        #region キャスト関連
        public static int ToInt(this bool Bool)
        {
            if (Bool) return 1;
            else return 0;
        }

        public static string ToString(this bool Bool, string TrueStr, string FalseStr)
        {
            if (Bool) return TrueStr;
            else return FalseStr;
        }
        #endregion
        #endregion

        #region 拡張:int
        #region キャスト関連
        public static char ToAlphaBets(this int Base) => (char)Base;
        #endregion
        #endregion

        #region 拡張:char
        #region 変換関連
        public static char NextAlpha(this char Char) => (char)((Char) + 1); //次の文字を取得
        #endregion
        #endregion

        #region 拡張:int[]
        public static long Sum(this int[] Array)
        {
            int Ret = 0;
            for (int loop = 0; loop < Array.Length; loop++) Ret += Array[loop];
            return Ret;
        }
        #endregion

        #region 拡張: string
        public static string Multi(this string THIS, int Value) 
        {
            string RetValue = "";

            for (int loop = 0; loop < Value; loop++) RetValue += THIS;

            return RetValue;
        }
        #endregion

        #region 拡張: List<string>
        public static string Sum(this List<string> THIS, string Split) 
        {
            string RetValue = "";

            for (int loop = 0; loop < THIS.Count; loop++) 
            {
                RetValue += THIS[loop];
            }

            return RetValue;
        }
        #endregion
    }
}


Measured memory_bytes: 28572
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,x;
    cin>>a>>b;
    x=(a+b)/2;
    if((a+b)%2==0){
        cout<<x<<endl;
    }
    else {
        cout<<x+1<<endl;
    }
    
   
    return 0;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fordec(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define int long long
#define fi first
#define se second

const int maxn=3000;
int n;
double f[maxn][maxn]; ///f[i][j]-prob den i co j lan mat ngua

main()
{
    cout<<setprecision(10)<<fixed;
    cin>>n;
    f[0][0]=1;
    forinc(i,1,n)
    {
        double p;
        cin>>p;
        forinc(j,0,i)
        {
            f[i][j]+=f[i-1][j-1]*p;
            f[i][j]+=f[i-1][j]*(1-p);
        }
    }
    double ret=0;
    forinc(i,0,n)
    {
        int z=n-i;
        if(i>z) ret+=f[n][i];
    }
    cout<<ret;
}


Measured memory_bytes: 68864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//試してて御免

const int cm = 1 << 20;
char ci[cm];
char *cn = ci + cm;
inline char getcha() { 
	if (cn - ci == cm) { fread(ci, 1, cm, stdin); cn = ci; }
	char ret = *cn;
	cn++;
	return ret;
}
inline char getcha2() {
	char ret = *cn;
	cn++;
	return ret;
}

inline int getint() {
	if (cn - ci + 25 > cm) {
		char C = getcha();
		int A = C - '0';
		while (isdigit(C = getcha())) A = A * 10 + C - '0';
		return A;
	}
	else {
		char C = getcha2();
		int A = C - '0';
		while (isdigit(C = getcha2())) A = A * 10 + C - '0';
		return A;
	}
}

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


	int N, X;
	N = getint();
	X = getint();

	int A = 0;
	ll kotae = 0;
	rep(i, N) {
		int B = getint();
		if (A + B > X) {
			kotae += A + B - X;
			B = X - A;
		}
		A = B;
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    
    long long n;
    vector<long long> a, b, c;
    
    cin >> n;
    for(long long i = 0; i < n; i++){
        long long temp;
        cin >> temp;
        a.push_back(temp);
    }
    for(long long i = 0; i < n; i++){
        long long temp;
        cin >> temp;
        b.push_back(temp);
    }
    for(long long i = 0; i < n; i++){
        long long temp;
        cin >> temp;
        c.push_back(temp);
    }
    
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    
    long long count = 0;
    for(long long j = 0; j < n; j++){
        long long a_idx = distance(a.begin(), upper_bound(a.begin(), a.end(), b[j]-0.5));
        long long c_idx = distance(c.begin(), lower_bound(c.begin(), c.end(), b[j]+0.5));
        count += a_idx * (n - c_idx);
    }
    
    cout << count << endl;
    
    return 0;
    
}


Measured memory_bytes: 3316
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

##############################
n, m, r = map(int,input().split()) #n:頂点数　m:辺の数 r:訪れる町の数
R = list(map(int,input().split()))

d = [[float("inf") for i in range(n)] for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(m):
    x, y, z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
wa = warshall_floyd(d)

# 訪れる町の順番を順列で用意
from itertools import permutations
ptn = permutations(R)

ans = 10**19
for p in ptn:
  cost = 0
  roots = [(j-1, i-1) for i, j in zip(p, p[1:])]
  for i, j in roots:
    cost += wa[i][j]
  ans = min(ans, cost)
  
print(ans)

Measured memory_bytes: 60376
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using Deq = deque<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define pf push_front
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

Vec fac, finv;

ll PowMod(ll a, ll n){
	if(n < 0) return PowMod(PowMod(a, -n), MOD-2);
	if(n == 0) return 1;
	if(n == 1) return a;
	if(n%2 == 0) return PowMod(a*a%MOD, n/2);
	return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll inv(ll a){
	return PowMod(a, MOD - 2);
}

void init(ll n = 2e6){
	fac.resize(n+1);
	fac[0] = 1;
	repn(i, n) fac[i] = fac[i-1]*i%MOD;
	finv.resize(n+1);
	finv[n] = PowMod(fac[n], MOD-2);
	repr(i, n) finv[i] = finv[i+1]*(i+1)%MOD;
	finv[0] = 1;
}

ll combi(ll n, ll k){
	return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int main(void){
	init();
	ll n, a, b, c;
	cin >> n >> a >> b >> c;

	ll ans = 0;
	ll s = a * inv(a + b) % MOD;
	ll t = b * inv(a + b) % MOD;
	REP(k, n, 2 * n){
		ans += combi(k - 1, n - 1) * PowMod(s, n) % MOD * PowMod(t, k - n) % MOD * k % MOD;
		ans += combi(k - 1, n - 1) * PowMod(t, n) % MOD * PowMod(s, k - n) % MOD * k % MOD;
		ans %= MOD;
	}

	ans *= 100;
	ans %= MOD;
	ans *= inv(a + b);
	ans %= MOD;
	co(ans);

	return 0;
}


Measured memory_bytes: 31488
N = int(input())
XYH = [list(map(int, input().split())) for _ in range(N)]

for x0 in range(101):
    for y0 in range(101):
        a = -1
        ok = True
        for x, y, h in XYH:
            if h == 0:
                continue
            if a == -1:
                a = abs(x-x0) + abs(y-y0) + h
                continue
            if a != abs(x-x0) + abs(y-y0) + h:
                ok = False
                break
        for x, y, h in XYH:
            if h != max(a- abs(x0-x) - abs(y0-y), 0):
                ok = False
        if ok:
            print(x0, y0, a)
            break
    if ok:
        break

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

using namespace std;
using ll = long long;

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

const int INF=1e9;
const int MOD=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
    int a,b;
    while(cin>>a>>b) {
        cout<<a+b<<endl;
    }
    return 0;
}

Measured memory_bytes: 3096
def main():
	n = int(input())
	# b = int(input())
	s,t = list(map(str,input().split()))
	# A = [list(map(int, input().split())) for _ in range(H)]
	s = list(s)
	t = list(t)

	# print(s,t)
	ans = ''
	for i in range(n):
		ans += s[i] + t[i]

	print(ans)

	




if __name__ == '__main__':
	main()

Measured memory_bytes: 38484
n, m = map(int, input().split())
plist = list(map(int, input().split()))

parent = [i for i in range(n)]
height = [1 for _ in range(n)]

def root(i):
  if parent[i] != i:
    parent[i] = root(parent[i])
  return parent[i]

def union(i, j):
  pi = root(i)
  pj = root(j)
  if pi == pj:
    return
  else:
    if height[pi] < height[pj]:
      parent[pi] = pj
    elif height[pi] > height[pj]:
      parent[pj] = pi
    else:
      if pi < pj:
        parent[pj] = pi
        height[pi] += 1
      else:
        parent[pi] = pj
        height[pj] += 1

for _ in range(m):
  x, y = map(int, input().split())
  union(x-1, y-1)

ans = 0
for i, p in enumerate(plist):
  if root(i) == root(p-1):
    ans += 1

print(ans)


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

int main() {
    long long res = 0;
    long long h = 0;
    long n;
    cin >> n;
    for(int i = 0; i < n ; i++) {
        long x;
        cin >> x;
        if(x < h) {
            res += (h - x);
        } else {
            h = x;
        }
        //cout << res << ' ' << x <<  endl;
    }
    cout << res << endl;
}

Measured memory_bytes: 3616
import numpy as np

N,K = map(int,input().split())
h = np.array(list(map(int,input().split())))
dp = np.zeros(N,dtype=int)
  
for i in range(N):
  if i <= K:
    dp[i] = abs(h[0]-h[i])
  else:
    cost = min(dp[i-K:i]+abs(h[i]-h[i-K:i]))
    dp[i] = cost
print(dp[N-1])

Measured memory_bytes: 22804