akhauriyash/Code-Regression huggingface dataset:
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int x, y;
	scanf("%d%d", &x, &y);
	if (x == y && x == 1) {
		printf("%d\n", 1000000);
		return 0;
	}
	else {
		if (x == 1)x = 300000;
		else if (x == 2)x = 200000;
		else if (x == 3)x = 100000;
		else x = 0;
		if (y == 1)y = 300000;
		else if (y == 2)y = 200000;
		else if (y == 3)y = 100000;
		else y = 0;
		printf("%d\n", x + y);
	}

	Please AC;
}


Measured memory_bytes: 256
import scala.io.StdIn
object Main extends App {
  val x = StdIn.readLine.toInt
  val r = math.sqrt(x).toInt
  val res = if( r == 1) Seq(x) else
    (2 to r).map { i =>
      val e: Seq[Int] = for {
        j <- (2 to r)
        e = math.pow(i,j).toInt if(e <= x)
      } yield e
      e.max
    }
  val ans = res.max
  println(ans)
}

Measured memory_bytes: 25420
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a =new int[n];
        int no=0;
        for(int i = 0;i<n;i++){
            a[i] = sc.nextInt();
            if(a[i]%2==0){
                if(a[i]%3 ==0 ||a[i]%5 ==0){
                    
                }else{
                    no++;
                }
            }
        }
        if(no>0){
            System.out.println("DENIED");
        }else{
            System.out.println("APPROVED");
        }
    }
}

Measured memory_bytes: 35760
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


H,W=map(int,input().split())
S=[]
for i in range(H):
  S.append(list(input()))

rowGroups=UnionFind(H*W)
colGroups=UnionFind(H*W)

for i in range(H):
  for j in range(W):
    if j-1>=0 and S[i][j-1]=='.' and S[i][j]=='.':
      rowGroups.union(i*W+j,i*W+j-1)
    if i-1>=0 and S[i-1][j]=='.' and S[i][j]=='.':
      colGroups.union(i*W+j,(i-1)*W+j)
ans=0
for i in range(H):
  for j in range(W):
    ans=max(rowGroups.size(W*i+j)+colGroups.size(W*i+j)-1,ans)
print(ans)

Measured memory_bytes: 297368
#include <cstdio>

int search(int a[],int n,int key){
  int i=0;
  a[n]=key;
  while(a[i]!=key) i++;
  return i != n;
}

//key????????£??????true,???????????°false????????????

int main(){
  int n,q,key,a[10001],cnt=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++) scanf("%d",&a[i]);
  scanf("%d",&q);
  for(int j=0;j<q;j++){
    scanf("%d",&key);
    cnt+=search(a,n,key);
  }
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 1064
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

deque<int> deq;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,K;
    cin >> n >> K;
    string s;
    cin >> s;
    rep(i,n){
        if(s[i] == 'A'){
            deq.pb(0);
        }else{
            deq.pb(1);
        }
    }
    int cnt = min(4*n+K%2,K);
    int flip = 0;
    rep(i,cnt){
        if(deq[0] == flip % 2){
            deq[0] ^= 1;
        }else{
            flip++;
            deq.pop_front();
            deq.pb(flip % 2);
        }
    }
    rep(j,n){
        if(deq[j] == flip % 2){
            cout << 'A';
        }else{
            cout << 'B';
        }
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 1560
#include <stdio.h>
int main(void)
{
	int t[4];
	int n[4];
	int i;
	
	for(i=0;i<4;i++)
	scanf("%d %d",&t[i],&n[i]);
	
	for(i=0;i<4;i++){
		if(t[i]==1)
			t[i]=6000;
		if(t[i]==2)
			t[i]=4000;
		if(t[i]==3)
			t[i]=3000;
		if(t[i]==4)
			t[i]=2000;
	}
	
	for(i=0;i<4;i++)
	printf("%d\n",t[i]*n[i]);
	
	return 0;
}

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

int main() {
  int N,i,c=0;
  cin >> N;
  string s = to_string(N);
  int l = s.size();
  
  for(i=1; i<l; i++)
    if(i%2!=0)
      c+=(int)pow(10,i-1)*9;
  
  if(l%2!=0)
    c+=N-(int)pow(10,l-1)+1;
  
  cout << c << endl;
}

Measured memory_bytes: 256
class Num:
    def __init__(self, a, b):
        self.a = a
        self.b = b


N, K = map(int, input().split())
nums = []
for _ in range(N):
    a, b = map(int, input().split())
    nums.append(Num(a, b))

m = {}
num_list = []
for num in nums:
    if num.a not in m:
        num_list.append(num.a)
    m.setdefault(num.a, 0)
    m[num.a] += num.b

num_list.sort()
cnt = 0
for n in num_list:
    cnt += m[n]
    if K <= cnt:
        print(n)
        break


Measured memory_bytes: 33052
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <random>
#include <chrono>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

class UnionFind {
private:
	vector<int> data;
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }

public:
	UnionFind(int size) : data(size, -1) { }
	bool is_same(int x, int y) { return root(x) == root(y); }
	int size(int x) { return -data[root(x)]; }

	void unify(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
};

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

cout << 3*N*N;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    int k, x;
    cin >> k >> x;
    if(500*k>=x){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
aa = []
bb = []
for _ in range(n):
    a, b = map(int, readline().split())
    aa.append(a)
    bb.append(b)
aa.sort()
bb.sort()
if n % 2 == 1:
    print(bb[n // 2] - aa[n // 2] + 1)
else:
    print(bb[n // 2] + bb[n // 2 - 1] - aa[n // 2] - aa[n // 2 - 1] + 1)


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

using namespace std;

typedef long long ll;
ll r, d, x, ans;

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

	cin >> r >> d >> x;

	for (int i = 1; i <= 10; i++) {
		if (i == 1)ans = r * x - d;
		else ans = r * ans - d;
		
		cout << ans << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int N=1e5+5;
const double eps=1e-4;
typedef long long ll;
typedef pair<int,int> pii;
int a[N];
char s[N];
int vis[N];
int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",s);
    int len=strlen(s);
    for(int i=0;i<len;i++)
    {
        vis[s[i]-'a']++;
    }
    ll ans=1;
    for(int i=0;i<=26;i++)
    {
        ans=1ll*ans*(vis[i]+1)%mod;
    }
    ans%=mod;
    printf("%lld\n",ans-1ll);
    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

#define MAXV 1000000000
#define MOD 1000000007
using ll = long long;

bool operator<(const pair<int, int>& a, const pair<int, int>& b) {
	if (a.first == b.first) {
		return a.second < b.second;
	}
	return a.first < b.first;
}
int H, W; 


int main() {

	while (cin >> H >> W) {
		if (H == 0 && W == 0) break;
        vector<string> v;
		cin.ignore();
		for (int i = 0; i < H; ++i) {
			string s; 
			getline(cin, s);
			v.push_back(s);
		}

		int dp[510][510] = { 0 };
        for(int i=0; i<H; ++i){
            int x = 1;
            for(int j=W-1; j>=0; --j){
                if(v[i][j]=='.'){
                    dp[i][j] = x++;
                }else{
                    dp[i][j]=0;
                    x=1;
                }
            }
        }
        
        int maxV=0;
        for(int i=0; i<H; ++i){
            for(int j=0; j<W; ++j){
                //if(0<i && dp[i][j] == dp[i-1][j] || dp[i][j]==0) continue;
                
                int k = 1;
                int minV = dp[i][j];
                maxV = max(maxV, k*minV);
                while(i+k<H && dp[i+k][j]>0){
                    minV = min(minV, dp[i+k][j]);
                    k++;
                    maxV = max(maxV, k*minV);
                }
            }
        }
        cout << maxV << endl;
	}
	int a; cin >> a;
	int t; cin >> t;
}


Measured memory_bytes: 4308
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace Test1 {

    class ClassMain {


       
        public static void Main(String[] args) {
            string line;

            while ((line = Console.ReadLine()) != null) {
                char[] chrs = line.ToCharArray();
                if (chrs[0] == '0') { break; }
                int[] points = new int[2];
                for (int i = 1; i < chrs.Length; i++) {
                    if (chrs[i] == 'A') { points[0]++; }
                    else { points[1]++; }
                }
                if (points[0] > points[1]) { points[0]++; } else { points[1]++; }

                Console.WriteLine(points[0] + " " + points[1]);

            }
        }


    }

}

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

d,g = map(int,input().split())
p = []
s = []
for i in range(d):
    x,y = map(int,input().split())
    p.append(x)
    s.append(100*(i+1)*x+y)

ans = 10**10
for i in range(1<<(d+1)):
    cnt = 0
    res = 0
    tank = []
    for j in range(d):
        if (i>>j)&1 == 1:
            cnt += s[j]
            res += p[j]
        else:
            tank.append([100*(j+1),p[j]])
    if cnt >= g:
        ans = min(ans,res)
    else:
        while cnt < g and tank[-1][1] > 0:
            cnt += tank[-1][0]
            tank[-1][1] -= 1
            res += 1
        if cnt >= g:
            ans = min(ans,res)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
 
typedef long long ll;
#define INF 1e9
 
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> k(M);
  int s[10][10];
  vector<int> p(M);;
  REP(i, M){
    cin >> k[i];
    REP(j, k[i]){
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  REP(i, M){
    cin >> p[i];
  }
  int ans = 0;
  REP(i, 1<<N){
    int flag = 1;
    REP(j, M){
      int cnt = 0;
      REP(h, k[j]){
        cnt+=(i>>s[j][h])&1;
      }
      if(cnt % 2 != p[j]){
        flag  =0;
      }
    }
    if(flag){
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

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

int main(){
    int n,q;
    string s;
    cin >> n >> q >> s;
    s = '#' + s;
    vector<int> S(n+1,0);
    int sum=0;
    rep(i,n){
        if(s[i]=='A' && s[i+1]=='C') sum++;
        S[i] = sum;
        //cout << S[i];
    }
    //cout << endl;
    rep(i,q){
        int l,r;
        cin >> l >> r;
        l--;
        r--;
        //cout << "S[r]=S[" << r << "]=" << S[r] << " S[l]=S[" << l << "]=" << S[l] << endl;
        cout << S[r] - S[l] << endl;
    }
}

Measured memory_bytes: 1404
#include <iostream>
#include<math.h>
#include<string>
#include<iomanip>
#include<limits>

using namespace std;

int main()
{
int a,b; cin>>a>>b;
if((a+b)%3==0||a%3==0||b%3==0) cout<<"Possible";
else cout<<"Impossible";
return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    int a, b;
    cin >> a >> b;
    if(a<1 || a>9 || b<1 || b>9) cout << "-1" << endl;
    else cout << a*b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int N, K, R, S, P;
  cin >> N >> K >> R >> S >> P;

  string T;
  cin >> T;

  int answer = 0;

  for (int i = 0; i < N; i++) {
    if (T[i] == 'r') {
      answer += P;
    } else if (T[i] == 's') {
      answer += R;
    } else {
      answer += S;
    }
  }

  for (int i = 0; i < N; i++) {
    if (K <= i) {
      if (T[i - K] == T[i]) {
        if (T[i] == 'r') {
          answer -= P;  
        } else if (T[i] == 's') {
          answer -= R; 
        } else {
          answer -= S; 
        }
        T[i] = 'z';
      }
    }
  }

  cout << answer << endl;
 
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>
using namespace std;

int main() {
    int a[3][3] = { {} }, n, b[10];
    for (int i = 0; i < 3;++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> a[i][j];
        }
    }
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    int c[3][3] = { {} };
    for (int i = 0; i < 3;++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < n;++k) {
                if (a[i][j] == b[k]) c[i][j] = 1;
            }
        }
    }
    int x = 0;
    for (int i = 0; i < 3; ++i) {
        if (c[i][0] == 1 && c[i][1] == 1 && c[i][2] == 1) {
             x += 1;
        }
    }
    for (int i = 0; i < 3; ++i) {
        if (c[1][i] == 1 && c[2][i] == 1 && c[0][i] == 1) {
            x += 1;
        }
    }
    if ((c[1][1] == 1 && c[2][2] == 1 && c[0][0] == 1) || (c[0][2] == 1 && c[1][1] == 1 && c[2][0] == 1)) {
            x += 1;
    }
    if (x == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

   

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n, m, T;
int dp[310];
vector<int> akuma[310]; // ©ª©gªfromÆÈÁÄ¢éedgeÌindexÌW
int edgeCount[1100];
int edgeTo[1100];
vector<int> edgeFrom[1100];

void Push(priority_queue<pair<int, int> > &que, int index) {
  int e = edgeFrom[index].size();
  vector<int> costs(e);
  REP(i, e) {
    costs[i] = dp[edgeFrom[index][i]];
  }
  sort(costs.rbegin(), costs.rend());
  int ans = 0;
  REP(i, e) {
    ans = max(ans, costs[i] + i);
  }
  que.push(make_pair(-ans, edgeTo[index]));
}

int main() {
  while (scanf("%d %d %d", &n, &m, &T) > 0) {
    // initialize
    T--;
    MEMSET(dp, -1);
    REP(i, 310) { akuma[i].clear(); }
    REP(i, 1100) { edgeFrom[i].clear(); }
    MEMSET(edgeCount, 0);
    MEMSET(edgeTo, -1);
    priority_queue<pair<int, int> > que;

    // input
    REP(i, n) {
      int leaf;
      int v = scanf("%d", &leaf);
      assert(v == 1);
      if (leaf == 1) {
        que.push(make_pair(-1, i));
      }
    }
    REP(i, m) {
      int k, to;
      int v = scanf("%d %d", &to, &k);
      assert(v == 2);
      to--;
      edgeTo[i] = to;
      edgeCount[i] = k;
      REP(j, k) {
        int from;
        int v = scanf("%d", &from);
        assert(v == 1);
        from--;
        edgeFrom[i].push_back(from);
        akuma[from].push_back(i);
      }
    }

    // process
    while (!que.empty()) {
      int node = que.top().second;
      int cost = -que.top().first;
      que.pop();
      if (dp[node] != -1) { continue; }
      dp[node] = cost;
      FORIT(it, akuma[node]) {
        edgeCount[*it]--;
        assert(edgeCount[*it] >= 0);
        if (edgeCount[*it] == 0) {
          Push(que, *it);
        }
      }
    }
    //REP(i, n) {
    //  cout << dp[i] << " ";
    //}
    //cout << endl;
    printf("%d\n", dp[T]);
  }
}

Measured memory_bytes: 0
N = int(input())
S = [0] *  N
A,B = [0]*N,[0]*N
for i in range(N):
    A[i],B[i] = map(int,input().split(" "))
    S[i] = (A[i]+B[i],i)
S.sort(reverse=True)

ans = 0
for i in range(N):
    if i % 2 == 0:
        ans += A[S[i][1]]
    else:
        ans -= B[S[i][1]]

print(ans)

Measured memory_bytes: 52896
t_ = x_ = y_ = flag = 0
for i in range(input()):
    t, x, y = map(int, raw_input().split())
    flag += t - t_ < abs(x - x_) + abs(y - y_) or (x + y + t + x_ + y_ + t_) % 2
    t_, x_, y_ = t, x, y

print ["Yes", "No"][flag > 0]

Measured memory_bytes: 5764
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.15f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto s = RD!string;

	char inv(char c)
	{
		return c == 'S' ? 'W' : 'S';
	}
	bool same(char ox, char sw)
	{
		return !((ox == 'o') ^ (sw == 'S'));
	}

	char[] ans;
	(){
	foreach (i; 0..2)
	{
		foreach (j; 0..2)
		{
			auto t = new char[](N);
			t[0] = i == 0 ? 'S' : 'W';
			t[1] = j == 0 ? 'S' : 'W';
			foreach (k, c; s[0..$-1])
			{
				if (k == 0) continue;
				auto l = (N + k - 1) % N;
				auto r = (k + 1) % N;
				t[r]   = same(c, t[k]) ? t[l] : inv(t[l]);
			}
			bool ok;
			if (same(s[$-1], t[$-1]))
				ok = t[$-2] == t[0];
			else
				ok = t[$-2] != t[0];
			if (ok)
			{
				if (same(s[0], t[0]))
					ok = t[$-1] == t[1];
				else
					ok = t[$-1] != t[1];
				if (ok)
				{
					ans = t;
					return;
				}
			}
		}
	}}();

	if (ans.empty)
		writeln(-1);
	else
		writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 1020
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, int> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = { 0, 1, 0, -1 };



int main() {

	int h;
	int a;
	cin >> h >> a;
	int cnt = 0;
	while (h > 0) {
		h = h - a;
		cnt++;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
import sys

def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,K = MI()
A = LI()
A.sort()


def f(n):  # Anが必要か否か
    B = [0] + [A[i] for i in range(N) if i != n]
    dp = [0]*K  # dp[i][j] = B1~Biを用いてjを作れるか(メモリ節約のため工夫してる)
    dp[0] = 1
    for i in range(1,N):
        b = B[i]
        for j in range(K-1,-1,-1):
            if j >= b:
                dp[j] |= dp[j-b]
            else:
                dp[j] = dp[j]
    if sum(dp[j] for j in range(max(K-A[n],0),K)) != 0:
        return True
    else:
        return False


left = -1  # 不必要
right = N  # 必要
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid

print(right)


Measured memory_bytes: 74376
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String,
    }

    let y: i32 = (&s[0..4]).parse().unwrap();
    let m: i32 = (&s[5..7]).parse().unwrap();
    let d: i32 = (&s[8..10]).parse().unwrap();

    if y <= 2018 {
        println!("Heisei");
    } else if m <= 3 || m == 4 && d <= 30 {
        println!("Heisei");
    } else {
        println!("TBD");
    }

}


Measured memory_bytes: 4352
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;

ll binary_search(function<bool(ll)> func, ll start, ll end) {
    /*      func:int ->bool
            returns smallest int x where func(x) evaluates to true, searches in [start,end), it is assumed the values are false, .. , false, true ...
             */
    if (end <= start) {   return end;  }   // has to be here, otherwise func(end-1) in next line could be a problem
    if (!func(end-1)) {  return end;  }
    while (end-start>1) {
        ll mid = (start+end)/2;
        if (func(mid)) {  end = mid;  } else { start = mid;   }
    }
    if (func(start)) {  return start;  } else {  return end;   }
};


template<class T>
T fastpower(T a, long long n) {  // n must be >= 1
  if (n==0) {return 1;}
  if (n % 2 == 0) {  
      T halfpower = fastpower<T>(a, n/2);
      return (halfpower*halfpower) % modd;
  } else {
      if (n == 1) {  return a; } else {  
          T halfpower = fastpower<T>(a, n/2);
          return (((halfpower*halfpower)%modd)*a)%modd;
      }
  }
};


int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
 
//    auto start = chrono::steady_clock::now();
  
//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n); readstring(s);

        map<char,int> freq;
        for(char c : s) {
            freq[c]++;
        }

        ll ret = 1;
        for(auto x : freq) {
            ret *= (1+x.second);
            ret = ret % modd;
        }
        cout << ret-1 << endl;

    }
 
//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;
 
    return 0;
}

Measured memory_bytes: 3728
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x;
		x = sc.nextInt();
		sc.close();
		
		if(x == 7 || x == 5 || x == 3)System.out.println("YES");
		else System.out.println("NO");
	}

}


Measured memory_bytes: 22612
S = input()

string = 'abcdefghijklmnopqrstuvwxyz'
r_string = 'zyxwvutsrqponmlkjihgfedcba'

string = list(string)

if len(S)<26:
    
    for i in range(len(S)):
        for j in range(len(string)):
            if S[i]==string[j]:
                del string[j]
                break
    
    print(S+string[0])
elif S==r_string:
    print(-1)
else:
    for i in range(24, -1, -1):
        if S[i]<S[i+1]:
            end = i
            break
        
    now = S[end+1]
    th = S[end]
    
    for i in range(end+2, 26):
        if th<S[i]:
            if S[i]<now:
                now = S[i]
                
    print(S[0:end]+now)
        

Measured memory_bytes: 3064
program ABC177B
    implicit none
    integer(8)::i,j,ans=100000000,calc
    character(1000)::S,T
    read*,S,T
    do i=1,len_trim(S)-len_trim(T)+1
        calc=0
        do j=1,len_trim(T)
            if(S(i+j-1:i+j-1)/=T(j:j))calc=calc+1
        end do
        ans=min(ans,calc)
    end do
    print'(i0)',ans
end program ABC177B

Measured memory_bytes: 2900
#include <iostream>
#include <algorithm>

int main(int argc, char **argv)
{
    int A, B, C;
    std::cin >> A >> B >> C;

    int ap = A % 2;
    int bp = B % 2;
    int cp = C % 2;

    int count = 0;

    if(ap == bp && bp == cp){
        // pass
    }else{
        count++;
        if(ap == bp){
            A++; B++;
        }else if(ap == cp){
            A++; C++;
        }else{ // bp == cp
            B++; C++;
        }
    }
    
    int max = std::max(std::max(A, B), C);
    count += (max - A) / 2;
    count += (max - B) / 2;
    count += (max - C) / 2;

    std::cout << count << std::endl;
}


Measured memory_bytes: 256
// 物极必反

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9;
const double PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug(){
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

long long h[N], dp[N];

void solve(){
    long long n; cin >> n;

    for(long long i = 1; i <= n; i++){
        cin >> h[i];
        dp[i] = INF;
    }

    dp[1] = 0;
    for(long long i = 2; i <= n; i++){
        if(i - 1 >= 1) dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if(i - 2 >= 1) dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[n];
}

int main(){
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long q = 1; // cin >> q;

    while(q--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 5180
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    vector<int> l(n);
    for (int i = 0; i < n; i++) cin >> l[i];

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (l[i] == l[j]) continue;
            for (int k = j + 1; k < n; k++) {
                if (l[k] == l[i] || l[k] == l[j]) continue;
                if (l[i] + l[j] > l[k] && abs(l[i] - l[j]) < l[k]) {
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
import java.util.*;
import java.math.BigInteger;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        
        if(str.equals("keyence")){
            System.out.println("YES");
        }else if(str.matches(".*"+"keyence") || str.matches("k"+".*"+"eyence")
        || str.matches("ke"+".*"+"yence") || str.matches("key"+".*"+"ence")
        || str.matches("keye"+".*"+"nce") || str.matches("keyen"+".*"+"ce")
        || str.matches("keyenc"+".*"+"e") || str.matches("keyence"+".*")){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
 ll N;
  cin >>N;
 if(N%2!=0) {
   cout<<0<<endl;
 }
  else {
    ll ans=0;
     N /= 10;
    ans +=N;
    while(N){
      N /= 5;
      ans += N;
    }
    cout << ans <<endl;
  }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007
#define iP pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define pb push_back
#define inf 1e15
#define mod1 998244353
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
int power(int x,int y){
    int res=1;
    while(y>0){
        if(y&1)res=(res*x)%mod1;
        x=(x*x)%mod1;
        y/=2;
    }
    return res;
}
// int mulmod(int x,int y){
//     int res=0ll;
//     while(y>0){
//         if(y&1)res=(res+x)%mod;
//         x=(2*x)%mod;
//         y/=2ll;
//     }
//     return res%mod;
// }
// bool prime[1000001];
// int spf[2000005];
// int fact[1000001];
// // vector<int> p;
// void sieve(){
//     for(int i=2;i<2000005;i++){spf[i]=i;}
//     for (int i=2;i<2000005;i++){
//         if (spf[i]==i){  
//             // p.push_back(i);
//             for (int j=i*i;j<2000005;j+=i)
//                 spf[j]=i;
//         }
//     }
// }
// int phi(int n){
// 	//phi(p)=p-1;
// 	//phi(p^k)=(p^(k-1))(p-1);
// 	//phi(ab)=phi(a)*phi(b) if a and b are co-prime;
// 	//phi(ab)=phi(a)*phi(b)*(gcd(a,b))/(phi(gcd(a,b));
// 	//a^(phi(b)) is equivalent to 1 mod b if a and b are co-prime;
// 	int result=n;
// 	for(int i=2;i*i<=n;i++){
// 		if(n%i==0){
// 			while(n%i==0)
// 				n/=i;
// 			result-=(result)/i;
// 		}
// 	}
// 	if(n>1)
// 		result-=result/n;
// 	return result;
// }
// void bfs(vector<int> adj[],int src,int n,vector<int> &dist){
// 	priority_queue<iP,vector<iP>,greater<iP>> pq;
// 	pq.push({0,src});
// 	dist[src]=0;
// 	vector<bool> vis(n+1,false);
// 	while(!pq.empty()){
// 		int a=pq.top().second;
// 		pq.pop();
// 		if(vis[a])continue;
// 		vis[a]=1;
// 		for(auto it: adj[a]){
// 		    if(dist[it]>dist[a]+1){
// 				pq.push({dist[it],it});
// 				dist[it]=dist[a]+1;
// 		    }
// 		}
// 	}
// }
void dfs(vector<int> adj[],int x,vector<bool> &vis){
    vis[x]=1;
    for(auto it: adj[x]){
        if(!vis[it]){
            dfs(adj,it,vis);
        }
    }
}
int32_t main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);cout<<fixed;
    int a,b,c;
    cin>>a>>b>>c;
    if(c>a+b&&4ll*a*b+2ll*a*c+2ll*b*c<c*c+a*a+b*b+2ll*a*b)cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;


// 68 11 55

int gcd(int a, int b) {
    while (b != 0) {
        auto na = a % b;
        a = b;
        b = na;
    }
    return a;
}


void oneCase() {
    int n, m;
    cin >> n >> m;
    map<int ,int> c;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        if (min(a, b) == 1 || max(a, b) == n) {
            ++c[a];
            ++c[b];
        }

    }
    for (auto p : c) {
        if (p.first != 1 && p.first != n) {
            if (p.second > 1) {
                cout << "POSSIBLE" << "\n";
                return;
            }
        }
    }
    cout << "IMPOSSIBLE" << "\n";

}


int main() {
    int t = 1;
//    cin >> t;
    while (t--) {
       oneCase();
    }

    return 0;
}

ll fact(ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        res = (res * n) % mod;
        --n;
    }
    return res;
}


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

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

    long long n, k;
    cin >> n >> k;

    vector<long long> cnt(k, 0);
    for(int i = 1; i <= n; i++){
        cnt[i % k]++;
    }

    long long ans = 0;
    for(int i = 0; i < k; i++){
        if(i * 2 % k != 0) continue;
        ans += cnt[i] * cnt[i] * cnt[i];
        if(k % 2) break;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[100010];
    rep(i, N) cin >> A[i];
    sort(A, A + N, greater<int>());
    ll a = 0, b = 0;
    rep(i, N) {
        if (A[i] == A[i + 1]) {
            if(a == 0) a = A[i];
            else b = A[i];
            i++;
        }
        if(b > 0) break;
    }
    cout << a * b << endl;
    


    return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Main{
    public static void main(String[] args) throws Exception {
        int num;
        int[] x = new int[10001];
        int a = 1;
        int i = 0;
        int c = 0;
        int d =0;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));    
        for (i=0;a!=0;i++) {
            x[i] = Integer.parseInt(br.readLine());
            a = x[i];
        }
        i--;
        while(i!=0){
            c++;
            System.out.println("Case "+c+": "+x[d]);
            d++;
            i--;
        }
    }
}


Measured memory_bytes: 32916
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint,dijkstra

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n,x;
        cin>>n>>x;
        vl A(n);
        rep(i,n)cin>>A[i];
        ll res=0;
        rep(i,n-1){
            if(A[i]+A[i+1]<=x)continue;
            res+=A[i]+A[i+1]-x;
            A[i+1]=max(x-A[i],0LL);
        }
        cout<<res<<endl;
    }

Measured memory_bytes: 1024
import numpy as np

H, W = list(map(int, input().split()))
S = np.array([list(input()) for _ in range(H)]) == '.'
ups = np.zeros((H, W), dtype=int)
downs = np.zeros((H, W), dtype=int)
rights = np.zeros((H, W), dtype=int)
lefts = np.zeros((H, W), dtype=int)

for h in range(1, H):
  ups[h] = (ups[h-1]+1)*S[h-1]
  downs[H-h-1] = (downs[H-h]+1)*S[H-h]
for w in range(1, W):
  lefts[:, w] = (lefts[:, w-1]+1) * S[:, w-1]
  rights[:, W-w-1] = (rights[:, W-w]+1) * S[:, W-w]
  
print(((ups+downs+rights+lefts)*S).max()+1)  

Measured memory_bytes: 219816
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;

const int N = 111;
int n;
int W;
int w[N], v[N];
ll dp[N][100010];

int main() {

	scanf("%d%d", &n, &W);
	for(int i = 1; i <= n; i++) 
		scanf("%d%d", w + i, v + i);
	
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= W; j++){
			if(w[i] > j) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
		}
	}

	cout << dp[n][W] << endl;

	return 0;
}

Measured memory_bytes: 79360
#include<cstdio>
#define min(a,b) (a<b?a:b)
#define abs(x)   (x>0?(x):-(x))
int n,x,y,ans[2333];
int main(){
	scanf("%d%d%d",&n,&x,&y);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++){
			int far=min(j-i,min(abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1));
			ans[far]++;
		}
	for(int i=1;i<n;i++)printf("%d\n",ans[i]);
}

Measured memory_bytes: 128
Scanf.scanf "%d %s" (fun n s ->
    let count s1 s2 =
        let hist s =
            let h = Array.make 26 false in
            String.iter (fun c -> h.(int_of_char c - 97) <- true) s;
            h

        in
        let f1 = hist s1 in
        let f2 = hist s2 in
        let rec loop i acc =
            if i = 26 then acc else
                let acc = if f1.(i) && f2.(i) then acc + 1 else acc in
                loop (i + 1) acc
        in
        loop 0 0
    in
    let rec loop i acc =
        if i = n then acc else
            let acc = max acc (count (String.sub s 0 i) (String.sub s i (n - i))) in
            loop (i + 1) acc
    in
    loop 0 0 |> Printf.printf "%d\n"
)

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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;

const int M = 200200;

int h, w;
int n;
vector<int> b[M];

bool blocked(int x, int y) {
  return binary_search(all(b[y]), x);
}

int lb(int x, int y) {
  return *lower_bound(all(b[y]), x);
}

void read() {
  cin >> h >> w >> n;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    b[y].push_back(x);
  }
}

void kill() {
  for (int i = 0; i < w; ++i) {
    b[i].push_back(h);
    sort(all(b[i]));
  }

  int curx = 0, cury = 0;
  int ans = h;
  while (true) {
    if (blocked(curx + 1, cury)) {
      ans = min(ans, curx + 1);
      break;
    }
    
    ++curx;
    ans = min(ans, lb(curx, cury));
    if (cury + 1 < w && !blocked(curx, cury + 1))
      ++cury;
  }

  cout << ans << "\n";
}

int main() {
#ifdef LOCAL
  assert(freopen("d.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  read();
  kill();
}



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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n;
  string s;
  cin >> n >> s;
  vector<int> W(n, 0), E(n, 0);
  for(int i = 0; i < n - 1; ++i)
  {
    W[i + 1] = W[i] + (s[i] == 'W');
  }
  int ans = W.back();
  for(int i = n - 1; i >= 1; --i)
  {
    E[i - 1] = E[i] + (s[i] == 'E');
    ans = min(ans, W[i - 1] + E[i - 1]);
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

#define all(x) (x).begin(),(x).end()

#define MOD 1000000007

using namespace std;

int main(){
	int n, m;	cin >> n >> m;
	int h[n];	for( int i = 0; i < n; i++ )	cin >> h[i];
	vector< pair<int, int> > way(m);
	for( int i = 0; i < m; i++ ){
		cin >> way[i].first >> way[i].second;
		way[i].first--;
		way[i].second--;
	}
	bool good[n];
	int ans = 0;

	for( int i = 0; i < n; i++ )	good[i] = true;

	sort( all(way) );

	for( int i = 0; i < m; i++ ){
		if( h[way[i].first] <= h[way[i].second]  ){
			good[way[i].first] = false;
		}
		if( h[way[i].first] >= h[way[i].second]  ){
			good[way[i].second] = false;
		}
	}

	for( int i = 0; i < n; i++ ){
		if( good[i] )	ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4580
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long INF = 1e9 + 7;
using namespace std;
map<int, int> mp;
int main()
{
	int n, m;
	cin >> n >> m;
	const int nmmax = 50;
	char a[nmmax][nmmax], b[nmmax][nmmax];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			cin >> b[i][j];
		}
	}
	bool exist = false;
	for (int li = 0; li < n; li++) {
		for (int lj = 0; lj < n; lj++) {
			if (li + m - 1 >= n || lj + m - 1 >= n) continue;
			bool match = true;
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < m; j++) {
					if (a[li + i][lj + j] != b[i][j]) match = false;
				}
			}
			if (match) exist = true;
		}
	}
	if (exist) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256