akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    double r;cin>>r;
    printf("%.10lf %.10lf\n",PI*(double)r*(double)r,2*PI*(double)r);
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------

































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

int main() {
  int N;
  cin >> N;
  vector<int> vec1(N, 0);
  vector<int> vec2(N, 0);
  for(int i = 0; i < N; i++){
    cin >> vec1[i];
  }
  for(int i = 0; i < N; i++){
  vec2[vec1[i]-1] = i + 1;
  }
  for(int i = 0; i < N; i++){
    cout << vec2[i] << " ";
  }
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long; using ll = long long; using ld = long double;
using pi = pair<int, int>; using pll = pair<ll, ll>;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
template<typename T> using minQ = priority_queue<T, vector<T>, greater<T>>;

#define endl '\n'
#define ALL(a)       (a).begin(),(a).end()
#define FOR(i,a,b)   for(ll i = (ll)(a); i < (ll)(b); ++i)
#define FORO(i,a,b)  for(ll i = (ll)(a); i <= (ll)(b); ++i)
#define RFOR(i,a,b)  for(ll i = (ll)(b) - 1; i >= (ll)(a); --i)
#define RFORO(i,a,b) for(ll i = (ll)(b); i >= (ll)(a); --i)
#define REP(i,n)     for(ll i = 0; i < (ll)(n); ++i)
#define REPO(i,n)    for(ll i = 1; i <= (ll)(n); ++i)
#define RREP(i,n)    for(ll i = (ll)(n) - 1; i >= 0; --i)
#define RREPO(i,n)   for(ll i = (ll)(n); i >= 1; --i)
#define SORT(a)      sort(ALL(a))
#define UNIQ(a)      a.erase(unique(ALL(a)), a.end())
#define SUNIQ(a)     SORT(a), UNIQ(a)
#define MINI(a,b)    a=min(a,(b))
#define MAXI(a,b)    a=max(a,(b))

const ll mod = 1e9 + 7;
const int INF = 1e9 + 10;
const ll LINF = 1000000000000000000ll;
const ld eps = 1e-8;
const ld PI = acosl(-1);

ll Nll() { ll a; cin >> a; return a; }
ld Nld() { ld a; cin >> a; return a; }
int Ni() { int a; cin >> a; return a; }
char Nc() { char a; cin >> a; return a; }
string Ns() { string a; cin >> a; return a; }

template <typename T>
void O(const T &a) { cout << a << endl; }
template <typename T>
void O(T &&a) { cout << a << endl; }
template <typename T>
void Os(const vector<T> &v) { REP(i, v.size() - 1) cout << v[i] << " \n"[i + 1 == (ll)v.size()]; }
template <typename T>
void Os(vector<T> &&v) { REP(i, v.size() - 1) cout << v[i] << " \n"[i + 1 == (ll)v.size()]; }
template <typename T>
void Is(vector<T> &v) { for (auto& t : v) cin >> t; }

void yes(bool f) { cout << (f ? "yes" : "no") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }

struct Edge {
	int from, to;
	Edge() {}
	Edge(int f, int t) : from(f), to(t) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void solve();

int main() { ios::sync_with_stdio(false), cin.tie(0); cout << fixed << setprecision(20); solve(); }

//-----------------------------------------------template-------------------------------------------------------------

//-----------------------------------------------library-------------------------------------------------------------

void solve()
{
	ll Q, H, S, D, N;
	cin >> Q >> H >> S >> D >> N;
	MINI(S, min(Q * 4, H * 2));
	O(min(N * S, N / 2 * D + N % 2 * S));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define ve vector
const ll INF = 2e12;
int main(){
    ll n, k;
    cin >> n >> k;
    ve<ll> a(n),f(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> f[i];
    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());
    ll l = -1, r = INF;
    while(r-l>1){
        ll mid = (l+r)/2;
        bool ok = [&]{
            ll s = 0;
            rep(i,n){
                s += max((ll)0,a[i]-mid/f[i]);
            }
            return s <= k;
        }();
        if(ok) r = mid;
        else l = mid;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int n, k;
int a[60];
vector<P>ans;

int main()
{
	cin >> n;
	int mx = 0, mn = 0;
	int mxi, mni = -1;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] > mx) {
			mx = a[i];
			mxi = i;
		}
		if (a[i] < mn) {
			mn = a[i];
			mni = i;
		}
	}
	if (mx == 0 && mn == 0) { cout << 0 << endl; }
	else if (mn >= 0) {
		cout << n - 1 << endl;
		for (int i = 0; i < n - 1; i++) {
			cout << i+1 << " " << i + 2 << endl;
		}
	}
	else if (mx == 0) {
		cout << n - 1 << endl;
		for (int i = n - 1; i > 0; i--) {
			cout << i + 1 << " " << i << endl;
		}
	}
	else if (mn < 0 && -mn >= mx) {
		cout << 2 * n - 1 << endl;
		for (int i = 0; i < n; i++) {
			cout << mni+1 << " " << i+1 << endl;
		}
		for (int i = n - 1; i >= 1; i--) {
			cout << i + 1 << " " << i << endl;
		}
	}
	else if (mn < 0 && -mn < mx) {
		cout << 2 * n - 1 << endl;
		for (int i = 0; i < n; i++) {
			cout << mxi + 1 << " " << i + 1 << endl;
		}
		for (int i = 0; i < n - 1; i++) {
			cout << i + 1 << " " << i + 2 << endl;
		}
	}




	return 0;
}

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

#define ll long long int
#define hell 1000000007
#define vi vector <ll>
#define pb push_back
#define pii pair<ll,ll>
#define vii vector <pii>
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define sep(i,a,b)  for(ll i=a-1;i>=b;i--)
#define inf (ll)(1e16)

using namespace std;

void solve()
{
    string s;
    cin>>s;
    ll ans=1;
    char c=s[0];
    bool flag=true;
    rep(i,1,s.length())
    {
        if(s[i]==s[i-1]&&flag)
        {
            if(i<s.length()-1)
                ans++;
            i++;
            flag=!flag;
        }
        else
        {
            ans++;
            flag=true;
        }
    }
    cout<<ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
//	freopen("subtask_1_02.txt", "r", stdin);
	int n;
	cin >> n;
	vi a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	for(int i = 0; i < n; i++) {
		a[i] -= i + 1;
	}
	
	sort(all(a));
	ll total = 0;
	for(int i = 0; i < n; i++) total += a[i];
	
	ll sum = 0, ans = INF;
	for(int i = 0; i < n; i++) {
		ll b = a[i];
		sum += a[i];
		if(i + 1 < n && a[i] == a[i + 1]) continue;
		ll res = b * (i + 1) - sum + (total - sum) - (n - i - 1) * b;
		ans = min(ans, res);
	}
	
	cout << ans << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define sz size()
#define all(A)    A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define f0(i,b)   for(int i=0;i<(b);i++)
#define f1(i,b)   for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define mod 1000000007

#define forr(i,n)    for(i=0; i<n; i++)
#define whilee(i,t)  while(i!=t)
#define  sl(a)  scanf("%lld",&a)
#define  pl(a)  printf("%lld",a)

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);
//scanf("%d",&x);
//printf("%d\n",x);

//vector <int> A;
//deque <int> A;
//queue <int> A;
//stack <int> A;
//set <int> A;
//map <int,int> A;
//pair <int,int> A ;
//vector <pair <int,int>> A ;
//bitset<32> bset1;
//char ch;
//string S, T, U;
ll i, j, k, a, b, c, d, f, g, h, l, m, n, p, q, r, s, t, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);//NULL
    cout.tie(nullptr);//NULL

    cin>>n;
    int A[n+1];

    A[0]=0;
    f1(i,n)
    {
        cin>>A[i];
    }

    ans=0;
    x=0;
    y=0;
    forr(i,n)
    {
        if(A[i]<=A[i+1])
        {
            x = A[i+1];
        }
        else
        {
            ans += (x-y);
            x = A[i+1];
            y = A[i+1];
        }
    }
    ans += (x-y);


    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3644
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

//#include "Union_Find.h"

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
//#include <unordered_set>
//#include <unordered_map>
#include <iomanip>
#include <sstream>

using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define REPM(i,n,a) for(int i = n - 1; i >= a; --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFFFFFFFFFF
#define INFD 1.0e+308
typedef long long LL;
typedef unsigned long long ULL;

typedef pair<LL, LL> PP;

LL N;
LL A[100001];
char op[100001];
LL dp[3][100001];

int main() {
	cin >> N;
	op[0] = '+';
	REP(i, 0, N) {
		if (i != 0) {
			cin >> op[i];
		}
		cin >> A[i];
	}

	dp[0][0] = A[0];
	dp[1][0] = -INFLL;
	dp[2][0] = -INFLL;
	REP(i, 1, N) {
		if (op[i] == '-') {
			dp[0][i] = max(max(dp[0][i - 1] - A[i], dp[1][i - 1] + A[i]), dp[2][i - 1] - A[i]);
			dp[1][i] = max(max(dp[1][i - 1] + A[i], dp[2][i - 1] - A[i]), dp[0][i - 1] - A[i]);
			dp[2][i] = max(dp[2][i - 1] - A[i], dp[1][i - 1] + A[i]);
		} else {
			dp[0][i] = max(dp[0][i - 1] + A[i], dp[1][i - 1] - A[i]);
			dp[1][i] = max(dp[1][i - 1] - A[i], dp[2][i - 1] + A[i]);
			dp[2][i] = dp[2][i - 1] + A[i];
		}
	}
	cout << max(max(dp[0][N - 1], dp[1][N - 1]), dp[2][N - 1]) << endl;

	return 0;
}

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

inline int read()
{
	int x=0; bool f=1; char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=0;
	for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
	if(f) return x;
	return -x;
}

const int N = 1e5;
struct Interval
{
	int l,r;
	bool operator <(const Interval &arg) const {return l<arg.l || (l==arg.l && r<arg.r);}
} a[N+3];
int mxl1[N+3],mxl2[N+3],mnr1[N+3],mnr2[N+3];
llong ans;
int n;

int main()
{
	scanf("%d",&n);
	for(int i=1; i<=n; i++) scanf("%d%d",&a[i].l,&a[i].r),ans = max(ans,a[i].r-a[i].l+1ll);
	sort(a+1,a+n+1);
	for(int i=1; i<=n; i++) mxl1[i] = max(mxl1[i-1],a[i].l);
	for(int i=n; i>=1; i--) mxl2[i] = max(mxl2[i+1],a[i].l);
	mnr1[0] = 1e9; for(int i=1; i<=n; i++) mnr1[i] = min(mnr1[i-1],a[i].r);
	mnr2[n+1] = 1e9; for(int i=n; i>=1; i--) mnr2[i] = min(mnr2[i+1],a[i].r);
	for(int i=1; i<=n; i++)
	{
		llong tmp = a[i].r-a[i].l+1,l = max(mxl1[i-1],mxl2[i+1]),r = min(mnr1[i+1],mnr2[i+1]);
		ans = max(ans,tmp+max(0ll,r-l+1));
	}
	for(int i=1; i<n; i++)
	{
		llong tmp = max(0ll,mnr1[i]-mxl1[i]+1ll)+max(0ll,mnr2[i+1]-mxl2[i+1]+1ll);
		ans = max(ans,tmp);
	}
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)

#define INF 987654321
#define IINF 2987654321987654321
#define MOD 998244353

int main() {
	int n; scanf("%d", &n);
	printf("%.11f\n", (double)((n+1)/2) / n);
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
using namespace std;

int a;
string s;

int main() {
    cin >> a >> s;
    if (a >= 3200) {
        cout << s << endl;
    } else {
        cout << "red" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
x1, y1, x2, y2 = list(map(int, input().split()))

if x1 > x2 and y1 == y2:
    x3 = x2
    y3 = y2 - (x1 - x2)
    x4 = x1
    y4 = y3
elif x1 == x2 and y1 > y2:
    x3 = x2 + (y1 - y2)
    y3 = y2
    x4 = x3
    y4 = y1
elif x1 < x1 and y1 == y2:
    x3 = x2
    y3 = y2 + (x2 - x1)
    x4 = x1
    y4 = y3
elif x1 == x2 and y1 < y2:
    x3 = x2 - (y2 - y1)
    y3 = y2
    x4 = x3
    y4 = y1
elif x1 > x2 and y1 < y2:
    subx = x1 - x2
    suby = y2 - y1
    x3 = x2 - suby
    y3 = y2 - subx
    x4 = x3 + subx
    y4 = y3 - suby
elif x1 > x2 and y1 > y2:
    subx = x1 - x2
    suby = y1 - y2
    x3 = x2 + suby
    y3 = y2 - subx
    x4 = x3 + subx
    y4 = y3 + suby
elif x1 < x2 and y1 > y2:
    subx = x2 - x1
    suby = y1 - y2
    x3 = x2 + suby
    y3 = y2 + subx
    x4 = x3 - subx
    y4 = y3 + suby
else:
    subx = x2 - x1
    suby = y2 - y1
    x3 = x2 - suby
    y3 = y2 + subx
    x4 = x3 - subx
    y4 = y3 - suby

print("{} {} {} {}".format(x3, y3, x4, y4))


Measured memory_bytes: 3064
from bisect import bisect_left

A,B,Q=list(map(int,input().split()))
s=[-10**11]+[int(input()) for _ in range(A)]+[10**11]
t=[-10**11]+[int(input()) for _ in range(B)]+[10**11]
x=[int(input()) for _ in range(Q)]


for xi in x:
    p1=bisect_left(s,xi)
    p2=bisect_left(t,xi)
    l=10**11
    for ss in s[p1-1:p1+1]:
        for tt in t[p2-1:p2+1]:
            l=min(l,min(abs(ss-xi),abs(tt-xi))+abs(ss-tt))
    
    print(l)


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

string S;
bool isExistAZ[26];

int main(int argc, char* argv[]){
  cin >> S;
  for(int i = 0; i < 26; i++) isExistAZ[i] = false;
  if(S.size()==26){
	for(int i = S.size()-1; i >= 0; i--){
	  int AZNum = S[i]-'a';
	  for(int j = AZNum+1; j < 26; j++){
		if(isExistAZ[j]){
		  for(int k = 0; k < i; k++) cout << S[k];
		  cout << (char)('a'+j) << endl;
		  return 0;
		}
	  }
	  isExistAZ[AZNum] = true;
	}
	cout << -1 << endl;
  }else{
	for(int i = 0; i < S.size(); i++) isExistAZ[S[i]-'a'] = true;
	for(int i = 0; i < 26; i++){
	  if(!isExistAZ[i]){
		cout << S << (char)('a'+i) << endl;
		break;
	  }
	}
  }
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    a,b=map(int,input().split())
    A=str(a);B=str(b)
    N=min(len(A),len(B))
    ans=None
    for i in range(N):
        if int(A[i])>int(B[i]):
            ans='B'
            break
        elif int(B[i])>int(A[i]):
            ans='A'
            break
    else:
        if len(A)==N:
            ans=A
            z=b
        else:
            ans=B
            z=a
    if ans=='A':
        print(str(a)*b)
    elif ans=='B':
        print(B*a)
    else:
        print(ans*z)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <stdio.h>

int main()
{
    long long int n, m, i, a, b, h1, h2, cnt, t1, t2;
    scanf("%lld %lld", &n, &m);
    long long int h[n], num[n];
    for (i=0; i<n; i++) {
        scanf("%lld", &h[i]);
        num[i]=1;
    }

    while (m--) {
        scanf("%lld %lld", &a, &b);
        h1=h[a-1];
        h2=h[b-1];
        t1=h1>h2;
        if (t1) num[b-1]=0;
        else {
            if (h1==h2) {
                num[a-1]=0; num[b-1]=0;
            }
            else num[a-1]=0;
        }
    }
    cnt=0;
    for (i=0; i<n; i++) {
        cnt+=num[i];
    }
    printf("%lld\n", cnt);
    return 0;
}


Measured memory_bytes: 3240
#include<iostream>
#include<vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> d(N+1,0);
  int i,j;
  d[1] = 1;
  for(i=2;i<=N;i++) {
    if(d[i] > 0)continue;
    for(j=1;i*j<=N;j++)if(d[i*j] == 0)d[i*j] = i;
  }
  vector<long long> f(N+1,1);
  int cnt,x;
  for(i=2;i<=N;i++) {
    cnt = 0,x = i;
    while(x % d[i] == 0) {
      x /= d[i];
      cnt++;
    }
    if(cnt == 0)f[i] = 2;
    else f[i] = f[x] * (cnt + 1);
  }
  long long ans = 0;
  for(i=0;i<N;i++)ans += (i+1)*f[i+1];
  cout << ans << endl;
}

Measured memory_bytes: 120440
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  string S;
  string keyence = "keyence";
  cin >> S;

  long int start=7, end=-1;

  if(S.size()<7){
    printf("NO\n");
    return 0;
  }

  for(int i=0; i<7; ++i){
    if(S[i]!=keyence[i]){
      start=i-1;
      break;
    }
  }

  for(int i=0; i<7; ++i){
    if(S[S.size()-1-i]!=keyence[6-i]){
      end=6-i+1;
      break;
    }
  }

  if(start==7 || end==-1 || end-start<=1){
    printf("YES\n");
  }else{
    printf("NO\n");
  }


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	int nax = 0;
	rep(i,N){
		cin >> A[i];
		nax = max(nax, A[i]);
	}
	int g = A[0];
	for(int i = 1; i < N; ++i)g = gcd(g, A[i]);
	cout << ((nax >= K && K % g == 0) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
	return 0;
}


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

int main() {
 int N;
  cin >>N;
  vector<int>v(N);

  for(int i=0;i<N;i++){
  cin >>v[i];
  }
    sort(v.begin(),v.end());
  double ans;
  for(int i=0;i<N;i++){
  if(i==0){ans=v[i];}
  else{ans=(ans+v[i])/2;}
  }
  cout << setprecision(10) << ans <<endl;
}


Measured memory_bytes: 764
using System;
using System.Linq;
class Program
    {
        static void Main(string[] args)
        {
            int n, m, c;
            
            string[] strNMC = Console.ReadLine().Split(' ');
            n = int.Parse(strNMC[0]);
            m = int.Parse(strNMC[1]);
            c = int.Parse(strNMC[2]);

            var l = new System.Collections.Generic.List<int[]>(n);


            for(int i = 0; i<n+1; i++)
            {
                var values = System.Console.ReadLine().Split(' ');
                l.Add(values.Select(v => System.Int32.Parse(v)).ToArray());
            }

            //int kekka;
            int result = 0;

            
            for(int i = 1; i<=n; i++)
            {
                int kekka = 0;

                for(int j = 0; j<m; j++)
                {
                    kekka = kekka + (l[0][j] * l[i][j]);
                }
                kekka = kekka + c;
                if(kekka > 0)
                {
                    result++;
                }
            }
          
            Console.WriteLine(result);
        } 
    }

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < n;i++)
using namespace std;
 
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    rep(i, s.size()) {
        s[i] = (s[i] - 'A' + n) % 26 + 'A';
    }
    cout << s << endl;
}


Measured memory_bytes: 256
# AOJ 0015 National Budget
# Python3 2018.6.9 bal4u

n = int(input())
for i in range(n):
    a = str(input())
    b = str(input())
    if len(a) > 80 or len(b) > 80:
        print('overflow')
    else:
        s = str(int(a)+int(b))
        if len(s) <= 80:
            print(s)
        else:
            print('overflow')


Measured memory_bytes: 5584
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int N, K;
	cin >> N >> K;
	vector<int> h;
	rep(i, 0, N) {
		int tmp;
		cin >> tmp;
		h.push_back(tmp);
	}
	vsort(h);

	int rsl = 1e9;
	rep(i, 0, N - K + 1) {
		rsl = min(rsl, h[i + K - 1] - h[i]);
	}

	cout << rsl << endl;
}


Measured memory_bytes: 892
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef long long llint;
typedef vector<long long int> vint;
typedef vector< vector<int> > vvint;
typedef vector<string> vstr;


int main(void) {
	llint N,ans;
	ans = 0;
	cin >> N;
	vint V(N), C(N),dif(N);
	for (int i = 0; i < N; i++)cin >> V[i];
	for (int i = 0; i < N; i++)cin >> C[i];
	for (int i = 0; i < N; i++)dif[i] = V[i] - C[i];

	for (int i = 0; i < N; i++) {
		if (dif[i] > 0)ans += dif[i];
	}
	cout << ans << endl;

}


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

int main()
{
    std::string sample = "";
    std::string circle_sample = "";
    std::string word = "";
    bool judge = false;
    int matching = 0;

    std::cin >> sample;
    std::cin >> word;

     circle_sample += sample;
     circle_sample += sample;

    for (int i = 0; i < sample.length(); i++) {
        for (int j = 0; j < word.length(); j++) {
            if (circle_sample[i + j] == word[j])  {
                matching += 1;

                if (matching == word.length()) {
                    judge = true;
                    break;
                }
            } else {
                matching = 0;
                break;
            }
        }
        if (matching == word.length()) {
            judge = true;
            break;
        }

    }

    if (judge == true) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
}

Measured memory_bytes: 1188
#include<iostream>
#include<complex>
#include<cmath>
using namespace std;
typedef complex<double> xy_t;

int n;
double s,x,y;
xy_t p[100],a,b,c;

double cross_product(xy_t a,xy_t b){ //クロス積
    return (conj(a)*b).imag();
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        p[i]=xy_t(x,y);
    }
    a=p[0];
    for(int i=1;i<n-1;i++){
        b=p[i],c=p[i+1];
        s+=cross_product(b-a,c-a)/2;
    }
    printf("%.1f\n",abs(s));
}


Measured memory_bytes: 3280
import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    public static final PrintStream out = System.out;
    public static final PrintStream err = System.err;

    public static void main(String[] args) {
        String Si = in.next();
        char[] S = new StringBuilder(Si).reverse().toString().toCharArray();

        long[] dp = new long[13];
        dp[0] = 1;

        for (int i = 0, d = 1; i < S.length; i++, d = d * 10 % 13) {
            long[] nd = new long[13];

            err.println("d: " + d + ", i: " + i + ", S[i]: " + S[i]);
            char c = S[i];

            if (Character.isDigit(c)) {
                int x = (c - '0') * d;

                for (int j = 0; j < 13; j++) {
                    nd[(j + x) % 13] = dp[j];
                }
            } else {
                for (int xi = 0; xi < 10; xi++) {
                    int x = xi * d;

                    for (int j = 0; j < 13; j++) {
                        int ni = (j + x) % 13;
                        nd[ni] = (nd[ni] + dp[j]) % 1000000007;
                    }
                }
            }

            err.println(Arrays.toString(nd));
            dp = nd;
        }

        out.println(dp[5]);
    }
}


Measured memory_bytes: 120072
#include <iostream>
#include <cstring>

using namespace std;


int main() {
    int n,k;
     char str[15];
    cin>>n;
    cin>>str;
    cin>>k;
    int i=0;
    while(str[i])
	{
		if(str[i]==str[k-1])
		cout<<str[i];
		else 
		cout<<"*";
		i++;
	}

    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int n,m,a[2505][2505];
int t,p;

int main(){
    while(1){
        cin>>m>>n>>t>>p;
        if(m==0) return 0;
        rep(i,2505) rep(j,2505) a[i][j] = 0;
        for(int i=1200;i<1200+n;i++) for(int j=1200;j<1200+m;j++) a[i][j] = 1;
        int a1 = 1200, a2 = 1200+n-1;
        int b1 = 1200, b2 = 1200+m-1;
        rep(i,t){
            int d,c; cin>>d>>c;
			int aa=1e9,bb=1e9;
			int ac=-1e9,bc=-1e9;
			
            if(d == 1){
                for(int x=b1;x<b1+c;x++){
					for(int i=a1;i<=a2;i++) {a[i][(b1+c)*2-1-x] += a[i][x];if(a[i][(b1+c)*2-1-x]){
						aa=min(aa,i); ac=max(aa,i); bb=min(bb,(b1+c)*2-1-x); bc=max(bc,(b1+c)*2-1-x);}
						a[i][x] = 0;}
                }
            }
            else if(d == 2){
                for(int x=a2;x>a2-c;x--){
					for(int i=b1;i<=b2;i++) { a[(a2-c)*2+1-x][i] += a[x][i];if(a[(a2-c)*2+1-x][i] ){
						aa=min(aa,(a2-c)*2+1-x); ac=max(aa,(a2-c)*2+1-x); bb=min(bb,i); bc=max(bc,i);}a[x][i] = 0;}
                }
            }
			int  A= aa-30,B=bb-30;
			for(int i=A;i<=A+60;i++) for(int j=B;j<=B+60;j++){
				if(a[i][j]){
					aa=min(aa,i); ac = max(ac,i);
					bb=min(bb,j); bc = max(bc,j);
				}
			}
            a1 = aa; a2 = ac; b1 = bb; b2 = bc;
        }
        rep(i,p){
            int x,y; cin>>x>>y;
            cout << a[a2-y][b1+x] << endl;
        }
    }
}



Measured memory_bytes: 27580
#include <stdio.h>
#include <string.h>

int main()
{
  char str[81];
  int i,j,l;

  while(fgets(str,sizeof(str),stdin) != NULL){
    l = strlen(str);
    for(i = 0; i < 26; i++){
      if(strstr(str,"the") != '\0' || strstr(str,"this") !=  '\0' || strstr(str, "that") != '\0')
        break;
      else{
        for(j = 0; j < l; j++){
          if(('a' <= str[j] && str[j] <= 'y') || ('A' <= str[j] && str[j] <= 'Y'))
            str[j]++;
          else if(str[j] == 'z')
            str[j] = 'a';
          else if(str[j] == 'Z')
            str[j] = 'A';
        }
      }
    }
    printf("%s", str);
  }

  return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#define int long long
signed main(){
	int a1,b1,c1,d1;
	int a2,b2,c2,d2;
	while( scanf("%lld %lld %lld %lld", &a1, &b1, &c1, &d1) != EOF ){
		scanf("%lld %lld %lld %lld", &a2, &b2, &c2, &d2);
		vector<int> listn(10,0);
		listn[a1] = 1;
		listn[b1] = 1;
		listn[c1] = 1;
		listn[d1] = 1;
		int hit=0, blow=0;
		if (a1==a2) hit++;
		else blow += listn[a2];
		if (b1==b2) hit++;
		else blow += listn[b2];
		if (c1==c2) hit++;
		else blow += listn[c2];
		if (d1==d2) hit++;
		else blow += listn[d2];
		cout << hit << " " << blow << endl;
	}
	return 0;
}

Measured memory_bytes: 3244
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if(a == 1 || a == 3 || a == 5 || a == 7 || a == 8 || a ==10 || a == 12) {
			if(b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b ==10 || b == 12) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}else if(a == 2 || b == 2) {
			System.out.println("No");
		}else if(a == 4 || a == 6 || a == 9 || a == 11) {
			if(b == 4 || b == 6 || b == 9 || b == 11) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
	}

}


Measured memory_bytes: 21972
#include <iostream>

using namespace std;

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

    int i=0;
    while(true){
        if(i%2==0){
            c-=b;
            if(c<=0){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
        else{
            a-=d;
            if(a<=0){
                cout<<"No"<<endl;
                return 0;
            }
        }
        i++;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
using namespace std;
using ll = long long;
template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> vector<T> make_vec(size_t n) { return vector<T>(n); }
template<typename T, typename... Args> auto make_vec(size_t n, Args... args) {
    return vector<decltype(make_vec<T>(args...))>(n, make_vec<T>(args...));
}
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value>::type fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<!is_same<T, U>::value>::type fill_v(U& u, const V... v) {
    for (auto& e : u) fill_v<T>(e, v...);
}

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

    string s;
    cin >> s;
    int n = s.size();
    int cnt = 0;
    rep(i, n/2) {
        if (s[i] != s[n-1-i]) cnt++;
    }
    cout << cnt << '\n';
}


Measured memory_bytes: 3652
N = int(input())
A = [int(i) for i in input().split()]
count = 0
while True:
  exist_odd = False
  for i in range(N):
    if A[i]%2 != 0:
      exist_odd = True
    A[i] /= 2
  if exist_odd == True:
    break
  count += 1
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 2019

int main() {
    long long int l, r;
    cin >> l >> r;
    long long int minv = 2.0e9+1;
    for(long long int i = l; i < r+1; i++) {
        for(long long int j = i+1; j< r+1; j++) {
            if(i%N == 0 || j % N == 0) {
                cout << 0 << endl;
                return 0;
            }
            else {
                minv = min(minv, i*j%N);
            }
        }
    }
    //cout << l*(l+1) % N << endl;
    cout << minv << endl;
    return 0;

}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

void solve(){
    ll N, x;
    cin >> N >> x;

    ll ans = 0;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        if (a[i] > x) {
            ans += a[i] - x;
            a[i] = x;
        }
    }

    vector<ll> b = a;
    for (int i = 1; i < N; i++) {
        if (x < b[i-1] + b[i]) {
            b[i] -= (b[i-1] + b[i]) - x;
        }
    }

    for (int i = 0; i < N; i++) {
        ans += a[i] - b[i];
    }

    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 1792
END { load __FILE__ unless $stdin.eof? }

h, w, k = gets.split.map!(&:to_i)
cells = Array.new(h) { gets.chomp.chars.map! { |c| c == '#' } }

def each_selection(ary, selected, &block)
  if ary.empty?
    block.call(selected)
    return
  end

  x = ary.pop
  each_selection(ary, selected, &block)
  selected << x
  each_selection(ary, selected, &block)
  selected.pop
  ary << x
end

cnt = 0
each_selection(cells, []) do |cells1|
  each_selection(cells1.transpose, []) do |cells2|
    cnt += 1 if cells2.flatten.count(true) == k
  end
end

puts cnt


Measured memory_bytes: 14828
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int n=Integer.parseInt(s.nextLine());
        List<Integer> is = new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            is.add(Integer.parseInt(s.nextLine()));
        }
        int m = Collections.max(is);
        int mi = is.indexOf(m);
        is.remove(is.indexOf(m));
        int m1 = Collections.max(is);
        for(int i=0;i<n;i++){
            if(i != mi){
                System.out.println(m);
                continue;
            }
            System.out.println(m1);
        }

    }
}

Measured memory_bytes: 160796
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define amari(x) ((x) % 1000000007)

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end());
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>());
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin();
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin();

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

int n;
long a[200000];
long scores[100001];

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

  int a, b, c;
  cin >> a >> b >> c;

  if (a == b && a == c) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) begin(x), end(x)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

int main(){
  int n;
  cin>>n;
  ll ans=0;
  for(int i=1;i<=n-1;i++){
    if(n%i==0){
      ans+=n/i-1;
    }
    else{
      ans+=n/i;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3632
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int X = sc.nextInt();
    	if (X < 4) {
    		System.out.println(1);
    	} else {
        	int ans = 0;
        	for (int i = 2; i <= X; i++) {
        		int d = 0;
        		for (int j = 2; d <= X; j++) {
        			if (ans < d) {
        				ans = d;
        			}
        			d = (int) Math.pow(i, j);
        		}
        	}
        	System.out.println(ans);
    	}
    }
}

Measured memory_bytes: 21844
N = int(input())
A = list(map(int,input().split()))

S = []
sumA = 0

for i in range(N):
  sumA += A[i]
  S.append(sumA)
  
S = sorted(S)

count = 0
mul = 0

#print(S)
for i in range(N - 1):
  if S[i] == 0:
    count += 1
  
  if S[i] == S[i + 1]:
    mul += 1
  else:
    count += mul * (mul + 1) //2
    mul = 0
  
count += mul * (mul + 1) //2
if S[N-1] == 0:
  count += 1

print(count)

Measured memory_bytes: 100816
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
 
/*** Template Begins ***/
 
typedef unsigned long long    ll;
typedef pair<ll,ll>  pll;
typedef pair<ll, pair<int, int> > plll;
typedef vector<long long>  vll;
typedef vector<pll>  vp;
typedef long double ld;
#define pb           push_back
#define INF          INT_MAX/10
#define F            first
#define S            second
#define mp           make_pair
// #define ios          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hell         1000000007
// #define h 998244353
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p)
{
  ll res = 1;
  x = x % p;
  while (y > 0)
  { 
    if (y & 1) 
      res = (res*x) % p;
    y = y>>1;
    x = (x*x) % p;
  } 
  return res; 
} 
const int MAXN = 2e5+5;

// Debug //
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
// #define trace6(a, n,i;b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

// Constants //
 
/*** Template Ends ***/


void solve()
{
  ll h,n;
  cin>>h>>n;
  ll sum=0,num,i;
  for(i=0;i<n;i++)
  {
    cin>>num;
    sum+=num;
  }
  if(sum>=h)
    cout<<"Yes";
  else
    cout<<"No";
}
int main()
{ 
  // ios;
  // fxreopen("inputt.txt", "w", stdout);
  ll t;
  // cin >> t;
  t=1;
  while(t--)
    solve();
  return 0;
}

Measured memory_bytes: 256
// Code by H~$~C
#include <bits/stdc++.h>
using namespace std;

static const int Maxn = 15;

int n, m, tot;
int eu[Maxn * Maxn], ev[Maxn * Maxn], ew[Maxn * Maxn];
int g[Maxn][Maxn];

int sum[1 << Maxn];
int dp[1 << Maxn][Maxn];

int main() {
  scanf("%d%d", &n, &m);
  tot = 0;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", eu + i, ev + i, ew + i);
    eu[i]--, ev[i]--;
    g[eu[i]][ev[i]] = g[ev[i]][eu[i]] = ew[i];
    tot += ew[i];
  }
  for (int mask = 0; mask < (1 << n); ++mask) {
    sum[mask] = 0;
    for (int i = 0; i < m; ++i) {
      if ((mask & (1 << eu[i])) && (mask & (1 << ev[i]))) {
        sum[mask] += ew[i];
      }
    }
  }
  
  memset(dp, -1, sizeof(dp));
  dp[1][0] = 0;
  for (int mask = 1; mask < (1 << n); ++mask) {
    for (int i = 0; i < n; ++i) {
      if ((mask & (1 << i)) == 0) continue;
      if (dp[mask][i] == -1) continue;
      
      for (int j = 0; j < n; ++j) {
        if (!!(mask & (1 << j)) == 1) continue;
        if (g[i][j] == 0) continue;
        dp[mask | (1 << j)][j] = max(dp[mask | (1 << j)][j], dp[mask][i] + g[i][j]);
      }
      
      int submask = (mask ^ ((1 << n) - 1));
      do {
        dp[mask | submask][i] = max(dp[mask | submask][i], dp[mask][i] + sum[submask | (1 << i)]);
        submask = (submask - 1) & (mask ^ ((1 << n) - 1));
      } while (submask != (mask ^ ((1 << n) - 1)));
    }
  }
  int ans = dp[(1 << n) - 1][n - 1];
  for (int mask = 0; mask < (1 << n); ++mask) {
    if (dp[mask][n - 1] != -1) {
      ans = max(ans, dp[mask][n - 1]);
    }
  }
  printf("%d\n", tot - ans);
  return 0;
}


Measured memory_bytes: 2304
import math
 
A, B, H, M = map(int, input().split())
 
m = (M / 60) * 2 * math.pi
t = (H + (M / 60)) * math.pi / 6
angle = m-t
res = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(angle))
print(res)

Measured memory_bytes: 9388
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << endl
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>=0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
#define maxemt(v) *max_element(v.begin(), v.end())
#define minemt(v) *min_element(v.begin(), v.end())
#define lb(v,x) v[lower_bound(v.begin(), v.end(), x) - v.begin()]
#define ub(v,x) v[upper_bound(v.begin(), v.end(), x) - v.begin()]
template<class T> inline bool print(T& x){ cout << x << endl; return true; }
template<class T> inline bool print_(T& x){ cout << x << " "; return true; }
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; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
ll lcm(ll x, ll y){
  return x / gcd(x,y) * y;
}
const int INF = 1e9;
const ll llINF = 1LL<<60;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main(){
  int n, k; cin >> n >> k;
  vector<int> a(n), v(n,0); 
  rep(i,n){
    cin >> a[i];
    v[a[i]-1]++;
  }
  sort(all(v),greater<int>());
  cout << accumulate(v.begin()+k, v.end(), 0);
  
return 0;
}

Measured memory_bytes: 1792
use proconio::input;/*
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// */

fn main() {
  input! {
    r: usize, c: usize, k: usize,
    items: [(usize, usize, i64); k]
  }
  
  let mut table_item = vec![vec![0; c+1]; r+1];
  for (i, j, v) in items {
    table_item[i][j] = v;
  }
  
  let mut dp = vec![vec![vec![0; 4]; c+1]; r+1];
  
  for i in 0..r {
    for j in 0..c {
      let item = table_item[i+1][j+1];
      dp[i+1][j+1][0] = dp[i+1][j][0].max(dp[i][j+1][3]);
      dp[i+1][j+1][1] = dp[i+1][j][1].max(dp[i+1][j+1][0]+item);
      dp[i+1][j+1][2] = dp[i+1][j][2].max(dp[i+1][j+1][1]).max(dp[i+1][j][1]+item);
      dp[i+1][j+1][3] = dp[i+1][j][3].max(dp[i+1][j+1][2]).max(dp[i+1][j][2]+item);
    }
  }

  /*
  for row in &dp {
    println!("{:?}", row);
  }// */
  
  println!("{}", dp[r][c][3]);
}

Measured memory_bytes: 709068