akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(2)
#include <bits/stdc++.h>
typedef long long ll;
const int mod=1e9+7;
const int maxn=2e6+16;
const ll INF=100000000000005;
const double eps=1e-11;
using namespace std;
ll n,m,p;
map<ll,ll>mp;
ll sum[maxn];
ll num[maxn];
int main()
{
    ll res=0;//记录最终答案
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&num[i]);
        sum[i]=sum[i-1]+num[i];
    }
    for(int i=1;i<=n;i++)
        sum[i]=(sum[i]-i%m+m)%m;//预处理前缀和
    ll low=min(m-1,n);
    for(int i=0;i<=low;i++)
    {
        res+=mp[sum[i]];
        mp[sum[i]]++;
    }
    for(int i=low+1;i<=n;i++)
    {
        mp[sum[i-m]]--;
        res+=mp[sum[i]];
        mp[sum[i]]++;
    }
    printf("%lld\n",res);
    return 0;
}
 
 
 

Measured memory_bytes: 18432
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int h, w;
  cin >> h >> w;
  int ans = 1145141919;
  int ht[25][25];
  rep(i, 0, h) rep(j, 0, w) {
    cin >> ht[i][j];
  }
  rep(i, 0, h) rep(j, 0, w) {
    int sum = 0;
    rep(k, 0, h) rep(l, 0, w) {
      sum += min(abs(i - k), abs(j - l)) * ht[k][l];
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;
}



Measured memory_bytes: 3204
import sys
h,w = list(map(int, input().split()))
a = []
for i in range(h):
    tmp = input()
    a.append(tmp)

print("#"*(w+2))

for j in range(h):
    print("#", end = "")
    print(a[j], end = "")
    print("#")

print("#"*(w+2))

Measured memory_bytes: 3064
#include <iostream>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
int main(){
	int t, n, b, e;
	while(cin >> t, t) {
		cin >> n;
		rep(i,n) {
			cin >> b >> e;
			t -= e-b;
		}
		if(t<=0) cout << "OK" << endl;
		else cout << t << endl;
	}
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const string YES = "Yes";
const string NO = "No";
const ll mod = 1e9+7;



int main(){
	cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    vll p(n), q(n);
    REP(i,n) cin >> p[i];
    REP(i,n) cin >> q[i];
    if (p>q) swap(p,q);
    ll ans = 0;
    while(p != q){
        next_permutation(p.begin(), p.end());
        ans++;
    }
    cout << ans;
    return 0;
    
}



Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int a, b, c, k;
  scanf("%d %d %d %d", &a, &b, &c, &k);
  
  if (a >= k) {
    printf("%d\n", k);
    return 0;
  }
  
  // k <= a + b + c
  // k - (a + b) <= c
  int minC = 0;
  if (a + b < k) {
    minC = k - (a + b);
  }
  
  printf("%d\n", a - minC);
  
  return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007

ll sum(vector<ll> &a, int n) {
    ll ans = 0, pre_sum = 0; 
    vector<ll> sum(n+1, 0);
    for (int i=n-1; i>=0; i--){
      sum[i] = sum[i+1]+a[i];
      sum[i]%=mod;
    }

    for(int i=0;i<n; i++){
      ans += ((a[i]%mod)*(sum[i+1]%mod))%mod;
      ans%=mod;
    }
    return ans; 
} 

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n; cin>>n;
  vector<ll> a(n);
  for(int i=0; i<n; i++)
    cin>>a[i];
  ll ans = sum(a, n);
  cout<<(ans%mod)<<"\n";
  return 0;
}

Measured memory_bytes: 6364
#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0);
using namespace std;

const long long INF = 1e7;
const long long N = 5e5 + 7;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;

long long cnt, n, m , x , k , z , mn = 1e9 , mn1 = 1e9;
long long a , b , c;
string s;
int main(){
    TIME
   cin >> n;
   cout << (n + 1) / 2;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>

using std::vector;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) {
    vec.resize(len);
    for (auto &v : vec) ndarray(v, args...);
}

int main() {
    //std::ifstream in("0_normal_2");
    //std::cin.rdbuf(in.rdbuf());
    
    //A_i = min(B_i-1,B_i), B_0 = B_N = 1000000
    
    int N;
    std::cin >> N;
    vector<int> A(N), B(N+1);
    B[0] = 1000000;
    B[N] = 1000000;
    for (int i = 0; i < N-1; i++) {
        int b;
        std::cin >> b;
        B[i+1] = b;
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        A[i] = std::min(B[i], B[i+1]);
        ans += A[i];
        //std::cout << A[i] << ", " << ans << std::endl;
    }
    std::cout << ans << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<set>
#include<sstream>
using namespace std;
typedef long long ll;
const ll maxn=1e4+10;
const ll inf=0x3f3f3f3f3f3f3f3f;
const ll mod=998244353;
void io(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
ll a[maxn],dp[maxn],f[3100][3100];
int main()
{
	io();
	ll n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i]; 
	ll ans=0;
//	dp[0]=1; 
//	for(int i=1;i<=n;i++)
//	{
//		dp[0]+=1;
//		for(int j=k;j>=a[i];j--)
//			dp[j]=(dp[j]+dp[j-a[i]])%mod;
//		for(int m=0;m<=k;m++)
//			cout<<dp[m]<<" ";
//		cout<<endl;
//		ans=(ans+dp[k])%mod;
//	}
//	cout<<ans<<endl;
//	cout<<endl<<endl;
	ans=0;
	f[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		f[i][0]=(f[i-1][0]+1);
		for(int j=1;j<=k;j++)
		{
			if(j<a[i])
				f[i][j]=f[i-1][j]%mod;
			else
				f[i][j]=(f[i-1][j]+f[i-1][j-a[i]])%mod;
		}
//		for(int m=0;m<=k;m++)
//			cout<<f[i][m]<<" ";
//		cout<<endl;
		ans=(ans+f[i][k])%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 73984
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>=1;
    }
    return res;
}


int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<vint> c(h, vint(w, 0));
    rep(i,h){
        rep(j,w){
            char s;
            cin >> s;
            if(s == '#'){
                c[i][j] = 1;
            }
        }
    }
    int ans = 0;
    rep(bit_h,1<<h){
        rep(bit_w, 1<<w){
            int tmp=0;
            rep(i,h){
                if(bit_h>>i &1) continue;
                rep(j,w){
                    if(bit_w>>j &1)continue;
                    if(c[i][j] == 1) tmp++;
                }
            }
            if(tmp==k) ans++;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (ll i = (ll)(start); i < (ll)(n); ++i)
static const ll INFTY = 1L << 62L;
ll d_max(vector<ll> A, ll *a, ll *b, ll *c, ll *d, ll q)
{
    ll ans = 0;
    rep(i, 0, q)
    {
        if (a[i] - 1 < A.size() && b[i] - 1 < A.size())
        {
            if (A[b[i] - 1] - A[a[i] - 1] == c[i])
                ans += d[i];
        }
    }
    return ans;
}
ll solver(ll *a, ll *b, ll *c, ll *d, ll n, ll m, ll q)
{

    queue<vector<ll>> que;
    rep(i, 1, m + 1) que.push(vector<ll>(1, i));
    ll ans = 0;
    while (!que.empty())
    {
        vector<ll> A = que.front();
        ans = max(ans, d_max(A, a, b, c, d, q));
        que.pop();
        ll tmp = A.back();
        if (A.size() < n)
        {
            while (tmp <= m)
            {
                A.push_back(tmp);
                que.push(A);
                A.pop_back();
                ++tmp;
            }
        }
    }
    return ans;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m, q;
    cin >> n >> m >> q;
    ll a[q], b[q], c[q], d[q];
    rep(i, 0, q)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    cout << solver(a, b, c, d, n, m, q) << endl;
}

Measured memory_bytes: 14640
import numpy as np
n=int(input())
#n,m=list(map(int,input().split()))
a=list(map(int,input().split()))

ans=np.zeros(n)

for i in range(n-1):
	tmp= a[i] -1
	ans[tmp] += 1
    
for i in range(n):
	print(int(ans[i]))

Measured memory_bytes: 50880
H, W = map(int, input().split())
a = []
for _ in range(H):
    a.append(input())

dp = [[0]*W for _ in range(H)]
dp[0][0] = 1
for i in range(H):
    for j in range(W):
        if a[i][j] == '#': 
            continue
        if i + 1 < H and a[i+1][j] == '.':
            dp[i+1][j] += dp[i][j]
            dp[i+1][j] %= 1e9 + 7
        if j + 1 < W and a[i][j+1] == '.':
            dp[i][j+1] += dp[i][j]
            dp[i][j+1] %= 1e9 + 7
        
print(int(dp[-1][-1]))

Measured memory_bytes: 90592
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ff first 
#define ss second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define testcase(t) int t;cin>>t;while(t--)
#define mp(x,y) make_pair(x,y)
#define in(x) insert(x)
#define rep(i,a,b)  for (__typeof((b)) i=(a);i<=(b);i++)
#define nrep(i,a,b)  for (__typeof((b)) i=(b);i>=(a);i--)
#define PI 3.14159265358979323846
#define SP(x) setprecision(x)
#define reflex ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define M 1000000007
#define sz(a) (int)a.size()
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(x) x.resize(distance(x.begin(), unique(all(x))))
#define mem(arr,val) memset(arr,val,sizeof(arr)) //For "0" and "-1"                  
#define inp0(a,n) rep(i,0,n-1) cin>>a[i];
#define inp1(a,n) rep(i,1,n) cin>>a[i]; 
#define prll(x) printf("%lld",x)
#define nth_ele(v,n) nth_element(v.begin(), v.begin()+n ,v.end())//O(N)
#define DEBUG(x) cerr << (#x) << ": " << (x) << endl
#define DEBUGV(x) for(auto IT:x) cout<<IT<<" "; cout<<endl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll gcd(ll n1, ll n2){if(n2!=0) return gcd(n2, n1%n2);else return n1;}
ll powerM(ll a,ll b){if(b==0) return 1;  if(b==1) return a%M; ll x=powerM(a,b/2)%M; if(b&1){return ((((a%M)*(x%M))%M)*(x%M))%M;}return ((x%M)*(x%M))%M;}
ll power(ll a,ll b){if(b==0) return 1;  if(b==1) return a; ll x=power(a,b/2); if(b&1){return ((((a)*(x)))*(x));}return ((x)*(x));}
 
const ll INF=1e18; 
const int SIZE = 200005;

int main(){
	reflex;
	int n,k;
	cin>>n>>k;
	ll h[n+2];
	inp0(h,n)
	ll dp[n+n+1];
	rep(i,0,n+n) dp[i]=INT_MAX;
	dp[n-1]=0;
	nrep(i,0,n-1){
		rep(j,1,k){
			if(i+j>n) break;
			dp[i] = min(dp[i], abs(h[i]-h[i+j])+dp[i+j]);
		}
	}
	cout<<dp[0]<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const int MOD = 1e9 + 7;
using namespace std;
typedef long long ll;

map<ll, int> mp;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	ll k;
	cin >> k;
	char ans = '1';
	for (int i = 0; i < s.size(); i++) {
		if (k - 1 <= i && s.at(i) == '1') break;
		if (s.at(i) != '1') {
			ans = s.at(i);
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int N;
  cin>>N;
  cout<<(N-2)*180;
return 0;}

Measured memory_bytes: 3556
#include<stdio.h>

int main(void){
  int W,a,b;
  scanf("%d %d %d",&W,&a,&b);
  if(a+W < b) printf("%d\n",b-(a+W));
  else if(b+W < a)printf("%d\n",a-(b+W));
  else printf("%d\n",0);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>

using namespace std;


int main() {

    long A, B, K;
    cin >> A >> B >> K;

    cout << (max(A - K, 0L)) << " " << max(B + min(A - K, 0L),0L) << endl;

    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <assert.h>

void koch(double x0, double y0, double x4, double y4, int d){
    assert(d>=0);
    if(d==0){
        printf("%.8lf ", x0);
        printf("%.8lf\n", y0);
    } else {
    double x1 = x0 + (x4-x0)/(double)3;
    double y1 = y0 + (y4-y0)/(double)3;
    double x3 = x0 + (x4-x0) * (double)2 / (double)3;
    double y3 = y0+ (y4-y0) * (double)2/  (double)3;

    double mx = (x0+x4)/(double)2;
    double my = (y0+y4)/(double)2;
    double distance = hypot(x4-x0,y4-y0) * sqrt(3) / (double)6;
    double x2 = mx + distance * (y0-y4) / hypot(y0-y4,x4-x0);
    double y2 = my + distance * (x4-x0) / hypot(y0-y4,x4-x0);
    
    koch(x0,y0,x1,y1,d-1);
    koch(x1,y1,x2,y2,d-1);
    koch(x2,y2,x3,y3,d-1);
    koch(x3,y3,x4,y4,d-1);
    }
}

int main(void){
    int n;
    scanf("%d",&n);
    koch((double)0, (double)0, (double)100, (double)0, n);
    printf("%.8lf ", (double)100);
    printf("%.8lf\n", (double)0);
    return 0;
}


Measured memory_bytes: 652
while True:
   m, f, r = map(int, input().split())
   if m == -1 and f == -1 and r == -1:
      break
   
   if m == -1 or f == -1 or m + f < 30:
      print("F")
   elif m + f >= 80:
      print("A")
   elif m + f >= 65 and m + f < 80:
      print("B")
   elif m + f >= 50 and m + f < 65:
      print("C")
   else:
      if r >= 50:
         print("C")
      else:
         print("D")


Measured memory_bytes: 5588
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,d,w,h,i,j,k,l,m,n,x,y,z;
	ll		ans = 0;
	string	s;
	cin >> s;
	//vector<ll>	aa(n);
	//for(i=0;i<n;i++) cin >> aa[i];
	//vector<ll>	dp(n+1,INFL);
	//vector<vector<ll>>	dp2(x , vector<ll>(y,INFL));
	for(i=0;i<s.size();i++) {
		ans += s[i]-'0';
	}
	if (ans % 9 == 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3708
import java.awt.*;
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
//        double r=sc.nextInt();
        ArrayList<Double> arr=new ArrayList<>();
        System.out.println((float) (2D*(3.14159265358979D)*(sc.nextDouble())));
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 33372
from collections import Counter

N = int(input())
a = list(map(int, input().split()))
c = dict(Counter(a))
cx = {i: 0 for i in range(10 ** 5 + 1) if i not in c.keys()}
c.update(cx)
c = sorted(c.items(), key=lambda x: x[0])
ans = 0
for i in range(10 ** 5 - 1):
  ans = max(sum((c[i][1], c[i+1][1], c[i+2][1])), ans)
  
print(ans)

Measured memory_bytes: 30664
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int n,w;
vector<int> a;

int r[2000],R[2000];
int REC(int);
int rec(int x=0){
    if(r[x]>=0)
        return r[x];
    int s{};
    for(int i=x+1;i<n;++i) s=max(s,REC(i));
    s=max(s,abs(a[n]-a[x]));
    return r[x]=s;
}

int REC(int x){
    if(R[x]>=0)
        return R[x];
    int s{INT_MAX};
    for(int i=x+1;i<n;++i) s=min(s,rec(i));
    s=min(s,abs(a[n]-a[x]));
    return R[x]=s;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    in>>n>>w>>w;
    a.resize(n+1);
    Fr(i,n) in>>a[i];
    a[0]=w;
    fr(i,n) r[i]=R[i]=-1;
    cout<<rec()<<'\n';
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
  int i,j,tmp,N,minj,flag,cnt=0;
 int A[100];
 scanf("%d",&N);

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

 for(i=0;i<N;i++)
{
  minj = i;
  flag = 0;
  for(j=i;j<N;j++){
    if(A[j] < A[minj]){
      minj = j;
      flag = 1;
}
}
  if(flag == 1){
    tmp = A[i];
    A[i] = A[minj];
    A[minj] = tmp;
    cnt++;
}
 }

 for(i=0;i<N;i++){
   if(i == N-1)
     {printf("%d\n",A[i]);
     break;
}

   printf("%d ",A[i]);
}
 printf("%d\n",cnt);
  return 0;
}



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

int N;
int V[20], C[20];

int main() {
    cin >> N;
    rep(i, N) {
        cin >> V[i];
    }

    rep(i, N) {
        cin >> C[i];
    }

    int ans = 0;
    rep (i, N) {
        // cout << V[i] - C[i] << endl;
        if (V[i] - C[i] > 0) ans += (V[i] - C[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int main() {
	fastio;
	ll N, K;
	cin >> N >> K;

	ll ans = N % K;
	ans = min(ans, abs(ans - K));

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x1,x2,y1,y2,x,y,k,s,c=0,i,j;
	scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
	x=x2-x1;
	y=y2-y1;
	for(i=0;i<x;i++)
	printf("R");
	for(i=0;i<y;i++)
	printf("U");
	for(i=0;i<x;i++)
	printf("L");
	for(i=0;i<y;i++)
	printf("D");
	printf("L");
	for(i=0;i<=y;i++)
	printf("U");
	for(i=0;i<=x;i++)
	printf("R");
	printf("D");
	printf("R");
	for(i=0;i<=y;i++)
	printf("D");
	for(i=0;i<=x;i++)
	printf("L");
	printf("U");
	
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	unsigned long long N,M;
	cin >> N >> M;

	if(N==1 && M==1) cout << 1 << "\n";
	else if(N==1) cout << M-2 <<"\n";
	else if(M==1) cout << N-2 <<"\n";
	else cout << (N-2)*(M-2) << "\n";

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {



        Scanner sc = new Scanner(System.in);

        long x = sc.nextLong();
        long y = sc.nextLong();
        int result = 0;


        long target = y / x;
        while(true) {
        	if(target  < 1) {
        		break;
        	}
        	target /= 2;
        	result++;
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 23508
class Combination:
    '''MOD上の
    計算量：階乗・逆元テーブルの作成O(N)
    nCkを求めるO(1)'''

    def __init__(self, n, MOD):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % MOD)
        self.inv_fact = [pow(self.fact[i], MOD - 2, MOD) for i in range(n + 1)]
        self.MOD = MOD

    def factorial(self, k):
        """k!を求める O(1)"""
        return self.fact[k]

    def inverse_factorial(self, k):
        """k!の逆元を求める O(1)"""
        return self.inv_fact[k]

    def permutation(self, k, r):
        """kPrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[r]) % self.MOD

    def combination(self, k, r):
        """kCrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD



x, y = map(int, input().split())
MOD = 10**9 + 7
comb = Combination(10**6, MOD)

if (x+y) % 3 != 0:
    print(0)
    exit()
    
tmp = (x + y) // 3
diff = abs(x - y)

if tmp < diff:
    print(0)
else:
    k = (tmp - diff) // 2
    print(comb.combination(tmp, k))



Measured memory_bytes: 116380
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

N = INT()

ans = 1000 - N % 1000 if N % 1000 else 0
print(ans)


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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m = M) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int exp(int n, int k) {
  if (k == 0) return 1;
  if (k == 1) return n;
  int ax = exp(n, k / 2);
  ax = mod(ax * ax);
  if (k % 2) ax = mod(ax * n);
  return ax;
}

int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
//#define MULTIPLE_TEST_CASE
void solution() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, 0, n, 1) cin >> v[i];
  sort(all(v), greater<int>());
  int p = -1;
  int cnt = 0;
  int ans = 0;
  for (int x : v) {
    if (p == -1) {
      p++;
      continue;
    }
    ans += v[p];
    cnt++;
    if ((p == 0 && cnt == 1) || (cnt == 2)) {
      p++;
      cnt = 0;
    }
  }
  cout << ans << endl;
}

int32_t main() {
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--) solution();
}


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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int n;
    while(cin >> n, n){
        int field[n][n];
        for(int i=0; i < n; i++)for(int j=0; j< n; j++) field[i][j] = 0;
        int x = n/2+1, y = n/2;
        field[x][y] = 1;
        for(int i=2; i <= n*n; i++){
            x++; y++;
            if(!(0 <= x && x < n)) x = 0;
            if(!(0 <= y && y < n)) y = 0;
            if(field[x][y] != 0){
                x++; y--;
                if(!(0 <= x && x < n)) x = 0;
                if(!(0 <= y && y < n)) y = n-1;
            }
            field[x][y] = i;
        }
        for(int i=0; i< n; i++){
            for(int j=0; j < n; j++){
                printf("% 4d", field[i][j]);
            }
            cout << endl;
        }
    }
}

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

class unionfind {
  vector<int> par, s;
  
public:
  unionfind(int n) {
    for (int i = 0; i < n; i++) {
      par.push_back(i);
      s.push_back(1);
    }
  }
  
  int find(int n) {
    if (par.at(n) == n) return n;
    return par.at(n) = find(par.at(n));
  }
  
  void merge(int m, int n) {
    m = find(m);
    n = find(n);
    if (s.at(m) > s.at(n)) swap(m, n);
    par.at(m) = n;
    s.at(n) += s.at(m);
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  unionfind tr(n);
  for (int i = 0; i < q; i++) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t == 0) {
      tr.merge(u, v);
    } else {
      cout << (tr.find(u) == tr.find(v)) << endl;
    }
  }
}


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

using namespace std;	
typedef long long LL;
const int nn = 1e6 + 5;

int main() {
	LL q, a, b, tipe, l1 = 0, l2 = 0;
	LL tot_l = 0, tot_r = 0, tot = 0;
	priority_queue<LL> pq1, pq2;
	scanf("%lld", & q);
	while (q--) {
		scanf("%lld", & tipe);
		if (tipe == 1) {
			scanf("%lld %lld", & a, & b);
			tot += b;
			if (pq1.empty() || a <= pq1.top()) {
				pq1.push(a);
				l1++;
				tot_l += a;
			} else {
				pq2.push(-a);
				l2++;
				tot_r += a;
			}
			if (l1 - l2 > 1) {
				l1--;
				tot_l -= pq1.top();
				tot_r += pq1.top();
				l2++;
				pq2.push(-pq1.top());
				pq1.pop();
			} else if (l2 - l1 > 1) {
				l2--;
				tot_l -= pq2.top();
				tot_r += pq2.top();
				l1++;
				pq1.push(-pq2.top());
				pq2.pop();
			}
		} else {
			if (l1 >= l2) {
				LL ans = pq1.top() * l1 - tot_l + tot_r - l2 * pq1.top() + tot;
				printf("%lld %lld\n", pq1.top(), ans);
			} else {
				LL ans = -pq2.top() * l1 - tot_l + tot_r - l2 * -pq2.top() + tot;
				printf("%lld %lld\n", -pq2.top(), ans);
			}
		}
	}
}

Measured memory_bytes: 3828
import sys
input=sys.stdin.readline
n=int(input())
ab=[]
A=-1e20
B=-1e20
C=1e20
D=1e20
for i in range(n):
	x,y=map(int,input().split())
	A=max(A,x+y)
	B=max(B,x-y)
	C=min(C,x+y)
	D=min(D,x-y)
print(max(A-C,B-D))

Measured memory_bytes: 9204
#include<iostream>

using namespace std;

int main() {
	int h,w;
while(1){
	std::string line = "";
	cin >> h >> w;
if (h!=0 || w!=0){
	line += "#";
	for (int i=0;i<w-2;i++){ line += "."; }
	line += "#";
	for (int k=0;k<w;k++){
		cout << "#";
	}
	cout << endl;
	for (int j=0;j<h-2;j++){
		cout << line << endl;
	}
	for (int k=0;k<w;k++){
		cout << "#";
	}
	cout << endl;
	cout << "" << endl;
}else{ break; }
}
	return 0;
}


Measured memory_bytes: 3172
#include <stdio.h>

int main(void)
{
	 int a,b,c,w;
  
   scanf("%d %d %d",&a,&b,&c);
  
   if(a > b){w = a;
             a = b;
             b = w;}
  
   if(a > c){w = a;
             a = c;
             c = w;}
  
   if(b > c){w = b;
             b = c;
             c = w;}
  
   printf("%d %d %d\n",a,b,c);
  
	return 0;
}

Measured memory_bytes: 1784
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = list(input())
    res = s[:4] + [" "] + s[4:]
    print("".join(res))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0) {
			string temp = "RUD";
			if (temp.find(s[i]) == string::npos) {
				cout <<"No";
				return 0;
			}
		}
		else {
			string temp = "LUD";
			if (temp.find(s[i]) == string::npos) {
				cout <<"No";
				return 0;
			}
		}
	}
	cout << "Yes";
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define mkp make_pair
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<<endl;}}
#define print1d(mat,n){for(int i=0;i<(int)(n);i++)cout<<mat[i]<<" ";cout<<endl;}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define printpair(v) for(auto val: v){cout<<val.fi<<":"<<val.se<<", ";}cout<<endl;
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<endl;
#define init(v,x) for (auto &itr:v){itr=x;}
#define ln length()
const int mod = 1000000007;
#define sz size()
const int inf = 1e18;
int n,m;
string arr[1005];
int dp[1005][1005];
int f(int i,int j){
    if(i==n-1 and j==m-1){
        return 1;
    }
    if(i==n){
        return 0;
    }
    if(j==m){
        return 0;
    }
    if(arr[i][j]=='#'){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    int ans=0;
    ans+=f(i+1,j);
    ans%=mod;
    ans+=f(i,j+1);
    ans%=mod;
    dp[i][j]=ans;
    return ans;
}
void solve() {
    clr(dp,-1);
    cin>>n>>m;
    rep(i,0,n){
        cin>>arr[i];
    }
    cout<<f(0,0)<<endl;

}

int32_t main(){
    fastIO
#ifndef ONLINE_JUDGE
    freopen(R"(C:\Users\swast\CLionProjects\untitled\input.txt)", "r", stdin);
#endif
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 12688
#include <iostream>
#include <string>

using namespace std;

string display(string param) {
	int mouth, day;

	mouth = (param[5] - 0x30) * 10 + (param[6] - 0x30);

	return (mouth > 4) ? "TBD" : "Heisei";
}

int main() {
	string input;

	cin >> input;

	cout << display(input);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=200001;
int n;
int a[N];
int suma,sumb,j;
long long s;//要用long long，因为最多可能性为20000100000
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		while(suma+a[j+1]==(sumb^a[j+1])&&j+1<=n)//位运算加括号，因为运算级别较低 
		{
			suma=suma+a[j+1];
			sumb=(sumb^a[j+1]);
			j++;
		}
		s=s+j-i+1;
		suma=suma-a[i];
		sumb=(sumb^a[i]);
	}
	cout<<s; 
	return 0;
}

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

using namespace std;

typedef long long ll;

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

  vector<ll> A, coef1, coef2;
  for (int i = 0; i < N; i++) {
    ll x;
    scanf("%lld", &x);

    A.push_back(x);

    if (i & 1) {
      coef1.push_back(1);
      coef2.push_back(-1);
    }
    else {
      coef1.push_back(-1);
      coef2.push_back(1);
    }

    if (i != 0 && i != N - 1) {
      coef1[i] *= 2;
      coef2[i] *= 2;
    }
  }

  sort(A.begin(), A.end());
  sort(coef1.begin(), coef1.end());
  sort(coef2.begin(), coef2.end());

  ll ans = 0, pans1 = 0, pans2 = 0;
  for (int i = 0; i < N; i++) {
    pans1 += A[i] * coef1[i];
    pans2 += A[i] * coef2[i];
  }
  ans = max(pans1, pans2);

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 2912
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
	int a, b, c, k; cin >> a >> b >> c >> k;
	int sum = a + b + c - max({ a,b,c });

	sum = sum + max({ a,b,c }) * pow(2, k);

	cout << sum << endl;

	return 0;
}

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

struct node{
	node *parent,*left,*right;
	int key;
	node():parent(nullptr),left(nullptr),right(nullptr){}
};

node* insert(node *root,int key){
	node *z=new node;
	z->key=key;
	node *x=root,*y=nullptr;
	while(x!=nullptr){
		y=x;
		if(key<x->key)x=x->left;
		else x=x->right;
	}
	z->parent=y;
	if(y==nullptr)root=z;
	else if(z->key<y->key)y->left=z;
	else y->right=z;
	return root;
}

void inorder(node *root){
	if(root==nullptr)return;
	inorder(root->left);
	cout<<" "s<<root->key;
	inorder(root->right);
}

void preorder(node *root){
	if(root==nullptr)return;
	cout<<" "s<<root->key;
	preorder(root->left);
	preorder(root->right);
}

void print(node *root){
	inorder(root);
	cout<<"\n"s;
	preorder(root);
	cout<<"\n"s;
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int m;
	cin>>m;
	string com;
	node *root=nullptr;
	for(int i=0,key;i<m;++i){
		cin>>com;
		if(com=="insert"s){
			cin>>key;
			root=insert(root,key);
		}
		else print(root);
	}
}


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

int main() {
long long n,a,b,c,h[100000],l=0,r=1000000001;
cin>>n>>a>>b;
c=a-b;
for(int i=0;i<n;i++){
    cin>>h[i];
}
while(r-l>1){
    long long m=(r+l)/2;
    long long k=0;
    for(int i=0;i<n;i++){
        long long d=h[i]-m*b;
        if(d>0){
            k+=(d+c-1)/c;
        }
        
    }
    if(m>=k){
        r=m;
    }else{
        l=m;
    }
}
cout<<r<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
    int A,B;
    int max;
    cin >> A >> B;
    max=A+B;
    if(max<=A-B){
        max=A-B;
    }
    if(max<=A*B){
        max=A*B;
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}
template<typename T> inline void in(T &e){cin>>e;}
template<typename T> inline void out(T e){cout<<e<<endl;}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n,m;
vi box;
vi ruiwa;
map<int,int> maap;

signed main(){
    io();

    cin>>n>>m;
    box.resize(n);
    ruiwa.resize(n+1);
    rep(i,n) {
        cin>>box[i];
        ruiwa[i+1]=box[i];
    }
    REP(i,1,n) ruiwa[i+1]+=ruiwa[i];
    rep(i,n+1) maap[ruiwa[i]%m]++;
    
    int ans=0;
    for(auto e : maap){
        if(e.second<2) continue;
        ans+=(e.second*(e.second-1))/2;
    }
    out(ans);
    /*
    ans=0;

    rep(l,n+1)
        REP(r,l+1,n+1)
            if((ruiwa[r]-ruiwa[l])%m==0) ans++;
        
    out(ans);
    */

    return 0;
}


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

#define MAX_N 100001

long N, M;
vector<long> E[MAX_N];
long ans[MAX_N];

void bfs(){
    bool seen[N + 1];
    queue<long> todo;
    seen[1] = true;
    fill(seen + 2, seen + N + 1, false);
    todo.push(1);
    ans[1] = 0;
    
    while(!todo.empty()){
        long u = todo.front(); todo.pop();
        vector<long>::iterator it;
        for(it = E[u].begin(); it != E[u].end(); it++){
            long v = *it;
            if(!seen[v]){
                ans[v] = u;
                seen[v] = true;
                todo.push(v);
            }
        }
    }
    return;
}

int main(){
    cin >> N >> M;
    for(long i = 0; i < M; i++){
        long A, B;
        cin >> A >> B;
        E[A].push_back(B);
        E[B].push_back(A);
    }
    bfs();
    cout << "Yes" << endl;
    for(long i = 2; i <= N; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 13100
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,t,ans=0,l,r;
  cin >> n >> t;
  int x[t+5]={};
  for(int i=0; i<n; i++) {
    cin >> l >> r;
    x[l]++,x[r]--;
  }
  for(int i=1; i<=t; i++) {
    x[i]+=x[i-1];
  }
  for(int i=0; i<=t; i++) {
    ans=max(ans,x[i]);
  }
  cout << ans << endl;
}



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

int main(){
  int x;
  cin >>x;
  int curMax = 1;
  for(int i = 2; i<x; i++){
    int num = i;
    while(true){
      num *= i;
      if(x<num) break;
      if(curMax<num) curMax = num;
    }
  }
  cout << curMax << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   string s, t; cin >> s >> t;
   int ans = 0;
   rep(i,s.size()){
      ans += (s[i] != t[i]);
   }
   cout << ans << endl;
}

Measured memory_bytes: 3700
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_variables)]
        #[allow(unused_mut)]
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("parse error")
    };
}

fn main() {
    input!{
        s: chars,
    }
    let n = s.len();
    let m = 2019;

    let mut ans = 0;

    let mut tbl = vec![0; m];

    for i in 0..n {
        let cur = ((s[i] as u8) - b'0') as usize;
        let mut ntbl = vec![0; m];
 
        for j in 0..m {
            ntbl[(j * 10 + cur) % m] += tbl[j];
        }

        ans += ntbl[0];
        ntbl[cur % m] += 1;
        tbl = ntbl;
    }
    println!("{}", ans);

}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define W first
#define T second
using namespace std;
typedef pair<long long,long long> P;
P book[200005],tana[20];
long long mem[1<<16];
long long m,n;
long long wacc[200005]={0};long long tacc[200005]={0};
long long bitDP();
main(){
  cin>>m>>n;
  for(int i=1;i<=m;i++){
    cin>>book[i].W>>book[i].T;
    wacc[i]=wacc[i-1]+book[i].W;
    tacc[i]=tacc[i-1]+book[i].T;
  }
  for(int i=1;i<=n;i++){
    cin>>tana[i].W>>tana[i].T;
  }
  memset(mem,0,sizeof(mem));
  cout<<bitDP()<<endl;
}
long long bitDP(){
  for(int i=0;i<(1<<n);i++){
    long long d=1;
    for(int j=1;j<=n;j++){
      if((i&d)==0){
	long long a=upper_bound(wacc+mem[i],wacc+m+1,wacc[mem[i]]+tana[j].W)-wacc-1;
	long long b=upper_bound(tacc+mem[i],tacc+m+1,tacc[mem[i]]+tana[j].T)-tacc-1;
	//cout<<j<<" "<<a<<" "<<b<<endl;
	mem[(i|d)]=max(mem[(i|d)],min(a,b));
      }
      d=d<<1;
    }
  }
  for(int i=0;i<(1<<n);i++){
    //cout<<mem[i]<<endl;
  }
  return mem[(1<<n)-1];
}

Measured memory_bytes: 9808
a,b,c = map(int,raw_input().split())
if b <= a:
	if b <= c <= a:
		print b,c,a
	elif c <= b:
		print c,b,a
	else:
		print b,a,c
elif a < b:
	if a <= c <= b:
		print a,c,b
	elif c <= a < b:
		print c,a,b
	else:
		print a,b,c
 

Measured memory_bytes: 6384
#include<stdio.h>
#include<string>
#include<algorithm>
#include<vector>
#include<iostream>
using namespace std;
int  main() {
	string s;
	cin >> s;
	int n;
	n = s.size();
	if (s[n - 1] == 's') {
		s.push_back('e');
		s.push_back('s');
	}
	else {
		s.push_back('s');
	}
	cout << s << endl;
	return 0;
}

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

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

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

    int p[101][101] = {};
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            p[i][j] = -1;
        }
    }

    int d[4] = { 1, 101, -1, -101 };
    int k = 0, l = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        for (int j = 0; j < a; j++) {
            p[0][k] = i + 1;
            if (p[0][k + d[l]] >= 0) l = (l + 1) % 4;
            k += d[l];
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << p[i][j] << " \n"[j == w - 1];
        }
    }

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    string s;
    cin >> s;

    long long sol = (s.length() * (s.length() - 1)) / 2;

    for (char i = 'a'; i <= 'z'; ++i)
    {
        long long c = count(s.begin(), s.end(), i);
        sol -= (c * (c - 1)) / 2;
    }

    cout << sol + 1 << '\n';
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using vc=vector<char>;
using vvc=vector<vc>;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using tiii = tuple<int,int,int>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#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++)
int MOD=1e9+7;

ll power(ll a, int b) {
  if(!b) return 1;
  ll c = power(a, b/2);
  if(b%2) return c*c%MOD*a%MOD;
  return c*c%MOD;
}

int main() {
  int S;
  cin >> S;
  vl pro(S,1);
  rep(i,S-1) (pro[i+1]=pro[i]*(i+1))%=MOD;
  
  ll ans=0;
  for(int k=1;3*k<=S;k++)
    (ans+=pro[S-2*k-1]*power(pro[S-3*k],MOD-2)%MOD*power(pro[k-1],MOD-2)%MOD)%=MOD;
  
  cout << ans << endl;
}

Measured memory_bytes: 3596