akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;

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

int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll n, m, K;
	ll memo[1003][1003] = { {} };
	ll memox[1003] = {};
	ll memoy[1003] = {};
	ll x[1000006] = {};
	ll y[200005] = {};
	ll z[200005] = {};
	string s;
	string s1, s2;
	//IntStack yStack;
	//charStack Stack;
	//vector<pair<int, int> > pairs(a);
	cin >> b;
	cin >> a;
	cin >> x[0];
	if (a == 1||a<=b)
	{
		cout << 0 << endl;
	}
	else
	{

		for (int i = 1; i < a; i++)
		{
			cin >> x[i];
		}
		sort(x, x + a);
		ans = x[a - 1] - x[0];
		for (int i = 1; i < a; i++)
		{
			y[i - 1] = x[i] - x[i - 1];
		}
		sort(y, y + a - 1);

		for (int i = a - 2; i > a - 1 - b; i--)
		{
			ans -= y[i];
		}
		cout << ans << endl;
	}


	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 9600
#include <stdio.h>
#include <math.h>

int main(){
  double q, x;
  while(scanf("%lf", &q) && q != -1){
    x = q / 2.0;
    while(fabs(x*x*x -q) > 0.00001 * q) x -= (x*x*x - q) / (3 *x*x);
    printf("%.6f\n", x);
  }
  return 0;
}

Measured memory_bytes: 1076
#include <stdio.h>

int a, b, c, d;

int main() {

    scanf("%1d %1d %1d %1d", &a, &b, &c, &d);
    if (a + b + c + d == 7) printf("%d+%d+%d+%d=7\n", a, b, c, d);
    else if (a + b + c - d == 7) printf("%d+%d+%d-%d=7\n", a, b, c, d);
    else if (a + b - c + d == 7) printf("%d+%d-%d+%d=7\n", a, b, c, d);
    else if (a + b - c - d == 7) printf("%d+%d-%d-%d=7\n", a, b, c, d);
    else if (a - b + c + d == 7) printf("%d-%d+%d+%d=7\n", a, b, c, d);
    else if (a - b + c - d == 7) printf("%d-%d+%d-%d=7\n", a, b, c, d);
    else if (a - b - c + d == 7) printf("%d-%d-%d+%d=7\n", a, b, c, d);
    else printf("%d-%d-%d-%d=7\n", a, b, c, d);

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define SIZE 128

char pict[SIZE][SIZE];

int main(void)
{
    int H, W, i, j;
    scanf("%d%d", &H, &W);
    getchar();
    for (i = 0; i <= H + 1; i++)
        for (j = 0; j <= W + 1; j++)
            pict[i][j] = '#';
    for (i = 1; i <= H; i++) {
        for (j = 1; j <= W; j++)
            pict[i][j] = getchar();
        getchar();
    }
    for (i = 0; i <= H + 1; i++) {
        for (j = 0; j <= W + 1; j++)
            putchar(pict[i][j]);
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

string S;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> S;
    cout << (S == "ABC" ? "ARC" : "ABC") << endl;
    return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<vector>
int main()
{
  using namespace std;
  int n;
  while(cin>>n){
  vector<int> a_vec(n),b_vec(n),c_vec(n-1);
  for(int i=0;i<n;i++) cin>>a_vec[i];
  for(int i=0;i<n;i++) cin>>b_vec[i];
  for(int i=0;i<n-1;i++) cin>>c_vec[i];
  for(int i=1;i<n;i++) b_vec[i]+=b_vec[i-1];
  for(int i=1;i<n;i++) 
    if(a_vec[i]-a_vec[i-1]==1)
      b_vec[n-1]+=c_vec[a_vec[i-1]-1];
    cout<<b_vec[n-1]<<endl;
  }
  return 0;
}

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

#define sqr(A) ((A) * (A))
#define F first
#define S second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;

const int N = 2e3 + 20;
vector<int> G[N];
int n, k, ans = INF, cnt1[N], cnt2[N];

void dfs(int v, int p = -1, int h = 0) {
	if (h > k / 2) {
		if (h == k / 2 + 1)
			cnt2[v] = 1;
		cnt1[v] = 1;
	}
	for (int u : G[v])
		if (u != p) {
			dfs(u, v, h + 1);
			cnt1[v] += cnt1[u];
			cnt2[v] += cnt2[u];
		}
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	for (int i = 0, v, u; i < n - 1; i++) {
		cin >> v >> u;
		G[v].push_back(u);
		G[u].push_back(v);
	}
	for (int i = 1; i <= n; i++) {
		dfs(i);
		if (k % 2) {
			int res = cnt1[i], tmp = -1;
			for (int v : G[i])
				tmp = max(tmp, cnt2[v]);
			ans = min(ans, res - tmp);
		}
		else {
			ans = min(ans, cnt1[i]);
		}
		memset(cnt1, 0, sizeof cnt1);
		memset(cnt2, 0, sizeof cnt2);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,k;
  cin >> a >> b>> c >> k;
vector<int>v(3);
v[0] = a;
v[1] = b;
v[2] = c;

  for(int i = 0;i < k;i++){
sort(v.begin(),v.end());
v[2] *= 2;
}

cout << v[0]+v[2]+v[1] <<endl;
}



Measured memory_bytes: 256
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)
function bsearch(a,x);l,r=0,length(a)+1;while r-l>1;m=(r+l)>>1;if a[m]<=x;l=m;else;r=m;end;end;l;end
function main()
	n,m,k = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	b = readline() |> split |> parseMap
	for i in 2:n
		a[i]+=a[i-1]
	end
	for i in 2:m
		b[i]+=b[i-1]
	end
	s = bsearch(b,k)
	for i in 1:n
		if a[i]<=k
			s = max(s,i+bsearch(b,k-a[i]))
		end
	end
	println(s)
end

main()

Measured memory_bytes: 202476
a,b,c,x,y=map(int,input().split())
ans=0
min_n=min(x,y)
if a+b>c*2:
    ans+=2*c*min_n
else:
    ans+=(a+b)*min_n

if x>y:
    ans+=min(a*(x-y),2*c*(x-y))
else:
    ans+=min(b*(y-x),2*c*(y-x))

print(ans)



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

int main() {
    string n; cin >> n;
    if(n[0]=='9'||n[1]=='9') cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string>
#include<string.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	char a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	if (a == f&&b == e&&c == d) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// AOJ 	2302: On or Off
// 2018.1.31 bal4u

#include <stdio.h>
#include <string.h>

typedef struct { int r, c, t; } Q;
Q q[2600]; int top, end;

char map[53][53];
char pr[53][53], prev[53][53][2];		// prev (r,c)
int keep[53][53], onoff[53][53];
int cost[53][53];
int visited[53][53];
char mk[53][53];
int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};

#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int R, C, M, i, k, r, c, t, nr, nc, sr, sc, gr, gc, tm, ans;
	
	R = in(), C = in(), M = in();
	memset(map, 1, sizeof(map));
	for (r = 1; r <= R; r++) {
		fgets(map[r]+1, 53, stdin);
		for (c = 1; c <= C; c++) map[r][c] &= 1;
		map[r][C+1] = 1;
	}
	for (r = 1; r <= R; r++) for (c = 1; c <= C; c++) keep [r][c] = in();
	for (r = 1; r <= R; r++) for (c = 1; c <= C; c++) onoff[r][c] = in();
	for (r = 1; r <= R; r++) for (c = 1; c <= C; c++) onoff[r][c]+= in();

	tm = 1;
	sr = in()+1, sc = in()+1;
	visited[sr][sc] = tm;
	while (--M) {
		gr = in()+1, gc = in()+1;
		memset(mk, 0, sizeof(mk));
		q[0].r = sr, q[0].c = sc, q[0].t = tm, top = 0, end = 1;
		while (top != end) {
			r = q[top].r, c = q[top].c, t = q[top++].t;
			if (r == gr && c == gc) break;
			if (mk[r][c]) continue;
			mk[r][c] = 1;
			for (i = 0; i < 4; i++) {
				nr = r+mv[i][0], nc = c+mv[i][1];
				if (map[nr][nc] || mk[nr][nc]) continue;
				prev[nr][nc][0] = r, prev[nr][nc][1] = c;
				q[end].r = nr, q[end].c = nc, q[end++].t = t+1;
			}
		}
		nr = gr, nc = gc, tm = t;
		while (nr != sr || nc != sc) {
			if (visited[nr][nc]) {
				k = (t - visited[nr][nc])*keep[nr][nc];
				if (k > onoff[nr][nc]) k = onoff[nr][nc];
				cost[nr][nc] += k;
			}
			visited[nr][nc] = t;
			r = prev[nr][nc][0], c = prev[nr][nc][1], t--;
			nr = r, nc = c;
		}
		sr = gr, sc = gc;
	}

	ans = 0;
	for (r = 1; r <= R; r++) for (c = 1; c <= C; c++) {
		if (visited[r][c]) ans += cost[r][c] + onoff[r][c];
	}
	printf("%d\n", ans);
	return 0;
}


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

int main() {

	ll n, k; cin >> n >> k;

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

	ll ans = 9223372036854775807LL;
	for (int i = 0; i <= n - k; i++) {
		ll l = x[i];
		ll r = x[i + k - 1];
		ll tmp = min(abs(l) + abs(l - r), abs(l - r) + abs(r));
		ans = min(ans, tmp);
	}

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

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

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P = pair<int, int>;

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

template <class T>
void dump_vec(const vector<T>& v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == (int)len - 1 ? "\n" : " ");
    }
}

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} FASTIO;

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

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

signed main() {
    int N;
    cin >> N;
    i64 tot = 0;
    rep(i, 1, N + 1) {
        if (i % 3 != 0 && i % 5 != 0) {
            tot += (i64)i;
        }
    }
    cout << tot << "\n";
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <stack>
#include <tuple>
#include <queue>
#include <vector>
#include <cmath>
#include <math.h>
#include <random>



#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define rREP(i, n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define ALL(TheArray) TheArray.begin(), TheArray.end()

using lli = long long int;
using pii = std::pair<int, int>;

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

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

constexpr int mod = 1e9+7;

class combinationMod{
private:
    using LLi = long long int;
    static const int mod_number = 1e9+7;

    const int n; // 最大
    std::vector<LLi> Factional, invFactional, inv;

    // ユークリッドの互除法により逆元を求める関数
    LLi inverse_mod_euclid(LLi a, LLi mod_number___ = mod_number){
        LLi b = mod_number___, u = 1, v = 0;
        while (b != 0) { LLi t = a / b; a -= t * b; std::swap(a, b);
            u -= t * v; std::swap(u, v);}
        u %= mod_number___; if (u < 0) u += mod_number___;
        return u;
    }
public:
    // コンストラクタ
    combinationMod(int N): n(N){
        Factional.resize(n+1);
        invFactional.resize(n+1);
        inv.resize(n+1);
    }
    void build(){
        Factional[0] = 1;
        invFactional[0] = 1;
        inv[0] = 1;
        for(int x = 1; x <= n; x++){
            Factional[x] = (x * Factional[x-1]) % mod_number;
            inv[x] = inverse_mod_euclid(x);
            invFactional[x] = (inv[x] * invFactional[x-1]) % mod_number;
        }
    }

    // nCkを求める関数 : n < k の入力に注意せよ
    LLi combination(int N, int K){
        if(N < K) return 0;
        return ((Factional[N] * invFactional[K] % mod_number) * invFactional[N-K]) % mod_number;
    }
};

std::vector<int> A;

int main(void){
    // 入力部
    int n; scanf("%d", &n);
    A.resize(n, -1);
    int nN;
    for(int i = 0; i <= n; i++){
        int k; scanf("%d", &k); k--;
        if(A[k] != -1){
            nN = n - i + A[k];
            break;
        }
        A[k] = i;
    }

    
    combinationMod C(n+1); C.build();
    // l O r => Oの数は　r - l - 1個 => n+1-(r-l-1)-2_C_(k-1) : n-r+l := Diff
    for(int k=0;k<=n;++k){
        printf("%lld\n", (C.combination(n+1, k+1) - C.combination(nN, k)+ mod) % mod );
    }
    return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n;  i++) a[i] = i;
    int T;cin >> T;
    for (int i = 0; i < 1 << n; i++) {
        vector<int> res;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) { res.push_back(j); }
        }
        if (T==res.size()) {
            cout << i << ":";
            for (int re : res) {
                cout << " " << re;
            }
            cout << endl;
        }
    }
}


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

using namespace std;

const long long MOD = 1000000007LL;

int main() {
    long long n, k; cin >> n >> k;
    vector<vector<long long>> dp(n+1, vector<long long>(k+1));
    for (int i = 0; i <= n; ++i) {
        dp[i][0] = 1;
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= k; ++j) {
            dp[i][j] = (dp[i-1][j-1] + dp[i-1][j]) % MOD;
        }
    }
    for (int i = 1; i <= k; ++i) {
        long long ans = (dp[n-k+1][i] * dp[k-1][i-1]) % MOD;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 31616
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

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

int main() {

    LL N;
    cin >> N;

    vector<LL> P(N);
    for (int i = 0; i < N; i++) cin >> P[i];

    vector<pair<LL, LL>> A(N);
    for (int i = 0; i < N; i++) A[i] = make_pair(P[i], i);
    sort(A.rbegin(), A.rend());

    set<int> st;
    st.insert(A[0].second);
    st.insert(-1);
    st.insert(N);

    LL ans = 0;
    for (int i = 1; i < N; i++) {
        LL val = A[i].first;
        LL pos = A[i].second;

        st.insert(pos);

        auto l_pos = st.lower_bound(pos);
        auto r_pos = st.lower_bound(pos);
        l_pos--;
        r_pos++;
        auto ll_pos = l_pos;
        auto rr_pos = r_pos;
        if (l_pos != st.begin())
            ll_pos--;
        if (r_pos != prev(st.end()))
            rr_pos++;
        LL d = 0;
        d += (*l_pos - *ll_pos) * (*r_pos - pos);
        d += (*rr_pos - *r_pos) * (pos - *l_pos);
        ans += d * val;
    }

    cout << ans << endl;

}






























































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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)9e18);
const int ninf=((int)-9e18);
const int mod=1000000007;

using namespace std;

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","w",stdout);
    //FILE *fptr2=freopen("out.txt","w",stdout);


    int n;
    cin>>n;
    vector <int> a(n);
    loop(i,0,n) cin>>a[i];

    int ans=0;
    loop(i,0,n-1)
    {
        ans+=max(0LL,a[i]-a[i+1]);
        if(a[i]>a[i+1])
            a[i+1]=a[i];
    }
    cout<<ans;


    return 0;
}


Measured memory_bytes: 4772
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
#define NMAX 100005
#define LAST 1000000000002


int main()
{   int books[12][13]={0};
    int n,m,x;
    int mincoast=INF;
    cin>>n>>m>>x;
    for(int i=0 ; i<n ; ++i){
        for(int j=0 ; j<m+1 ; ++j){
            cin>>books[i][j];
        }
    }

    for (int i = 1; i <= pow(2,n); ++i){
        bool done = true;
        int pos=0;
        int tab[12] = {0};
        int coast=0;
        int a=i;
        while(a){
            if(a & 1){
                coast += books[pos][0];
                for(int j=0 ; j<m ; ++j){
                    tab[j] += books[pos][j+1];
                }
            }
            
            pos++;
            a = a>>1;
        }
        for(int k=0 ; k<m ; ++k){
            if(tab[k]<x){
                done = false;
                break;
            }
        }
        if(done){
            mincoast = min(mincoast,coast);
        }
    }
    cout<<(mincoast == INF ? -1 : mincoast)<<endl;
   return 0;
}


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

int main() {
	int N;
	int sum = 0;
        cin >> N;
	int A[N];
	int B[N];
	int C[N];
	for(int i = 1; i <= N; i++)
	   cin >> A[i];
	for(int i = 1; i <= N; i++)
	   cin >> B[i];
	for(int i = 1; i < N; i++)
	   cin >> C[i];
	   
	for(int i = 1; i <= N; i++)
	{
		sum += B[i];
		if (A[i+1] == A[i] + 1)
		sum += C[A[i]];
	}
	cout << sum;
	return 0;
}

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

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

int main(){
  
  ll n,k;
  cin>>n>>k;
  ll a[n];
  ll maxa=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    maxa=max(a[i],maxa);
  }
  ll gcd=a[0];
  for(int i=1;i<n;i++){
    gcd=GCD(gcd,a[i]);
  }
  if(k%gcd==0&&maxa>=k) cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
  
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int MAXN=1010;
int n,m;

char s[MAXN],t[MAXN];

int main()
{
	scanf("%s",s);
	n=strlen(s);
	scanf("%s",t);
	m=strlen(t);
	for(int i=0;i<n;i++)
	{
		s[i+n]=s[i];
		bool flag=0;
		for(int j=i;j<=i+n-1;j++)
			if(t[j-i]!=s[j])
			{
				flag=1;
				break;
			}
		if(!flag)
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std;

unordered_map<string, int> hashh;

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

    char s;
    long long int answer = 0;
    for (int i = 0; i < N; i++) {
        vector<char> mojis;

        for (int j = 0; j < 10; j++) {
            cin >> s;
            mojis.push_back(s);
        }
        sort(mojis.begin(),mojis.end());

        string key(mojis.begin(), mojis.end());

        if (hashh.count(key) == 0) hashh[key] = 0;
        else hashh[key] += 1;

        answer += hashh[key];
    }

    cout << answer << endl;
}

Measured memory_bytes: 10660
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    n,m = map(int, input().split())
    l = list(map(int, input().split()))
    l.sort()

    ans = 0
    if n<m:
        L = []
        for i in range(m-1):
            L.append(l[i+1] - l[i])
        L.sort()
        for i in range(m-n):
            ans += L[i]
    print(ans)

if __name__=="__main__":
    main(
    )


Measured memory_bytes: 92484
#!/usr/bin/ruby
#is07kuno report10b

def accept(s,atm)
	cur = 0
	s.each_byte{|c|
		cur = atm[cur][c.chr]
		if cur == nil then return false end
	}
	return atm[cur][:final] == true
end

atm = [
	{"0" => 1, "1" => 2},
	{"1" => 3},
	{"0" => 1},
	{"0" => 4, "1" => 5},
	{"0" => 5, "1" => 2},
	{"0" => 2, "1" => 1, :final => true}
]

while gets
	exit if $_.chomp=='#'
	puts accept($_.chomp,atm) ? 'Yes' : 'No'
end

Measured memory_bytes: 2332
#include<iostream>
using namespace std;
int max2,max1;
int main()
{
	string a;
	cin>>a;
	for(int i=0;i<a.size();i++)
	{
		if(i%2==0) if(a[i]=='0') max2++;
		if(i%2==1) if(a[i]=='1') max2++;
	}
	for(int i=0;i<a.size();i++)
	{
		if(i%2==0) if(a[i]=='1') max1++;
		if(i%2==1) if(a[i]=='0') max1++;
	}
	cout<<min(max1,max2);
} 

Measured memory_bytes: 512
S = input()
S = S[::-1]
i = 0
while len(S) > 0:
    if S.startswith('maerd'):
        S = S[5:]
    elif S.startswith('remaerd'):
        S = S[7:]
    elif S.startswith('esare'):
        S = S[5:]
    elif S.startswith('resare'):
        S = S[6:]
    else:
        print('NO')
        exit()
else:
    print('YES')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define fill(x,v) memset(x, v, sizeof(x))
#define PI (ld)acos(-1)
#define endl '\n'
#define dbg(x) cout<<#x<<"="<<(x)<<endl;
#define dbg2(x,y) cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<endl; 
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define IO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
const ld eps=(ld)1e-9;
const ll inf=(ll)1e18;
const ll mod=(ll)1e9+7;
int n, a[100007][3] ,dp[100007][3];
int f(int i, int x){
	if(i==1){
		return a[i][x];
	}
	if(dp[i][x]!=-1){
		return dp[i][x] ;
	}
	dp[i][x]=a[i][x]+max(f(i-1,(x+1)%3),f(i-1,(x+2)%3));
	return dp[i][x];
}


void solve(){
	cin>>n;
	fill(dp,-1);
	for (int i = 1; i <=n; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			cin>>a[i][j];
		}
	}
	int ans=INT_MIN;
	for (int i = 0; i < 3; ++i)
	{
		ans=max(ans,f(n,i));
	}
	cout<<ans;
}

int main(){fio;
int test=1;
// cin>>test;
while(test--){
	solve();
	cout<<endl;
}
return 0;
}

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

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

  if (N % 500 <= A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  // ここにプログラムを追記
}

Measured memory_bytes: 3544
from collections import defaultdict
n = int(input())
cnt = 0
d = defaultdict(int)
for i in range(1,n+1):
  a = int(str(i)[0])
  b = int(str(i)[-1])
  if b != 0:
    d[a*10+b] += 1
for i in range(1,n+1):
  a = int(str(i)[0])
  b = int(str(i)[-1])
  if b != 0:
    cnt += d[b*10+a]
print(cnt)

Measured memory_bytes: 9452
from itertools import permutations

N, M = map(int, input().split())
INF = 10**18
matrix = [[INF]*N for _ in range(N)]
for _ in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    matrix[a][b] = 1
    matrix[b][a] = 1

ans = 0


for p in permutations(range(1, N)):
    ok = True
    cur = 0
    for pi in p:
        if matrix[cur][pi] == INF:
            ok = False
            break
        cur = pi
    if ok:
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
    int n,a[100] ;
    scanf("%d",&n);
    for(int i = 0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i = 1; i<= n; i++)
    {
        printf("%d", a[n-i]);
        if (i==n)
            printf("\n");
        else 
            printf(" "); 
    }
    return 0;    
}


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

long GCD(long m, long n) {
  if (m < n) swap(m, n);
  
  if (m % n == 0) return n;
  
  return GCD(n, m % n);
}

long LCM(long m, long n) {
  return m / GCD(m, n) * n;
}

int main() {
  int N;
  cin >> N;
  
  vector<long> T(N);
  for (int i = 0; i < N; i++) cin >> T.at(i);
  
  if (N == 1) cout << T.at(0);
  else {
    long answer = LCM (T.at(0), T.at(1));
  
    for (int i = 2; i < N; i++) answer = LCM(answer, T.at(i));
  
    cout << answer << endl;
  }
}

Measured memory_bytes: 256
N = int(input())

open = []
earn = []

for _ in range(N):
    open.append(list(map(int, input().split())))

for _ in range(N):
    earn.append(list(map(int, input().split())))


ans = -float('inf')
for i in range(1, 1 << 10):
    tmp = 0
    same = [0]*N
    for j in range(N):
        for k in range(10):
            if open[j][k] == 1 and (i & (1 << k)):
                same[j] += 1

    for j in range(N):
        tmp += earn[j][same[j]]
    ans = max(ans, tmp)

print(ans)


Measured memory_bytes: 3064
N = int(input())
A = [int(a) for a in input().split()]

ans = [0]*N
num = 0
B = sorted(A)
j = 0
for i in range(N):
    cnt = 0
    while j < N and B[j] <= A[i]:
        cnt += max(0, B[j]-num)
        j += 1
    ans[i] = cnt + max(0, (N-j)*(A[i]-num))
    num = max(num, A[i])

for a in ans:
    print(a)

Measured memory_bytes: 14208
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int main(){

	int N,M,left,right,point,dp[394];
	int words[394];

	for(int i = 1; i <= 393; i++)words[i] = 0;

	scanf("%d",&N);

	for(int loop = 0; loop < N; loop++){
		scanf("%d %d %d",&left,&right,&point);
		for(int i = left; i <= right; i++){
			words[i] = max(words[i],point);
		}
	}

	bool FLG = true;
	queue<int> Q;
	int length;

	scanf("%d",&M);

	for(int loop = 0; loop < M; loop++){
		scanf("%d",&length);

		for(int i = 0; i <= length; i++)dp[i] = 0;

		for(int i = 1; i <= length; i++){
			for(int loc = i; loc <= length; loc++){
				if(loc-i == 0 || dp[loc-i]  != 0){
					dp[loc] = max(dp[loc],dp[loc-i]+words[i]);
				}
			}
		}

		if(dp[length] == 0){
			FLG = false;
		}else{
			Q.push(dp[length]);
		}
	}

	if(!FLG){
		printf("-1\n");
	}else{
		while(!Q.empty()){
			printf("%d\n",Q.front());
			Q.pop();
		}
	}

	return 0;
}

Measured memory_bytes: 2712
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split(' ');
            var a = int.Parse(ab[0]);
            var b = int.Parse(ab[1]);

            Console.WriteLine((a - 1) * (b - 1));
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), cnt(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    int mn = *min_element(a.begin(), a.end());
    if (cnt[mn] > 2) {
        cout << "Impossible" << '\n';
        return 0;
    }
    int mx = mn * 2;
    if (cnt[mn] == 2) {
        mx--;
    }
    for (int i = mn + 1; i <= mx; i++) {
        if (cnt[i] < 2) {
            cout << "Impossible" << '\n';
            return 0;
        }
    }
    for (int i = mx + 1; i < n; i++) {
        if (cnt[i]) {
            cout << "Impossible" << '\n';
            return 0;
        }
    }
    cout << "Possible" << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    ll h,w,n;
    cin>>h>>w>>n;
    ll sx,sy;
    cin>>sx>>sy;
    bool win=false;
    string S,T;
    cin>>S>>T;
    pll H={0,h+1};
    pll W={0,w+1};
    reverse(S.begin(),S.end());
    reverse(T.begin(),T.end());
    vector<pll> A(n),B(n);
    for(int i=0;i<n;i++){
        if(T[i]=='U'){
            H.S++;
            H.S=min(H.S,h+1);
        }
        else if(T[i]=='D'){
            H.F--;
            H.F=max(H.F,0LL);
        }
        else if(T[i]=='R'){
            W.F--;
            W.F=max(W.F,0LL);
        }
        else{
            W.S++;
            W.S=min(W.S,w+1);
        }
        
        if(S[i]=='D'){
            H.S--;
            if(H.S<=1){win=true;}
        }
        else if(S[i]=='U'){
            H.F++;
            if(H.F>=h){win=true;}
        }
        else if(S[i]=='L'){
            W.F++;
            if(W.F>=w){win=true;}
        }
        else{
            W.S--;
            if(W.S<=1){win=true;}
        }
        if(W.F>=W.S || H.F>=H.S){win=true;}
        A[i]=H;
        B[i]=W;
    }
    if(H.F>=sx || H.S<=sx || W.F>=sy || W.S<=sy){win=true;}
    if(win){cout<<"NO"<<endl; return 0;}
    else{cout<<"YES"<<endl;}
    
    
    return 0;
}


Measured memory_bytes: 7048
"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.trim().split(/ |\n/), cid = 0;

function main() {
    let A = +cin.shift();
    let B = +cin.shift();
    let C = +cin.shift();
    let K = +cin.shift();
    if (K < A) {
        console.log(K);
    } else if (K <= A + B) {
        console.log(A);
    } else {
        console.log(A - K + (A + B));
    }
}
main();


Measured memory_bytes: 29888
from functools import reduce

n, x = map(int, input().split())
a_s = list(map(int, input().split()))

a_x = sorted([abs(a - x) for a in a_s])

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

x = reduce(gcd, a_x)
print(x)

Measured memory_bytes: 14596
from collections import deque
import sys
sys.setrecursionlimit(100000)

class Node():
    def __init__(self, p=None, l=None, r=None):
        self.parent = p
        self.left = l
        self.right = r
        self.depth = None

n = int(input())
nodes = [Node() for i in range(n)]
for i in range(n):
    id, k, *c = list(map(int, input().split(' ')))
    if k == 0: continue
    nodes[id].left = c[0]
    nodes[c[0]].parent = id
    for j in range(1, k):
        nodes[c[j-1]].right = c[j]
        nodes[c[j]].parent = id

root = None
for i in range(n):
    if nodes[i].parent == None:
        root = i

def get_childs(i):
    if nodes[i].left == None: return []
    j = 0
    childs = [nodes[i].left]
    while nodes[childs[j]].right != None:
        childs.append(nodes[childs[j]].right)
        j += 1
    return childs

# 再帰だと segmentation faultが発生する
# while で実装

def set_depth(s):
    nodes[s].depth = 0
    queue = deque([s])
    while len(queue) > 0:
        u = queue.popleft()
        par_depth = nodes[u].depth
        next_child = nodes[u].left
        while next_child != None:
            nodes[next_child].depth = par_depth + 1
            queue.append(next_child)
            next_child = nodes[next_child].right

set_depth(root)

for i in range(n):
    nodetype = 'internal node'
    childs = get_childs(i)
    if childs == []:
        nodetype = 'leaf'
    parent = nodes[i].parent
    if parent == None:
        parent = -1
        nodetype = 'root'
    print('node ' + str(i) + ': parent = ' + str(parent) + ', depth = ' + str(nodes[i].depth) + ', ' + nodetype + ', ' + str(childs))



Measured memory_bytes: 34036
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n,m,v,p = map(int,readline().split())
a = [int(i) for i in readline().split()]
a.sort(reverse=True)
ans = p
v -= (p-1)
g = a[p-1]
L = 1
use = m-g

for i in range(p,n):
  mar = g-a[i]
  V = v-(n-1-i)
  if mar > m:
    break
  if V <= 1:
    if mar <= m:
      ans += 1
      L += 1
      use += m-a[i]
    else:
      break
  else:
    if use+a[i]*L >= (V-1)*m:
      ans += 1
      L += 1
      use += m-a[i]
    else:
      break

print(ans)

Measured memory_bytes: 12992
V,E,F=map(int,input().split())
EDGE=dict()
EDGE2=[[] for i in range(V)]

for i in range(E):
    x,to,c,d=map(int,input().split())
    EDGE[(x,to)]=[c,d]
    EDGE2[x].append(to)

BACK=[-1]*V
P=[0]*V

# 一回ベルマンフォードをしてポテンシャルを求める.

ANS=[float("inf")]*V
ANS[0]=0

for rep in range(V):    
    for x,to in EDGE:
        c,d=EDGE[(x,to)]
        if c>0 and ANS[to]>ANS[x]+d:
            ANS[to]=ANS[x]+d
            BACK[to]=x

P=[ANS[i] for i in range(V)]
LA=ANS[V-1]

NOW=V-1
while NOW!=0:
    fr=BACK[NOW]
    EDGE[(fr,NOW)][0]-=1

    if (NOW,fr) in EDGE:
        EDGE[(NOW,fr)][0]+=1
    else:
        EDGE[(NOW,fr)]=[1,-EDGE[fr,NOW][1]]
        EDGE2[NOW].append(fr)

    NOW=fr
    
for x,to in EDGE:
    EDGE[(x,to)][1]+=P[x]-P[to]

# あとはダイクストラを使える.

import heapq

for i in range(F-1):
    ANS=[float("inf")]*V
    Q=[(0,0)]
    ANS[0]=0

    while Q:
        time,ind=heapq.heappop(Q)
        if time>ANS[ind]:
            continue

        for to in EDGE2[ind]:
            c,d=EDGE[(ind,to)]
            if c>0 and ANS[to]>ANS[ind]+d:
                ANS[to]=ANS[ind]+d
                BACK[to]=ind
                heapq.heappush(Q,(ANS[to],to))

    LA+=ANS[V-1]+P[V-1]-P[0]

    if LA==float("inf"):
        break

    P=[P[i]-ANS[i] for i in range(V)]

    NOW=V-1
    while NOW!=0:
        fr=BACK[NOW]
        EDGE[(fr,NOW)][0]-=1

        if (NOW,fr) in EDGE:
            EDGE[(NOW,fr)][0]+=1
        else:
            EDGE[(NOW,fr)]=[1,-EDGE[fr,NOW][1]]
            EDGE2[NOW].append(fr)

        NOW=fr

    for x,to in EDGE:
        EDGE[(x,to)][1]+=ANS[to]-ANS[x]
    

if LA==float("inf"):
    print(-1)
else:
    print(LA)
            
        



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

using namespace std;

//AOJ GRL_1_Cの問題
//こっちの方がより一般的かも

const long long inf = 1LL << 62;

void warshall_floyd(int n, vector<vector<long long>> &d) {
	for (int k = 0; k < n; k++) {       // 経由する頂点
		for (int i = 0; i < n; i++) {    // 始点
			if (d[i][k] == inf) { continue; }
			for (int j = 0; j < n; j++) {  // 終点
				if (d[k][j] == inf) { continue; }
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

int main() {

	int h, w;
	cin >> h >> w;

	int v, e; //頂点数、エッジ数
	//cin >> v >> e;
	v = 10;
	e = 100;

	//10までの隣接行列を読み込む
	//この問題では有向きグラフG[始点][終点]
	vector<vector<long long>> G(v, vector<long long>(v, inf));
	int in1;
	for (int i = 0; i < v; i++) {
		for (int j = 0; j < v; j++) {
			cin >> in1;
			G[i][j] = in1;
		}
	}

	warshall_floyd(v, G);

	//こっからはこの問題専用。
	long long res = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> in1;
			if (in1 != -1) {
				res += G[in1][1];
			}
		}
	}

	cout << res << endl;

	return 0;

}

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

using namespace std;
const int N = 302;
double dp[N][N][N];
int n;
int cnt[4];


int main(){
    cin >> n;
    for(int i = 0;i < n;i++){
        int x;
        scanf("%d", &x);
        cnt[x]++;
    }

    for(int k = 0;k <= cnt[3];k++){
        for(int j = 0;j <= cnt[2] + cnt[3] - k;j++){
            for(int i = 0;i <= n - j;i++){
                if(i == 0 && j == 0 && k == 0)
                    continue;
                dp[i][j][k] = 1;
                if(i)
                    dp[i][j][k] += 1.0 * i / n * dp[i - 1][j][k];
                if(j)
                    dp[i][j][k] += 1.0 * j / n * dp[i + 1][j - 1][k];
                if(k)
                    dp[i][j][k] += 1.0 * k / n * dp[i][j + 1][k - 1];
                dp[i][j][k] /= 1 - 1.0 * (n - i - j - k) / n;            
            }
        }
    }
    printf("%.10f", dp[cnt[1]][cnt[2]][cnt[3]]);
}

Measured memory_bytes: 111772
# ABC173b


def main():
    import sys
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    n = int(input())
    s = [input() for _ in range(n)]
    from collections import Counter
    d = Counter(s)
    for i in ['AC', "WA", "TLE", "RE"]:
        print(i, 'x', d[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 83404
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
ll euclidean_gcd(ll a, ll b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}


int main() {
  int w, a, b;
  cin >> w >> a >> b;
  int ans = max(0,abs(b-a)-w);
  cout << ans << endl;
  return 0;
}

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

const int INF = 1e9;

int main() {
  int n,k;
  cin>>n>>k;
  int h[n];
  for(int i=0;i<n;i++) cin>>h[i];

  sort(h, h+n);
  int ans = INF;
  for(int i=0;i<n-k+1;i++){
    ans = min(ans, h[i+k-1]-h[i]);
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 640
#include  <bits/stdc++.h>
    using namespace std;
     
    int main(){
      int a,b,c;
      
      cin >> a >> b;
      
      if (a%2 == 0 || b%2 == 0 )
        cout << "Even" << endl;
      else
        cout << "Odd" << endl;
      
        
    }


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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 10000000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
 ll N,M;cin >> N >> M;
 vector<ll> A(N),sum(N+1);
 for(int i = 0;i < N;i++){
   cin >> A[i];
   sum[i+1] = sum[i] + A[i];
   sum[i+1] %= M;
 }
 sort(sum.begin(),sum.end());
 /*for(int i = 0;i < N+1;i++){
   cout << sum[i] << ' ';
 }
 cout << endl;*/
 
 vector<ll> C(1,1);
 for(int i = 0;i < N;i++){
   if(sum[i] == sum[i+1])C.back()++;
   else C.push_back(1);
 }
 ll ans = 0;
 for(int i = 0;i < C.size();i++){
   //cout << C[i] << ' ';
   ans += (C[i] * (C[i] - 1)) / 2;
 }
 //cout << endl;
 cout << ans << endl;
}

Measured memory_bytes: 2428
N,K=map(int,input().split())
l=[0]*N
count=0
for i in range(K):
    d=int(input())
    A=list(map(int,input().split()))
    for index ,m in enumerate(A):
        l[m-1]+=1
for i in range(N):
    if l[i]==0:
        count+=1
print(count)



Measured memory_bytes: 9200
#include<stdio.h>
int main(void)
{
  int A,B,C,D,count;
  scanf("%d %d %d %d", &A, &B, &C, &D);
  while(A > 0 && C > 0){
    if(count % 2 == 0){
      C-=B;
    }else{
      A-=D;
	}
    count++;
  }

  if(A <= 0){
    printf("No\n");
  }

  if(C <= 0){
    printf("Yes\n");
  }

  return 0;

}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <cassert>
#include <random>  
#include <ctime>
#define pb push_back
#define x first
#define y second
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
using namespace std;

template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
typedef long long base;
typedef pair <int, int> point;


const string FILENAME = "input";
const int MAXN = 1e5 + 10;

long long n, k;
long long ans = 0;

int a[MAXN], b[MAXN];

long long try_mask(long long k) {
	//cout << k << endl;
	long long ans = 0;
	for (int i = 0; i < n; ++i) {
		if ((k & a[i]) == a[i])
			ans += b[i];
	}
	return ans;
}

int main() {
	ios::sync_with_stdio(0);
	srand(time(0));
	//read(FILENAME);
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		cin >> a[i] >> b[i];
	}
	ans = try_mask(k);
	for (int i = 0; i < 30; ++i) {
		if ((k >> i) & 1) {
			chkmax(ans, try_mask(k - (k % (2LL << i)) + (1LL << i) - 1));
		}
	}
	cout << ans << endl;
}











Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
ll n,cnt,flag;
int main()
{
    //IOS;
    cin>>n;
    flag=0;
    for(int i=1;i<=n;i++)
    {
        cin>>cnt;
        if(cnt%2==0)
        {
            if(cnt%3==0||cnt%5==0)
            {
                ;
            }
            else
            {
                flag=1;
            }
        }
    }
    if(flag==1)
    {
        cout<<"DENIED"<<endl;
    }
    else
    {
        cout<<"APPROVED"<<endl;
    }
    return 0;
}
/*

*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
const ll mod=1e9+7; 
int a[20];
int n,endd=1;
void solve(){
	sc(n);
	while(n){
		n--;
		int change=1;
		while(change<=endd){
			if(change==endd-1&&a[change]<9)break;
			if(a[change]<a[change+1]+1&&a[change]<9)break;
			change++;
		}if(change==endd)endd++;
		a[change]++;
		while(--change){
			a[change]=max(a[change+1]-1,0);
		}
	}dep(i,endd-1,1)pf("%d",a[i]);
	pf("\n");
}
int main(){
  	solve();
}

Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <cassert>
#include <deque>
#include <set>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

ll a[(int)1e5 + 1];
ll b[(int)1e5 + 1];
ll c[(int)1e5 + 1];

//#define LOCAL_DEBUG
int main() {
#ifdef LOCAL_DEBUG
	freopen("input.txt","r", stdin);
#endif
	int N; int K;
	cin >> N >> K;
	for (int i = 1; i <= N; i++) cin >> a[i];
	b[0] = 0;
	c[0] = 0;
	for (int i = 1; i <= N; i++) {
		b[i] = b[i - 1] + max(0LL, a[i]);
		c[i] = c[i - 1] + a[i];
	}

	ll ans = 0;
	for (int i = 1; i <= N - K + 1; i++) {
		ans = max(ans, (b[i - 1] - b[0]) + (b[N] - b[i + K - 1]));
		ans = max(ans, (b[i - 1] - b[0]) + (b[N] - b[i + K - 1]) + (c[i + K - 1] - c[i - 1]));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2560
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtype!real;
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
	int n = rint, m = rint, q = rint;
	
	long[][] cf = new long[][](n, n);
	foreach(_; 0 .. m){
		int l = rint - 1, r = rint - 1;
		cf[l][r] += 1;
	}
	log("cf:", cf);
	
	long[][] sf = new long[][](n, n);
	foreach(i; 0 .. n) foreach(j; 0 .. n){
		sf[i][j] += cf[i][j];
		if(i > 0) sf[i][j] += sf[i - 1][j];
		if(j > 0) sf[i][j] += sf[i][j - 1];
		if(i > 0 && j > 0) sf[i][j] -= sf[i - 1][j - 1];
	}
	log("sf:", sf);
	
	foreach(_; 0 .. q){
		int l = rint - 1, r = rint - 1;
		long ans = sf[r][r];
		if(l > 0) ans -= sf[l - 1][r];
		ans.writeln;
	}
	
	
	
}


Measured memory_bytes: 6012
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const double EPS = 1e-10;
const int INF = 1001001001;

void func(vi evidence[], int num[], int now, int& cnt)
{
	if(num[now] != -1)
		return;
	rep(i, evidence[now].size())
		func(evidence, num, evidence[now][i], cnt);
	num[now] = cnt;
	++cnt;
}

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	
	vi evidence[20];
	rep(i, m){
		int a, b;
		scanf("%d%d", &a, &b);
		--a;
		--b;
		evidence[b].push_back(a);
	}
	
	int num[20], cnt=0;
	fill(num, num+n, -1);
	rep(i, n)
		func(evidence, num, i, cnt);
	
	int tmp[20];
	rep(i, n)
		tmp[num[i]] = i;
	
	rep(i, n)
		printf("%d\n", tmp[i]+1);
	
	return 0;
}

Measured memory_bytes: 1052