akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
  
namespace rika
{
  template <typename T>
  class edge
  {
  public:
    int to;
    T cost;
      
    edge() = default;
    edge(const edge<T>&) = default;
    edge(edge<T>&&) = default;
    edge& operator =(const edge<T>&) = default;
    edge& operator =(edge<T>&&) = default;
  
    ~edge() = default;
  
    edge(int _to, T _cost) : to(_to), cost(_cost) {}
  };
}
  
namespace rika
{
  namespace internal
  {
    template <typename TValue, typename TGraph>
    std::pair<TValue, int> visit(int from, int v, const TGraph &g)
    {
      auto r = std::make_pair(TValue(), v);
      try{
      for(auto it = g[v].begin(); it != g[v].end(); ++it)
      {
        if(it->to == from)
          continue;
        auto r2 = visit<TValue>(v, it->to, g);
        if(r2.first + it->cost >= r.first)
          r = std::make_pair(r2.first + it->cost, r2.second);
      }
      }
      catch (bool x) {}
      return r;
    }
  }
  
  template <typename TValue, typename TGraph>
  TValue tree_diameter(const TGraph &g)
  {
    using namespace internal;
    auto r1 = visit<TValue>(-1, 0, g);
    auto r2 = visit<TValue>(-1, r1.second, g);
    return r2.first;
  }
}
  
#include<bits/stdc++.h>
using namespace std;
using namespace rika;
int main()
{
  int N;
  cin >> N;
  vector<vector<edge<int>>> g(N * 10);
  for(int i = 0; i < N - 1; i++)
  {
    int s, t, w;
    cin >> s >> t >> w;
    g[s].push_back(edge<int>(t, w));
    g[t].push_back(edge<int>(s, w));
  }
  cout << tree_diameter<int>(g) << endl;
}

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

using namespace std;

int main() {
    long long int a, b, c, d, n, p, q, r, s, tmp;
    scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
    scanf("%lld", &n);
    if ((d < 2 * c)  && (d < 4 * b) && (d < 8 * a)) {
        if (n % 2) {
            if ((c < 2 * b) && (c < 4 * a)) {
                tmp = c;
            }
            else if ((b < 2 * a) && (2 * b < c)) {
                tmp = 2 * b;
            }
            else {
                tmp = 4 * a;
            }
            printf("%lld", ((n - 1) * d) / 2 + tmp);
        }
        else {
            printf("%lld", (n * d) / 2);
        }
    }
    else {
        if ((c < 2 * b) && (c < 4 * a)) {
            tmp = c;
        }
        else if ((b < 2 * a) && (2 * b < c)) {
            tmp = 2 * b;
        }
        else {
            tmp = 4 * a;
        }
        printf("%lld", n * tmp);
    }
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  int n, m;
  cin >> n >> m;
  vector<pii> St(n), M(m);
  rep(i, n){
    int a , b; cin >> a >> b;
    St[i] = (pii(a,b));
  }
  rep(i, m){
    int c, d; cin >> c >> d;
    M[i] = (pii(c, d));
  }

  rep(i, n){
    int res = -1, minD = INF;
    rep(j, m){
      int x = abs(M[j].first - St[i].first);
      int y = abs(M[j].second - St[i].second);
      if(minD > x + y){
        minD = x + y;
        res = j + 1;
      }
    }
    cout << res << ln;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll rui[ohara];
ll tate[ohara];
deque<ll> ans;

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>k;
    if(n==0){
        if(k==0)Cout("0 0");
        else Cout(-1);
    }
    else if(n==1){
        if(k==0)Cout("0 0 1 1");
        else Cout(-1);
    }
    else{
    cnt=2;
    rui[0]=1;
    rrep(i,1,46){
        rui[i]=cnt;
        cnt*=2;
    }
    if(k==0){
        rep(i,rui[n]){
            if(i==rui[n]-1){
                cout<<i<<" "<<i<<"\n";
            }
            else cout<<i<<" "<<i<<" ";
        }
        return 0;
    }
    tmp=k;
    while(1){
        rrrep(i,45,0){
            if(rui[i]<=tmp){
                tmp-=rui[i];
                tate[i+1]++;
                break;
            }
        }
        if(tmp==0)break;
    }
    if(rui[n]<=k)Cout(-1);
    else{
        ans.push_back(0);
        ans.push_back(k);
        ll judge=0;
        
        rrep(i,1,rui[n]){
            if(i==k||i==0)continue;
            ans.push_front(i);
            ans.push_back(i);
            judge=(judge xor i);
        }
        ans.push_front(0);
        ans.push_back(k);
        if(judge==k){
            rep(i,Size(ans)){
                if(i==Size(ans)-1)Cout(ans[i]);
                else cout<<ans[i]<<" ";
            }
        }
        else{
            Cout(-1);
        }
    }
    }
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int b[n-1];
    for(int i=0;i<(n-1);i++)    cin >> b[i];
    int a[n];
    a[0]=b[0];
    for(int i=1;i<(n-1);i++)
    {
        a[i]=min(b[i],b[i-1]);
    }
    a[n-1]=b[n-2];
    long long sm=0;
    for(int i=0;i<n;i++)    sm+=a[i];
    cout << sm;
    return 0;
}

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

int main(){
    int n ; 
    string s ;
    cin >> n ;
    cin >> s ;
    
    int ans = 0 ;  
    int count = 0 ;
    rep(i,n-1){
        int count = 0 ;
        vector<int> count_l(26) ;
        vector<int> count_r(26) ;
        for(int j = 0 ; j < i+1 ; j++ ) count_l[ (int) s[j] - 'a' ]++ ;
        for(int k = i+1 ; k < n ; k++ ) count_r[ (int) s[k] - 'a' ]++ ;
        rep(l,26){
            if(count_l[l] >  0 && count_r[l] >  0 ) count++ ; 
        }
        ans = max(ans,count) ;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
ν=int(input())
τ=list(map(int,input().split()))
α=list(map(int,input().split()))

τ.append(0)
α.append(0)
ρ=1
μ=10**9+7

for ι in range(ν):
  ε=10**10
  if τ[ι]>τ[ι-1]:
    ε=min(1,ε)
    if α[ι]<τ[ι]:
      ε=0
  if α[ι]>α[ι+1]:
    ε=min(1,ε)
    if α[ι]>τ[ι]:
      ε=0
  if τ[ι]<τ[ι-1] or α[ι]<α[ι+1]:
    ε=0
  ε=min(ε,α[ι],τ[ι])
  ρ=(ρ*ε)%μ
print(ρ)
  

Measured memory_bytes: 97584
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
#define FOR(i,a,b) for(int i=(int)a,c=(int)b;i<c;++i)
#define rep(i,b) FOR(i,0,b)
#define ROF(i,a,b) for(int i=b-1,c=(int)a;i>=c;--i)
#define per(i,b) ROF(i,0,b)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

signed main(){
  int n,m;
  cin>>n>>m;
  vector<vector<int> > s(m);
  rep(i,m){
    int k;
    cin>>k;
    rep(j,k){
	 int ss;
	 cin>>ss;
	 ss--;
	 s[i].pb(ss);
    }
  }
  vector<int> p(m);
  rep(i,m)cin>>p[i];

  int ans=0;
  rep(i,1<<n){
    int f=1;
    rep(j,m){
	 int sum=0;
	 rep(k,sz(s[j])){
	   if(i>>s[j][k]&1)sum++;
	 }
	 if(sum%2!=p[j])f=0;
    }
    ans+=f;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define mii map<int,int>
#define MOD 1000000007
#define fr(i,k,n) for(int i=k;i<n;i++)
#define fl(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
typedef long long ll;
int prime[100001]={};
void sieve()
{
	prime[0]=1;
	prime[1]=1;
	for(int i=0;i*i<100001;i++)
	{
		if(prime[i]==0)
		{
			for(int j=i*i;j<100001;j+=i)
			{
				prime[j]=1;
			}
		}
	}
}
ll binpow(ll a,ll b,ll m)
{
	ll res=1;
	while(b>0)
	{

	if(b&1)
	{
		res=res*a%m;
	}
	a=a*a%m;
	b>>=1;
   }
   return res;
}
bool solve()
{
	int k,a,b;
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		return true;
	}
	return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
if(solve())
cout<<"OK"<<endl;
else
cout<<"NG"<<endl;
return 0;
}




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

using namespace std;

bool check(int begin, int end, char *tmp){
  int first = begin-1;
  int second = end-1;
  int count = (end-begin)/2;
  while(count >= 0){
    //cout << tmp[first] << " " << tmp[second] << endl;
    if(tmp[first] != tmp[second]){
      return false;
    }
    first++;
    second--;
    count--;
  }
  return true;
}

int main(){
  string S;
  cin >> S;
  vector<char> s;
  int n = S.size();
  bool flag = true;
  for(int i=0;i<S.size();i++){
    s.push_back(S.at(i));
  }

  flag = check(1, n, s.data());
  if(!flag){
    cout << "No" << endl;
    return 0;
  }

  flag = check(1, (n-1)/2, s.data());
  if(!flag){
    cout << "No" << endl;
    return 0;
  }

  flag = check((n+3)/2, n, s.data());
  if(!flag){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

//jyjfÅ é©Ì»èÖ
//1 : jyjfÅ é, 0 : jyjfÅÈ¢
int isMSPrime(int x){
	int i;
	int p = 6;

	for(i=0;p<x;i++){
		if(x % p == 0) return 0;
		if(i % 2 == 0){
			p += 2;
		} else{
			p += 5;
		}
	}
	return 1;
}

int main(void){
	int i,p,flg;
	int x; //üÍl

	while(1){
		scanf("%d",&x);
		if(x == 1) break;

		printf("%d:",x);
		flg = 0;
		p = 6; //êÔÅÌjyjf
		for(i=0;p<x;i++){
			if(x % p == 0 && isMSPrime(p)){
				printf(" %d",p);
				flg = 1;
			}

			if(i % 2 == 0){
				p += 2;
			} else{
				p += 5;
			}
		}
		if(flg == 0) printf(" %d",x);
		printf("\n");
	}

	return 0;
}

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

// long int minpath(int *a, int l, int n, long int cost, long int mini){
//   if(n==l){
//     if(mini>cost){
//       mini=cost;
//     }
//     return cost;
//   }
//   if(l+2<=n){
//     if(cost+abs(a[l+1]-a[l])>mini && cost+abs(a[l+2]-a[l])>mini){
//       return mini;
//     }
//     else if(cost+abs(a[l+1]-a[l])>mini){
//       return minpath(a,l+2,n,cost+abs(a[l+2]-a[l]),mini);
//     }
//     else if(cost+abs(a[l+2]-a[l])>mini){
//       return minpath(a,l+1,n,cost+abs(a[l+1]-a[l]),mini);
//     }
//     else{
//       return min(minpath(a,l+1,n,cost+abs(a[l+1]-a[l]),mini),minpath(a,l+2,n,cost+abs(a[l+2]-a[l]),mini));
//     }
//   }
//   if(cost+abs(a[l+1]-a[l])>mini){
//     return mini;
//   }
//   return minpath(a,l+1,n,cost+abs(a[l+1]-a[l]),mini);
// }

int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int dp[n+1];
  dp[0]=0;
  for(int i=1;i<n;i++){
      dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
    //   cout<<dp[i]<<'\t';
      if(i>1)
          dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
    //   cout<<dp[i]<<endl;
  }
  cout<<dp[n-1];
//   cout<<minpath(a,0,n-1,0,9999999)<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <vector>
#include <random>
using namespace std;

/////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
const ll MOD = 1e9 + 7;

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

    while (a > 0 && c > 0) {
        c -= b;
        if (c <= 0) {
            break;
        }
        a -= d;
        if (a <= 0) {
            break;
        }
    }

    cout << ((a > 0) ? "Yes" : "No") << endl;
 
    return 0;
}



Measured memory_bytes: 3636
i = list(map(int, input().split()))
k = i[0]
s = i[1]
#print("k=",k,"s=",s)
ans = 0
for x in range(k+1):
  for y in range(k+1):
    z = s-x-y
    #print("x=",x,"y=",y,"z=",z)
    if k >= z and z >=0:
        #print("clear!")
        ans += 1
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define INF 1 << 28
#define S second
#define F first
typedef pair<int,int> Pi;

inline void chmax(int &a, int b) { a = max(a,b); }
inline void chmin(int &a, int b) { a = min(a,b); }


int N, K;
int data[105];
int memo[105][4][2];

int dfs(int it, int ch, int cnt)
{
  int ret = 0;
  if(it == N)return 1;
  if(~memo[it][ch][cnt])return memo[it][ch][cnt];
  if(data[it + 1] != INF) {
    int nc;
    if(data[it + 1] == ch) nc = cnt + 1;
    else nc = 0;
    if(nc < 2) (ret += dfs(it + 1,data[it + 1],nc)) %= 10000;
  }else {
    Rep(i,3) {
      int nc;
      if(ch == i) nc = cnt + 1;
      else nc = 0;
      if(nc < 2) (ret += dfs(it + 1,i,nc)) %= 10000;
    }
  }
  return memo[it][ch][cnt] = ret;
}

int main()
{
  memset(memo,-1,sizeof(memo));
  cin >> N >> K;
  int A, B;
  fill(data,data + 105,INF);
  Rep(i,K) {
    cin >> A >> B; --B;
    data[A] = B;
  }
  cout << dfs(0,3,0) << endl;
  return(0);
}
  

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 A,B,m;
  cin >> A >> B >> m;
  vector<int32> a(A),b(B);
  int32 amn=INF,bmn=INF;
  REP(i,A)cin >> a[i], amn=min(amn,a[i]);
  REP(i,B)cin >> b[i], bmn=min(bmn,b[i]);
  int32 ans = amn + bmn;
  REP(i,m){
    int32 x,y,c;
    cin >> x >> y >> c;
    --x;--y;
    ans = min(ans, a[x]+b[y]-c);
  }
  ANS(ans);
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#define ll long long
using namespace std;

ll mod=1000000007, dp[100010][2];
bool checked[100010];

void solve(int key, vector<vector<int>> &v){
    ll white=1, black=1;
    checked[key]=1;
    for(int i=0; i<v[key].size(); ++i){
        if(!checked[v[key][i]]){
            solve(v[key][i], v);
            white=(white*((dp[v[key][i]][0]+dp[v[key][i]][1])%mod))%mod;
            black=(black*dp[v[key][i]][0])%mod;
        }
    }
    dp[key][0]=white;
    dp[key][1]=black;
}

int main() {
	int N;
	cin >> N;
	vector<vector<int>> g(N+1);
	for(int i=1; i<N; ++i){
	    int x, y;
	    cin >> x >> y;
	    g[x].push_back(y);
	    g[y].push_back(x);
	}
	solve(1, g);
	cout << (dp[1][0]+dp[1][1])%mod;
	return 0;
}


Measured memory_bytes: 12928
#include<bits/stdc++.h>;
using namespace std;
#define ll long long
int main(){
    ll n;
    cin>>n;
    vector<int> v(n), a(n);
    for(int i=0; i<n; i++){
        cin>> v[i];
        a[i]=v[i];
    }
    sort(a.begin(), a.end());
    int count=0;
    int cnt =0;
    for(int j=0; j<n; j++){
        if(v[j]!=a[j])cnt++;
    }
    if(cnt<=2)cout<< "YES";
    else cout<<"NO";
 return 0;
}


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

int main(){
    int c[3][3];
    int x[3], y[3];
    bool flag = true;
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> c[i][j];
        }
    }

    for(int i = 0; i < 3; i++){
        y[i] = c[0][i] - x[0];
    }
    for(int i = 0; i < 3; i++){
        x[i] = c[i][0] - y[0];
    }

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            if(x[i] + y[j] != c[i][j]) flag = false;
        }
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

s = raw_input()
c, f = 1e10, -1
for i, si in enumerate(s):
    if si == "C":
        c = min(c, i)
    if si == "F":
        f = max(f, i)
print "Yes" if c < f else "No"


Measured memory_bytes: 4496
n=int(input())
s=set()
w=input()
s.add(w)
tmp=w[-1]
can=True
for i in range(n-1):
    w=input()
    if w in s:
        can=False
    s.add(w)
    if w[0]==tmp:
        tmp=w[-1]
    else:
        can=False
if can:
    print('Yes')
else:
    print('No')

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll x, y;
  cin >> x >> y;

  ll en = 0;
  if (x == 1) en += 300000;
  else if (x == 2) en += 200000;
  else if (x == 3) en += 100000;

  if (y == 1) en += 300000;
  else if (y == 2) en += 200000;
  else if (y == 3) en += 100000;

  if (x == 1 && y == 1) en += 400000;

  cout << en << endl;

  return 0;
}

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

int main()
{
    int i,c=0,mx=0;
    string s;

    cin>>s;

    for(i=0;i<3;i++){
        if(s[i]=='R'){
            c++;
        }
        else{
            mx=max(mx,c);
            c=0;
        }
    }
    if(c>0){
        mx=max(mx,c);
    }
    cout<<mx<<endl;

    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int win = 0;
    for( int i = 0; i < s.size(); ++i ) {
        if( s[i] == 'o' ) ++win;

    }
    if( win + 15 - s.size() >= 8 ) cout << "YES";
    else cout << "NO";
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 998244353
#define F first
#define S second
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
bool isPowerOfTwo(int n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}
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;
}
bool isPalindrome(string str)
{
    // Start from leftmost and rightmost corners of str
    int l = 0;
    int h = str.length()- 1;

    // Keep comparing characters while they are same
    while (h > l)
    {
        if (str[l++] != str[h--])
        {
            return false;
        }
    }
    return true;
}

signed main()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n;
cin>>n;
int a[n];
map<int,vector<int>>m;
for(int i=0;i<n;i++)
{
    cin>>a[i];
    m[a[i]].push_back(i);
}
int ans=0;
for(auto it=m.begin();it!=m.end();it++)
{
    vector<int>v=it->second;
    int x=v.size();
    if(x<2)
        ans+=0;
    else
        ans+=((x*(x-1))/2);
}
for(int i=0;i<n;i++)
{
    int temp=ans;
    int x=m[a[i]].size();
    if(x<2)
        cout<<ans<<endl;
    else
    {
        temp-=((x*(x-1))/2);
        temp+=(((x-1)*(x-2))/2);
        cout<<temp<<endl;
    }
}
}









Measured memory_bytes: 17664
import bisect

A, B, Q = map(int, input().split())
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]

for _ in range(Q):
    x = int(input())
    s_pl = bisect.bisect_left(s, x) - 1
    s_pr = s_pl + 1
    t_pl = bisect.bisect_left(t, x) - 1
    t_pr = t_pl + 1
    
    dist = 10 ** 11
    if 0 <= s_pl < A and 0 <= t_pr < B:
        dist = x + t[t_pr] - 2 * s[s_pl]
        dist = min(dist, 2 * t[t_pr] - s[s_pl] - x)
    if 0 <= s_pr < A and 0 <= t_pr < B:
        dist = min(dist, max(s[s_pr], t[t_pr]) - x)
    if 0 <= s_pl < A and 0 <= t_pl < B:
        dist = min(dist, x - min(s[s_pl], t[t_pl]))
    if 0 <= s_pr < A and 0 <= t_pl < B:
        dist = min(dist, x + s[s_pr] - 2 * t[t_pl])
        dist = min(dist, 2 * s[s_pr] - t[t_pl] - x)

    print(dist)

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

int main(void){
    int N, X;
    cin >> N >> X;
    int L[110];
    int i;
    int res = 0;
    int D = 0;
    L[N] = 0;
    for(i=0; i<N+1; i++){
        if(D <= X){
            res++;
        }
        if(i==N) break;
        cin >> L[i];
        D += L[i];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main() {

	char s[9][5]={".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
	char answer[76],enter[1025];
	int n,i,j,k,l,r,flag;

	scanf("%d",&n);
	for(i=0;i<n;i++) {
		scanf("%s",enter);
		for(j=0;j<76;j++)
			answer[j]='\0';

		flag=0;
		k=0;
		l=0;
		r=-1;
		for(j=0;j<=strlen(enter)-1;j++) {
			if(flag&&enter[j]=='0') {
				if(l==6||l==8)
					answer[k]=s[l][r%4];
				else if(l==0)
					answer[k]=s[l][r%5];
				else
					answer[k]=s[l][r%3];
				k++;
				flag=0;
				r=-1;
			}
			else if(enter[j]-'0'>0) {
				flag=1;
				l=(enter[j]-'0')-1;
				r++;
			}
		}
		printf("%s\n",answer);
	}

	return 0;
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
    i64 a, b;
    cin >> a >> b;

    cout << (a + b == 15 ? "+" : a * b == 15 ? "*" : "x") << endl;
}

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


Measured memory_bytes: 3600
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.string;
import std.uni;
import std.range;
import std.algorithm;

void main()
{
    auto n = readln.strip.to!int;
    auto h = 0, t = 0;
    while (n--)
    {
        auto k = readln.strip.split(" ");
        if (k[0] == k[1])
        {
            t++;
            h++;
        }
        else if (k[0] > k[1])
        {
            t += 3;
        }
        else
        {
            h += 3;
        }
    }
    writeln(t, " ", h);
}


Measured memory_bytes: 2460
import Control.Monad
import Data.List

getInt = read <$> getLine :: IO Int
getInts = ((map read) . words) <$> getLine :: IO [Int]

f k x = 2 * min x (k-x)

main = do
    n <- getInt
    k <- getInt
    xs <- getInts
    print $ sum $ map (f k) xs

Measured memory_bytes: 892
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        while(true){
            int H = input.nextInt();
            int W = input.nextInt();
            if(H == 0 && W == 0){
                break;
            }
            for(int i = 0; i < H; i++){
                for(int j = 0; j < W; j++){
                    System.out.printf("#");
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}


Measured memory_bytes: 61240
#include <iostream>
#include <limits>

using namespace std;

int main(){
    long N;
    cin >> N;
    long sum = 0;
    bool bl_0 = false;
    long nk =0;
    long A[N];
    long min = numeric_limits<long>::max();
    long min_i = 0;
    for(long i=0;i<N;i++) A[i] = 0;
    for(long i=0;i<N;i++){
        cin >> A[i];
        if(A[i] < 0){
            A[i] = -A[i];
            nk++;
        }
        if(A[i] == 0) bl_0 = true;
        if(A[i] < min){
            min = A[i];
            min_i = i;
        }
        sum += A[i];
    }
    
    if(!bl_0){
        if(nk%2 != 0){
            sum -= 2*A[min_i];
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>

using namespace std;

 
int main(){

	int H;
	while(1){int X[11][11]={};
		cin>>H;if(H==0)break;
		
		int sum=0;

		for(int i=H-1;i>=0;i--)
			for(int j=0;j<5;j++)
				cin>>X[i][j];


		bool f=false;

		while(1){
			int Y=sum;
				for(int i=H-1;i>=0;i--){int p=0,r=1;
					for(int j=0;j<5;j++)
					{
						if(p!=X[i][j]){
							p=X[i][j];r=1;
						}

						else if(p==X[i][j]){
							r++;
							if(r==3){sum+=3*p;//cout<<p<<X[i][j];
								X[i][j-2]=0;X[i][j-1]=0;X[i][j]=0;
							}
							if(r>3){X[i][j]=0;sum+=p;}
						}
					}
				}
				for(int j=0;j<5;j++)
					for(int i=0;i<H;i++)
					{
						if(X[i][j]==0){
							for(int I=i+1;I<H;I++)
								if(X[I][j]>0){X[i][j]=X[I][j];X[I][j]=0;break;
							}
						}
					}
					/*
				for(int i=H-1;i>=0;i--){cout<<endl;
				for(int j=0;j<5;j++)cout<<X[i][j];
				}
			*/

					if(Y==sum)break;
		}
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;

signed main() {
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> v;
    rep(i, n) {
        ll a;
        cin >> a;
        v.push_back({a, 1});
    }
    rep(i, m) {
        ll b, c; 
        cin >> b >> c;
        v.push_back({c, b});
    }
    sort(v.begin(), v.end(), greater<pair<ll, ll>>());

    ll num = 0;
    ll res = 0;
    for (auto p : v) {
        if (num + p.second <= n) {
            res += p.first * p.second;
            num += p.second;
        }
        else {
            res += p.first * (n - num);
            num = n;
            break;
        }
    }
    mes(res);
}
    
    
    
    
    

Measured memory_bytes: 7376
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MODNUM (static_cast<int>(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int x;
	scanf("%d", &x);
	int min = x / 105;
	int max = (x + 99) / 100;
	bool result = false;
	for(int a = 0; a <= max; a++) {
		for(int b = 0; a + b <= max; b++) {
			for(int c = 0; a + b + c <= max; c++) {
				for(int d = 0; a + b + c + d <= max; d++) {
					for(int e = 0; a + b + c + d + e <= max; e++) {
						for(int f = min - a - b - c - d - e;
							a + b + c + d + e + f <= max;
							f++) {
							if(a * 100 + b * 101 + c * 102 + d * 103 + e * 104 +
								   f * 105 ==
							   x) {
								result = true;
								goto loop;
							}
						}
					}
				}
			}
		}
	}
loop:
	printf("%d\n", result ? 1 : 0);
	return 0;
}

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

using namespace std;

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

int main() {
  int N;
  long long C;
  cin >> N >> C;
  vector<long long> X(N), V(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> V[i];
  }
  vector<long long> VS(N + 2), WS(N + 2);
  vector<long long> VSR(N + 2), WSR(N + 2);
  long long v = 0;
  for (int i = 0; i < N; i++) {
    v += V[i];
    chmax(VS[i + 1], max(VS[i], v - X[i]));
    chmax(WS[i + 1], max(WS[i], v - X[i] * 2));
  }
  v = 0;
  for (int i = N - 1; i >= 0; i--) {
    v += V[i];
    chmax(VSR[i + 1], max(VSR[i + 2], v - (C - X[i])));
    chmax(WSR[i + 1], max(WSR[i + 2], v - (C - X[i]) * 2));
  }
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    chmax(ans, VS[i]);
    chmax(ans, VSR[i]);
    chmax(ans, VS[i] + WSR[i + 1]);
    chmax(ans, VSR[i] + WS[i - 1]);
  }
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 4992
A,V = (int(x) for x in input().split())
B,W = (int(x) for x in input().split())
T = int(input())

if V>W and abs(A-B)/(V-W)<=T:
    Flag = True
else:
    Flag = False
    
if Flag:
    print('YES')
else:
    print('NO')

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

#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 FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  char c;
  cin >> c;
  char ans = 1 + 'a' + (c - 'a');
  cout << ans << endl;
  return 0;
}

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

using namespace std;

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

struct BiConnectedComponents
{
  UnionFind uf;
  vector< vector< int > > g;
  vector< pair< int, int > > edges;
  vector< int > used, ord, low, comp;

  BiConnectedComponents(size_t v) : uf(v), g(v), used(v, 0), comp(v), ord(v), low(v)
  {
  }

  void add_edge(int x, int y)
  {
    g[x].push_back(y);
    g[y].push_back(x);
    edges.push_back(minmax(x, y));
  }

  void dfs(int idx, int &k, int par = -1)
  {
    used[idx] = true;
    ord[idx] = k++;
    low[idx] = ord[idx];

    for(auto &to : g[idx]) {
      if(!used[to]) {
        dfs(to, k, idx);
        low[idx] = min(low[idx], low[to]);
        if(ord[idx] >= low[to]) uf.unite(idx, to);
      } else if(to != par) {
        low[idx] = min(low[idx], ord[to]);
      }
    }
  }

  int operator[](int k)
  {
    return (comp[k]);
  }

  size_t size()
  {
    return (g.size());
  }

  void build(vector< vector< int > > &t)
  {
    int kk = 0;
    dfs(0, kk);

    int ptr = 0;
    vector< int > cc(g.size());
    for(int i = 0; i < g.size(); i++) {
      if(i == uf.find(i)) cc[i] = ptr++;
    }

    t.resize(ptr);
    for(int i = 0; i < g.size(); i++) {
      comp[i] = cc[uf.find(i)];
    }
    for(auto &e : edges) {
      int x = comp[e.first], y = comp[e.second];
      if(x == y) continue;
      t[x].push_back(y);
      t[y].push_back(x);
    }
  }
};

int N, M, W[100000];
vector< vector< int > > g;
vector< int > weightSum, sz;
int dp1[100000], dp3[100000];

int rec(int idx, int par = -1)
{
  int ret = 0;
  for(auto &to : g[idx]) {
    if(to == par) continue;
    ret = max(ret, rec(to, idx));
    dp1[idx] += dp1[to];
  }
  ret += weightSum[idx];
  if(sz[idx] >= 3 || dp1[idx] > 0) dp1[idx] += weightSum[idx];
  for(auto &to : g[idx]) {
    if(to == par) continue;
    else ret = max(ret, dp1[idx] - dp1[to] + dp3[to]);
  }
  return (dp3[idx] = ret);
}

int main()
{
  cin >> N >> M;
  BiConnectedComponents tree(N);
  for(int i = 0; i < N; i++) {
    cin >> W[i];
  }
  while(M--) {
    int U, V;
    cin >> U >> V;
    tree.add_edge(--U, --V);
  }
  tree.build(g);
  weightSum.assign(g.size(), 0);
  sz.assign(g.size(), 0);
  for(int i = 0; i < N; i++) {
    weightSum[tree[i]] += W[i];
    sz[tree[i]]++;
  }
  cout << rec(tree[0]) << endl;
}

Measured memory_bytes: 27860
/*********************************
*include
*********************************/
#include <stdio.h>
#pragma warning (disable:4996)

/*********************************
*define
*********************************/
signed long long ary[10000];

/*********************************
*function
*********************************/
int main(void)
{
	long long num;
	long long loop;
	long long min;
	long long max;
	long long sum;

	scanf("%lld", &num);

	for(loop = 0; loop < num; loop++) {
		scanf("%lld", &ary[loop]);
	}

	min = ary[0];
	max = ary[0];
	sum = 0;

	/* ????°????????????§??????????¨?????±??????? */
	for(loop = 0; loop < num; loop++) {
		if(min > ary[loop]) {
			min = ary[loop];
		}
		if(max < ary[loop]) {
			max = ary[loop];
		}
		sum = sum + ary[loop];
	}

	printf("%lld %lld %lld\n", min, max, sum);

	return 0;
}

Measured memory_bytes: 676
n=int(input())
sp=[[i+1]+list(input().split()) for i in range(n)]
change=True
while change:
    change=False
    for i in range(n-1):
        if sp[i][1]>sp[i+1][1]:
            sp[i],sp[i+1]=sp[i+1],sp[i]
            change=True
        elif sp[i][1]==sp[i+1][1] and int(sp[i][2])<=int(sp[i+1][2]):
            sp[i],sp[i+1]=sp[i+1],sp[i]
            change=True
for ans in sp:
    print(ans[0])

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
using namespace std;
long long N,A,x;
long long dp[300][8000],ans;
int main(){
	dp[0][0]=1;
	scanf("%lld%lld",&N,&A);
	for(int i=1;i<=N;i++){
		scanf("%lld",&x);
		for(int j=i;j>0;j--){
			for(int k=A*N;k>=x;k--){
				dp[j][k]+=dp[j-1][k-x];
			}
		}
	}
	for(int i=1;i<=N;i++){
		ans+=dp[i][i*A];
	}
	printf("%lld",ans);
	return 0;
}

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


//c++ templte for help............................................................................................................................................
typedef long long ll;

//template<typename... T>
//void print1(T... t){
	//((cout<<t<<" "),...);
//}

//template<typename... T>
//void print2(T... t){
		//vector<vector<ll>> ans={t...};
		//for(ll i=0;i<(ll)ans.size();i++){
			//if(i!=0) cout<<"\t";
			//else cout<<"\t";
			//for(ll j=0;j<(ll)ans[i].size();j++){
				//cout<<ans[i][j]<<" ";
			//}
			//if(i!=(ll)ans.size()-1)
			//cout<<endl;
		//}
//}	
//#define deb(...) cout<<" [ "#__VA_ARGS__<<" : "; print1(__VA_ARGS__); cout<<"]"<<endl; 
//#define vdeb(...) cout<<" [ "#__VA_ARGS__<<" : "; print2(__VA_ARGS__); cout<<"]"<<endl;





	
 
//for loop
#define fo(i,n) for(int i=0;i<(ll)n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
 
 
//to print vector element 
//template<typename T>
//void printV(T vec){
	//fo(i,vec.size()) cout<<vec[i]<<" "<<flush;
	//cout<<endl;
	//}
	
 
#define modulo 1000000007
const int INF=1e9+5;
 
//iterate map
//template<typename T>
//void itR(T map){
	 //for(auto itr=map.begin();itr!=map.end();itr++){
				//deb(itr->first,itr->second);
			//}
	//cout<<endl;
//}
 
 
 
//c++ template for help...........................................................................................................................................

ll solve(){
	ll n,k;
	cin>>n>>k;
	
	vector<int> vec(n);
	fo(i,n){
		cin>>vec[i];
	}
	
	vector<int> dp(n+1,INF);//dp[n] -- n pa jane ma kintna cost lagega
	dp[0]=0;
	dp[1]=0;
	
	for(int i=2;i<=n;i++){
		for(int j=1;j<=k;j++){
			if(i-j-1>=0) 
				dp[i]=min(dp[i],dp[i-j]+abs(vec[i-1]-vec[i-j-1]));
		}
	}
	
	return dp[n];
}

int main() {
	//stringstream ss;
	//ss<<"akhil";
	//cout<<ss.str()<<endl;
	cout<<setprecision(50);
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	
	 // TESTCASE KO DEKH KA BHAUT SARA CONDITION GENERATE MAT KRO 
	 // PAPER PD CONFIRM HO JAO THORA JADA TIME HI KYU NA LGA
	 // greedy ma jadatr exceptional case check kr ke dekh lo
	 
	 // WHILE DOING THE QUESTION OF DYNAMIC PROGRAMMING GREEDY KA TRAH SOCHNA BAND KRO
	 // DP M DATA KA BHI USE KRNA PDTA HA BE BHULO MT 
	 // DP BHI WO LEETCODE WALE MATRIX KA QUESTION KI TARAH HA
	 // CONSTRAIN WILL BE THE DIMENSION OF DP
	 // DP MA STATE PTA KRO AUR PHIR FUNCTION GENERATE KRO
	 // OBJECT KO CHOOSE KIA YA NAE KIA AGAR KIA TO KYA HOGA AUR NAE KIA TO KYA HOGA
	 // KYA KYA CHEJ IMPORTANT HA WO STATE BN JAGA AUR HUM LOG STATE KO CHANGE KR SKTA HA JYSA KNPSACK 2 WALE PROBLEM MA KIA THA
	 

	 
	//ll testCase;
	//cin>>testCase;
	//for(ll tt=0;tt<testCase;tt++){
		//solve();
		cout<<solve()<<endl;
	//}
	return 0;
}


Measured memory_bytes: 1024
import sys
import numpy as np
from collections import Counter
input = sys.stdin.buffer.readline
N = int(input())
A = np.array(list(map(int, input().split())))

# print(A.cumsum())

ans = 0
cumsum = A.cumsum()

# print(cumsum)

# for _ in range(len(cumsum)):
#     ans += np.count_nonzero(cumsum == 0)
#     cumsum = cumsum[1:] - cumsum[0]
#     print(cumsum)
# print(ans)

# [1 4 0 2 4 2]


# 自分より前に同じ値の数字があるか
def f(n):
    return n * (n - 1) // 2


ans = 0
for key, value in Counter(cumsum).items():
    if key == 0:
        ans += value
    if value >= 2:
        ans += f(value)
# _, counts = np.unique(cumsum, return_counts=True)
# print(counts)
# values, counts = np.unique(counts, return_counts=True)
# ans = 0
# for value, count in zip(values, counts):
#     ans += f(value) * count
print(ans)


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

int main() {
    int n, m;
    cin >> n >> m;

    vector<vector<bool>> b(m, vector<bool>(n, false));
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;

        for (int j = 0; j < k; j++) {
            int a;
            cin >> a;

            b.at(--a).at(i) = true;
        }
    }

    int cnt = 0;
    for (const auto &_b : b) {
        bool f = true;

        for (const auto &__b : _b)
            if (!__b) {
                f = false;
                break;
            }

        if (f)
            cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3628
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

#define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

template <typename T>
T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T>
T lcm(T m, T n) { return n * m / gcd(n, m); }

signed main(void)
{
  int n;
  cin >> n;
  vector<int> s(n);
  for (int i = 0; i < n; ++i)
  {
    int a;
    cin >> a;
    s[a - 1] = i + 1;
  }

  for (int i = 0; i < n; ++i)
  {
    cout << s[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll y_1[250001] = {};
ll x1[250001] = {};
ll y2[250001] = {};
ll x2[250001] = {};

ll a[501][501] = {};
int main() {
	ll h, w; cin >> h >> w;
	repe(i, 1, h)repe(j, 1, w) {
		ll x; cin >> x;
		a[i][j] = x % 2;
	}

	ll cnt = 0;
	repe(i, 1, h) repe(j, 1, w - 1) {
		if (a[i][j] & 1) {
			y_1[cnt] = i;
			x1[cnt] = j;
			y2[cnt] = i;
			x2[cnt] = j + 1;
			cnt++;

			a[i][j]--;
			a[i][j + 1]++;
		}
	}

	repe(i, 1, h - 1) {
		if (a[i][w] & 1) {
			y_1[cnt] = i;
			x1[cnt] = w;
			y2[cnt] = i + 1;
			x2[cnt] = w;
			cnt++;

			a[i][w]--;
			a[i + 1][w] ++;
		}
	}

	cout << cnt << endl;
	rep(i, 0, cnt) {
		cout << y_1[i] << " " << x1[i] << " " << y2[i] << " " << x2[i] << endl;
	}

	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repr(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<(int)(n);i++)
#define INF 99999999999999

    /*Solve*/
int main(){
    ll n;
    cin >> n;
    vector<ll> a;
    ll x;
    ll numo=0,nume=0;
    rep(i,n){
        cin >> x;
        a.push_back(x);
        if(x%2==1){
            numo++;
        }else{
            nume++;
        }
    }
    if(numo%2==1){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
}

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

int main(){
        int h,w,i,j,k,idx,cnt,ans=0;
        char tmp;
        cin >> h >> w;
        vector<vector<pair<int,int>>> g(h,vector<pair<int,int>>(w));
        for(i=0;i<h;++i){
                for(j=0;j<w;++j){
                        cin >> tmp;
                        if(tmp=='#') g.at(i).at(j) = make_pair(-1,0);
                }
        }
        for(i=0;i<h;++i){
                for(j=0;j<w;++j){
                        if(g.at(i).at(j).first==-1) continue;
                        if(g.at(i).at(j).first==0){
                                idx = j+1; cnt = 1;
                                while(idx<w){
                                        if(g.at(i).at(idx).first==-1) break;
                                        ++idx;
                                        ++cnt;
                                }
                                for(k=j;k<idx;++k) g.at(i).at(k).first = cnt;
                        }
                        if(g.at(i).at(j).second==0){
                                idx = i+1; cnt = 1;
                                while(idx<h){
                                        if(g.at(idx).at(j).first==-1) break;
                                        ++idx;
                                        ++cnt;
                                }
                                for(k=i;k<idx;++k) g.at(k).at(j).second = cnt;
                        }
                        ans = max(ans, g.at(i).at(j).first+g.at(i).at(j).second-1);
                }
        }
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 34656
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N, M = ni()

    var ans = 1
    rep(math.sqrt(M).toInt + 1, 2) { g =>
      if (M % g == 0 && M / g >= N) ans = max(g, ans)
    }

    rep_r(math.sqrt(M).toInt + 1, 1) { c =>
      if (M % c == 0 && c >= N) {
        ans = max(ans, M / c)
      }
    }

    out.println(ans)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}

Measured memory_bytes: 27464