akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <stack>
#include <cmath>
#include <functional>
#include <set>
#include <string>
#include <stdlib.h>
#include <utility>
 
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i = a;i<=b;i++)
#define ll long long int
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define iii pair<ii,int >
#define ff first
#define ss second
#define vi vector<int>
 
using namespace std;


int main(){
	int n;
	cin >> n;
	int a[n];
	int b[n];
	int c[n];
	FOR(i,n)cin >> a[i] >> b[i] >> c[i];

	int dp1[n];
	int dp2[n];
	int dp3[n];
	FOR(i,n)dp1[i] = dp2[i] = dp3[i];
	dp1[0] = a[0];
	dp2[0] = b[0];
	dp3[0] = c[0];

	FOR(i,n){
		if(i == 0)continue;

		dp1[i] = a[i] + max(dp2[i-1],dp3[i-1]);
		dp2[i] = b[i] + max(dp1[i-1],dp3[i-1]);
		dp3[i] = c[i] + max(dp2[i-1],dp1[i-1]);
	}
	cout << max(dp1[n-1] , max(dp2[n-1] , dp3[n-1])) << endl;
	return 0;
}


Measured memory_bytes: 2560
#include<set>
#include<list>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
    long long w,h,x,y;
    cin>>w>>h>>x>>y;
    cout<<(w*h/2.0)<<" ";
    if(w==x*2&&h==y*2)
        cout<<1;
    else
        cout<<0;
    return 0;
}

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

int main(){
	int x,y;
	cin >> x >> y;
	while(!(x==0&&y==0)){
		if(x<y) cout << x << " " << y << endl;
		else cout << y << " " << x << endl;
		cin >> x >> y;
	}
	return 0;
}

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

int main() {
  long n,m;
  bool b=false;
  string s;
  vector<long> ans;
  cin >> n >> m >> s;
  while(n>0) {
    for(long i=min(n,m);true;i--) {
      if(i==0) {
        b=true;
        break;
      }
      if(s[n-i]=='0') {
        n-=i;
        ans.push_back(i);
        break;
      }
    }
    if(b) break;
  }
  if(b) cout << -1;
  else for(long i=ans.size()-1;i>=0;i--) cout << ans[i] << " ";
  cout << endl;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  char c;
  cin >> c;
  c+=1;
  print(c);
  return 0;
}

Measured memory_bytes: 256
/**
       ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
      AnTi-MiRaGe on Anti-Mage xD
       ▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
**/
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <memory.h>
#include <math.h>
#include <time.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define show puts("Debug")

using namespace std;

int a, b, fl, ar[105][105];

main()
{
    cin >> a >> b;

    a--;
    for (int i = 1; i <= 100; i++)
    {
        ar[1][i] = 1;
        ar[100][i] = 1;
        ar[i][1] = 1;
        ar[i][100] = 1;
    }

    int i = 3;
    while (a)
    {
        if (i % 3 == 2)
        {
            i++;
            continue;
        }
        for (int j = 3; j <= 98; j++)
        {
            if ( (i + j) % 2 == 0 )
                ar[i][j] = 1, a--;
            if (!a)
                break;
        }
        i++;
    }
    b--;
    for (int i = 21; i <= 100; i++)
        for (int j = 1; j <= 100; j++)
            ar[i][j] = 1;

    i = 22;
    while (b)
    {
        if (i % 3 == 0)
        {
            i++;
            continue;
        }
        for (int j = 2; j <= 99; j++)
        {
            if ( (i + j) % 2 == 0 )
                ar[i][j] = 0, b--;

            if (!b)
                break;
        }
        i++;
    }
    puts("100 100");
    for (int i = 1; i <= 100; i++)
    {
        for (int j = 1; j <= 100; j++)
        {
            if (ar[i][j] == 1)
                putchar('.');
            else
                putchar('#');
        }
        printf("\n");
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#include <cmath>
#include <array>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9+7;


int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int h,w,n;
	const ll BS=1000000;
	cin >> h >> w >>n;
	VI a(n), b(n);
	rep(i,n){
		int y,x; cin >>y >>x;
		a[i] = y-1; b[i]=x-1;
	}
	ll ans[10]={};
	unordered_map<ll, int> mp;
	rep(t, n){
		int cy =a[t], cx =b[t];
		rep2(i,-1,2) rep2(j,-1,2){
			if(cy+i<1 || cy+i>h-2 || cx+j<1 || cx+j>w-2) continue;
			//printf("c%d:%d  ",cy+i,cx+j);
			mp[BS*(cy+i) + cx+j]++;
		}
	
	}
	ll sm=0;
	for(auto z: mp) ans[z.second]++;
	rep2(i,1,10) sm += ans[i];
	ans[0] = ((ll)h -2) * (w -2) - sm;
	rep(i,10) cout << ans[i] << "\n";
	return 0;
}


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

int main(){
  int L;

  while(cin >> L, L){
    int N, M;
    int sum = 0, ans = -1;

    for(int y = 1; y <= 12; y++){
      cin >> N >> M;
      sum += N - M;

      if(ans != -1){
        continue;
      }
      if(sum >= L){
        ans = y;
      }
    }

    if(ans == -1){
      cout << "NA\n";
    }
    else{
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main()
{
    int p,q,r;
    cin >> p >> q >> r;

    int MIN=1000;
    MIN=min(MIN,p+q);
    MIN=min(MIN,q+r);
    MIN=min(MIN,r+p);
    cout << MIN << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
#include <numeric>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back


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

    int N;
    cin >> N;
    if(N<=1000){
        cout << 1000-N << endl;
        return 0;
    }
    for(int i=1; i++; i<= 10){
        int a = 1000*(i-1), b = 1000*i;
        if (a<=N && N<=b){
            cout << b-N << endl;
            break;
        }
    }

    return 0;
}

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

#define      ll     long long int

const int N = 500;
int C[N];
int S[N];
int F[N];
int n;

int main()
{
    int i, j, k, l;
    cin >> n;
    for (i = 1; i < n; i++) {
        cin >> C[i] >> S[i] >> F[i];
    }
    for (i = 1; i <= n; i++) {
        ll s = S[i] + C[i];
        for (j = i + 1; j < n; j++) {
            if (S[j] <= s) {
                ll k = s / F[j];
                if (s % F[j] != 0) k++;
                s = k * F[j];
                s += C[j];
                continue;
            }
            s = S[j];
            s += C[j];
        }
        cout << s << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
n=gets.to_i
lines=gets.chomp.split.map(&:to_i)
team = {}
lines.each do |line|
  if team.has_key?(line)
    team[line] += 1
  else    
    team[line]=1
  end  
end  

1.upto(n) do |i|
  if team.has_key?(i)
  else    
    team[i]=0
  end  
end
team.sort.each do |key,value|
  puts value
end  

Measured memory_bytes: 55388
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,e;
    int t=0;
    cin>>a>>b>>c>>d>>e;
    if(a<0){
        t=t-a*c+d;
        a=0;
    }
    t=t+(b-a)*e;
    cout<<t;
    cout<<endl;
}



Measured memory_bytes: 3060
//package beg_163;

import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		String[] a = s.nextLine().split(" ");
		
		int b = Integer.parseInt(a[0]);
		
		String[] list = s.nextLine().split(" ");
		int count=0;
		for (String i: list) {
			int k = Integer.parseInt(i);
			count=count+k;
		}
		if (b-count<0) {
			System.out.println(-1);
		}
		else {
			System.out.println(b-count);
		}
	}

}


Measured memory_bytes: 38704
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;

char s[MaxN + 5];
int sum[MaxN + 5];

int main()
{
	int n,k,biu;
	while(~scanf("%s %d",s,&k))
	{
		getchar();
		n = strlen(s);
		for(int i = 0;i < n;i++)
		{
			if(s[i]=='a') 
			{
				sum[i] = 0;
				continue;
			}
			sum[i] = 'z' - s[i] + 1;
		}
		for(int i = 0;i < n;i++)
		{
			if(i==n-1)
			{
				k += s[i] - 'a';
				k %= 26;
				s[i] = 'a' + k;
			}
			else if(k >= sum[i])
			{
				k -= sum[i];
				s[i] = 'a';
			}
			if(k==0) break;
		}
		printf("%s\n",s);
	}
	return 0;
}

Measured memory_bytes: 768
from collections import Counter
from functools import reduce
import fractions
import math
import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  # LIST INT
def LF(): return [float(x) for x in sys.stdin.readline().split()]  # LIST FLOAT
def LS(): return sys.stdin.readline().split()  # LIST STRING
def MI(): return map(int, sys.stdin.readline().split())  # MAP INT
def II(): return int(sys.stdin.readline())  # INPUT INT
def IS(): return input()  # INPUT STRING
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  # greatest common divisor
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  # least common multiple
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))

n = II()
dp = [INF] * n
h = LI()
dp[0], dp[1] = 0, abs(h[1] - h[0])
for i in range(2, n):
    dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i])
    dp[i] = min(dp[i-2] + abs(h[i]-h[i-2]), dp[i])
P(dp[n-1])



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

int main() {
	string N;
	cin >> N;
	cout << "ABC" << N << endl;
	return 0;
}


Measured memory_bytes: 3524
import java.io.*;

class Main {
    static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static final PrintWriter pw = new PrintWriter(System.out);
    public static void main(String[] args) throws IOException {
        String[] inputs = br.readLine().split(" ");
        int vacation = Integer.parseInt(inputs[0]);
        int works = Integer.parseInt(inputs[1]);

        int workDay = 0;
        inputs = br.readLine().split(" ");
        for(int i = 0; i < works; i++) {
            workDay += Integer.parseInt(inputs[i]);
        }

        int ans = vacation - workDay;
        ans = ans < 0 ? -1 : ans;

        pw.println(ans);
        pw.flush();
    }
}

Measured memory_bytes: 34352
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    int n, d;
    cin >> n >> d;

    vector<vector<int>> x(n, vector<int>(d));

    REP(i, n)
    {
        REP(j, d)
        {
            cin >> x.at(i).at(j);
        }
    }

    int cnt = 0;
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            double ans = 0.0;
            REP(k, d)
            {
                ans += (x.at(i).at(k) - x.at(j).at(k)) * (x.at(i).at(k) - x.at(j).at(k));
            }
            ans = sqrt(ans);
            if (ans - int(ans) == 0.0)
            {
                cnt++;
            }
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
ue = [0]*10**6
sita = [0]*10**6
for i in range(n):
  if i % 2 == 0:
    ue[a[i]] += 1
  else:
    sita[a[i]] += 1

m_ue = max(ue)
m_ue_idx = ue.index(m_ue)
m_sita = max(sita)
m_sita_idx = sita.index(m_sita)
if m_ue_idx != m_sita_idx:
  print(n - m_ue - m_sita)
else:
  s_ue = sorted(ue, reverse=True)
  s_sita = sorted(sita, reverse=True)
  print(min(n-s_ue[0]-s_sita[1], n-s_ue[1]-s_sita[0]))


Measured memory_bytes: 40876
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,i,j,sum=0;
   cin>>a>>b;
   for(i=0;i<b;i++)
   {
       cin>>c;
       sum+=c;
   }
   if(sum>=a)
    cout<<"Yes"<<endl;
   else
    cout<<"No"<<endl;




}


Measured memory_bytes: 256
n,m=map(int,input().split())
e=[[]for _ in[0]*-~n]
for _ in[0]*m:
    a,b=map(int,input().split())
    e[a]+=[b]
    e[b]+=[a]
candy=[[1]]
for _ in[0]*~-n:
    tmp=[]
    for c in candy:
        for next in e[c[-1]]:
            tmp+=[c+[next]]
    candy=tmp
print(sum(c==set(range(1,n+1))for c in map(set,candy)))

Measured memory_bytes: 141808
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    List<Integer> A = new ArrayList<Integer>();
    String result = "APPROVED";

    int N = scan.nextInt();
    for(int i=0;i<N;i++) {
    A.add(scan.nextInt());
    }

for(int j:A) {
	if(j%2==0) {
		if(j%3!=0 && j%5!=0){
		result = "DENIED";
		}
	}

}
    System.out.println(result);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <list>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
*/

// 実装が大変でした

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

	int n;
	cin >> n;
	vector<ll>a(n);
	ll sum = 0;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	// すべて均等になるようにしたい
	// どうやるんだろう

	// まず半分に分ける？
	// 半分に分ける位置を全探索する
	ll leftSum = 0;
	ll rightSum = 0;
	int index;

	ll leftleftSum = 0;
	ll leftrightSum;
	int leftIndex = 0;

	ll rightleftSum = 0;
	ll rightrightSum;
	int rightIndex = 0;

	ll ans = infll;

	rep(i, n) {
		leftSum += a[i];
		rightSum = sum - leftSum;
		if (i == 0) continue;
		if (i >= n - 2) continue;

		// i番目とi+1番目で区切る
		index = i;

		// 尺取り法を使って計算量を大幅カット

		// 左側で区切る
		Rep(j, leftIndex, index + 1) {
			leftleftSum += a[j];
			leftrightSum = leftSum - leftleftSum;
			if (leftrightSum < leftleftSum) {
				if (abs(leftleftSum - leftrightSum) < abs(leftrightSum - leftleftSum + 2 * a[j])) {
					leftIndex = j;
				}
				else {
					leftleftSum -= a[j];
					leftrightSum += a[j];
					leftIndex = j - 1;
				}
				break;
			}
		}
		leftIndex++;
		if (index == 1) rightIndex = index + 1;
		else rightleftSum -= a[index];
		// 右側で区切る
		Rep(j, rightIndex, n) {
			rightleftSum += a[j];
			rightrightSum = rightSum - rightleftSum;

			if (rightrightSum < rightleftSum) {
				if (abs(rightleftSum - rightrightSum) < abs(rightrightSum - rightleftSum + 2 * a[j])) {
					rightIndex = j;
				}
				else {
					rightleftSum -= a[j];
					rightrightSum += a[j];
					rightIndex = j - 1;
				}
				break;
			}
		}
		rightIndex++;

		ll ma = max({ leftleftSum, leftrightSum, rightleftSum, rightrightSum });
		ll mi = min({ leftleftSum, leftrightSum, rightleftSum, rightrightSum });

		//cout << index + 1 << "番目と" << index + 2 << "番目の間で区切る" << endl;
		//cout << leftleftSum << " " << leftrightSum << " " << rightleftSum << " " << rightrightSum << endl;
		//cout << ma - mi << endl;
		ans = min(ans, ma - mi);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <deque>
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}


#define INF 1e9+7
#define LLINF 1e18+7

main(){
    ll n=lin();
    ll ans=1e18;
    int sq=sqrt(n);
    for(ll i=sq;i>=1;i--){
        if(n%i==0){
            printf("%lld",n/i+i-2);
            return 0;
        }
    }
}

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

int main()
{
	int h, w;
	while(1) {
		cin >> h >> w;
		if (h == 0 & w == 0) break;

		int i, j;
		for (i = 0; i < h; i++) {
			for (j = 0; j < w; j++) {
				if (i != 0 & i != h-1 & j != 0 & j != w-1) {
					cout << ".";
				} else {
					cout << "#";
				}
			}
			cout << "\n";
		}
		cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 1120
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef double db;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=200005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int X,Y,A,B,C;
int p[max_n],q[max_n],r[max_n];
ll sp[max_n],sr[max_n];
ll t[max_n];
int main(){
    scanf("%d%d%d%d%d",&X,&Y,&A,&B,&C);
    for(int i=1;i<=A;i++)scanf("%d",p+i);
    for(int i=1;i<=B;i++)scanf("%d",q+i);
    for(int i=1;i<=C;i++)scanf("%d",r+i);
    sort(p+1,p+A+1,greater<int>());
    sort(q+1,q+B+1,greater<int>());
    sort(r+1,r+C+1,greater<int>());
    for(int i=1;i<=A;i++)sp[i]=sp[i-1]+p[i];
    for(int i=1;i<=C;i++)sr[i]=sr[i-1]+r[i];
    ll ans=0;
    priority_queue<int,vector<int>,greater<int>> que;
    ll cur=0;
    for(int i=1;i<=Y;i++){
        que.push(q[i]);
        cur+=q[i];
    }
    t[C+1]=cur;
    for(int i=C;i>=1;i--){
        if(r[i]>que.top()){
            cur-=que.top();que.pop();
            cur+=r[i];que.push(r[i]);
        }
        t[i]=cur;
    }
    for(int i=0;i<=min(A,X);i++){
        if(X-i>C)continue;
        ll res=sp[i]+sr[X-i]+t[X-i+1];
        //cout<<i<<' '<<res<<endl;
        ans=max(ans,res);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 6520
n,l=map(int,input().split())
r=[]
t=0
for i in range(1,n+1):
    r.append(int(l+i-1))
zero =0 in r
if zero==0 and r[0]>0:
    r.pop(0)
elif zero==0 and r[0]<0:
    r.pop(n-1)
elif zero==1:
    r.remove(0)
for i in range(n-1):
    t+=r[i]
print(t)
    

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1<<29;
typedef long long ll;

int dp[100][2][100];//dp[keta][未満である][0でない数の個数]

struct UnionFind {
  vi parent;
  UnionFind(int N) : parent(N) {
    rep(i, N)parent[i] = i;
  }

  int getRoot(int child){
    return ((parent[child] == child) ? child : parent[child] = getRoot(parent[child]));
  }
  void unite(int x, int y){
    int root_x = getRoot(x);
    int root_y = getRoot(y);
    if(root_x == root_y)return;
    parent[root_x] = parent[root_y];
  }
  bool isSame(int x, int y){
    return getRoot(x) == getRoot(y);
  }
};

const int di[] = {1, 0, -1, 0};
const int dj[] = {0, 1, 0, -1};

int main(){
    int a[3];cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if(a[0] == 5 && a[1] == 5 && a[2] == 7)
        cout << "YES";
    else
        cout << "NO";
}


Measured memory_bytes: 256
a, b, k = map(int, input().split())
a_res = 0
b_res = b
if a - k > 0:
    a_res = a - k
else:
    k_temp = k - a
    b_res = b - k_temp
    if b_res < 0:
        b_res = 0
print(str(a_res) + ' ' + str(b_res))


Measured memory_bytes: 2940
/*  -*- coding: utf-8 -*-
 *
 * 1580.cc: Barter
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_X = 300;
const int MAX_Y = 300;

/* typedef */

/* global variables */

int as[MAX_N], bs[MAX_N], cs[MAX_N], ds[MAX_N];
int dp[2][MAX_X + 1][MAX_X + MAX_Y + 1];

/* subroutines */

inline void setmax(int &a, int b) { if (a < b) a = b; }

/* main */

int main() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);

  int bsum = 0, csum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d%d", as + i, bs + i, cs + i, ds + i);
    bsum += bs[i], csum += cs[i];
  }
  //printf("bsum=%d, csum=%d\n", bsum, csum);

  memset(dp, -1, sizeof(dp));
  int z = (bsum > y) ? bsum - y : 0;
  int maxy = z + y + bsum;

  dp[0][x][z + y] = 0;
  int cur = 0, nxt = 1;

  for (int i = 0; i < n; i++) {
    memcpy(dp[nxt], dp[cur], sizeof(dp[cur]));
    for (int j = 0; j <= x; j++)
      for (int k = 0; k <= maxy; k++)
	if (dp[cur][j][k] >= 0) {
	  if (j >= as[i])
	    setmax(dp[nxt][j - as[i]][k + bs[i]], dp[cur][j][k]);
	  if (k >= cs[i])
	    setmax(dp[nxt][j][k - cs[i]], dp[cur][j][k] + ds[i]);
	}

    cur ^= 1, nxt ^= 1;
  }

  int maxd = 0;
  for (int j = 0; j <= x; j++)
    for (int k = z; k <= maxy; k++)
      setmax(maxd, dp[cur][j][k]);

  printf("%d\n", maxd);
  return 0;
}



Measured memory_bytes: 4704
N,K = map(int,input().split())

n_1 = N//K
if K%2 == 0:
    if N%K < K/2:
        n = (N//K)
    else:
        n = (N//K) +1
    count = n_1 + n_1*(n_1-1)*3 + n_1*(n_1-1)*(n_1-2)
else:
    n = N//K
    count = 0
count += n + n*(n-1)*3 + n*(n-1)*(n-2)

print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstdio>
#include <cstring>
#include <assert.h>
#include <functional>
#define  lowbit(x) (x&(-x))
#define  ll long long
#define  ull unsigned long long
#define  max(a,b) (a>b?a:b)
#define  min(a,b) (a>b?b:a)
#define  PI acos(-1.0)
#define  fir first
#define  sec second
#define  SZ(x) (x.size())
#define  inf 0x3f3f3f3f
#define  PB push_back
#define  MP make_pair
#define  all(x) (x).begin(),(x).end()
#define  PII pair<int,int>
#define  E 2.7182818284590452353602874713527
using namespace std;

/**********************************************Head-----Template****************************************/
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

const ll mod = 9901;
ll ksm(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1) ans=ans*a%mod;a=a*a%mod;}return ans;}
/********************************Head----Template**********************************************/

bool judge(string ss){
    int k1=0,k2=0,k3=0;
    for(int i=0;i<ss.size();i++){
        if(ss[i]=='c') k1=1;
        if(ss[i]=='o') k2=1;
        if(ss[i]=='w') k3=1;
    }
    return k1&&k2&&k3;
}

int a[100000],b[100000];

int main (){
    int n;cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    int ans=0;
    for(int i=0;i<n;i++) {
        if(a[i]>b[i]) ans+=a[i]-b[i];
    }cout<<ans<<endl;
    //printf("%d\n",c/a*b);
    return 0;
}



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

#define INF 2000000000

class max_flow {
private:
	struct edge { int to, cap, rev; };
	int v;
	vector<vector<edge>>G;
	vector<int>itr, level;
public:
	max_flow(int v) :v(v) { G.assign(v, vector<edge>()); }

	void add_edge(int from, int to, int cap) {
		G[from].push_back(edge { to, cap, (int)G[to].size() });
		G[to].push_back(edge { from, 0, (int)G[from].size() - 1 });
	}

	void bfs(int s) {
		level.assign(v, -1);
		queue<int>q;
		level[s] = 0; q.push(s);
		while (!q.empty()) {
			int v = q.front(); q.pop();
			for (auto &e : G[v]) {
				if (e.cap > 0 && level[e.to] < 0) {
					level[e.to] = level[v] + 1;
					q.push(e.to);
				}
			}
		}
	}

	int dfs(int v, int t, int f) {
		if (v == t)return f;
		for (int& i = itr[v]; i < (int)G[v].size(); ++i) {
			edge& e = G[v][i];
			if (e.cap > 0 && level[v] < level[e.to]) {
				int d = dfs(e.to, t, min(f, e.cap));
				if (d > 0) {
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}

	int run(int s, int t) {
		int ret = 0, f;
		while (bfs(s), level[t] >= 0) {
			itr.assign(v, 0);
			while ((f = dfs(s, t, INF)) > 0)ret += f;
		}
		return ret;
	}
};

int gcd(int a, int b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}

int main() {
	int m,n;
	while (1) {
		cin >> m >> n;
		if (m == 0)break;
		max_flow max_flow(m + n + 2);
		vector<int>b, r;
		for (int i = 0; i < m; i++) {
			int buf;
			cin >> buf;
			b.push_back(buf);
		}
		for (int i = 0; i < n; i++) {
			int buf;
			cin >> buf;
			r.push_back(buf);
		}
		for (int i = 0; i < m; i++) {
			max_flow.add_edge(m + n, i, 1);
			for (int j = 0; j < n; j++) {
				if (gcd(b[i], r[j]) != 1)max_flow.add_edge(i, m + j, 1);
				if (i == 0)max_flow.add_edge(m + j, m + n + 1, 1);
			}
		}
		int ans = max_flow.run(m + n, m + n + 1);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 7248
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int x = Integer.parseInt(sc.next());
    int remain = x;
    int ans = (remain / 500) * 1000;
    remain = remain % 500;
    ans += (remain / 5) * 5;
    pw.println(ans);
  }
}


Measured memory_bytes: 22996
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll [[maybe_unused]] = long long;
using ull [[maybe_unused]] = unsigned long long;
using ld [[maybe_unused]] = long double;

[[maybe_unused]] static constexpr int mod = (int)1e9 + 7;
[[maybe_unused]] static constexpr int inf = 100100100;
[[maybe_unused]] static constexpr ll linf = 1e18;
[[maybe_unused]] static constexpr double eps = 1e-9;
[[maybe_unused]] static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, a, b) for (ll i = a; i < b; ++i)
#define rrrep(i, a, b) for (ll i = a; i >= b; --i)
#define all(obj) begin(obj), end(obj)
#define rall(obj) rbegin(obj), rend(obj)
#define pb push_back
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    int K;
    cin >> K;
    int ans = 0;
    if (K % 2 == 0) {
        for (int j = 2; j <= K; j += 2) {
            for (int i = 1; i <= K; i += 2) {
                ++ans;
            }
        }
    } else {
        for (int j = 1; j <= K; j += 2) {
            for (int i = 2; i <= K; i += 2) {
                ++ans;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
  int n,m;
  cin >> n >> m;
  
  vector<pair<lli, lli>> a(n);
  for(int i = 0; i < n; i++)
    cin >> a[i].first >> a[i].second;
  
  sort(a.begin(), a.end());
  lli sum_many = 0;
  lli sum_money = 0;
  for(int i = 0; i < n; i++){
    if(m - sum_many < a[i].second){
      sum_money += (m - sum_many) * a[i].first;
      break;
    }
    else{
      sum_many += a[i].second;
      sum_money += a[i].first * a[i].second;
      //cout << a[i].first << endl;
    }
  }
  
  cout << sum_money << endl;  
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(a, max(b, c))
#define MIN(x, y, z) min(a, min(b, c))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll H, W;
  cin >> H >> W;

  vector<vector<char>> m(H, vector<char>(W));
  rep(i, H) rep(j, W) cin >> m[i][j];

  auto calc = [&](ll i, ll j) -> char {
    ll count = 0;
    if (i > 0) {
      if (m[i - 1][j] == '#') count++;
      if (j - 1 >= 0 && m[i - 1][j - 1] == '#') count++;
      if (j + 1 < W && m[i - 1][j + 1] == '#') count++;
    }
    if (j - 1 >= 0 && m[i][j - 1] == '#') count++;
    if (j + 1 < W && m[i][j + 1] == '#') count++;
    if (i < H - 1) {
      if (m[i + 1][j] == '#') count++;
      if (j - 1 >= 0 && m[i + 1][j - 1] == '#') count++;
      if (j + 1 < W && m[i + 1][j + 1] == '#') count++;
    }
    return to_string(count)[0];
  };

  rep(i, H) {
    rep(j, W) {
      if (m[i][j] == '.') {
        cout << calc(i, j);
      } else {
        cout << "#";
      }
    }
    ENDL;
  }

  return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<vector<vector<int>>> F(N,vector<vector<int>>(5,vector<int>(2)));
    rep(i,0,N)rep(j,0,5)rep(k,0,2) cin>>F.at(i).at(j).at(k);
    vector<vector<int64_t>> P(N,vector<int64_t>(11));
    rep(i,0,N)rep(j,0,11) cin>>P.at(i).at(j);

    int64_t ans=INT64_MIN;
    rep(i,1,1<<10){
        bitset<10> b(i);

        vector<int> _P(N,0);
        rep(j,0,10){
            if(b.test(j)){
                rep(k,0,N){
                    if(F.at(k).at(j/2).at(j%2)) _P.at(k)++;
                }
            }
        }

        int64_t _ans=0;
        rep(i,0,N){
            _ans+=P.at(i).at(_P.at(i));
        }
        ans=max(ans,_ans);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys, math
readline = sys.stdin.readline

A, B, H, M = map(int, readline().split())

a = (H / 12 + M / 60 /12) * 2 * math.pi
b = (M / 60) * 2 * math.pi

ans = (A * math.cos(a) - B * math.cos(b)) ** 2 + (A * math.sin(a) - B * math.sin(b)) ** 2
ans = ans ** 0.5
print(ans)

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

#define LINE_BUF_SIZE 256

int main(){

    int M,N,A,B,C,A_,B_,C_;
    int i,j,k;
    char line[LINE_BUF_SIZE];

    fgets(line,sizeof(line),stdin);
    sscanf(line,"%d %d %d", &A_,&B_,&C_);

    int count = 0;

    if(A_ >= B_ && B_ >= C){
        A = A_;
        B = B_;
        C = C_;
    }

    if(A_ >= B_ && C_ >= B_){
        A = A_;
        B = C_;
        C = B_;
    }

    if(B_ >= A_ && A_ >= C_){
        A = B_;
        B = A_;
        C = C_;
    }

    if(B_ >= C_ && C_ >= A_){
        A = B_;
        B = C_;
        C = A_;
    }

    if(C_ >= B_ && B_ >= A_){
        A = C_;
        B = B_;
        C = A_;
    }

    if(C_ >= A_ && A_ >= B_){
        A = C_;
        B = A_;
        C = B_;
    }
    
        if((A-B) % 2 == 0 && (A-C) % 2 == 0){
            count += (A - B) / 2;
            count += (A - C) / 2 ;
            printf("%d",count);
            return 0;
        }
        else if((A-B) % 2 == 0 && (A-C) % 2 != 0){
            count += (A - B) / 2;
            count += (A - C) / 2 + 2;
            printf("%d",count);
            return 0;
        }
        else if((A-B) % 2 != 0 && (A-C) % 2 == 0){
            count += (A - B) / 2  + 2;
            count += (A - C) / 2;
            printf("%d",count);
            return 0;
        }        
        else if((A-B) % 2 != 0 && (A-C) % 2 != 0){
            count += (A - B) / 2;
            count += (A - C) / 2 + 1;
            printf("%d",count);
            return 0;
        }

    return 0;

}

Measured memory_bytes: 128
def dfs(i, Str, res):
    if i==3:
        if res==7:
            print(Str+"=7")
            exit()
        return
    
    dfs(i+1,Str+"+"+s[i+1],res+int(s[i+1]))
    dfs(i+1,Str+"-"+s[i+1],res-int(s[i+1]))

s=input()
dfs(0,s[0],int(s[0]))

Measured memory_bytes: 3064
N = int(input())
T,A=map(int,input().split())
H = list(map(int,input().split()))

ans = 100000000000
point = 0

for i in range(N):
    a = (T - H[i]*0.006)
    diff = abs(A - a)
    if diff <= ans:
        ans = diff
        point = i+1
        
print(point)

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

int main(){
  int n;
  cin >> n;
  vector<vector<int>> vec(n,vector<int>(2));
  rep(i,n){
    rep(j,2){
      if (j==1) vec.at(i).at(j)=i+1;
      else cin >> vec.at(i).at(j);
    }
  }
  sort(vec.begin(),vec.end());
//  reverse(vec.begin(),vec.end());
  rep(i,n) cout << vec.at(i).at(1) << endl;
}
  

Measured memory_bytes: 6272
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;

ll gcd(ll x,ll y){
    if(y==0) return 0;
    return gcd(y,x%y);
}

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}

int main(){
    int n;cin>>n;
    vector<int> a(n);
    map<ll,ll> cnt;
    vector<ll> sum(n+1,0);
    cnt[0]++;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum[i+1]=sum[i]+a[i];
        cnt[sum[i+1]]++;
    }
    ll ans=0;
    for(auto it:cnt){
        ans+=(it.second)*(it.second-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 15104
#ABC057

n,m = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(n)]
c = [list(map(int,input().split())) for _ in range(m)]

for i in range(n):
    x,y = a[i]
    
    count = 0
    l = abs(x-c[0][0]) + abs(y-c[0][1])
    for j in range(m):
        
        p,q = c[j]
        
        if l > abs(x-p)+abs(y-q):
            l = abs(x-p)+abs(y-q)
            count = j
    print(count+1)




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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef long long ll;
 
//const int INF = 1001001001;
const long long INF = 2e18;
const int MOD = 1000000007;
const double PI=acos(-1);


//-------------------------------------------------
struct edge{ll to, cost;};
//typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    for(int i=0; i<V; i++){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    for(int i=0; i<V; i++){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>, greater<pair<ll,ll>> > que; //first:dist from start, second:next v
    que.push(make_pair(0,s));
    while(!que.empty()){
      auto p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(make_pair(d[e.to],e.to));
        }
      }
    }
  }
};

int main() {
    int n,m,s,t;
    cin >> n >> m >> s >> t;
    s--,t--;
    graph g1(n), g2(n);

    rep(i,m) {
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        u--,v--;
        g1.add_edge(u,v,a);
        g1.add_edge(v,u,a);
        g2.add_edge(u,v,b);
        g2.add_edge(v,u,b);
    }
    
    g1.dijkstra(s);
    g2.dijkstra(t);

    priority_queue<pair<ll,ll>, vector<pair<ll,ll>>> d;
    ll total = 1000000000000000;
    rep(i,n) {
        d.push(make_pair(total-(g1.d[i] + g2.d[i]),i));
    }

    rep(i,n) {
        while (d.top().second<i) {
            d.pop();
        }
        auto ans = d.top();
        cout << ans.first << endl;
    }


}

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

#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define lg long long
#define db double
#define lb(x) ((x)&-(x))
#define ft first
#define sd second

#define HII cerr<<"HI"<<endl
#define LLLINE cerr<<"@@@@@@@@@@@@@@@@@@@@"<<endl

template <class _T_>
void read(_T_& d){
	d=0;int f=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f*=-1;
	for(;c>='0'&&c<='9';c=getchar())d=d*10+c-'0';
	d*=f;
}

/************************************************/
int a,b,c;
int main(){
	read(a);read(b);read(c);
	int res=0;
	res+=b;
	res+=min(a+b+1,c);
	cout<<res;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma optimizer(O2)
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
//#define MXN 300000
#define N 100005

int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    vector<int> odd,even;
    for(int i = 0;i<m;i++){
        int x;
        scanf("%d",&x);
        if(x&1)odd.pb(x);
        else even.pb(x);
    }
    if(odd.size()>2){
        printf("Impossible\n");
    }
    else{
        if(n&1){
            for(auto it:odd)printf("%d",it);
            for(auto it:even)printf(" %d",it);
            if(m!=1||n==1){
                odd[0]--;
                if(odd[0]==0)m--;
                printf("\n%d\n",m+1);
                for(auto it:odd)if(it)printf("%d",it);
                for(auto it:even)printf(" %d",it);
                printf(" 1\n");
            }
            else{
                printf("\n2\n");
                printf("1 %d\n",n-1);
            }
        }
        else{
            if(odd.size()){
                printf("%d",odd[0]);
                for(auto it:even)
                printf(" %d",it);
                printf(" %d\n",odd[1]);
                odd[0]--;
                odd[1]++;
                if(odd[0]==0){
                    printf("%d\n",m-1);
                    for(auto it:even)
                    printf("%d ",it);
                    printf("%d\n",odd[1]);
                }
                else{
                    printf("%d\n",m);
                     printf("%d",odd[0]);
                    for(auto it:even)
                    printf(" %d",it);
                    printf(" %d\n",odd[1]);
                }
            }
            else{
                for(auto it:even)printf("%d ",it);
                printf("\n");
                printf("%d\n",m+1);
                printf("1");
                even.back()--;
                for(auto it:even)printf(" %d",it);
                printf("\n");
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 5100
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n,x; cin >> n >> x;
    vl v(n+1), p(n+1);
    v[0] = 1;
    p[0] = 1;
    rep(i,n){
        v[i+1] = v[i] * 2 + 3;
        p[i+1] = p[i] * 2 + 1;
    }
    ll ans = 0;
    for(ll i=n; i>=0; i--){
        while(x >= v[i]){
            x -= v[i];
            ans += p[i];
            if(x>=1){
                ans++; x--;
            }
        }
        if(x == 0) break;
        x--;
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
  int N;
  cin>>N;
  int ans=0;
  for(int n=1;n<=N;n++){
    ans=0;
    for(int A=2;A<=141;A++){
      for(int B=2;B<=141;B++){
        int X=A*A+B*B;
        if(X>=2*n) break;
        int C=sqrt(2*n-X);
        int S=A+B+C;
        if(C*C==2*n-X && S%2==0 && S/2>max({A,B,C})){
          ans++;
        }
      }
    }
    cout<<ans<<endl;
    }
  return 0;}

Measured memory_bytes: 3592
n = int(input())
a = list(map(int, input().split()))


ans = 0
ansans = 0
now = 0

for i in range(n):
    now += a[i]
    if i % 2 == 0:
        if now < 0:
            ans += abs(now) + 1
            now = 1
        elif now == 0:
            ans += 1
            now = 1
    else:
        if now >= 0:
            ans += abs(now) + 1
            now = -1
        elif now == 0:
            ans += 1
            now = -1

now = 0
for i in range(n):
    now += a[i]
    if i % 2 == 0:
        if now > 0:
            ansans += abs(now) + 1
            now = -1
        elif now == 0:
            ansans += 1
            now = -1
    else:
        if now < 0:
            ansans += abs(now) + 1
            now = 1
        elif now == 0:
            ansans += 1
            now = 1

print(min(ans, ansans))


Measured memory_bytes: 14468
while True:
    h,w = map(int, input().split())
    if (h==0 and w==0):
        break
    for i in range(h):
        for j in range(w):
            if i==0 or i==h-1 or j==0 or j==w-1:
                print("#", end='')
            else:
                print(".", end='')
        print()
    print()


Measured memory_bytes: 7000
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int A,B;
    cin >> A>>B;
    if(A+B>=10) cout << "error" << endl;
    else cout << A+B << endl;

   return 0;
}

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

int n;
bool d[60000];

int main(){
    vector<int> v;
    for (int i = 2; i < 55556; i++){
        if (!d[i]){
            if (i%5 == 1) v.push_back(i);
            int x = 2;
            while (x*i < 55556){
                d[x*i] = true;
                x++;
            }
        }
    }
    cin >> n;
    if (n%2 == 1) {
        cout << 2 <<" ";
        for (int i = 0; i < n - 1; i++) cout << v[i] <<" ";
    }
    else{
        for (int i = 0; i <= n - 1; i++) cout << v[i] <<" ";
    }
    
}

Measured memory_bytes: 256
n = int(input())
al = list(map(int, input().split()))
sum_d = {0:1}
c_sum = 0
ans = 0
for a in al:
    c_sum += a
    sum_d.setdefault(c_sum,0)
    ans += sum_d[c_sum]
    sum_d[c_sum] += 1

print(ans)

Measured memory_bytes: 117452