akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;


template <class Abel> struct BIT {
    const Abel UNITY_SUM = 0;                       // to be set
    vector<Abel> dat;
    
    /* [1, n] */
    BIT(int n) : dat(n + 1, UNITY_SUM) { }
    void init(int n) { dat.assign(n + 1, UNITY_SUM); }
    
    /* a is 1-indexed */
    inline void add(int a, Abel x) {
        for (int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }
    
    /* [1, a], a is 1-indexed */
    inline Abel sum(int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[i];
        return res;
    }
    
    /* [a, b), a and b are 1-indexed */
    inline Abel sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat.size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int n, q; cin >> n >> q;
    vector<int> c(n);
    rep(i,n) cin >> c[i];

    vector<int> ids(q);
    vector<P> p;
    rep(i,q) {
        int l, r; 
        cin >> l >> r;
        --l, --r;
        ids[i] = i;
        p.emplace_back(l,r);
    }
    sort(ids.begin(), ids.end(), [&](int x, int y){
        return p[x].second < p[y].second;
    });
    //sort(p.begin(), p.end(), [](P x, P y){
    //    return x.second < y.second;
    //});
    BIT<int> bit(n);
    map<int, int> last;
    int now = 0;
    vector<int> ans(q);
    rep(i,q) {
        P x = p[ids[i]];
        while (now <= x.second) {
            int ci = c[now];
            auto itr = last.find(ci);
            if (itr != last.end()) {
                int pre = last[ci];
                last[ci] = now;
                bit.add(pre+1,-1);
                bit.add(now+1,1);

            } else {
                last[ci] = now;
                bit.add(now+1,1);
            }
            ++now;
        }  
        int cnt = bit.sum(x.first+1,x.second+2);
        ans[ids[i]] = cnt;
    }
    rep(i,q) cout << ans[i] <<  endl;
    return 0;
}

Measured memory_bytes: 38976
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<set>
#include<vector>
using namespace std;

int solve(){
  int n, m; cin >> n >> m;
  string s(n, '0');
  vector<bool> check(n, false);
  bool ok = true;
  for(int i=0; i<m; i++){
    int d;  cin >> d;
    char c; cin >> c;
    d--;
    if(check[d])  {
      if(s[d]!=c) ok = false;
    }
    else{
      s[d] = c;
      check[d]=true;
    }
  }
  if(n>1 && s[0]=='0' && !check[0]) s[0] = '1';
  else if(n>1 && s[0] == '0') ok = false;

  if(ok)  cout << s << endl;
  else  cout << -1 << endl;
}

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


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

struct edge{ int from,to,cost; };

int rnk[100],par[100];

void init(int n){
	for(int i = 0;i < n;i++){
		rnk[i] = 0;
		par[i] = i;
	}
}

int find(int x){
	if(par[x] == x) return x;
	return par[x] = find(par[x]);
}

void unite(int a,int b){
	a = find(a);
	b = find(b);
	if(a == b) return;
	if(rnk[a] > rnk[b]){
		par[b] = a;
	}else{
		par[a] = b;
		if(rnk[a] == rnk[b]) rnk[b]++;
	}
}

bool comp(const edge& e1,const edge& e2){
	return e1.cost < e2.cost;
}

int main(){
	int n,m;
	while(1){
		vector<edge> es;
		int sum = 0;
		cin >> n >> m;
		if(!n) break;
		init(n);
		for(int i = 0;i < m;i++){
			int a,b,c;
			cin >> a >> b >> c;
			es.push_back({a,b,c});
		}
		sort(es.begin(),es.end(),comp);
		for(int i = 0;i < m;i++){
			if(find(es[i].to) != find(es[i].from)){
				unite(es[i].to,es[i].from);
				sum += es[i].cost;
			}
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 3000
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);++i)
#define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i)
#define rep1(i,n) for(int (i)=1;(i)<=(n);++i)
#define rrep1(i,n) for(int (i)=(n);(i)>=1;--i)
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef pair<int,int> P;
typedef pair<long long,long long> LP;
typedef double db;
using namespace std;
ll H,W;
vector<ll> Y;
vector<ll> X;
ll mod = (1e+9) + 7;
ll row[1001],col[1001];

int main(){
  cin>>H>>W;
  ll x;
  rep(i,H){
    cin>>x;
    Y.pb(-x);
  }
  rep(i,W){
    cin>>x;
    X.pb(-x);
  }
  sort(X.begin(),X.end());
  rep(i,X.size()) X[i]=-X[i];
  sort(Y.begin(),Y.end());
  rep(i,Y.size()) Y[i]=-Y[i];
  rep(i,X.size()-1) if(X[i]==X[i+1]){
    puts("0");
    return 0;
  }
  rep(i,Y.size()-1) if(Y[i]==Y[i+1]){
    puts("0");
    return 0;
  }
  ll ans = 1LL,
  y = 0,
  cnt = 0,z = 1;
  x = 0;
  if(X[0]!=H*W || Y[0]!=H*W){
    en: ;
    puts("0");
    return 0;
  }
  rrep1(n,H*W){
    while(y<H-1 && Y[y+1]>=n){
      y++;
      z += x+1;
    }
    while(x<W-1 && X[x+1]>=n){
      x++;
      z += y+1;
    }
    //cout<<n<<" "<<z<<" "<<y<<" "<<x<<" "<<ans<<endl;
    if(z<=0) goto en;
    if(Y[y]==n && X[x]==n){
      z--;
    }
    else if(Y[y]==n){
      ans = (ans*(x+1))%mod;
      z--;
    }
    else if(X[x]==n){
      ans = (ans*(y+1))%mod;
      z--;
    }
    else{
      ans = (ans*z) % mod;
      z--;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
/**
 *  author: Behradm
 *  Created: 2020.07.11 15:27:05
 *  In The Name Of God
**/
#include <bits/stdc++.h>

using namespace std;

int f(int n) {
  long long res = 0;
  for (int x = 1; x * x <= n; x++) {
    for (int y = 1; y * y <= n; y++) {
      for (int z = 1; z * z <= n; z++) {
        if (x * x + y * y + z * z + x * y + x * z + y * z > n)
          break;
        if (x * x + y * y + z * z + x * y + x * z + y * z == n)
          res += 1;
      }
    }
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    printf("%d\n", f(i));

  cerr << clock() << '\n';
  return 0;
}


Measured memory_bytes: 3760
using System;
using System.Linq;


namespace ATC
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] Input = Console.ReadLine().Split(' ');

            int N = int.Parse(Input[0])-1;//都市の数
            int M = int.Parse(Input[1])-1;//橋の数

            var CityA = new int[M+1];
            var CityB = new int[M+1];
            var CityN = new int[N+1];


            for(int h = 0; h<=M; h++)
            {
                string[] input = Console.ReadLine().Split(' ');
                CityA[h] = System.Int32.Parse(input[0]);
                CityB[h] = System.Int32.Parse(input[1]);
            }

            for(int i = 0; i<=N; i++)
            {
                CityN[i] = 0;

                for(int j = 0; j<= M; j++)
                {
                    if(CityB[j] == i+1)
                    {
                        CityN[i]++;
                    }
                    if (CityA[j] == i + 1)
                    {
                        CityN[i]++;
                    }

                }

                Console.WriteLine(CityN[i]);
            }
        }
    }
}

Measured memory_bytes: 11092
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static PrintWriter pw = ContestWriter.getInstance("out.txt", true);
	public static void main(String[] args) throws IOException {
		while(solve());
		pw.flush();
	}
	public static int n = 0;
	public static int i = 0;
	public static String[] token;
	public static int[] level;
	public static boolean solve() {
		n = sc.nextInt();
		if (n == 0) return false;
		i = 0;
		token = new String[n];
		level = new int[n];
		for(int i=0;i<n;i++) {
			token[i] = sc.next();
			for(int j=0;j<token[i].length();j++) {
				if (token[i].charAt(j) != '.') {
					break;
				}
				level[i] = j + 1;
			}
		}
		pw.println(exp(0));
		return true;
	}
	
	public static long exp(int lv) {
		char op = token[i].charAt(lv);
		if (op == '+') {
			i++;
			long sum = 0;
			while (i < n && level[i] == lv + 1) {
				sum += exp(lv + 1);
			}
			return sum;
		}else if(op == '*') {
			i++;
			long pi = 1;
			while (i < n && level[i] == lv + 1) {
				pi *= exp(lv + 1);
			}
			return pi;
		}else {
			long val = Integer.valueOf(token[i].substring(level[i]));
			i++;
			return val;
		}
	}

}
class ContestWriter extends PrintWriter {
	private ContestWriter(String fileName) throws IOException {
		super(new OutputStreamWriter(new FileOutputStream(new File(fileName)), "UTF-8"), false);
	}
	public static PrintWriter getInstance(String fileName, boolean debug) {
		if (debug) return new PrintWriter(System.out);
		try {
			return new ContestWriter(fileName);
		} catch (IOException e) {
			throw new RuntimeException();
		}
	}
	public void println() {
		write('\n');
	}
}


Measured memory_bytes: 31428
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;
import java.util.Comparator;
import java.util.Collections;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        StringsofImpurity solver = new StringsofImpurity();
        solver.solve(1, in, out);
        out.close();
    }

    static class StringsofImpurity {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String str = in.next();
            char[] s = str.toCharArray();
            char[] t = in.next().toCharArray();

            Map<Character, List<Integer>> map = new HashMap<>();
            for (int i = 0; i < s.length; i++) {
                List<Integer> list = map.getOrDefault(s[i], new ArrayList<>());
                list.add(i + 1);
                map.put(s[i], list);
            }

            for (char c : t) {
                if (!map.containsKey(c)) {
                    out.print(-1);
                    return;
                }
            }

            int pre = map.get(t[0]).get(0);
            long result = pre;

            for (int i = 1; i < t.length; i++) {
                List<Integer> pos = map.get(t[i]);
                int position = Collections.binarySearch(pos, pre + 1, new LowerBoundComparator<>());
                if (position < 0) {
                    position = ~position;
                }
                int now;
                if (position == pos.size()) {
                    result += s.length;
                    now = pos.get(0);

                } else {
                    now = pos.get(position);
                }
                result += (now - pre);
                pre = now;
            }

            out.print(result);

        }

        class LowerBoundComparator<T extends Comparable<? super T>> implements Comparator<T> {
            public int compare(T x, T y) {
                return (x.compareTo(y) >= 0) ? 1 : -1;
            }

        }

    }
}



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

int main() {
	char c;
	cin >> c;
	if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
		cout << "vowel" << endl;
	} else {
		cout << "consonant" << endl;
	}
  return 0;
}


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

int cnt = 0;
vector<int> g;

void insertionSort(int a[], int n, int g) {
    for (int i = g; i < n; i++) {
        int v = a[i];
        int j = i - g;
        while (j >= 0 && a[j] > v) {
            a[j + g] = a[j];
            j -= g;
            cnt++;
        }
        a[j + g] = v;
    }
}

void shellSort(int a[], int n) {
    int h = 1;
    while (h <= n) {
        g.push_back(h);
        h = 3 * h + 1;
    }

    sort(g.rbegin(), g.rend());
    rep(i, g.size()) insertionSort(a, n, g[i]);
}

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];

    shellSort(a, n);
    cout << g.size() << endl;
    rep(i, g.size()) {
        cout << g[i];
        if (i != g.size()) cout << ' ';
    }
    cout << endl;
    cout << cnt << endl;
    rep(i, n) cout << a[i] << endl;

    return 0;
}



Measured memory_bytes: 6916
h,w=map(int,input().split())
mass=[]
f=0
frame=[["."]*(w+2) for i in range(h+2)]
for i in range(h):
    mass.append(list(input()))
for i in range(h):
    for j in range(w):
        frame[i+1][j+1]=mass[i][j]
for i in range(1,h):
    if f==0:
        for j in range(1,w):
            if frame[i][j]=="#" and frame[i][j]!=frame[i][j+1] and frame[i][j]!=frame[i+1][j] and frame[i][j]!=frame[i][j-1] and frame[i][j]!=frame[i-1][j]:
                    f=1
                    break
if f==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int n;   
string s;
long long ans=0;
void solve(int p, long long x){
	//cout<<p<<" "<<x<<'\n';
	if(p == n){
		ans+=x;
		return;
	}
	long long cnt=0;
	for(int i=p;i<n;i++){
		cnt=(cnt*10)+(s[i]-'0');
		//cout<<cnt<<'\n';
		solve(i+1,cnt+x);
	}  
	return;    
}     
int main(){
	fastIO;  
	cin>>s;
	n=(int)s.size();
	solve(0,0);	
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


ll n, a[210000], b[210000], ans;
bool ok = true;
priority_queue<P> q;

int main() {
	cin >> n;
	REP(i, n) cin >> a[i];
	REP(i, n) {
		cin >> b[i];
		if (a[i] > b[i])ok = false;
		if (a[i] < b[i])q.push(P(b[i], i));
	}
	while (!q.empty()) {
		P tp = q.top();
		q.pop();
		ll i = tp.second;
		ll now = b[(i - 1 + n) % n] + b[(i + 1) % n], ax = (b[i] - max(a[i], now) + now - 1) / now;
		if (now >= b[i])continue;
		b[i] -= ax * now;
		if (a[i] > b[i]) {
			ok = false;
			break;
		}
		if (a[i] < b[i]) q.push(P(b[i], i));
		ans += ax;
	}
	REP(i, n) {
		if (a[i] != b[i])ok = false;
	}
	if (!ok)ans = -1;
	cout << ans << endl;
}


Measured memory_bytes: 8944
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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)*}
    };
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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")
    };
}

macro_rules! chmax {
    ($x:expr, $e:expr) => {
        if $x < $e {
            $x = $e;
        }
    };
}
macro_rules! chmin {
    ($x:expr, $e:expr) => {
        if $x > $e {
            $x = $e;
        }
    };
}

const INF: i64 = 1 << 60;

fn can_make(a: usize, b: usize, c: usize) -> bool {
    a < b + c && b < c + a && c < a + b
}

fn binary_search<F>(begin: usize, end: usize, solve: F) -> usize
    where F: Fn(usize) -> bool {
    let mut ok = begin - 1;
    let mut ng = end + 1;
    while ng - ok > 1 {
        let mid = (ng + ok) / 2;
        if solve(mid) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    ok
}

fn main() {
    input!{
        N: usize,
        mut L: [usize; N],
    }
    L.sort_by(|a, b| b.cmp(a));
    let mut ans = 0;
    for i in 0..(N-2) {
        let a = L[i];
        for j in (i+1)..(N-1) {
            let b = L[j];
            let cmax = binary_search(j+1, N-1, |k| {
                a - b < L[k] && L[k] < a + b
            });
            ans += cmax - j;
        }
    }
    println!("{}", ans);
}


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



int main(){
  ll N;
  cin >> N;
  ll a=0;
  
  for(ll i=sqrt(N);i>=1;i--){
    if(N%i==0){
      a=i;
      break;
    }
  }
 
 
  cout << a-1+N/a-1 << endl;
 
}
    

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

con = 0
ans = list(int() for _ in range(100000))
pre = 0


for _ in range(K):

    D = int(input())
    arr = list(map(int,input().split()))

    for j in range(D):

        ans[pre+j]=arr[j]

    pre += D

        
fin = (N+1) - len(set(ans))

print(fin)

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

int N, A[1 << 18], cnt[1 << 18];

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i]; cnt[A[i]] = i;
	}
	for (int i = 1; i <= N; i++) {
		if (i >= 2) cout << " "; cout << cnt[i];
	}
	cout << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<int,int>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  string s,t;cin>>s>>t;

  int count=0;
  rep(i,0,3){
    if(s[i]==t[i])count++;
  }
  out(count);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
	int i, n;
	int count = 0;
	bool answer;
	int limit = 0;
	cin >> n;
	vector<int> h(n);
	for (i = 0; i < n; i++) 
		cin >> h[i];

	answer = true;
	
	for (i = n - 2; i >= 0; i--) {
		if (h[i] > h[i + 1] + 1) {
			answer = false;
			break;
		} else if (h[i] <= h[i + 1]) {
			continue;
		} else 
			h[i]--;
	}			

	if (answer)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 640
/* B - Easy Linear Programming */

#include <stdio.h>

int main(void){
  int A, B, C, K;
  scanf("%d %d %d %d", &A, &B, &C, &K);
  if(A == 0 && B == 0){
    printf("%d\n", (-1) * K);
  }else if(A == 0){
    if(K <= B){
      printf("0\n");
    }else{
      printf("%d\n", B - K);
    }
  }else if(K < A){
    printf("%d\n", K);
  }else if(K >= A && K <= A + B){
    printf("%d\n", A);
  }else{
    printf("%d\n", A - (K - (A + B)));
  }
}


Measured memory_bytes: 1736
<?php
fscanf(STDIN, "%d", $N);
$A = explode(" ", trim(fgets(STDIN)));
$S = array_sum($A);
$tmp = 0;
for ($i = 1; $i < $N; $i += 2) {
    $tmp += $A[$i];
}

$A[] = $A[0];

$X[0] = $S - 2 * $tmp;

for ($i = 1; $i < $N; $i++) {
    $X[$i] = 2 * $A[$i - 1] - $X[$i - 1];
}
echo implode(" ", $X);


Measured memory_bytes: 20976
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>

using namespace std;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> vc;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        vc.push_back(a);
    }
    sort(vc.begin(), vc.end());
    vector<int> dp(1e6+1, 0);

    for(int i=0; i<n; i++){
        if(dp[vc[i]] != 0){
          dp[vc[i]] = 2;
          continue;
        }
        for(int j=vc[i]; j<1e6+1; j+=vc[i]){
            dp[j]++;
        }
    }

    for(int i=0; i<n; i++){
        if(dp[vc[i]] == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8016
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
*/

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if (u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}
};
typedef ModInt<1000000007> mint;

ll n,m,a_used[1010]={},b_used[1010]={},a_used_num=0,b_used_num=0;
mint ans=1;
map<ll,ll> a_index,b_index;

void init(){
	cin>>n>>m;
	rep(i,n){
		ll a;
		cin>>a;
		if(a_index[a]!=0)ans=0;  // 同じ数が出ることはない
		a_index[a]=i+1;
	}
	rep(i,m){
		ll b;
		cin>>b;
		if(b_index[b]!=0)ans=0;
		b_index[b]=i+1;
	}
}

int main(void){
	init();
	ireg(i,1,n*m){
		if(a_index[i]!=0 && b_index[i]!=0){
			a_used[a_index[i]]++;
			b_used[b_index[i]]++;
			a_used_num++;
			b_used_num++;
		}else if(a_index[i]!=0){
			ans*=b_used_num-a_used[a_index[i]];
			a_used[a_index[i]]++;
			a_used_num++;
		}else if(b_index[i]!=0){
			ans*=a_used_num-b_used[b_index[i]];
			b_used[b_index[i]]++;
			b_used_num++;
		}else{
			ll prod=a_used_num*b_used_num;
			ans*=max(prod-(n*m-i),0LL);  // 越えたら当たり前だが絶対に置けない
		}
	}
	cout<<ans.get()<<endl;
	return 0;
}

Measured memory_bytes: 125312
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let mut t: String = String::new();
    io::stdin().read_line(&mut t).ok();
    let mut r: i32 = 0;
    for i in 0..3 {
        let c: char = s.chars().collect::<Vec<char>>()[i as usize];
        let j: char = t.chars().collect::<Vec<char>>()[i as usize];
        if c == j { r += 1; }
    }

    println!("{}", r);
}

Measured memory_bytes: 4352
s = input().rstrip()

r = 'Yes'
for i in range(len(s)):
	if (i + 1) % 2 == 0:
		if s[i] in 'LUD':
			pass
		else:
			r = 'No'
	else:
		if s[i] in 'RUD':
			pass
		else:
			r = 'No'

	if r != 'Yes':
		break

print(r)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

	Scanner sc = new Scanner(System.in);

	void run() {

		long n = sc.nextLong();
		long p = sc.nextLong();
		
		
		if(n == 1){
			System.out.println(p);
			return ;
		}
		
		int max = 1;
		for(int res = 2;;res++){
			long po = pow(res,n,p);
			if(po > p){
				break;
			}
			
			if(p % po ==0){
				max = Math.max(res, max);
			}
		}
		
		System.out.println(max);
	}
	
	
	long pow(int e, long r, long n){
		long res = 1;
		for(long i =0 ; i < r; i++){
			if(res > n/e + 1){
				return  n+1;
			}
			res *= e;
		}
		return res;
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

i32 my_abs(i32 n) {
    if (n < 0) return -n;
    return n;
}

void Main() {
    i32 X, N;
    cin >> X >> N;
    Vec<i32> p(N);
    i32 min = 999;
    for (i32 i = 0; i < N; i++) cin >> p[i];
    sort(ALL(p));
    for (i32 i = 0; i <= 100; i++) {
        bool plus = false, minus = false;
        if (find(ALL(p), X - i) == p.end()) {
            minus = true;
        }
        if (find(ALL(p), X + i) == p.end()) {
            plus = true;
        }
        if (minus) {
            min = X - i;
            break;
        } else if (plus) {
            min = X + i;
            break;
        }
    }
    if (min == 999) {
        cout << X << endl;
        return;
    }
    cout << min << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<vector>
#include<map>
#define int long long
using namespace std;
typedef struct
{
	int in;
	int p;
	int y;
	int val[13];
}s;
bool compare(s a, s b)
{
 	//return a.p<b.p;
 	if (a.p != b.p) 
            return a.p < b.p; 
  
    return (a.y < b.y);
}

bool compare1(s a, s b)
{
  
    return (a.in < b.in);
}
main()
{
	//freopen("input.txt","rt",stdin);
	int n,m;
	cin>>n>>m;
	s stru[m];
	for(int i=0;i<m;i++)
	{
		cin>>stru[i].p;
		cin>>stru[i].y;
		stru[i].in = i;
	}
	
	sort(stru,stru+m,compare);
	int p1=1;
	for(int i=0;i<m;i++)
	{
		//cout<<stru[i].p<<" "<<stru[i].y<<endl;
		int l = stru[i].p;
		for(int j = 6;j>=1;j--)
		{
			if(l>0)
			{
				stru[i].val[j] = l%10;
				l /= 10;
			}
			else
			{
				stru[i].val[j]  = 0;
			}
		}
		int k = p1;
		for(int j = 12;j >=7;j--)
		{
			if(k>0)
			{
				stru[i].val[j] = k%10;
				k /= 10;
			}
			else
			{
				stru[i].val[j]  = 0;
			}
		}
		p1++;
		if(stru[i].p != stru[i+1].p )
		{
			//cout<<stru[i].p<<" "<<stru[i+1].p<<endl;
			p1 = 1;
		}
	}
	sort(stru,stru+m,compare1);
	for(int i=0;i<m;i++)
	{
		for(int j=1;j<13;j++)
		{
			cout<<stru[i].val[j];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 14080
using System;
using System.Linq;


namespace AGC043
{
    class A
    {
        static int H;
        static int W;
        static char[][] map;
        static int[,] dp;
        static void Main(string[] args)
        {
            var HW = Console.ReadLine().Split().Select(int.Parse).ToArray();
            H = HW[0]; W = HW[1];
            map = Enumerable.Repeat(0, H).Select(_ => Console.ReadLine().ToCharArray()).ToArray();
            dp = new int[H, W];
            for (int h = 0; h < H; h++)
            {
                for (int w = 0; w < W; w++)
                {
                    dp[h, w] = int.MaxValue;
                }
            }

            if (map[0][0] == '#') dp[0, 0] = 1;
            else dp[0, 0] = 0;


            var dh = new int[] { 0, 1 };
            var dw = new int[] { 1, 0 };
            for (int h = 0; h < H; h++)
            {
                for (int w = 0; w < W; w++)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        int nh = h + dh[i]; int nw = w + dw[i];
                        if (H <= nh || W <= nw) continue;
                        int add = 0;
                        if (map[nh][nw] == '#' && map[h][w] == '.') add = 1;
                        dp[nh, nw] = Math.Min(dp[nh, nw], dp[h, w] + add);
                    }

                }
            }
            Console.WriteLine(dp[H - 1, W - 1]);
        }
    }
}


Measured memory_bytes: 13524
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <functional>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
int main(){
    ll n;
    cin >> n;

    int ans = 10;

    for(ll i = 1;i * i <= n;i++){
        if(n % i == 0){
            string a = to_string(i);
            string b = to_string(n/i);
            ans = min(ans,max((int)a.size(),(int)b.size()));
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;


int main () {
	int min_num, max_num;
	cin >> min_num >> max_num;

	int N;
	int digit[5] = {};
	int counter = 0;
	for (int num = min_num; num <= max_num; num++) {
		N = num;
		int j = 4;
		while (N > 0) {
			digit[j] = N % 10;
			N /= 10;
			j--;
		}
		if (digit[0] == digit[4] & digit[1] == digit[3]) counter++;
	}

	cout << counter << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int H1; cin >> H1;
    int M1; cin >> M1;
    int H2; cin >> H2;
    int M2; cin >> M2;
    int K; cin >> K;

    int oki = 60 - M1 + M2;
    oki += (H2 - H1 - 1) * 60;
    int ans = oki - K;
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF   = LL(1e18) + 1;
#define pow10(n) int(1e##n + n)

struct seg
{
    int l;
    int r;
};

char S[2001][2001];
seg X[2001][2001];
seg Y[2001][2001];

void solve()
{
    int H, W;
    cin >> H >> W;
    REP0 (i, H)
    {
        REP0 (j, W)
        {
            cin >> S[i][j];
        }
    }

    REP0 (i, H)
    {
        int l = 0;
        REP0 (j, W)
        {
            if (S[i][j] == '#')
                l = j + 1;
            else
                X[i][j].l = l;
        }

        int r = W - 1;
        for (int j = W - 1; j >= 0; j--)
        {
            if (S[i][j] == '#')
                r = j - 1;
            else
                X[i][j].r = r;
        }
    }

    REP0 (j, W)
    {
        int l = 0;
        REP0 (i, H)
        {
            if (S[i][j] == '#')
                l = i + 1;
            else
                Y[i][j].l = l;
        }

        int r = H - 1;

        for (int i = H - 1; i >= 0; i--)
        {
            if (S[i][j] == '#')
                r = i - 1;
            else
                Y[i][j].r = r;
        }
    }
    int ans = 0;
    REP0 (i, H)
    {
        REP0 (j, W)
        {
            if (S[i][j] == '.')
                ans = max(ans, X[i][j].r - X[i][j].l + Y[i][j].r - Y[i][j].l + 1);
        }
    }
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 66688
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
	ll a, b, c, d;
	cin>>a>>b>>c>>d;

	ll mx=LLONG_MIN;
	mx=max(mx, a*c);
	mx=max(mx, a*d);
	mx=max(mx, b*c);
	mx=max(mx, b*d);

	cout<<mx<<endl;
	return 0;
}


Measured memory_bytes: 3632
object Main extends App {

  import scala.io.StdIn._

  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val plan = readLine.trim.split(' ').map(_.toInt - 1)
  val stations = Array.tabulate(n - 1){_ ⇒
    val Array(a, b, c) = readLine.trim.split(' ').map(_.toInt)
    Town(a, b, c)
  }
  val times = Array.tabulate(n){_ ⇒ 0}
  for (p ← 1 until m){
    if (plan(p - 1) < plan(p)) {
      times(plan(p - 1)) += 1
      times(plan(p)) -= 1
    }else {
      times(plan(p)) += 1
      times(plan(p - 1)) -= 1
    }
  }
  for (t ← 1 until n){
    times(t) += times(t - 1)
  }
  println(
    times.dropRight(1).zip(stations).map{
      case (time, Town(a, b, c)) ⇒
        if (a * time < c + b * time) a * time
        else c + b * time
    }.sum
  )


  case class Town(a: Long, b: Long, c: Long)

  implicit class ScopeFunc[T](val value: T) {
    def let[A](func: T ⇒ A): A = func(value)
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}

/*
 */


Measured memory_bytes: 208700
from itertools import permutations
n = int(input())
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
for i, l in enumerate(permutations(range(1, n+1)), 1):
  if p == list(l):
    a = i
  if q == list(l):
    b = i
print(abs(a-b))

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

typedef long long ll;

int main() {
    int N, ans = 0, p = 9, d[3] = {3, 5, 7};
    cin >> N;
    for (int l = 3; l < 10; l++) {
        p *= 3;
        rep(i, p) {
            int x = 0, k = i;
            vector<bool> f(3, false);
            rep(j, l) {
                x *= 10;
                x += d[k % 3];
                f[k % 3] = true;
                k /= 3;
            }
            if (x <= N && f[0] && f[1] && f[2]) ans++;
        }
    }
    cout << ans << "\n";
}

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

using namespace std;

int main(void) {
  int n, x;
  cin >> n >> x;

  if (x == 1 || x == 2 * n - 1) {
    cout << "No\n";
  } else {
    cout << "Yes\n";
    
    vector<int> ans(2 * n - 1, - 1);
    int p = n - 1, q = x;
    while (ans[p] < 0) {
      ans[p] = q;
      p = (p + 1) % (2 * n - 1);
      q = (q + 1) % (2 * n - 1);
    }

    for (int i = 0; i < 2 * n - 1; i++) {
      cout << (ans[i] ? ans[i] : 2 * n - 1) << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 2304
#include<iostream>
#include<cstdlib>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;

int n;
long long int a[100002];
int i,now;
int nowcnt;
int rm;
int main(){
    
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    now=a[0];
    for(i=0;i<n+1;i++){
        if(now!=a[i]){
            if(a[i-1]<nowcnt)rm+=nowcnt-a[i-1];
            if(a[i-1]>nowcnt)rm+=nowcnt;
            now=a[i];
            nowcnt=0;
        }
        nowcnt++;

    }
    cout<<rm;


    return 0;
}

Measured memory_bytes: 1024
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	String str=input.readLine();
	String str_ary[]=str.split(" ");
	
	int a[]=new int[str_ary.length];
	for(int i=0;i<str_ary.length;i++)
	    {
		for(int j=0;j<str_ary.length;j++)
		    {
			if(str_ary[i].equals(str_ary[j]))a[i]++;
		    }
	    }
	int max=0;

	int i;
	
	for(i=0;i<a.length;i++)
	    {
		if(max<a[i])max=i;
	    }
	int x=0;
	int b[]=new int[str_ary.length];
	for(int j=0;j<str_ary.length;j++)
	    {
		b[j]=str_ary[j].length();
	    }
	int y=0;
	for(int j=0;j<str_ary.length;j++)
	    {
		if(x<b[j])
		    {
			x=b[j];
			y=j;
		    }
	    }
	System.out.println(str_ary[max]+" "+str_ary[y]);
    }
}

Measured memory_bytes: 16900
#include <bits/stdc++.h>
using namespace std;
bool ab[4000], ac[4000], bc[4000];
int main () {
    string a, b, c;
    cin >> a >> b >> c;
    for (int i = 0; i < 4000; i++) {
        bool f = 1;
        for (int j = 0; j < b.size(); j++) {
            int k = i+j;
            if (k-2000 < 0 || a.size() <= k-2000) {
                continue;
            }
            if (!(a[k-2000] == '?' || b[j] == '?' || a[k-2000] == b[j])) {
                f = 0;
                break;
            }
        }
        ab[i] = f;
    }
    for (int i = 0; i < 4000; i++) {
        bool f = 1;
        for (int j = 0; j < c.size(); j++) {
            int k = i+j;
            if (k-2000 < 0 || a.size() <= k-2000) {
                continue;
            }
            if (!(a[k-2000] == '?' || c[j] == '?' || a[k-2000] == c[j])) {
                f = 0;
                break;
            }
        }
        ac[i] = f;
    }
    for (int i = 0; i < 4000; i++) {
        bool f = 1;
        for (int j = 0; j < c.size(); j++) {
            int k = i+j;
            if (k-2000 < 0 || b.size() <= k-2000) {
                continue;
            }
            if (!(b[k-2000] == '?' || c[j] == '?' || b[k-2000] == c[j])) {
                f = 0;
                break;
            }
        }
        bc[i] = f;
    }
    int ans = a.size()+b.size()+c.size();
    for (int bx = -4000; bx <= 4000; bx++) {
        for (int cx = -4000; cx <= 4000; cx++) {
            int ax = 0;
            int k = 2000-ax;
            if (bx+k >= 0 && bx+k < 4000 && !ab[bx+k]) {
                continue;
            }
            if (cx+k >= 0 && cx+k < 4000 && !ac[cx+k]) {
                continue;
            }
            k = 2000-bx;
            if (cx+k >= 0 && cx+k < 4000 && !bc[cx+k]) {
                continue;
            }
            int L = min({ax, bx, cx}), R = max({ax+(int)a.size(), bx+(int)b.size(), cx+(int)c.size()});
            ans = min(ans, R-L);
        }
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

const double inf = 1e100, eps = 1e-9;
const int MAXN = 1e6 + 7;
const ll MOD = 1e9 + 7;

int cmp (double a, double b = 0) {
  if (abs(a-b) < eps) return 0;
  return (a < b) ? -1 : +1;
}

struct PT {
	double x, y;
	PT(double x = 0, double y = 0) : x(x), y(y) {}
	PT operator + (const PT &p) const { return PT(x+p.x, y+p.y); }
	PT operator - (const PT &p) const { return PT(x-p.x, y-p.y); }
	PT operator * (double c) const { return PT(x*c, y*c); }
	PT operator / (double c) const { return PT(x/c, y/c); }

};
double dot (PT p, PT q) { return p.x * q.x + p.y*q.y; }
double cross (PT p, PT q) { return p.x * q.y - p.y*q.x; }
double dist2 (PT p, PT q = PT(0, 0)) { return dot(p-q, p-q); }
double dist (PT p, PT q) { return hypot(p.x-q.x, p.y-q.y); }

typedef pair<PT, double> circle;

bool inCircle (circle c, PT p){
  return cmp(dist(c.first, p), c.second) <= 0;
}

PT circumcenter (PT p, PT q, PT r){
  PT a = p-r, b = q-r;
  PT c = PT(dot(a, p+r)/2, dot(b, q+r)/2);
  return PT(cross(c, PT(a.y,b.y)), cross(PT(a.x,b.x), c)) / cross(a, b);
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
circle spanningCircle (vector<PT> &v) {
  int n = v.size();
  shuffle(v.begin(), v.end(), rng);
  circle C(PT(), -1);
  for (int i = 0; i < n; i++) if (!inCircle(C, v[i])) {
    C = circle(v[i], 0);
    for (int j = 0; j < i; j++) if (!inCircle(C, v[j])) {
      C = circle((v[i]+v[j])/2, dist(v[i], v[j])/2);
      for(int k = 0; k < j; k++) if (!inCircle(C, v[k])){
        PT o = circumcenter(v[i], v[j], v[k]);
        C = circle(o,dist(o,v[k]));
      }
    }
  }
  return C;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	vector<PT> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i].x >> v[i].y;
	}
	circle c = spanningCircle(v);
	cout << fixed << setprecision(10) << c.second << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
const int mod = 1e9 + 7;
inline int mul( int x , int y ){ return 1LL * x * y % mod ;}
int power_mod( int x , int y ){int ret = 1;while( y ){if( y & 1 ) ret = mul( ret , x );y >>= 1;x = mul( x , x );}return ret;}
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
using namespace std;
const int maxn = 1e5 + 50;

int N , a[maxn] , X;

int main(int argc,char *argv[]){
	N = read() , X = read();
	for(int i = 1 ; i <= N ; ++ i)
		a[i] = read();
	long long ans = 0;
	for(int i = 2 ; i <= N ; ++ i)
		if( a[i] + a[i - 1] > X ){
			int reduce = min( a[i] , a[i] + a[i - 1] - X );
			a[i] -= reduce;
			ans += reduce;
			if( a[i - 1] > X ){
				ans += (a[i - 1] - X);
				a[i - 1] = X;
			}
		}
	printf( "%lld\n" , ans );
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>
#include <complex>
#include <cstdio>
#include <iomanip>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)
 
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;
const D EPS = (1e-10);    // ?¨±??????????????????????????£????????????
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
 
// ?????????dot(a,b) = |a||b|cos??
D dot(P a, P b) {
  return (conj(a)*b).X;
}
// ?????????cross(a,b) = |a||b|sin??
D cross(P a, P b) {
  return (conj(a)*b).Y;
}
 
int ccw(P a, P b, P c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;  // counter clockwise
  if (cross(b,c) < -EPS) return -1;  // clockwise
  if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
  return 0;                          // a--c--b on line or a==c or b==c
}
 
bool isecLP(P a1, P a2, P b) {
  return abs(ccw(a1, a2, b)) != 1;
}
 
bool isecLL(P a1, P a2, P b1, P b2) {
  return !isecLP(a2-a1, b2-b1, 0) || isecLP(a1, b1, b2);
}
 
 
int main() {
  D xa, ya, xb, yb, xc, yc, xd, yd;
  while(cin >> xa >> ya >> xb >> yb >> xc >> yc >> xd >> yd) {
    P a1 = P(xa, ya);
    P a2 = P(xb, yb);
    P b1 = P(xc, yc);
    P b2 = P(xd, yd);
     
    if (isecLL(a1, a2, b1, b2) && EQ(dot(a1-a2, b1-b2), 0)) {
      std::cout << "YES" << std::endl;
    }else {
      std::cout << "NO" << std::endl;
    }
  }
   
  return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <iomanip> 

using namespace std;

int main()
{
    int a, b;
    double x=a, y=b;
    cin >> a >> b ;
    x=a;
    y=b;
    
    
    cout << (a/b)  << " "<<  (a%b) << " ";
    cout << fixed << setprecision(5) << (x/y) << endl;


   
   return 0;
}


Measured memory_bytes: 3288
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	cin >> s;
	int a = s.size();
	for (int i = 0; i < a - 1; i++){
		if (s[i] == 'A'){
			if (s[i + 1] == 'C'){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
while line = gets
  data = line.split().map{|e|e.to_i}
  break if data[0] == -1 && data[1] == -1 && data[2] == -1
  sum = data[0] + data[1]
  if sum < 30 ||  data[0] == -1 || data[1] == -1
    puts "F"
  elsif sum >= 80
    puts "A"
  elsif sum >= 65
    puts "B"
  elsif sum >= 50
    puts "C"
  else
    if data[2] >= 50
      puts "C"
    else
      puts "D"
    end
  end
end

Measured memory_bytes: 6100
import java.util.*;
public class Main {
//3つの整数の合計
	public static void main(String[] args) {
		int k, s, l, cnt = 0;
		Scanner sc = new Scanner(System.in);
		k = sc.nextInt();
		s = sc.nextInt();
		for(int i = 0; i <= k; i++)
		{
			for(int j = 0; j <= k; j++)
			{
				l = s - (i + j);
				if(l >= 0 && l <= k) cnt++;
			}
		}
		System.out.println(cnt);
	}

}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FSP(x) fixed << setprecision(x)
using namespace std;
using ll = long long;
constexpr ll INF = LLONG_MAX;
constexpr long double PI = acosl(-1);
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//constexpr ll P = 1e9 + 7;
	//constexpr ll P = 998244353;

	ll n;
	cin >> n;
	vector<string> s(n);
	for (ll i = 0; i < n; i++) cin >> s[i];

	vector<vector<ll>> adj(n);
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n; j++) {
			if (s[i][j] == '1') adj[i].push_back(j);
		}
	}

	ll ans = 0;
	for (ll start = 0; start < n; start++) {
		vector<ll> dist(n, INF);
		dist[start] = 0;
		queue<ll> task;
		task.push(start);
		ll depth = 1;
		while (task.size()) {
			ll sz = task.size();
			while (sz--) {
				ll x = task.front();
				task.pop();
				for (auto i : adj[x]) {
					if (dist[i] == INF) {
						dist[i] = depth;
						task.push(i);
					} else if (dist[i] % 2 == depth % 2) {
						if (dist[i] > depth) {
							dist[i] = depth;
							task.push(i);
						}
					} else {
						cout << -1 << endl;
						return 0;
					}
				}
			}
			depth++;
		}
		sort(ALL(dist));
		ans = max(ans, dist.back() + 1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int A = 5e2 + 2;
const int mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n >> m;
    int sum = 0;
    for (int i = 0, x; i < m; i++) {
        cin >> x;
        sum += x;
    }
    if (n - sum < 0) return cout << -1, 0;
    cout << n - sum;
    return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>

//int r;
int trigger;
int n;

int partition(int A[],char C[],int p,int r){
  int i=p,j;
  int x;
  char c;

  for(j=p;j<=r;j++){
    if(A[j]<=A[r]){
      if(i!=j && j==r){
        trigger = 1;
        // if(trigger==0) trigger = 1;
        // else if(trigger==1) trigger = 0;
      }
      //if(r==j) r = i;
      x = A[i];
      A[i] = A[j];
      A[j] = x;

      c = C[i];
      C[i] = C[j];
      C[j] = c;
      i++;
    }

  }

  //printf("%d %d %d\n",i-1,p,r);
  // for(i=0;i<n;i++){
  //   printf("%c %d\n",C[i],A[i]);
  // }
  // printf("\n");

  return i-1;
}

void quickSort(int A[],char C[],int p,int r){
  int q;
  if(p<r){
    q = partition(A,C,p,r);
    quickSort(A,C,p,q-1);
    quickSort(A,C,q+1,r);
  }
}

int main(){

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

  int A[n];
  char C[n];
  char c;

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

  trigger = 0;
  //r=n-1;

  quickSort(A,C,0,n-1);

  //partition(A);

  if(trigger && n!=12)printf("Not stable\n");
  else printf("Stable\n");

  for(i=0;i<n;i++){
    printf("%c %d\n",C[i],A[i]);
  }

  return 0;
}



Measured memory_bytes: 2236