akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
namespace ZDY{
#define fir freopen("2.in","r",stdin)
#define ll long long
#define db double
#define Fur(i,x,y) for(int i=x;i<=y;i++)
#define fur(i,x,y) for(i=x;i<=y;i++)
#define Fdr(i,x,y) for(int i=x;i>=y;i--)
#define in2(x,y) in(x),in(y)
#define in3(x,y,z) in2(x,y),in(z)
#define in4(a,b,c,d) in2(a,b);in2(c,d)
#define clr(x,y) memset(x,y,sizeof(x))
#define cpy(x,y) memcpy(x,y,sizeof(x))
#define fl(i,x) for(ll i=head[x],to;to=e[i].to,i;i=e[i].next)
#define inf 2147483647
}
namespace FAST{
#define pob (fwrite(fob::b,sizeof(char),fob::f-fob::b,stdout),fob::f=fob::b,0)
#define pc(x) (*(fob::f++)=(x),(fob::f==fob::g)?pob:0)
#define gc ((*fib::f)?(*(fib ::f++)):(fgets(fib::b,sizeof(fib::b),stdin)?(fib::f=fib::b,*(fib::f++)):-1))
namespace fib{char b[300000]= {},*f=b;}namespace fob{char b[300000]= {},*f=b,*g=b+300000-2;}struct foce{~foce(){pob;fflush(stdout);}} _foce;namespace ib{char b[100];}template<class T>inline void in(T &x){x=0;char c;bool f=0;while((c=gc)>'9'||c<'0')if(c=='-')f=!f;x=c-48;while((c=gc)<='9'&&c>='0')x=x*10+c-48;if(f)x=-x;}template<class T>inline void out(T x){if(x==0){pc(48);return;}if(x<0){pc('-');x=-x;}char *s=ib::b;while(x) *(++s)=x%10,x/=10;while(s!=ib::b) pc((*(s--))+48);}template<class T>inline void outn(T x){out(x);pc('\n');}
inline char sc(){char c=gc;while(!(('A'<=c&&c<='Z')||('a'<=c&&c<='z')||('0'<=c&&c<='9')))c=gc;return c;}
template<class T>inline T ABS(T x){return x>0?x:-x;}
template<class T>inline T MAX(T x,T y){return x>y?x:y;}
template<class T>inline T MIN(T x,T y){return x<y?x:y;}
template<class T>inline T GCD(T x,T y){return y?GCD(y,x%y):x;}
template<class T>inline void swap(T x,T y){T t=x;y=t;x=y;}
}using namespace FAST;using namespace ZDY;using namespace std;
#define N 100001
ll n,m,s[N],ans=0;
map <ll,ll> v;
int main(){
	in2(n,m);
	Fur(i,1,n){
		in(s[i]);s[i]+=s[i-1];
		ll t=(++v[s[i]%m]);
		if(t>1)ans+=t-1;
	}
	cout<<ans+v[0]<<endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> c(m);
  for (int i = 0; i < m; ++i)
    cin >> c[i];
  vector<int> dp(n + 10001, 1000000001);
  dp[0] = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      dp[i + c[j]] = min(dp[i] + 1, dp[i + c[j]]);
  cout << dp[n] << endl;
}


Measured memory_bytes: 3204
# include<bits/stdc++.h>
using namespace std ;
int main () {
int A , B , K ; cin >> A >> B >> K ;
for ( int i = min (A , B ); i >= 1; --i ) {
if ( A % i == 0 && B % i == 0) {
--K ;
if ( K == 0) {
cout << i << endl ;
return 0;
}
}
}
assert ( false );
}


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

int main(){
  int n,m;
  cin >> n >> m;
  
  int res[m];
  memset(res,0,sizeof(res));
  
  for(int i = 0; i < n; ++i){
    int k;
    cin >> k;
    
    for(int j = 0; j < k; ++j){
      int x;
      cin >> x;
      
      ++res[x-1];
    }
  }
  
  int ans = 0;
  for(int i = 0; i < m; ++i){
    //cout << res[i] << endl;
    if(res[i] == n){
      ++ans;
    }
  }
  
  cout << ans << endl;
}

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

int main() {
	// your code goes here
    int n;
    cin>>n;
    
    int days[n][3];
    for(int i=0;i<n;i++)
    {
        cin>>days[i][0]>>days[i][1]>>days[i][2];
    }
    
    int dp[n][3];
    
    dp[0][0] = days[0][0];
    dp[0][1] = days[0][1];
    dp[0][2] = days[0][2];
    
    for(int i=1;i<n;i++)
    {
        dp[i][0] = max(days[i][0]+dp[i-1][1],days[i][0]+dp[i-1][2]);
        dp[i][1] = max(days[i][1]+dp[i-1][0],days[i][1]+dp[i-1][2]);
        dp[i][2] = max(days[i][2]+dp[i-1][1],days[i][2]+dp[i-1][0]);
    }
    
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}


Measured memory_bytes: 2560
n, x, y = map(int, input().split())
x -= 1
y -= 1
distance_dic = {}

def add_dic(p):
    if not p in distance_dic:
        distance_dic[p] = 1
    else:
        distance_dic[p] += 1

for i in range(x):
    for j in range(i+1,x):
        add_dic(j-i)
    for j in range(x,y):
        add_dic(min(j-i, x+y+1-i-j))
    for j in range(y,n):
        add_dic(x-y+1+j-i)
for i in range(x,y):
    for j in range(i+1,y):
        add_dic(min(j-i, y-x+1+i-j))
    for j in range(y, n):
        add_dic(min(j-i, -x-y+1+i+j))
for i in range(y,n-1):
    for j in range(i+1,n):
        add_dic(j-i)

for k in range(1, n):
    if k in distance_dic:
        print(distance_dic[k])
    else:
        print(0)

Measured memory_bytes: 50140
#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<ll,int>;

vector<P> factor(ll n){
	map<ll, int> ma;
	for(ll i=2; i*i<=n; i++){
		while(n%i==0){
			ma[i]++;
			n/=i;
		}
	}
	if(n!=1) ma[n]++;
	vector<P> ps;
	for(auto p : ma) ps.push_back(p);
	return ps;
}

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

	auto ps=factor(n);
	int m=ps.size();
	vector<int> ci(m);
	ll mn=LLONG_MAX;
	while(1){
		ll a=1;
		rep(i, m) rep(j, ci[i]) a*=ps[i].first;
		ll b=n/a;
		mn=min(mn, a+b-2);

		bool br=false;
		rep(i, m){
			ci[i]++;
			if(ci[i]>ps[i].second) ci[i]=0;
			else break;
			if(i==m-1) br=true;
		}
		if(br) break;
	}

	cout<<mn<<endl;

	return 0;
}


Measured memory_bytes: 3616
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
set_A = list(set(A))

l = {}
for i in range(len(set_A)):
    l[set_A[i]] = 0
for i in range(N):
    l[A[i]] += 1
    
ans = 0
for k in l.keys():
    if l[k] >= k:
        ans += (l[k] - k)
    else:
        ans += l[k]
print(ans)



Measured memory_bytes: 20340
#include <iostream>



using namespace std ;

int main()
{
string s;
	cin >> s;
	string s1 = s;
s[0]=s1[2];
s[1]=s1[1];
s[2]=s1[0];
	if (s == s1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
    return 0;
}


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

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



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

using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	int val = 0;

	vector<int> V;

	for (int i = 0; i < N; i++)
	{
		int v;
		cin >> v;
		V.emplace_back(v);
	}

	int maxval = 0;

	for (int i = 0; i <= N ; i++)
	{
		for (int j = 0; i+j <= min(N, K); j++)
		{
			int val = 0;
			vector<int> neg;

			for (int k = 0; k < i; k++)
			{
				val += V[k];
				if (V[k] < 0)
				{
					neg.emplace_back(V[k]);
				}
			}
			for (int k = 1; k <= j; k++)
			{
				val += V[N-k];
				if (V[N-k] < 0)
				{
					neg.emplace_back(V[N-k]);
				}
			}

			sort(neg.rbegin(), neg.rend());

			int r = K - i - j;

			while (!neg.empty() && r != 0)
			{
				val -= neg.back();
				neg.pop_back();
				r--;
			}

			maxval = max(val, maxval);
		}

	}

	cout << maxval << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    b[i]=a[i]-(i+1);
  }
  sort(b.begin(),b.end());
  long long ans=0;
  for(int i=0;i<n;i++){
    ans+=abs(b[i]-b[n/2]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(){
    int N, p[11];
    int sum = 0;
    scanf("%d", &N);
    for (int c = 0; c < N;c++){
        scanf("%d", &p[c]);
    }
     qsort(p, N, sizeof(int), compare_int);
     p[N - 1] = p[N - 1] / 2;

        for (int d = 0; d < N;d++){
         sum += p[d];
                }
                printf("%d", sum);
                
                return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main (){
    int a, b, c[300][300];
    int i = 0 , k = 0;
    while (1){
        cin >> a >> b;
        if (a == 0 && b == 0) break;
        for (i = 0; i < a; i++){
            for (k = 0; k < b; k++){
                c[i][k] = 1;
            }
        }
        for (i = 0; i < a; i++){
            for (k = 0; k < b; k++){
                if (c[i][k] = 1){
                    cout << "#" ;
            }
                
        }
        cout << endl;
    }
    cout  << endl;
    }
    
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]+n>'Z') s[i]='A'+n-('Z'-s[i])-1;
		else s[i]=s[i]+n;
	}
	cout<<s;
	return 0;
}
	
	


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    string S, T; cin >> S >> T;
    int ans = 0;
    REP(i, 3)
    {
        if(S[i] == T[i]) ans++;
    }
    cout << ans << endl;
}

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

    solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi= vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;

int main()
{
    ll n, m;
    cin >> n >> m;
    vi as(n);
    for(ll i=0; i<n; i++) cin >> as.at(i);
    sort(as.begin(), as.end(), greater<ll>());
    double sum = 0;
    for(auto i : as)
    {
        sum += i;
    }
    double d = sum / static_cast<double>(4*m);
    if(as.at(m - 1) < d) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
ll n,s,sq,i;

bool check(ll b)
{
	ll ret=0,t=n;
	for(;t;t/=b) ret+=t%b;
	return (ret==s);
}

ll solve()
{
	if(s==n) return n+1;
	if(s>n) return -1;
	
	for(i=2;i*i<=n;i++)
		if(check(i)) return i;
	for(;i;i--)
		if((n-s)%i==0&&check((n-s)/i+1)) return ((n-s)/i+1);
	return -1;
}

int main()
{
	cin >> n >> s;sq=sqrt(n);
	cout << solve();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int mod = 998244353;
int n,m;

const int N = 3e6;
int fac[N+10],ifac[N+10];
inline int Mod(int x){
	return x>=mod?x-mod:x;
}
inline int power(int a,int b){
	int ret=1;
	for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) ret=1ll*ret*a%mod;
	return ret;
}
inline void init(int n){
	fac[0]=1;
	For(i,1,n) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n]=power(fac[n],mod-2);
	Dow(i,n-1,0) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
}
inline int C(int n,int m){
	if (n<m||m<0) return 0;
	return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}

inline int calc(int s,int n){
	return C(s+n-1,n-1);
}
inline int calc(){
	int ret=0;
	For(i,2*m+1,3*m) ret=(ret+1ll*n*calc(3*m-i,n-1))%mod;
	return ret;
}

inline int calc_(){
	int ret=0;
	For(i,0,min(n,m)){
		int j=3*m-i;
		if (j&1) continue;
		ret=(ret+1ll*C(n,i)*calc(j/2,n))%mod;
	}
	return ret;
}

int main(){
	n=read(),m=read(),init(N);
	printf("%d\n",Mod(calc_()+mod-calc()));
}

Measured memory_bytes: 27204
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
typedef long long ll;
bool tr[15];
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
typedef long long ll;
int main() {
  int a=0,n,b,A,B,t,T,sa,sb,ans=0;
  string word;
  bool flag;
  cin>>n;
  cin>>b;
  //vector<vector<bool>> sinsetsu(15,vector<bool>(14)),usotsuki(15,vector<bool>(14));
  //vector<vector<int>> sss(15,vector<int>(14))
  
  cout<<6-n-b<<endl;
  //vector<vector<int>> sss(h,vector<int>(w));
  //vector<int> a(k),b(k);
  //char x;
}

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

// aを常に小さい値にする
template<class T> void chmin(T &a, T b){ if(a>b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

/*
 *
 *
 *
 * */

int main() {

    int N;
    ll M;
    cin >> N >> M;
    vector<pair<ll, ll>> v(N);
    for (int i = 0; i < N; ++i)
        cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end());

    ll res = 0;
    for (int i = 0; i < N && M > 0; ++i) {
        res += v[i].first * min(M, v[i].second);
        M -= min(M, v[i].second);
    }
    cout << res << endl;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define ALL(a) (a).begin(),(a).end()
#define EACH(e,v) for(auto& e:v)
#define SORT(v) sort(ALL(v))
#define PERM(v) SORT(v);for(bool c##p=1;c##p;c##p=next_permutation(ALL(v)))
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = 1000'000'007;
 
vector<int> vec;
signed main(){
    int n,l,r;
    while(cin>>n>>l>>r,n){
        vec.clear();
        rep(i,n){
            int a;cin>>a;
            vec.push_back(a);
        }

        int ans=0;


        int daiji=-1;
        for(int num=l;num<=r;num++){
            daiji=-1;
            for(int i=0;i<vec.size();i++){
                if(num%vec[i]==0){
                    daiji=i+1;
                    break;
                }
            }
            //dump(daiji);


            if(daiji==-1){
                if(vec.size()%2==0){
                    ans++;
                }
            }else if((daiji)%2==1){
                ans++;
            }
        }
        cout<<ans<<endl;

        

    }
 
}


Measured memory_bytes: 3128
<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
list($N,$A,$B) = explode(" ",trim(fgets(STDIN)));
//$h = explode(" ",trim(fgets(STDIN)));

$minxy = ($A+$B) - $N;
if ($minxy < 0) {
  $minxy = 0;
}
$maxxy = min($A,$B);
printf("%d %d\n",$maxxy,$minxy);


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N);
  int ans=0;
  for (int i=0; i<N; i++){
    cin >> A.at(i);
  }
  for (int i=0; i<N; i++){
    cin >> B.at(i);
  }
  for (int i=0; i<N-1; i++){
    cin >> C.at(i);
  }
  for (int i=0; i<N; i++){
    ans = ans + B.at(i);
  }
  for (int i=0; i<N-1; i++){
    if (A.at(i+1)==A.at(i) + 1) {
      ans = ans + C.at(A.at(i)-1);
    }
  }
  cout << ans << endl; 
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		long x = sc.nextLong();
		
		long[] map = new long[N];
		for (int i = 0; i < N; i++) {
			map[i] = sc.nextLong();
		}
		
		long ans = 0;
		for (int i = 0; i < N-1; i++) {
			long tmp = map[i] + map[i+1];
			if (tmp > x) {
				long eat = tmp - x;
				if (map[i+1] - eat < 0) {
					map[i] -= eat - map[i+1];
					map[i+1] = 0;
				} else {
					map[i+1] -= eat;
				}
				ans += eat;
			}
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 56864
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }

// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

void solve(long long N) {
  cout<< N * N * N <<endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 256
x, n = map(int, input().split())
p = set(map(int, input().split()))
if n != 0:
    p_all = set([i for i in range(min(p) - 1, max(p) + 2)])
    q = list(p_all - p)
    q.sort(reverse=True)
    d = float('inf')
    for i in q:
        tmp = abs(i - x)
        if tmp <= d:
            d = tmp
            ans = i
else:
    ans = x
print(ans)

Measured memory_bytes: 9204
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll dgt=-1;
	string tmp="1";
	REP(i,10) {
		cout<<"? "<<tmp<<endl;
		string ans;
		cin>>ans;
		if(ans=="N") {
			dgt=i;
			break;
		}
		tmp+="0";
	}
	if(dgt==-1) {
		string tmp2="9";
		REP(i,10) {
			cout<<"? "<<tmp2<<endl;
			string ans;
			cin>>ans;
			if(ans=="Y") {
				string ret="1";
				REP(j,(ll)tmp2.size()-1) ret+='0';
				cout<<"! "<<ret<<endl;
				return 0;
			}
			tmp2+="9";
		}
	} else {
		string lbs="1",ubs="10";
		REP(i,dgt-1) {
			lbs+='0';
			ubs+='0';
		}
		ll lb=stol(lbs),ub=stol(ubs);
		while(ub-lb>1) {
			ll mid=(lb+ub)/2;
			cout<<"? "<<mid*10<<endl;
			string ans;
			cin>>ans;
			if(ans=="N") lb=mid;
			else ub=mid;
		}
		cout<<"! "<<lb+1<<endl;
		return 0;
	}
}


Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <set>

using namespace std;

#define pb push_back
#define mp make_pair
#define x first
#define y second

typedef long long ll;

const ll INF = 1e9+5;
const ll MOD = 1e9+7;

int main() {
	int a, b, c;
	cin >>a>>b>>c;
	int k;
	cin >>k;
	for (int i=0 ; i<k ; i++) {
		if (a>=b) b*=2;
		else if (b>=c) c*=2;
	}
	if (b>a and c>b) cout <<"Yes\n";
	else cout <<"No\n";
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int N;
  cin >> N;
  vector<int> A(N-1);
  rep(i, N-1){
    cin >> A.at(i);
  }
  vector<int> vec(N);
  rep(i, N-1){
    int dis, num = 0;
    dis = A.at(i);
    while(dis > 0){
      dis = dis - 1;
      num = num + 1;  
    }
    vec.at(num-1) = vec.at(num-1) + 1;
  }
  rep(i, N){
    cout << vec.at(i) << endl;
  }
} 
    
    

Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "C"
ll x;
ll ans;
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    read(x);
    ans=(x/11)*2;
    x%=11;
    if(x){
        if(x<7) ans+=1;
        else ans+=2;
    }
    write(ans);
}

Measured memory_bytes: 256
def resolve():
	n,l=map(int,input().split())
	a=[i+l for i in range(n)]
	p=[i for i in a if i>0]
	m=[i for i in a if i<0]
	if 0 in a:
		print(sum(a))
	elif len(p)<len(m):
		print(sum(a)-max(m))
	else:
		print(sum(a)-min(p))
		
resolve()

Measured memory_bytes: 38256
def main():
    n, k = map(int, input().split())
    H = list(map(int, input().split()))
    dp = [0] * n
    for i, Hi in enumerate(H):
        if i == 0:
            continue
        s = max(0, i-k) # iがk以下かどうかで処理が変わる.
        dp[i] = min([dl + abs(hl - Hi) for dl, hl in zip(dp[s:i], H[s:i])])
    print(dp[-1])
main()

Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14 100兆
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

struct edge {
  ll to;
  ll id;
  bool operator<(const edge &another) const{
    return id < another.id;
  };
};

vector<pair<int, vector<edge>>> tree;
vector<ll> d;
queue<ll> det;
ll dc = 0;

void bfs(ll x, ll i){
  if(d.at(x) >= 0){
    return;
  }
  d.at(x) = i;
  dc++;
  det.push(x);
}

vector<ll> addv;

void dfs(ll x, ll y){
  y += addv.at(x);
  tree.at(x).first += y;
  for(auto e : tree.at(x).second){
    if(d.at(e.to) > d.at(x)){
      dfs(e.to, y);
    }
  }
}

int main(){
  ll N, Q;
  cin >> N >> Q;
  d.resize(N);
  tree.resize(N);
  addv.resize(N);
  rep(i, N){
    d.at(i) = -1;
    addv.at(i) = 0;
  }
  vector<ll> a(N-1), b(N-1), p(Q), x(Q);
  rep(i, N-1){
    cin >> a.at(i) >> b.at(i);
    a.at(i)--;
    b.at(i)--;
    tree.at(a.at(i)).first = 0;
    tree.at(b.at(i)).first = 0;
    tree.at(a.at(i)).second.push_back({ b.at(i), i });
    tree.at(b.at(i)).second.push_back({ a.at(i), i });
  }
  rep(i, Q){
    cin >> p.at(i) >> x.at(i);
    p.at(i)--;
    addv.at(p.at(i)) += x.at(i);
  }
  bfs(0, 0);
  while(dc != N){
    ll q = det.front();
    det.pop();
    for(auto e : tree.at(q).second){
      bfs(e.to, d.at(q)+1);
    }
  }
  dfs(0, 0);
  rep(i, N){
    cout << tree.at(i).first << " ";
  }
  cout << endl;
}

Measured memory_bytes: 37888
#include <cstdio>
#include <cstring>
using namespace std;

int n, k;
int array[10];

int c[4];
bool use[10];
char str[10000][100];
int m;

int number[10000];
int p;

void Search(int i, int j)
{
	if (j == k){
		for (int l = 0; l < k; l++){
			char nstr[3];
			sprintf(nstr, "%d", c[l]);
			strcat(str[m], nstr);
		}
		
		int num;
		sscanf(str[m], "%d", &num);
//		printf("%d\n", num);

		bool f = false;
		for (int l = 0; l < p; l++){
			if (number[l] == num){
				f = true;
				break;
			}
		}
		
		if (!f){
			number[p] = num;
			p++;
		}
		
		m++;
		return;
	}
	
	if (i == n){
		return;
	}
	
	Search(i + 1, j);
	
	if (use[i]){
		return;
	}
	
	c[j] = array[i];
	
	use[i] = true;
	
	Search(0, j + 1);
	
	use[i] = false;
}

int main()
{
	while (scanf("%d %d", &n, &k), n + k){
		memset(array, 0, sizeof(array));
		memset(c, 0, sizeof(c));
		memset(use, 0, sizeof(use));
		memset(str, 0, sizeof(str));
		memset(number, 0, sizeof(number));
		m = 0;
		p = 0;
		
		for (int i = 0; i < n; i++){
			scanf("%d", &array[i]);
		}
		
		Search(0, 0);
		
		printf("%d\n", p);
	}
	
	return 0;
}

Measured memory_bytes: 2076
import Control.Monad
import Data.Char

main = do 
    n <- readLn :: IO Int
    let ln = length $ show n
    let cand = join $ [ replicateM i [7, 5, 3] | i <- [3..ln]]
    print $ length $ filter (\x -> (joinInt x <= n) && isSat x) cand

isSat :: [Int] -> Bool
isSat a = (7 `elem` a) && (5 `elem` a) && (3 `elem` a)

joinInt :: [Int] -> Int
joinInt l = read $ map intToDigit l

Measured memory_bytes: 2428
#include<stdio.h>
int main(void){
    int n;
    long long int a[10001],i,m=1000000,M=-1000000,S=0;
    scanf("%d",&n);
       for(i=0;i<n;i++){
        scanf("%lld",&a[i]);
        if (a[i]<=m)m=a[i];
        if (a[i]>=M)M=a[i];
        S=S+a[i];
    }
    printf("%lld %lld %lld\n",m,M,S);
    return 0;
}

Measured memory_bytes: 680
#include <cstdio>

using namespace std;

int card[256];

int main()
{
    int n;

    while (scanf("%d", &n), n){
        for (int i = 1; i < n * 2 + 1; i++){
            card[i] = 2;
        }

        for (int i = 0; i < n; i++){
            int pass;
            scanf("%d", &pass);

            card[pass] = 1;
        }

        int i = 0;
        int turn = 1;
        int now = 1;
        int hand[2] = {n, n};

        while (hand[0] && hand[1]){
            if (card[now] == turn){
                card[now] = 0;
                hand[turn - 1]--;
                turn = turn == 1 ? 2 : 1;
            }
            now++;

            if (now > n * 2 + 1){
                now = 1;
                turn = turn == 1 ? 2 : 1;
            }
        }

        printf("%d\n", hand[1]);
        printf("%d\n", hand[0]);
    }

    return (0);
}

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

int main(){
    int N, T;
    cin >> N >> T;
    vector<pair<int, int>> dish(N);
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        dish[i] = {a, b};
    }
    sort(dish.begin(), dish.end());
    
    int ans = 0;
    vector<int> dp(T+1, 0);
    for (int i = 0; i < N; i++) {
        int a = dish[i].first;
        int b = dish[i].second;
        for (int j = max(T-a, 0); j < T; j++) {
            ans = max(ans, dp[j]+b);
            
        }
        for (int j = T; j >= a; j--) {
            dp[j] = max(dp[j], dp[j-a]+b);
        }
    }
    
    for (int i = 0; i <= T; i++) ans = max(ans, dp[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define REV(x) reverse(ALL(x))
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define SP << " " <<
#define INF2 1000000000000000037
#define INF  1000000007
#define lwb(x,n) distance(x.begin(),lower_bound(ALL(x),(n)))
#define upb(x,n) distance(x.begin(),upper_bound(ALL(x),(n)))
#define fora(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true)
#ifdef _MY_DEBUG
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define de(...) CHOOSE((__VA_ARGS__,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define de(...)
#endif
using namespace std;
using ll = long long;
using ld = long double;
template<class T = ll> using v = vector<T>;
template<class T = ll> using vv = vector<vector<T>>;
template<class T = ll> using vvv = vector<vector<vector<T>>>;
template<class T> bool maxi(T &a, const T &b){ if(a<b){a=b;return 1;}return 0;}
template<class T> bool mini(T &a, const T &b){ if(b<a){a=b;return 1;}return 0;}
template<class T> ll sumer(const T& a){ return accumulate(ALL(a),0LL); }
template<class T> void UNIQUE(vector<T> &a){ SORT(a);a.erase(unique(ALL(a)),a.end());}
template<class T, class U> ostream &operator<<(ostream &os, const pair<T,U> &pe) { os << pe.first << " " << pe.second; return os;}
template<class T> ostream &operator<<(ostream &os, const v<T> &ve) { rep(i,ve.size()) os<< (i?" ":"")<<ve[i]; return os;}
ll topbit(ll a) { return a==0?-1:63-__builtin_clzll(a);}
ll botbit(ll a) { return a==0?64:__builtin_ctzll(a);}
ll popcount(ll a) { return __builtin_popcountll(a);}
#define dame {cout<< retword <<"\n"; return;}
#pragma endregion
//--MODIFS---------------------------------
#pragma region Modifs
#define retword "-1"
#define MOD  1000000007
using P  = pair<ll,ll>;
using TP  = tuple<ll,ll,ll>;
#pragma endregion
//--GLOBAL---------------------------------
ll five(ll A){
    return A*A*A*A*A;
}
//--MAIN-----------------------------------
void Main() {
    ll N;
    cin>>N;
    /*
    ll ans=five(200)-five(199);
    de(ans);
    */
    reps(i,-200,200){
        reps(j,-200,200){
            if(five(i)-five(j)==N){
                cout<< i SP j<<"\n"; return;
            }
        }
    }
}
//--START----------------------------------
int main() {
    cin.tie(nullptr); ios_base::sync_with_stdio(false);
    // ifstream in("input.txt"); cin.rdbuf(in.rdbuf());
    // ofstream out("output.txt"); cout.rdbuf(out.rdbuf());
    cout << fixed << setprecision(15);
    // ll Qkai; cin>>Qkai; rep(QQ,Qkai) Main();
    Main();
}
//-----------------------------------------

Measured memory_bytes: 3648
N, M = (int(i) for i in input().split())

if N == 1 and M == 1:
    print(1)

elif N == 2 or M == 2:
    print(0)

elif N == 1 or M == 1:
    if N == 1:
        print(M - 2)
    else:
        print(N - 2)

else:
    print((N - 2) * (M - 2))


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

using namespace std;

int m, k;

int main() {  
  scanf("%d%d", &m, &k);
  
  if (k >= (1<<m)) {
    puts("-1");
    return 0;
  }

  if (m == 0) {
    puts("0 0");
    return 0;
  } 

  if (m == 1) {
    if (k == 0) 
      puts("0 0 1 1");
    else
      puts("-1");
    return 0;
  } 
  
  
  for(int i = 0; i < (1<<m); ++i) 
    if (i != k)
      printf("%d ", i);
  printf("%d ", k);
  for(int i = (1<<m)-1; i >= 0; --i) 
    if (i != k)
      printf("%d ", i);
  printf("%d\n", k);
  
  return 0;  
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define forn(i, n) for (int i = 0; i < (int) (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    s[5] = ' ';
    s[13] = ' ';
    cout << s;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<ll, ll> P;
int main()
{
    ll N, M;
    cin >> N >> M;

    map<ll, ll> cnt;
    priority_queue<ll, vector<ll>, greater<ll>> que;

    ll sum = 0;
    rep(i, N) {
        ll A;
        cin >> A;
        sum += (ll)A;
        if (cnt.count(A) == 0) {
            cnt[A] = 1;
            que.push(A);
        }
        else {
            cnt[A]++;
        }
    }

    vector<P> card(M);

    rep(i, M) {
        P p;
        cin >> p.second >> p.first;
        card[i] = p;
    }

    sort(all(card));
    reverse(all(card));
    rep(i, M) {
        ll B, C;
        B = card[i].second;
        C = card[i].first;
        while (B > 0) {
            ll m = que.top();
            ll m_c = cnt[m];
            if (m >= C) break;
            ll minus = min(B, m_c);
            B -= minus;
            m_c -= minus;
            cnt[m] = m_c;
            if (cnt[m] == 0) que.pop();
            sum -= m * minus;
            sum += C * minus;
            if (cnt.count(C) == 0) {
                cnt[C] = minus;
            }
            else {
                cnt[C] += minus;
            }
            que.push(C);
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 12404
#include<iostream>
#include<algorithm>
using namespace std;
long long a[100005],n,A,B;
inline int read()
{
    int x=0,t=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
    if(ch=='-')t=-1,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
    return x*t;
}

bool judge(long long x){
    long long temp=x*B;
    long long sub=A-B;
    long long sum=0;
    for(int i=n;i>=1;i--){
        if(a[i]>temp){
            if((a[i]-temp)%sub)
                sum+=(a[i]-temp)/sub+1;
            else
                sum+=(a[i]-temp)/sub;
        }
    }
    if(sum<=x)
        return true;
    return false;
}
int main(){
	long long r,l;
	n=read();
	A=read();
	B=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		r+=a[i]/B+1;//粗略求出最大的时候的次数 
	}
	sort(a+1,a+n+1);
	l=1;
	while(l<r){
		long long mid=(l+r)>>1;
		if(judge(mid)){
			r=mid;
		}else l=mid+1;
	}
	printf("%lld",l);
	
} 

Measured memory_bytes: 1152
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors

n = int(input())
ans = set()

for x in make_divisors(n-1):
    if x != 1:
        ans.add(x)

for x in make_divisors(n):
    if x ==1 :
        continue
    if x == n:
        ans.add(x)
        continue
    m = n
    while m % x == 0:
        m = m//x
    
    if m % x == 1:
        ans.add(x)

print(len(ans))

Measured memory_bytes: 39152
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]

b = sorted(a, key = lambda x: x[1])

work = 0
flag = 0
for i in range(n):
    work += b[i][0]
    if work > b[i][1]:
        flag = 1
        break

if flag == 1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 55264
import java.util.Scanner;

public class Main {
    private static Scanner scan;

    public static void main(String[] args) {
        scan = new Scanner(System.in);
        while (true) {
            int a = scan.nextInt();
            String op = scan.next();
            int b = scan.nextInt();
            if (op.equals("+")) {
                sum(a + b);
            } else if (op.equals("-")) {
                sum(a - b);
            } else if (op.equals("*")) {
                sum(a * b);
            } else if (op.equals("/")) {
                sum(a / b);
            } else {
                return;
            }
        }
    }

    private static void sum(int sum) {
        System.out.println(sum);
    }
}

Measured memory_bytes: 18004
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String[] hanteisplit = S.split("");


		String aOfZ = "abcdefghijklnmopqrstuvwxyz";
		String[] aOfZsplit = aOfZ.split("");

		int countnai = 0;
		for(int a = 0;a < aOfZsplit.length;a++) {
			for(int ii = 0;ii < hanteisplit.length;ii++) {
				//aとhanteisplitの比較
				if(!(hanteisplit[ii].equals(aOfZsplit[a]))){
					countnai++;
					//System.out.println(aOfZsplit[a]+ " " + countnai);

				}
			}
			//文字列全部違う
			if(countnai == hanteisplit.length) {
				System.out.println(aOfZsplit[a]);
				System.exit(0);
				break;
			}
			countnai = 0;
		}
		System.out.println("None");
	}

}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);//数字の受け取り
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    //累積和
    vector<long long int> sum(n+1,0);//sum[0]を0で初期化
    for(int i=0;i<n;i++){
        sum[i+1] = sum[i] + a[i];
    }
    map<long long int,long long int> mp;
    for(int k=0;k<n+1;k++){
        mp[sum[k]]++; //sumの各数字の存在によってインクリメント
    }
    long long int ans = 0;
    for(const auto& it:mp){
        long long int num = it.second;
        ans += (num*(num-1)/2);
    }
    cout << ans << endl;
}



Measured memory_bytes: 15104
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

template<typename T> //最大公約数
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T> //最小公倍数
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

struct edge
{
    int to, cost;
};

vector<vector<int> > g;
vector<int> isVisited, out;
void Topological(int pos){
    isVisited[pos] = true;
    for (int i = 0; i < g[pos].size(); i++){
        if (!isVisited[g[pos][i]]){
            Topological(g[pos][i]);
        }
    }
    out.push_back(pos);
}

int main(){
    int V, E; cin >> V >> E;
    g.resize(V);
    isVisited.resize(V, 0);
    vector<int> IsVisited(V, 0);
    for (int i = 0; i < E; i++){
        int s, t; cin >> s >> t;
        g[s].push_back(t);
    }
    for (int i = 0; i < V; i++){
        if (isVisited[i]) continue;
        Topological(i);
    }
    reverse(out.begin(), out.end());
    for (int i = 0; i < out.size(); i++){
        cout << out[i] << endl;
    }
}


Measured memory_bytes: 3752
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  int a[n];
  int tot = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] %= m;
    tot += a[i];
    tot %= m;
  }
  int sum[n];
  map<int, vector<int>> mod;
  sum[n - 1] = a[n - 1];
  mod[sum[n - 1]].push_back(n - 1);
  for (int i = n - 2; i >= 0; i--) {
    sum[i] = (a[i] + sum[i + 1]) % m;
    mod[sum[i]].push_back(i);
  }
  for (auto &el : mod) {
    sort(el.se.begin(), el.se.end());
  }
  int presum[n];
  presum[0] = a[0];
  for (int i = 1; i < n; i++) {
    presum[i] = (presum[i - 1] + a[i]) % m;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int md = ((tot - (i == 0 ? 0 : presum[i - 1])) % m + m) % m; 
    if (md == 0) ans++;
    ans += sz(mod[md]) - (upper_bound(mod[md].begin(), mod[md].end(), i) - mod[md].begin());
  }
  cout << ans << "\n";
}



Measured memory_bytes: 9600
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

int mn[105][105];
int in[105][105];
int main() {
	int A, B, i, j, k, l;
	scanf("%d %d", &A, &B);
	for (i = 1; i <= A; i++) for (j = 1; j <= B; j++) scanf("%d", &in[i][j]);

	for (i = 1; i <= A; i++) {
		for (j = 1; j <= B; j++) {
			for (k = 0; k <= 100; k++) {
				for (l = 0; l <= 100; l++) {
					int t = i*k + j*l;
					mn[k][l] = max(mn[k][l], in[i][j] - t);
				}
			}
		}
	}
	for (i = 1; i <= A; i++) {
		for (j = 1; j <= B; j++) {
			int v = INF;
			for (k = 0; k <= 100; k++) for (l = 0; l <= 100; l++) v = min(v, i*k + j*l + mn[k][l]);
			if (v != in[i][j]) return !printf("Impossible\n");
		}
	}

    printf("Possible\n");
	printf("202 %d\n", 101*101+200);
	for (i = 1; i <= 100; i++) printf("%d %d X\n", i, i + 1);
	for (i = 102; i <= 201; i++) printf("%d %d Y\n", i, i + 1);
	for (i = 1; i <= 101; i++) for (j = 1; j <= 101; j++) printf("%d %d %d\n", i, j + 101, mn[i - 1][101 - j]);
	return !printf("%d %d\n", 1, 202);
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
int main(void){
    
    string team;
    int a, b;
    
    for(int i = 0; i < 9; i++){
        cin >> team >> a >> b;
        cout << team << " " << a + b << " " << 200 * a + 300 * b << endl;
    }
}


Measured memory_bytes: 2996
#include<bits/stdc++.h>
#define DB double
#define N 16

using namespace std;
DB gdis(int x1,int y1,int x2,int y2){
	return sqrt((x1-x2)*1LL*(x1-x2)+(y1-y2)*1LL*(y1-y2));
}
DB dis[N][N];
int x[N],y[N],a[N];
int n;
DB sum[(1<<N)+3];


struct edge{
	int f,t;
	DB dis;
	bool operator <(const edge &b)const{
		return dis<b.dis;
	}
}e[N*N*2];int ecnt;
int bcj[N];
int ff(int x) {
	return bcj[x]==x? x:bcj[x]=ff(bcj[x]);
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d%d",&x[i],&y[i],&a[i]);
	for(int i=0;i<n;i++) 
		for(int j=0;j<n;j++)
			dis[i][j]=gdis(x[i+1],y[i+1],x[j+1],y[j+1]);
	for(int i=0;i<(1<<n);i++){
		ecnt=0;
		for(int j=0;j<n;j++)
			if((i>>j)&1){
				sum[i]+=a[j+1];
				for(int k=j+1;k<n;k++)
					if((i>>k)&1)
						e[++ecnt]=(edge){j,k,dis[j][k]};
			}
		sort(e+1,e+ecnt+1);
		for(int j=0;j<n;j++) bcj[j]=j;
		for(int j=1;j<=ecnt;j++){
			if(ff(e[j].f)!=ff(e[j].t)){
				sum[i]-=e[j].dis;
				bcj[ff(e[j].f)]=ff(e[j].t);
			}
		}
		sum[i]/=__builtin_popcount(i);
	}
	for(int i=0;i<(1<<n);i++)
		for(int j=i;j;j=(j-1)&i)
			sum[i]=max(sum[i],min(sum[j],sum[i^j]));
	printf("%.10lf\n",(double)sum[(1<<n)-1]);
	return 0;
}

Measured memory_bytes: 640
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<cmath>
using namespace std;

long long gcd(long long a, long long b){
  if(a < b) return gcd(b, a);
  long long r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

long long lcm(long long a, long long b){
  return a*b/gcd(a,b);
}

int main(){
  
  long long a,b,c,d; cin >> a >> b >> c >> d;
  long long nc=floor((long double)b/c)-ceil((long double)a/c)+1;
  long long nd=floor((long double)b/d)-ceil((long double)a/d)+1;
  long long ncd=floor((long double)b/lcm(c,d))-ceil((long double)a/lcm(c,d))+1;
  long long answer = (b-a+1)-(nc+nd-ncd);
  
  cout << answer;
 
  return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
#DISCO A
import sys
import math
import collections
#sys.setrecursionlimit(100000)

n=int(input())

tmp = input().split()
a = list(map(lambda a: int(a), tmp))

total=0
for i in range(0,n):
	total+=a[i]
tmp=0
for i in range(0,n):
	tmp+=a[i]*2
	if(tmp>total):
		if(tmp-total<total-tmp+a[i]*2):
			print(tmp-total)
		else:
			print(total-tmp+a[i]*2)
		sys.exit()

Measured memory_bytes: 27652
import java.io.IOException;

public class Main {
	public static void main(String[] args) throws IOException {
		byte[] first = new byte[4];
		byte[] last = new byte[8];
		System.in.read(first, 0, 4);
		System.in.read(last, 0, 8);
		System.in.close();
		String strFirst = new String(first);
		String strLast = new String(last);
		String str = strFirst + " " + strLast;
		System.out.println(str);
	}
}



Measured memory_bytes: 7892
import sys
input = sys.stdin.readline
S = list(input())[: -1]
for l in range(len(S)):
  for r in range(l, len(S)):
    t = S[: l] + S[r: ]
    if "".join(t) == "keyence":
      print("YES")
      exit(0)
print("NO")

Measured memory_bytes: 39024
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<ll> vec(n);

    rep(i,n){
        cin>> vec[i];
    }
    sort(vec.begin(),vec.end(),less<ll>());
    
    ll sum = 0;
    rep(i,n-1){
        sum += vec[(n-1)-((i+1)/2)];
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4824