akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#define ll long long
#define ull unsigned long long
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define pi acos(-1.0)
#define lowbit(x) ((x)&(-(x)))
#define debug(x) cout<<x<<'\n'
#define pii pair<ll,pair<ll,ll> >
using namespace std;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9;
const double eps = 1e-6;
ll gcd(ll a, ll b) {return b==0?a:gcd(b, a%b);}
ll lcm(ll a, ll b) {return a/gcd(a, b)*b;}
ll mul(ll a,ll b){ll ans=0;a%=mod,b%=mod;while(b) { if(b&1) ans = (ans+a)%mod; a = (a*2)%mod; b >>= 1; }return ans;}
ll powmod(ll a,ll b){ ll ans = 1, pow = a; while(b) { if(b&1) ans = (ans*pow)%mod; pow = (pow*pow)%mod; b >>= 1; } return ans;}
//(b/a)%p=b*a^(p-2)%p
//int pr(ll num){//判素
//     if(num == 1) return 0;
//     if(num ==2|| num==3 ) return 1 ;
//     if(num %6!= 1&&num %6!= 5) return 0 ;
//     int tmp =sqrt( num);
//     for(int i= 5;i <=tmp; i+=6 )
//          if(num %i== 0||num %(i+ 2)==0 )return 0 ;
//     return 1 ;
//}
int Day(int y,int m, int d){if(m==1||m==2) { m+=12; y--; }int w=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;return w+1;}
//int pri[10000005];
//void getpri(){
//    memset(pri,true,sizeof(pri));
//    pri[0]=pri[1]=0;
//    for(int i=2;i<=10000000;i++){
//        if(pri[i]){
//            for(int j=2*i;j<=10000000;j+=i) pri[j]=0;
//        }
//    }
//}
//struct ac{
//    int x,y;
//    int fa;
//} pre[10000005];
//void init(){
//    for(int i=1; i<=10000005;++i) pre[i].fa=i;
//}
//int getf(int x){
//    if(pre[x].fa == x) return x;
//    else return pre[x].fa = getf(pre[x].fa);
//}
//void join(int x,int y){
//    int a = getf(x);
//    int b = getf(y);
//    if(a!=b) pre[b].fa=a;
//}
//大小写转换
//String s;
//Form(s.begin(),s.end(),s.begin(),::toupper);
//Form(s.begin(),s.end(),s.begin(),::tolower);
//(char)toupper('a')
//(char)tolower('B')
//#pragma comment(linker, "/STACK:1024000000,1024000000")//外挂开栈
//stable_sort 排序不处理相同元素
//map<int,int>::reverse_iterator rit;
//for(rit=mp.rbegin();rit!=mp.rend();rit++)
//vec动态二维数组
//vector<vector<int>> g(26,vector<int>(100005));
//初始化vec里面套了n个vec
//lower_bound(begin,end,num) 有序数列中返回第一个>=num的数字的地址
//upper_bound( begin,end,num) 返回第一个>num的数字的地址
const int maxn=2e5+5;
vector<int> v[maxn];
ll go[maxn]={0};
ll dfs(int x){
    if(go[x]) return go[x];
    if(v[x].size()==0){
        go[x]=1;
        return 1;
    }
    ll maxx=0;
    for(auto i:v[x]){
        maxx=max(maxx,dfs(i));
    }
    go[x]=maxx+1;
    return go[x];
}
int main(){
    IO;
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;++i){
        int x,y;
        cin>>x>>y;
        v[x].push_back(y);
    }
    ll ans=0;
    for(int i=1;i<=n;++i){
        ans=max(ans,dfs(i));
        //cout<<dfs(i)<<endl;
    }
    cout<<ans-1<<endl;
    return 0;
}


Measured memory_bytes: 14280
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;

int main(){

    int n, m; cin >> n >> m;

    int mat[n][n];
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            mat[i][j] = 0;
        }
    }

    for(int i=0; i<m; i++){
        int t1, t2;
        cin >> t1 >> t2;

        mat[t1-1][t2-1] = 1;
        mat[t2-1][t1-1] = 1;
    }

    // for(int i=0; i<n; i++){
    //     for(int j=0; j<n; j++){
    //         cout << mat[i][j];
    //     }
    //     cout << endl;
    // }

    int perm[n-1];
    for(int i=1; i<n; i++){
        perm[i-1] = i;
    }

    int cnt = 0;
    // int cnt2 = 0;
    do{
        // cnt2++;
        int now = 0;
        bool flag = false;
        for(int i=0; i<n-1; i++){
            int to = perm[i];
            if(mat[now][to] == 0){
                break;
            }
            if(i == n-2){
                flag = true;
            }
            now = to;
        }
        if(flag) cnt++;
    } while(next_permutation(perm, perm+n-1));

    // cout << cnt2 << endl;
    cout << cnt;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

int main() {
  while( true ) {
    int n;
    cin >> n;
    if ( n == 0 ) break;
    vector<pair<int, int>> vs(n);
    for ( int i = 0; i < n; i++ ) {
      int q, c;
      cin >> q >> c;
      vs[ i ] = make_pair( c, q );
    }
    sort( vs.begin(), vs.end() );
    int sum = 0;
    bool success = true;
    for ( auto p : vs ) {
      sum += p.second;
      if ( sum > p.first ) {
	success = false;
	break;
      } 
    }
    cout << ( success ? "Yes" : "No" ) << endl;
  }  
}

Measured memory_bytes: 1188
import heapq

n=list(map(int,input().split()))
m=list(map(int,input().split()))
m = [-x for x in m]
heapq.heapify(m)

for i in range(n[1]):
  x=(-1*m[0])//2
  heapq.heappop(m)
  heapq.heappush(m, -x)

ans=0
for i in range(n[0]):
  ans+=-m[i]

print(ans)

Measured memory_bytes: 14180
#import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    N,M,Q = map(int, input().split())
    pair = []
    for i in range(Q):
        pair += list(map(int, input().split())),

    def score(A):
        nonlocal pair
        sum = 0
        for a,b,c,d in pair:
            if A[b-1] - A[a-1] == c:
                sum += d
        return sum

    ans = 0
    A = [1]*N
    i = N-1
    while True:
        ans = max(ans, score(A))
        while i >= 0 and A[i] == M:
            i -= 1
        if i < 0:
            break
        A[i] += 1
        j = i
        while i <= N-1:
            A[i] = A[j]
            i += 1
        i = N-1
        if A == [M]*N:
            break
        
    print(ans)
main()


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

long long N, K;

int main() {
  cin >> N >> K;
  long long a = N / K;
  long long b = (N + K / 2) / K;
  if(K % 2 == 1) {
    cout << a * a * a << endl;
  } else {
    cout << a * a * a + b * b * b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
using namespace std;
int main(){
    string s;
    cin>>s;
    int count;
    count=0;
  for(int i=0; i<s.size(); i++){
      
      if(s[i]=='1'){
          count=count+1;
      }
      else{
          count=count+0;
      }
  }
  cout<<count<<endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long
#define INF 100000000
#define mod 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll int, ll int>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

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

int L, R;
int main () {
  cin >> L >> R;

  // int l = L % 2019;
  // int r = R % 2019;

  if ((R - L) >= 2018) {
    cout << 0 << "\n";
  } else {
    ll int tmp = INF;
    
    for (ll int i=L;i<R;++i) {
      for (ll int j=i+1;j<=R;++j) {
        tmp = min(tmp, (i * j) % 2019);
      }
    }
    printf("%lld\n", tmp);
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int dp[3005][3005];
int pre[3005][3005];
deque<char> ans;
int main(int argc, char const *argv[])
{
	char s[3005], t[3005];
	scanf("%s%s", &s, &t);
	memset(dp, 0, sizeof dp);
	memset(pre, -1, sizeof pre);
	int slen = strlen(s), tlen = strlen(t);
	for(int i = 0; i < tlen; i++){
		if(s[0] == t[i]) {
			dp[0][i] = 1;
			pre[0][i] = 3;
		}
		else {
			if(i-1 >= 0) {
				dp[0][i] = dp[0][i-1];		
				pre[0][i] = 2;
			}
		}
	}
	for(int i = 0; i < slen; i++){
		if(s[i] == t[0]) {
			dp[i][0] = 1;
			pre[i][0] = 0;
		}
		else {
			if(i-1 >= 0) {
				dp[i][0] = dp[i-1][0];		
				pre[i][0] = 1;
			}
		}
	} 
	for(int i = 1; i < slen; i++){
		for(int j = 1; j < tlen; j++){
			if(s[i] == t[j]) {
				dp[i][j] = dp[i-1][j-1] + 1;
				pre[i][j] = 3;
			}
			else {
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
				pre[i][j] = dp[i-1][j] > dp[i][j-1] ? 1 : 2;
			}
		}
	}
	/*
	for(int i = 0; i < slen; i++){
		for(int j = 0; j < tlen; j++){
			printf("%d", pre[i][j]);
		}
		printf("\n");
	}
	*/
	int k = slen - 1, r = tlen - 1;
	while(k >= 0 && r >= 0 && pre[k][r] > 0){
		switch(pre[k][r]){
			case 1:
				k--;
				break;
			case 2:
				r--;
				break;
			case 3:
				ans.push_front(s[k]);
				k--, r--;
				break;
		}
	}
	if(k >= 0 && r >= 0 && pre[k][r] == 0) ans.push_front(s[k]);
	for(auto i : ans) printf("%c", i);
	printf("\n");
	return 0;
}

Measured memory_bytes: 74172
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long double d;
    cin>>d;
    cout << d * 2 * 3.1415926535 << endl;
    return 0;
}


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

int main() {
	int a, b;
	cin >> a >> b;
	if (a == 1 && b == 1) {
		cout << 1 << ' ' << 2 << endl;
		cout << ".#" << endl;
		return 0;
	}
	int h = 100, w = 100;
	string s[h];
	for (auto &t : s) {
		t = string(w, '.');
	}
	if (a == 1) {
		[&] {
			for (int i = 1; i < 100; i += 2) {
				for (int j = 1; j < 100; j += 2) {
					if (b-- == 0) {
						return;
					}
					s[i][j] = '#';
				}
			}
		}();
		cout << h << ' ' << w << endl;
		for (auto &t : s) {
			cout << t << endl;
		}
		return 0;
	}
	for (int i = 1; i < h - 1; i++) {
		s[1][i] = s[i][1] = s[h - 2][i] = s[i][h - 2] = '#';
	}
	a -= 2;
	b--;
	auto p = [&] {
		bool fin = false;
		int x = 2, y = 3;
		for (int i = 2; i < 98; i += 2) {
			for (int j = 3; j < 99; j += 2) {
				if (a-- == 0) {
					fin = true;
					x = j;
					y = i;
					break;
				}
				s[i][j] = '#';
			}
			if (fin) {
				for (int j = 1; j < x - 1; j++) {
					s[i + 1][j] = '#';
				}
				break;
			}
			for (int j = 1; j < 98; j++) {
				s[i + 1][j] = '#';
			}
		}
		return make_pair(y, x);
	}();
	[&] {
		for (int i = p.first + 1; i < 98; i += 2) {
			for (int j = (i == p.first + 1) ? p.second : 3; j < 97; j += 2) {
				if (b-- == 0) {
					return;
				}
				s[i][j] = '#';
			}
		}
	}();
	cout << h << ' ' << w << endl;
	for (auto &t : s) {
		cout << t << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< long long > vll;
typedef pair< int,int > ii;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define mp  make_pair
#define mod 1000000007
#define mod2 998244353
#define all(c) c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(all(c),x) != c.end())
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define fo(i,n) for(ll i=0;i<n;i++)
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define nl "\n"
ll gcd (ll a, ll b) {
    if (b == 0)
        return a;
    else
        return gcd (b, a % b);
}

unsigned long long factorial[1000004]; 
    /*factorial[0] = 1; 
    for (int i = 1; i <= n; i++) {
        factorial[i] = (factorial[i - 1] * i) % mod3; 
    }*/




unsigned long long power(unsigned long long x, 
                         int y, int p) 
{ 
    unsigned long long res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 



  
// Returns n^(-1) mod p 
unsigned long long modInverse(unsigned long long n, int p) 
{ 
    return power(n, p - 2, p); 
} 
unsigned long long nc(unsigned long long n, 
                                 int r, int p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
 
  
    return (factorial[n]* modInverse(factorial[r], p) % p * modInverse(factorial[n - r], p) % p) % p; 
} 
set<int> g[2000004];
vi vis(2000004);
int c;
/*int find(int a){
    if(v[a]==a){
        return a;
    }
    return v[a]= find(v[a]);
}

void join(int a,int b){
    a = find(a);
    b = find(b);
    if(a==b){
        return;
    }
    v[b]=a;
}*/

void dfs(int u){
    c++;
    vis[u]=1;
    for(auto j : g[u]){
        if(vis[j]==0){
            dfs(j);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    int a,b;
    fo(i,n){
        vis[i+1]=0;
    }
    
    fo(i,m){
        cin>>a>>b;
        g[a].insert(b);
        g[b].insert(a);
        
    }
    int c1=0;
    fo(i,n){
        c=0;
        if(vis[i+1]==0){
            dfs(i+1);
        }
        c1 = max(c1,c);
    }
    cout<<c1<<nl;
    
  
    

    return 0;
}


Measured memory_bytes: 129824
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define li          long
#define ll          long long
#define ull         unsigned long long
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define pli         pair<li,li>
#define pll         pair<ll,ll>
#define pb          push_back
#define fo(i,k,n)   for(int i = k;i<n; i++)
#define ro(i,k,n)   for(int i = k; i>=n; i--)
#define tc          int t;cin>>t;while(t--)
#define all(v)      v.begin(),v.end()
#define inf         INT_MAX
#define ninf        INT_MIN
#define W(x)        cout<<x<<endl
#define WW(x,y)     cout<<x<<' '<<y<<endl;
#define in(x)       cin>>x
#define v(x)        vector<x>
#define int         long long
#define ar(x,y)       array<x,y>
const ll mod1 = 99844353;
const ll mod2 = 1e9+7;
template <class T>
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

template<class T>
T power(T a,T b){
    T res = (T)1;
    while(b>0){
        if(b&1)res = res*a;
        b>>=1;
        a*=a;
    }
    return res;
}
struct dsu{
  map<int,int> pr,sz;
  dsu(){
    (this->pr).clear();
    (this->sz).clear();
  }
  void make(int x){
    pr[x] = x;
    sz[x] = 1;
  }
  int getpar(int x){
    if(pr[x] == x)return x;
    return pr[x] = getpar(pr[x]);
  }
  void merge(int x,int y){
    x = getpar(x);
    y = getpar(y);
    if(sz[x]<sz[y])swap(x,y);
    pr[y] = x;
    sz[x]+=sz[y];
    sz[y] = 0;
  }
};


void solve(){
  int n,k;
  cin>>n>>k;
  v(int)a(n);
  fo(i,0,n)cin>>a[i];
  sort(all(a));
  int ans = 0;
  for(int i = 0; i<min(k,n); i++)ans+=a[i];
  cout<<ans<<"\n";
}

signed main(){
    fastio();
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
}


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

#define ll long long
#define ar array

void solve() {
    string s, ts;
    int queries, t, f, i;
    char c;
    cin >> s;
    cin >> queries;
    for(i = 0; i < queries; ++i){
        cin >> t;
        if(t == 1){
            swap(s, ts);
        } else {
            cin >> f >> c;
            if(f == 1){
                ts += c;
            } else {
                s += c;
            }
        }
    }
    reverse(ts.begin(), ts.end());
    ts += s;
    cout << ts << endl;

}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int testCases;
    testCases = 1;
    while(testCases --) {
        solve();
    }
    return 0;
}



Measured memory_bytes: 1144
while True:
    n,k = map(int, input().split())
    if n == k == 0:
        break
    s = [int(x) for x in input().split()]
    for _ in range(n):
        b = [int(x) for x in input().split()]
        for i in range(k):
            s[i] -= b[i]
    print("Yes" if min(s) >= 0 else "No")

Measured memory_bytes: 7664
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

const long long MOD = 1000000007;

void test(int L, int R) {
    int a = 0, b = 0, c = 0;
    for(int x = L; x <= R; ++x) {
        for(int y = x; y <= R; ++y) {
            bool f = false, g = false;
            if ((x ^ y) == y % x) {
                ++a;
                f = true;
            }
            if (2 * x > y && (x & ~y) == 0) {
                ++b;
                g = true;
                cerr << x << "," << y << endl;
            }
            if (f != g) {
                ++c;
            }
        }
    }
    cerr << a << "," << b << "," << c << endl;
}

int dp[100][2][2][2];

void solve(long long L, long long R){
    int res = 0;

    int t = 62;
    dp[t][1][1][1] = 1;

    for(int i = t; i > 0; --i) {
        int ls = (L >> (i - 1)) & 1, rs = (R >> (i - 1)) & 1;

        // 0, 0, 0
        dp[i - 1][0][0][0] += dp[i][0][0][0] * 3 + rs * dp[i][1][0][0] + (1 - ls) * (dp[i][0][1][0] + dp[i][0][1][1]);
        dp[i - 1][0][0][0] %= MOD;

        // 0, 0, 1
        // This case doesn't exist

        // 0, 1, 0
        dp[i - 1][0][1][0] = ((2 - ls) * dp[i][0][1][0] % MOD + ls * dp[i][0][1][1]) % MOD + rs * (1 - ls) * dp[i][1][1][0];
        dp[i - 1][0][1][0] %= MOD;

        // 1, 0, 0
        dp[i - 1][1][0][0] += (1 + rs) * dp[i][1][0][0] % MOD + rs * (1 - ls) * (dp[i][1][1][1] + dp[i][1][1][0]) % MOD;
        dp[i - 1][1][0][0] %= MOD;

        // 0, 1, 1
        dp[i - 1][0][1][1] = (1 - ls) * (dp[i][0][1][1] + dp[i][1][1][1] * rs) % MOD;

        // 1, 0, 1
        // This case doesn't exist

        if (rs || !ls) {
            // 1, 1, 0
            dp[i - 1][1][1][0] = (dp[i][1][1][0] + dp[i][1][1][1] * rs * ls) % MOD;
        }

        dp[i - 1][1][1][1] = (1 - rs) * (1 - ls) * dp[i][1][1][1] % MOD;
    }

    for(int i = 0; i < 2; ++i) for(int j = 0; j < 2; ++j)  {
                res = (res + dp[0][i][j][0]) % MOD;
            }

    cout << res << endl;
}

signed main(){
    long long L;
    scanf("%lld",&L);
    long long R;
    scanf("%lld",&R);
    solve(L, R);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int d = in.nextInt();

            if (Math.abs(a - c) <= d) {
                System.out.println("Yes");
                return;
            }
            if (Math.abs(a - b) <= d && Math.abs(b - c) <= d) {
                System.out.println("Yes");
                return;
            }

            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define F first
#define S second
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
int main()
{
  int n; cin >> n;
  string s; cin >> s;
  if(n % 2 == 1) {
    cout << "No" << "\n";
  }
  else {
    int m = n/2;
    rep(i,m) {
      if(s[i] != s[i+m]) {
	cout << "No" << "\n";
	return 0;
      }
    }
    cout << "Yes" << "\n";
  }
  return 0;
}


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

int main (){
    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    
    int ans, temp;
    ans = 0;
    temp = 1;
    for (int i = 0; i < N - 1; i++)
    {
        if (a[i] == a[i + 1])
        {
            temp++;           
        } else
        {
            ans += (temp / 2);
            temp = 1;
        }   
    }
    ans += (temp / 2);
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <stdio.h>

int main (void) {
	char str1[101], str2[101], str3[101];

	scanf("%s", str1);
	scanf("%s", str2);
	scanf("%s", str3);

	printf("%c%c%c\n", str1[0], str2[0], str3[0]);

	return 0;
}

Measured memory_bytes: 128
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines

def main():
    N = int(input())
    for h in range(1, 3501):
        for n in range(1, 3501):
            shisu = h * N * n
            bosu = n * (h * 4 - N) - h * N
            if bosu >= 1:
                if not (shisu / bosu) % 1:
                    print(h, n , int((h * N * n) / (n * (h * 4 - N) - h * N)))
                    sys.exit()

if __name__ == '__main__':
    main()

Measured memory_bytes: 9264
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define vi vector<int>
#define vl vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define abu ios_base::sync_with_stdio(0)
#define said cin.tie(0)
using namespace std;

void yes(){
    cout<<"YES"<<endl;
}

void no(){
    cout<<"NO"<<endl;
}

void solve(){
    int h,w;
    cin>>h>>w;
    int d[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char a;
            cin>>a;
            if(a=='#'){
                d[i][j]=0;
            }else{
                d[i][j] = 1;
            }
        }
    }
    int dp[h][w];
    dp[0][0] = d[0][0]==0?1:0;
    for(int i=1;i<h;i++){
        if(d[i][0]==0){
            dp[i][0] = dp[i-1][0]+1;
        }else{
            dp[i][0] = dp[i-1][0];
        }
        for(int k = 0;k<=i;k++){
            if(dp[i][0]-dp[k][0]+1 == i-k+1 && d[k][0]==0 && d[i][0]==0){
                dp[i][0] = min(dp[k][0],dp[i][0]);
            }
            
        }
    }
    for(int i=1;i<w;i++){
        if(d[0][i]==0){
            dp[0][i] = dp[0][i-1]+1;
        }else{
            dp[0][i] = dp[0][i-1];
        }
        for(int k = 0;k<=i;k++){
            if(dp[0][i]-dp[0][k]+1 == i-k+1 && d[0][k]==0 && d[0][i]==0){
                dp[0][i] = min(dp[0][k],dp[0][i]);
            }
            
        }
    }
    for(int i=1;i<h;i++){
        for(int j=1;j<w;j++){
            if(d[i][j]==0){
                dp[i][j] = min(dp[i-1][j],dp[i][j-1])+1;
            }else{
                dp[i][j] = min(dp[i-1][j],dp[i][j-1]);
            }
            for(int k = 0;k<=i;k++){
                for(int z = 0;z<=j;z++){
                    if(dp[i][j]-dp[k][z]+1 == i-k+1+j-z && d[k][z]==0 && d[i][j]==0){
                        dp[i][j] = min(dp[k][z],dp[i][j]);
                    }
                }
            }
        }
    }
    
    cout<<dp[h-1][w-1]<<endl;
}

int main(){
    abu;
    said;
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


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

int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int left, right;
    left = A + B;
    right = C + D;

    if(left > right){
        cout << "Left" << endl;
    }else if(left < right){
        cout << "Right" << endl;
    }else{
        cout << "Balanced" << endl;
    }
}

Measured memory_bytes: 3596
//killer_R@$tog!
#include<bits/stdc++.h>
using namespace std;
#define hell 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define mp make_pair
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define ll long long int
#define N 100009
#define all(b) b.begin(),b.end();
//int pr[N];
//int seg[N];
/*int query(int l,int r,int sl,int sr,int p)
{
    if(r<sl || l>sr)
        return 0;
    if(sr<=r && sl>=l)
        return seg[p];
    int m=sl+(sr-sl)/2;
    return (__gcd(query(l,r,sl,m,2*p+1),query(l,r,m+1,sr,2*p+2)));
}

int build(int l,int r,int p,int arr[])
{
    if(l==r)
    {
        seg[p]=arr[l];
        return seg[p];
    }
    int m=l+(r-l)/2;
    seg[p]=__gcd(build(l,m,2*p+1,arr),build(m+1,r,2*p+2,arr));
    return seg[p];
}
void isprime()
{
    memset(pr,1,sizeof(pr));
    pr[1]=0;
    for(int i=2;i*i<=N;i++)
    {
        if(pr[i])
        {
            for(j=i*i;j<=N;j+=i)
            {
                pr[j]=0;
            }
        }
    }
}*/
void killer()
{
    int n;cin>>n;int a[n+3],dp[n+3]={0};
    rep(i,2,n+2)cin>>a[i];a[0]=a[2];a[1]=a[2];
    dp[0]=0;dp[1]=0;
    rep(i,2,n+2)
    {
        dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
    }
    cout<<dp[n+1];
    return;
}
int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    //int h=(int)ceil(log2(n));
    //h=2*(int)pow(2,h)-1;
    //build(0,n-1,0,a);

    ll t;
    //cin>>t;
    t=1;
    while(t--)
        killer();

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct num{
	ll tim; int data;
}n[102];
int main(){
	string s; ll k,sum=0;
	cin>>s>>k; bool ok=1;
	for(int i=0;i<s.size();i++){
		if(s[i]!='1') ok=0;
		if(ok&&i+1==k){cout<<1; return 0;}
		if(!ok){cout<<s[i]-'0'; return 0;}
	}
return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();     
        int N = r.i();
        int[] A = r.ii();
        int[] B = r.ii();
        long ans = 0;
        for(int i = 0; i < N; i++){
            if(A[i] <= B[i]){
                ans += A[i];
                B[i] -= A[i];
            } else{
                ans += B[i];
                B[i] = 0;
            }
            int temp = Math.min(B[i], A[i+1]); 
            A[i+1] -= temp;
            ans += temp;
        }
        println(ans);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

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


int main() {
  int N;
  ll ans=0;
  int d[110]={0};
  cin >> N;
  for(int i=0; i<N; i++){cin>>d[i];}

  for(int i=0; i<N; i++){
      for(int j=i+1; j<N; j++){
        ans += d[i]*d[j];                            
      }
  }
   cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <map>
#include <queue>
#include <deque>
#include <set>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define FOR(i,a,b) for (ll i = (a) ; i <= (b); ++i)
#define RFOR(i,a,b) for (ll i = (a) ; i >= (b); --i)
#define all(x) (x).begin(), (x).end()
//#define repitr(itr, st) for(auto itr = st.begin(); itr != st.end(); ++itr)
#define P_B push_back
#define PO_B pop_back
#define E_B emplace_back
#define M_P make_pair
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << endl
//#define print(x) printf("%d\n", x)

using namespace std;
using ll = long long;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<vector<int> >;
using VVL = vector<vector<ll> >;
//int dx[4] = {1, 0, -1, 0};
//int dy[4] = {0, 1, 0, -1};
//const ll LINF = (ll)1e18 - 1;
//const int INF = 1e9 - 1;
//int:±2*10^9くらい　ll:±9*10^18くらい

int cal(int x, int y, int z){
	int res;
	res = ((x+y)*(x+y) + (y+z)*(y+z) + (z+x)*(z+x)) / 2;
	return res;
}


void Main(){
	int n, x=1, y=1, z=1;
	cin >> n;
	VI f(n, 0);

	while(true){
		y=1;z=1;
		if(cal(x, y, z) > n) break;
		while(true){
			z=1;
			if(cal(x, y, z) > n) break;
			while(true){
				if(cal(x, y, z) > n) break;
				f[cal(x,y,z)]++;
 				z++;
			}
			y++;
		}
		x++;
	}

	rep(i, n){
		cout << f[i+1] << endl;
	}


}

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

  return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
int main(void)
{
long int n, k, s, t;

  scanf("%ld%ld", &n, &k);
  s=n%k;
  t=k-s;

    if(s>=t)
      printf("%ld", t);
    else
      printf("%ld", s);

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int dp[41][401][401];
int main(){
    int n,x,y;
    cin>>n>>x>>y;
    vi a(n);
    vi b(n);
    vi c(n);
    REP(i,n){
        cin>>a[i]>>b[i]>>c[i];
    }
    REP(i,41){
        REP(j,401){
            REP(k,401){
                dp[i][j][k]=INF;
            }
        }
    }
    dp[0][0][0]=0;
    REP(i,n){
        REP(j,401){
            REP(k,401){
                if(dp[i][j][k]!=INF){
                    dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
                    dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
                }
            }
        }
    }
    int ans=INF;
    FOR(i,1,10000){
            int p=x*i;
            int q=y*i;
            if(p>400||q>400){
                cout<<(ans==INF?-1:ans)<<endl;
                return 0;
            }
            cerr<<p<<" "<<q<<" "<<dp[n][p][q]<<endl;
            ans=min(ans,dp[n][p][q]);
    }
    return 0;
}

Measured memory_bytes: 25984
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

static const int MOD = (int)1e+9 + 7;

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

    unordered_set<int> dangers;
    for (int i = 0; i < M; ++i) {
        int ai;
        cin >> ai;
        dangers.emplace(ai);
    }

    vector<ll> dp(N+1);
    dp[0] = 1;
    dp[1] = 1;

    auto it = dangers.find(1);
    if (it != end(dangers)) {
        dp[1] = 0;
    }

    for (int i = 2; i <= N; ++i) {
        auto it = dangers.find(i);
        if (it != end(dangers)) {
            dp[i] = 0;
            continue;
        }

        dp[i] = (dp[i-1] + dp[i-2]) % MOD;
    }

    ll ans = dp[N];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5024
S = input()
N = len(S)

left = 0
right = N - 1

ans = 0
while left < right :
    if S[left] == S[right] :
        left += 1
        right -= 1
        continue
    if S[left] == 'x' :
        ans += 1
        left += 1
        continue
    if S[right] == 'x' :
        ans += 1
        right -= 1
        continue
    print('-1')
    break
else :
    print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define rrep(i, a, b) for(ll i = b-1; i >= a; i--)
#define  pii pair<ll,ll>
typedef long long ll;

int main(){
    ll N, T; cin >> N >> T;
    vector<pii> P(N);
    rep(i, 0, N) cin >> P[i].first >> P[i].second;
    
    vector<pii> dp(3010, make_pair(0,0));
    rep(i, 0, N){
        rrep(j, 0, T + 1){
            if(j - P[i].first >= 0){
                if(dp[j].first < dp[j-P[i].first].first + P[i].second){
                    dp[j] = make_pair(dp[j-P[i].first].first + P[i].second, dp[j-P[i].first].second);
                }else if(dp[j].first == dp[j-P[i].first].first + P[i].second){
                    dp[j].second = max(P[i].second,dp[j].second);
                    dp[j].second = max(P[i].second,dp[j-P[i].first].second);
                }
                else{
                    if(dp[j].second < P[i].second){
                        dp[j].second = P[i].second;
                    }
                }
                //dp[j] = max(dp[j-P[i].first] + P[i].second, dp[j]);
            }else{
                if(dp[j].second < P[i].second){
                    dp[j].second = P[i].second;
                }
            }
        }
    }
    ll ans = 0;
    rep(i, 0, T){
        ans = max(ans, dp[i].first + dp[i].second);
    }
    // ans = max(ans, dp[T].first);
    //rep(i, 0, T + 1) cout << i << " " << dp[i].first << " " << dp[i].second << " " << dp[i].first + dp[i].second << endl; 
    cout << ans << endl;

}

Measured memory_bytes: 384
A, B, C, K = map(int, input().split(" "))
if K-A <= 0:
    print(K)
else:
    if K - (A + B) <= 0:
        print(A)
    elif K == A+B+C:
        print(A-C)
    else:
        print(A - (K-(A+B)))


Measured memory_bytes: 9060
#include<iostream>
#include<map>
#include<string>
using namespace std;

map<string,int> data;
map<string,map<string,int> >tree;

int cal(string str){
	int r=data[str];
	int sum=-1;
	map<string,int>::iterator itr=tree[str].begin();
	for(;itr!=tree[str].end();itr++){
		sum+=cal(itr->first);
	}
	if(sum!=-1)return min(sum+1,r);
	else return r; 
}

int main(){
	int n;
	
	while(cin>>n && n){
		tree.clear();
		string str;
		int cost;
		for(int i=0;i<n;i++){
			cin>>str>>cost;
			data[str]=cost;
		}
		int m;
		cin>>m;
		for(int i=0;i<m;i++){
			string in;
			int num;
			cin>>in>>num;
			for(int j=0;j<num;j++){
				string tmp;
				cin>>tmp;
				tree[in][tmp]=1;
			}
		}
		
		string ma;
		cin>>ma;
		
		cout<<cal(ma)<<endl;
		
		
	}
	
}

Measured memory_bytes: 1240
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut seq = vec![0; n];
    for i in 0..n {
        seq[i] = read::<usize>();
    }
    let mut used = vec![false; n];
    let mut anss = vec![];
    let mut current = vec![];
    for i in 0..n {
        'j_loop: for j in (0..n).rev() {
            let v = seq[j];
            if used[j] || v > current.len() + 1 {
                continue;
            }
            let mut pos = v - 1;
            for k in (j + 1)..n {
                if seq[k] > v {
                    continue;
                }
                if pos >= current.len() || current[pos] != seq[k] {
                    continue 'j_loop;
                }
                pos += 1;
                while pos < current.len() && current[pos] > v {
                    pos += 1;
                }
            }
            if pos != current.len() {
                continue 'j_loop;
            }
            used[j] = true;
            anss.push(v);
            current.insert(v - 1, v);
            break;
        }
        if anss.len() != i + 1 {
            println!("-1");
            return;
        }
    }
    for &ans in anss.iter() {
        println!("{}", ans);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    int n;
    cin >> n;
    vector<string > s(n);
    map<string, int> m;
    REP(i,n){
        cin >> s[i];
        m[s[i]]++;
    }    
    cout << m.size() << endl;
    return 0;
}

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

const int INF = 20;
int sx, sy;
int gx, gy;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int h, w, ans = 0;
typedef pair<int, int> P;

int main() {
  cin >> h >> w;
  char maze[w][h];
  int d[w][h];
  string S;

  for (int i = 0; i < h; i++) {
    cin >> S;
    for (int j = 0; j < w; j++) {
      maze[j][i] = S[j];
    }
  }

  queue<P> que;

  for (int sy = 0; sy < h; ++sy) {
    for (int sx = 0; sx < w; ++sx) {
      for (int gy = 0; gy < h; ++gy) {
        for (int gx = 0; gx < w; ++gx) {
          if (sy == gy && sx == gx) continue;
          if (maze[sx][sy] == '#' || maze[gx][gy] == '#') continue;

          for (int initi = 0; initi < h; initi++)
            for (int initj = 0; initj < w; initj++) d[initj][initi] = INF;

          que.push(P(sx, sy));
          d[sx][sy] = 0;

          while (que.size()) {
            P p = que.front();
            que.pop();

//            if (p.first == gx && p.second == gy) break;

            for (int i = 0; i < 4; i++) {
              int nx = p.first + dx[i], ny = p.second + dy[i];

              if (0 <= nx && nx < w && 0 <= ny && ny < h &&
                  maze[nx][ny] != '#' && d[nx][ny] == INF) {
                que.push(P(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
              }
            }
          }

          ans = max(ans, d[gx][gy]);
          //          cout << ans << endl;
        }
      }
    }
  }

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


Measured memory_bytes: 256
package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		a := make([]int, 10)
		for i := 0; i < n; i++ {
			scanner.Scan()
			c, _ := strconv.Atoi(scanner.Text())
			a[c]++
		}
		for _, v := range a {
			if v == 0 {
				fmt.Println("-")
				continue
			}
			for i := 0; i < v; i++ {
				if i == v-1 {
					fmt.Println("*")
				} else {
					fmt.Print("*")
				}
			}
		}
	}
}


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

# define x first
# define y second
# define mp make_pair
// everything goes according to my plan
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right

//put debug temp

using namespace std;

typedef pair <int, int> pii;
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") {
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

template<typename T> using ordered_set = tree<T, null_type, less<T>, 
rb_tree_tag, tree_order_statistics_node_update>;
ordered_set<pair <ll, int> > s;

int a[Sz];
int n;
int k;

int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
  	cin >> a[i];

  ll pref = 0;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
  	s.insert({pref-(i-1)*1ll*k,i});  
  	pref += a[i];
  	auto it = s.upper_bound({pref-i * 1ll * k,n});
  	if (it != s.end())
      ans += s.order_of_key(*it);
    else
      ans += sz(s);

  }
  cout << ans;


  return 0;
}





// Coded by Z..

Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int N;cin>>N;
    int C[N-1],S[N-1],F[N-1];
    REP(i,N-1)cin>>C[i]>>S[i]>>F[i];
    REP(i,N){
        int nowT=0;
        if(i==N-1){
            cout<<0<<endl;
            break;
        }
        for(int j=i;j<N-1;j++){
            if(S[j]>=nowT)nowT=S[j];
            else{
                int z=S[j];
                while(nowT>z)z+=F[j];
                nowT=z;
            }
            nowT+=C[j];
        }
        cout<<nowT<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <cctype>
#include<cmath>
#include<vector>

using namespace std;


int main(void) {
	int A,B;
	
	cin >> A;
	cin >> B;
	
	if (A % 2 == 1 && B % 2 == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

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

int main() {
  string a, b;
  cin >> a >> b;
  string ans = "EQUAL";
  if (a.size() < b.size()) ans = "LESS";
  else if (a.size() > b.size()) ans = "GREATER";
  else {
    for (int i=0; i<a.size(); i++) {
      if (a[i] == b[i]) continue;
      else if (a[i] < b[i]) {
        ans = "LESS";
        break;
      }
      else {
        ans = "GREATER";
        break;
      }
    }
  }
  cout << ans << endl;
}


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

ll f(vector<vector<ll>>& dp, const vector<ll>& A, const vector<ll>& sum, int N, int beg, int end){
    if(dp[beg][end] != -1)return dp[beg][end];
    if(end - beg == 1){
        dp[beg][end] = A[beg]+A[end];
        return dp[beg][end];
    }
    if(end == beg){
        dp[beg][end] = 0;
        return dp[beg][end];
    }
    dp[beg][end] = 10000000000000LL;
    for(int i = beg;i < end;i++){
        ll c = f(dp,A,sum,N,beg,i) + f(dp,A,sum,N,i+1,end) + sum[end+1]-sum[beg];
        dp[beg][end] = min(dp[beg][end], c);
    }
    return dp[beg][end];

}

int main(){
    int N;cin>>N;
    vector<ll> A, sum(N+1,0);
    for(int i = 0;i < N;i++){
        int _a;cin>>_a;
        A.push_back(_a);
        sum[i+1] = sum[i] + _a;
    }
    vector<vector<ll>> dp(N,vector<ll>(N,-1));
    

    cout<<f(dp,A,sum,N,0,N-1)<<endl;
    // for(int i = 0;i < N;i++){
    //     for(int j = 0;j < N;j++){
    //         cout<<dp[i][j]<<"\t";
    //     }cout<<endl;
    // }
    // for(int i = 0;i < N+1;i++)cout<<sum[i]<<" ";
    // cout<<endl;
}

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

int main() {
	
	int n, d, x; cin >> n >> d >> x;
	int cnt = 0;
	while (n--) {
		int a; cin >> a;
		int time = 1;
		while (time<=d) {
			cnt++;
			time += a;
		}
	}
	cout << cnt + x << endl;
    return 0;
}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

//Atcoder用

/*
 * BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] abc = br.readLine().split(" ");
		int a = Integer.parseInt(abc[0]);
		int b = Integer.parseInt(abc[1]);
		int c = Integer.parseInt(abc[2]);
 */
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] get = br.readLine().split(" ");
		int n = Integer.parseInt(get[0]);

		if(n<1200){
			System.out.println("ABC");
		}else if(n<2800){
			System.out.println("ARC");
		}else{
			System.out.println("AGC");
		}
	}

}


Measured memory_bytes: 21204
import heapq
n = int(input())
v = list(map(int, input().split()))
heapq.heapify(v)
while len(v) >= 2:
    num1 = heapq.heappop(v)
    num2 = heapq.heappop(v)
    heapq.heappush(v, (num1 + num2) / 2)
print(v[0])

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

typedef pair<int,int> PI;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

typedef double D;
typedef complex<D> P;
#define X real()
#define Y imag()

const D eps=1e-8;
const D inf=1e12;

struct L : public vector<P> { // line and segment
  L(const P& a,const P &b){
    push_back(a);
    push_back(b);
  }
};

bool cmp_x(const P& a,const P& b){ return a.X==b.X?a.Y<b.Y:a.X<b.X; }
D dot(P a,P b){ return (conj(a)*b).X; }
D cross(P a,P b){ return (conj(a)*b).Y; }
vector<P> convex_hull(vector<P>& ps){
  sort(ps.begin(),ps.end(),[](const P& a,const P& b){ return a.X==b.X?a.Y<b.Y:a.X<b.X; });
  int n=ps.size();
  int k=0;
  vector<P> qs(n*2);
  for(int i=0;i<n;i++){
    while(k>1&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<=0)k--;
    qs[k++]=ps[i];
  }
  for(int i=n-2,t=k;i>=0;i--){
    while(k>t&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<=0)k--;
    qs[k++]=ps[i];
  }
  qs.resize(k-1);
  return qs;
}

bool intersectLP(L l,P p){
  //dbg(abs(cross(l[1]-p,l[0]-p)));
  return abs(cross(l[1]-p,l[0]-p))<eps;
}
P projection(L l,P p){
  P b=l[1]-l[0],c=p-l[0];
  return l[0]+b*(c/b).X;
}
P reflection(L l,P p) {
  return p+2.0*(projection(l,p)-p);
}

int N;
vector<P> ps;
set<PI> st;

int main(){
  cin>>N;
  rep(i,N){
    int x,y;
    cin>>x>>y;
    ps.push_back(P(x,y));
    st.insert(PI(x,y));
  }
  vector<P> cs=convex_hull(ps);
  int M=cs.size();
  vector<P> ds;
  rep(i,M){
    ds.push_back(cs[i]);
    ds.push_back((cs[i]+cs[(i+1)%M])*0.5);
  }
  vector<L> cand;
  rep(i,M){
    bool ok=true;
    P p1=ds[i],p2=ds[i+M];
    for(int l=(i-1+2*M)%(2*M),r=i+1;l!=r;l=(l-1+2*M)%(2*M),r=(r+1)%(2*M)){
      P m=(ds[l]+ds[r])*0.5;
      if(!intersectLP(L(p1,p2),m)||abs(dot(ds[l]-ds[r],p1-p2))>eps)ok=false;
    }
    if(ok){
      cand.push_back(L(p1,p2));
    }
  }

  bool is_sym=false;
  rep(i,cand.size()){
    bool ok=true;
    int cnt=0;
    rep(j,N){
      if(intersectLP(cand[i],ps[j])){cnt++;continue;}
      P r=reflection(cand[i],ps[j]);
      int px=round(r.X);
      int py=round(r.Y);
      if(abs((double)px-r.X)>eps)ok=false;
      if(abs((double)py-r.Y)>eps)ok=false;
      if(st.count(PI(round(r.X),round(r.Y)))==0)ok=false;
    }
    if(ok&&cnt<3)is_sym=true;
  }

  if(is_sym)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}



Measured memory_bytes: 3308