akhauriyash/Code-Regression huggingface dataset:
pub struct Poper<'a> {
	iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Poper<'a> {
	pub fn new(iter: std::str::SplitWhitespace) -> Poper {
		Poper { iter: iter }
	}
	pub fn read<T: std::str::FromStr>(&mut self) -> T
	where
		<T as std::str::FromStr>::Err: std::fmt::Debug,
	{
		self.iter.next().unwrap().parse().unwrap()
	}
}

fn main() {
	let input = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};
	let mut iter = Poper::new(input.split_whitespace());

	let n: usize = iter.read();
	let a_list: Vec<u64> = (0..n).into_iter().map(|_| iter.read()).collect();

	let mut x_list: Vec<u64> = Vec::new();

	for a in a_list {
		// print!("{:?} <- {} : ", x_list, a);
		match x_list.last() {
			Some(&m) => {
				if a <= m {
					x_list.push(a);
				} else {
					let i = match x_list.binary_search_by(|q| a.cmp(q)) {
						Ok(i) => {
							let mut i = i;
							while x_list[i] == a {
								i += 1;
							}
							i
						}
						Err(i) => i,
					};
					x_list[i] = a;
				}
			}
			None => {
				x_list.push(a);
			}
		}
		// println!("{:?}", x_list);
	}

	println!("{}", x_list.len());
}



Measured memory_bytes: 8444
#include <iostream>
#include<vector>
#include<stdio.h>

#define FOR(i,n) for(int i=0;i<n;i++)
#define SORT(v,n) sort(v[0],v[n-1])
#define INF 999999999
#define mod 1000000007

using namespace std;

int main(){
	string S;
	cin >> S;
	int leng = S.size();

	int a,z;
	for(int i=0;i<leng;i++){
		if(S.at(i)=='A'){
			a=i;
			break;
		}
	}
	//int z;
	for(int i=leng-1;i>=0;i--){
		if(S.at(i)=='Z'){
			z=i;
			break;
		}
	}
	int ans=z-a+1;

	cout << ans << endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTG(c) sort((c).begin(),(c).end(),greater<auto>())

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

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
int main(){
  int n,m ,cnt=0;
  cin >> n >> m;
  vector<PII> ab(n), cd(m);
  VI ans(n, m+1);
  REP(i, n){
      int a, b;
      cin >> a >> b;
      PII p1 = MP(a, b);
      ab[i]=p1;
  }
  REP(i, m){
      int c, d;
      cin >> c >> d;
      PII p2 = MP(c, d);
      cd[i]=p2;
  }
  int k;
  REP(i, n){
      LL k=MOD;
      REP(j, m){
          LL l = abs(ab[i].first-cd[j].first)+abs(ab[i].second-cd[j].second);
          if(l<k){
              k=l;
              ans[i]=j;
          }
      }
  }
  REP(i,n){
      cout << ans[i]+1 << endl;
  }



     
}

Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <list>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iterator> 
#include <limits>

#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define RALL(A) (a).rbegin(),(a).rend()
#define PB push_back
#define MP make_pair

#define dump(x) cerr << #x << " = " << (x) << endl;

using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
typedef long long LL;
const int INF = numeric_limits<int>::max() / 2;
const LL NEG_INF = numeric_limits<LL>::min() / 2;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

int N;
VI A;

int main(int argc, char const* argv[])
{
    cin >> N;
    REP(i, 3 * N) {
        int a; cin >> a; A.PB(a);
    }
    map<int, LL> left_sum_save;
    LL left_sum = 0;
    priority_queue<int> pq;
    REP(i, N) {
        pq.push(-A[i]);
        left_sum += A[i];
    }
    left_sum_save[0] = left_sum;
    REP(i, N) {
        pq.push(-A[i + N]);
        int top = pq.top();
        pq.pop();
        top = -top;
        left_sum = left_sum + A[i + N] - top;
        left_sum_save[i + 1] = left_sum;
    }

    map<int, LL> right_sum_save;
    LL right_sum = 0;
    priority_queue<int> pq2;
    REP(i, N) {
        pq2.push(A[i + 2 * N]);
        right_sum += A[i + 2 * N];
    }
    right_sum_save[0] = right_sum;
    REP(i, N) {
        pq2.push(A[2 * N - i - 1]);
        int top = pq2.top(); pq2.pop();
        right_sum = right_sum + A[2 * N - i - 1] - top;
        right_sum_save[i + 1] = right_sum;
    }

    LL ans = NEG_INF;
    REP(i, N + 1) {
        LL temp = left_sum_save[i] - right_sum_save[N - i];
        ans = max(ans, temp);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 14704
#include <cstdio>
#include <cmath>
#include <vector>

using namespace std;

//?¢????????????¨???????????°?????????

int N;
int A[100000000];
long long cnt;
vector<int> G;

//???????????????????????¢??° write ?????????

void write( int A[], int N ){

    for( int i = 0 ; i < N ; i++ ){

        if( i > 0 ){

            printf("\n");
            
        }

        printf("%d", A[i] );

    }

    printf("\n");

}

// insertion_sort?????????

void insertion_sort( int A[], int N, int g){

    int i, j, v ;

    for( i = g ; i < N ; i++ ){

        v = A[i];
        j = i - g;

        while( j >= 0 && A[j] > v ){

            A[j + g] = A[j] ;
            j = j - g;
            cnt++;

        } 

        A[ j + g ] = v;

    }

}

// shell_sort?????????

void shell_sort( int A[], int N ){

    int i, h;

    for( h = 1 ;;){

        if( h > N ) break;

        G.push_back(h);

        h = 3*h + 1;

    }

    for( i = G.size() - 1 ; i >= 0 ; i-- ){

        insertion_sort( A, N, G[i] );

    }

}

//??¬???

int main(){

    int i;

    cnt = 0;

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

    printf("%d\n", G.size() );

    for( i = G.size() - 1 ; i >= 0 ; i-- ){

        if( i < G.size() - 1 ) printf(" ");

        printf("%d", G[i]);

    }

    printf("\n");

    printf("%d\n", cnt);

    write( A, N);

    return 0;

}

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

int main(){

char ch;
  cin >> ch;
  
  if(ch=='A'||ch=='B'||ch=='C'||ch=='D'||ch=='E'||ch=='F'||ch=='G'||ch=='H'||ch=='I'||ch=='J'||ch=='K'||ch=='L'||ch=='M'||ch=='N'||ch=='O'||ch=='P'||ch=='Q'||ch=='R'||ch=='S'||ch=='T'||ch=='U'||ch=='V'||ch=='W'||ch=='X'||ch=='Y'||ch=='Z')
    cout << 'A';
  else if(ch=='a'||ch=='b'||ch=='c'||ch=='d'||ch=='e'||ch=='f'||ch=='g'||ch=='h'||ch=='i'||ch=='j'||ch=='k'||ch=='l'||ch=='m'||ch=='n'||ch=='o'||ch=='p'||ch=='q'||ch=='r'||ch=='s'||ch=='t'||ch=='u'||ch=='v'||ch=='w'||ch=='x'||ch=='y'||ch=='z')
     cout << 'a';
   
return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    string s;
    cin >> s;
    bool ans = true;
    if(s.find('S') != string::npos && s.find('N') == string::npos)ans = false;
    if(s.find('N') != string::npos && s.find('S') == string::npos)ans = false;
    if(s.find('E') != string::npos && s.find('W') == string::npos)ans = false;
    if(s.find('W') != string::npos && s.find('E') == string::npos)ans = false;
    if(ans)cout << "Yes";
    else cout << "No";
}      

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

using namespace std;
using ll=long long;
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define rep(i, n) rep2(i,0,n)
#define rall(a) (a).rbegin(), (a).rend()

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int n;cin>>n;
  vector<int> hoge(n);
  rep(i,n)cin>>hoge[i];
  sort(rall(hoge));
  int Alice=0,Bob=0;
  rep(i,n){
    i%2==0 ? Alice+=hoge[i] : Bob+=hoge[i];
  }
  cout<<Alice-Bob<<endl;
}


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

int main(){
  ll n,h,w,a,b;
  ll ans=0;
  cin>>n>>h>>w;
  for(int i=0;i<n;i++){
      cin>>a>>b;
      if(a>=h&&b>=w)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
h, w = [int(item) for item in input().split()]
total_item = h*w
MOD = 10**9 + 7
n = total_item + 10

fac = [1] + [0] * n
fac_inv = [1] + [0] * n
for i in range(1, n+1):
    fac[i] = fac[i-1] * (i) % MOD
    fac_inv[i] = fac_inv[i-1] * pow(i, MOD-2, MOD) % MOD

def mod_nPr(n, r):
    if n == 0 and r == 0:
        return 1
    if n < r or n < 0:
        return 0
    return fac[n] * fac_inv[n-r] % MOD

row_lim = [int(item) for item in input().split()] + [10**9]
col_lim = [int(item) for item in input().split()] + [10**9]
row_lim.sort()
col_lim.sort()

# Checked identity
for i in range(h):
    if row_lim[i] == row_lim[i+1]:
        print(0); exit()
for i in range(w):
    if col_lim[i] == col_lim[i+1]:
        print(0); exit()

citr = 0; ritr =0

ans = 1
itr = 0
available = total_item 
axis_num = h + w
while itr < axis_num:
    rlim = row_lim[ritr]
    clim = col_lim[citr]
    if rlim < clim:
        to_use = available - (total_item - rlim)
        if to_use < w:
            print(0); exit()
        ans *= (mod_nPr(to_use, w) - mod_nPr(to_use-1, w) + MOD)
        available -= w
        ritr += 1
        h -= 1
        itr += 1
    elif clim < rlim:
        to_use = available - (total_item - clim)
        if to_use < h:
            print(0); exit()
        ans *= (mod_nPr(to_use, h) - mod_nPr(to_use-1, h) + MOD)
        available -= h
        citr += 1
        w -= 1
        itr += 1
    else:
        to_use = available - (total_item - clim)
        if to_use < h + w - 1:
            print(0); exit()
        ans *= mod_nPr(to_use - 1, h + w - 2)
        available -= h + w - 1
        citr += 1; ritr += 1
        w -= 1; h -= 1
        itr += 2
    ans %= MOD
print(ans)

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

int main(){
    string S; cin >> S;
    int count = 0;
    int k = S.size();

    for(int i=0; i<S.size(); ++i){
        if(S[i] == 'o'){
            count++;
        }
    }

    if(count >= 8){
        cout << "YES" << endl;
    }else if((15-k) >= 8-count){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=list(map(int, input().split()))

ans=0
for i in range(n):
    r=a[i]-1
    if i > 0 and r == prev+1:
        ans+=b[r]+c[r-1]
    else :
        ans+=b[r]
    prev=r

print(ans)


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

int n,m,ans;
vector<vector<bool>>data(8,vector<bool>(8,false));

void dfs(int v,int p,int c,vector<bool>used){
  for(int i = 0;i < n;i++){
    if(i != p && data[v][i] && !used[i]){
      used[v] = true;
      dfs(i,v,c+1,used);
    }
  }
  if(c == n) ans++;
}
int main() {
  ans = 0;
  cin >> n >> m;
  for(int i = 0;i < m;i++){
    int a,b;
    cin >> a >> b;
    a--;b--;
    data[a][b] = true;
    data[b][a] = true;
  }
  vector<bool>st(8,false);
  dfs(0,-1,1,st);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vi vector<int>
#define vb vector<bool>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
using namespace std;
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
void show(ll x){cout<<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;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
//#define int long long 
#define lb lower_bound
#define mkp make_pair
//#define d double
void solve(){
 
 
	int n;
	cin>>n;
	vi vec(n);
	cin>>vec;
	Sort(vec);
	ll ans=inf;
	for(int i=1;i<=100;i++){
		ll tk=0;
		for(int j=0;j<n;j++){
			tk+=((vec[j]-i)*(vec[j]-i));
		}
		ans=min(ans,tk);
	}
	cout<<ans;
 
 
 
 
 
}
int32_t main(){
int t=1;
//cin>>t;
while(t--){
	solve();
}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h,w;
	cin>>h>>w;
	ll ans=h*w;
	if(h>1 && w>1) cout<<(ans+1)/2<<endl;
	else{
		cout<<1<<endl;
	}
}

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

const int INF = 1e9;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  for (int i = 0; i < M; i++) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }
  int ans = 0;
  for (int m = 0; m < M; m++) {
    vector<vector<int>> G(N, vector<int>(N, INF));
    for (int i = 0; i < N; i++) G[i][i] = 0;
    for (int i = 0; i < M; i++) {
      if (i == m) continue;
      G[a[i]][b[i]] = G[b[i]][a[i]] = 1;
    }

    for (int k = 0; k < N; k++) {
      for (int j = 0; j < N; j++) {
        for (int i = 0; i < N; i++) {
          G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
        }
      }
    }

    int f = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (G[i][j] == INF) f = 1;
      }
    }
    ans += f;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

/**
 * Engines
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            Vector[] V = new Vector[N];
            for (int i = 0; i < N; i++) {
                V[i] = new Vector();
                V[i].x = sc.nextLong();
                V[i].y = sc.nextLong();
            }

            for (Vector v : V) {
                v.r = Math.acos(v.x / Math.sqrt(v.x * v.x + v.y * v.y));
                if (v.y < 0) {
                    v.r = Math.PI * 2 - v.r;
                }
            }

            Arrays.sort(V, (o1, o2) -> Double.compare(o1.r, o2.r));

            double max = 0;

            for (int i = 0; i < N; i++) {
                long X = 0;
                long Y = 0;

                for (int j = i; j < N + i; j++) {
                    X += V[j % N].x;
                    Y += V[j % N].y;

                    double d = Math.sqrt(X * X + Y * Y);

                    if (max < d) {
                        max = d;
                    }
                }
            }

            System.out.println(max);
        }

    }

    static class Vector {

        long x;

        long y;

        double r;

    }

}


Measured memory_bytes: 28500
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int count = 0;
		Scanner sc = new Scanner(System.in);
		int i = sc.nextInt();
		ArrayList<Integer> al = new ArrayList<Integer>(i);
		for(int j = 0; j < i; j++) {
			al.add(sc.nextInt());
		}
		me: while(true) {
			for(int t = 0; t < i; t++) {
				if(al.get(t) % 2 == 0) {
					al.set(t, al.get(t) / 2);
				}else {
					System.out.println(count);
					break me;
				}
			}
			count++;
		}
	}

}

Measured memory_bytes: 22996
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		
		if(x<=W-r && x >=r && y<= H-r && y>= r){
		    System.out.println("Yes");
		}else{
		    System.out.println("No");
		}
	    
	}
    
}


Measured memory_bytes: 26396
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
int main()
{
 //	ios::sync_with_stdio(0);
 //   cin.tie(0);
    lli n;
    cin>>n;
    lli a[n][3];
    for(lli i=0;i<n;i++)cin>>a[i][0]>>a[i][1]>>a[i][2];
    lli ans[n][3];
    ans[0][0]=a[0][0],ans[0][1]=a[0][1],ans[0][2]=a[0][2];
    for(lli i=1;i<n;i++){
    	ans[i][0]=a[i][0]+max(ans[i-1][1],ans[i-1][2]);
    	ans[i][1]=a[i][1]+max(ans[i-1][0],ans[i-1][2]);
    	ans[i][2]=a[i][2]+max(ans[i-1][1],ans[i-1][0]);
	}
    cout<<(max(max(ans[n-1][0],ans[n-1][1]),ans[n-1][2]));
    
    return 0;
}


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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int, int> PI;
typedef pair<int, pair<int, int>> PII;
static const int INF = 1010000000000000017LL;
static const double eps = 1e-12;
static const double pi = 3.14159265358979323846;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};
static const int ddx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
static const int ddy[8] = {0, 0, 1, -1, 1, -1, 1, -1};

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

const int mod=998244353;

struct LazySegmentTree {

public:
    int n;
    vector<int> node, lazy;
    LazySegmentTree(vector<int> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, int x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
            node[k] %= mod;
        }
    }

    int getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        int vl = getsum(a, b, 2*k+1, l, (l+r)/2) % mod;
        int vr = getsum(a, b, 2*k+2, (l+r)/2, r) % mod;
        return (vl + vr) % mod;
    }
};

int N;
int K;
vector<PI> S;

signed main(){
    cin>>N>>K;
    for(int i=0;i<K;++i){
        int l,r;
        cin>>l>>r;
        S.push_back(PI(l,r));
    }
    vector<int> dp(N+5,0);
    dp[1]=1;
    LazySegmentTree seg(dp);
    for(int i=1;i<=N;++i){
        //cout << "i = " << i<< endl;
        //cout << seg.getsum(i,i+1) << endl;
        for(auto s:S){
            int l=i+s.first,r=min(i+s.second,N);
            if(l>r)continue;
            //cout<< l << " " << r << endl;
            seg.add(l,r+1,seg.getsum(i,i+1)%mod);
        }
    }
    cout<<(seg.node[N+seg.n-1]) % mod<<endl;
}

Measured memory_bytes: 14560
//皆さん、第9回シンデレラガール総選挙は、トップでオンリーワンを目指す城ヶ崎美嘉に
//そしてボイスアイドルオーディションは、プログラミングが趣味の才女大石泉に、ぜひ投票をお願いします！
//#城ヶ崎美嘉を009のシンデレラに
//#大石泉の必勝プログラム
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	string s;cin>>s;
	if(s=="ARC") cout<<"ABC"<<endl;else cout<<"ARC"<<endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printYes() printf("Yes\n")
#define printNo() printf("No\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;
 
int main() {
    int n,m,a,b;
    scan2Int(n,m);
    int h[n];
    bool flags[n];
    rep(i, n) {
        cin >> h[i];
        flags[i] = true;
    }
    rep(i, m) {
        scan2Int(a,b);
        a -= 1; b -= 1;
        if (h[a] == h[b])
            flags[a] = flags[b] = false;
        else if (h[a] > h[b])
            flags[b] = false;
        else
            flags[a] = false;
    }
    int count = 0;
    rep(i, n) if (flags[i]) count++;
    printInt(count);
    return 0;
}

Measured memory_bytes: 4272
def get_input_row():
  return [int(i) for i in input().split(" ")]

def calc(n):
  a = n % 4
  if a == 0:
    return n
  elif a == 1:
    return 1
  elif a == 2:
    return n + 1
  elif a == 3:
    return 0
  
A, B = get_input_row()
ans = calc(B)^calc(A-1)
print(ans)

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

#define rep(i,n) for(int i=0; i<(n); i++)
int main(){
     int n;
     cin >> n;
     int a = n / 1000;
     int b = (n % 1000) / 100;
     int c = (n % 100) / 10;
     int d = n % 10;
    
    
    vector<int> x(4);
     
    x[0] = a; x[1] = b; x[2] = c; x[3] = d;
    for(int temp=0; temp<(1<<3); temp++){
        bitset<10> s(temp);
        int t = x[0];
        rep(i, 3){
            if(s.test(i)){
                t += x[i+1];
            }else{
                t -= x[i+1];
            }
        }
        if(t == 7){
            cout << x[0];
            rep(j,3){
                if(s.test(j)){
                    cout << "+";
                }else{
                    cout << "-";
                }
                cout << x[j+1];
            }
            cout <<"="<<7<< endl;
            return 0;
        }
        
    }
    
    

    


}


Measured memory_bytes: 256
N = int(input())
s = set()
pre = ""
flag = True
for i in range(N):
    w = input()
    if len(s) == 0:
        pre = w[-1]
        s.add(w)
        continue
    else:
        if w[0] != pre:
            flag = False
        elif w in s:
            flag = False
        else:
            pre = w[-1]
            s.add(w)

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<numeric>
#include<cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#define ll long long int
#define CON 100010
const long long mod=1e9+7;
const int INF=1001001001;
const int inf=100000;
//const ll inf=1e9+7;
//const ll ful=1e18;
using namespace std;
//namespace mp = boost::multiprecision;
int main() 
{
	int x;
	cin>>x;
	if(x)
	{
		cout<<0<<endl;
	}
	else
	{
		cout<<1<<endl;
	}
	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  while (1) {
    int n, x;
    cin >> n >> x;
    if (n == 0 && x == 0) {
      break;
    }
    int count = 0;
    for (int i = 0; i < x/3; i++) {
      for (int j = 1+i; j < (x-i)/2; j++) {
        for (int k = 1+j; k < n; k++) {
          if (i+j+k+3 == x) {
            count ++;
          }
        }
      }
    }
    cout << count << endl;
  }
}



Measured memory_bytes: 3092
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define MN 300005
using namespace std;
typedef long long ll;
const int mod=998244353;
ll n,a,b,k,fac[MN],inv[MN],ans;
ll C(int x,int y){return fac[x]*inv[x-y]%mod*inv[y]%mod;}
void add(ll &x,ll y){(x+=y)>=mod?x-=mod:0;}
int main(){
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<=300000;i++)fac[i]=fac[i-1]*i%mod,inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	for(int i=2;i<=300000;i++)inv[i]=inv[i]*inv[i-1]%mod;
	scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
	for(int i=0;i<=n;i++){
		if((k-a*i<0)||((k-a*i)%b!=0)||((k-a*i)/b>n))continue;
		int tmp=(k-a*i)/b;
		add(ans,C(n,i)*C(n,tmp)%mod);
	}printf("%lld\n",ans);
}


Measured memory_bytes: 4864
n=int(input())
s=[int(input()) for i in range(n)]
t=sum(s)
if t%10!=0:
  print(t)
else:
  s.sort()
  a=1
  for i in range(n):
    if s[i]%10!=0:
      print(t-s[i])
      a=0
      break
  if a:
    print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    ll ans=1;
    bool flag=false;
    rep(i,n){
        if(a[i]==0){
            cout << 0 << endl;
            return 0;
        }
        if(log10(ans)+log10(a[i])>18){
            flag=true;
        }
        if(!flag)ans*=a[i];
    }
    if(ans>1000000000000000000||flag){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
}

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

#define int long long

signed main() {
    int n;
    cin >> n;
    int a, b;
    int ans = -1;
    int mx = -1;
    while(n--) {
        cin >> a >> b;
        if(a>mx) {
            mx = a;
            ans = a+b;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(300000)
input = sys.stdin.readline
n,q=map(int,input().strip().split())
d=[[] for _ in range(n)]

for _ in range(n-1):
    a,b=map(int,input().split())
    d[a-1].append(b-1)
    d[b-1].append(a-1)
l=[0]*n
for _ in range(q):
    a,b=map(int,input().split())
    l[a-1]+=b
rs=[0]*n

def rr(pa,s,dd,d):
    for c in d[s]:
        if c == pa:
            continue
        rs[c]=l[c]+dd
#        print(c,rs[c],dd)
        rr(s,c,dd+l[c],d)

s,dd=0,l[0]
rs[0] = l[0]
rr(None,s,dd,d)
for r in rs:
    print(r)


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

int main() {
  int n,K,l=0,r=0,memo=0,ans=0;
  float sum;
  //int64_t sum=0;
  cin >>n>>K;
  if (n==1){ans+=300000;}
  else if (n==2){ans+=200000;}
  else if (n==3){ans+=100000;}
  if (K==1){ans+=300000;}
  else if (K==2){ans+=200000;}
  else if (K==3){ans+=100000;}
  if (K==1&&n==1){ans+=400000;}
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int ans=1000;
string s;
int main(void){
    cin>>s;
    for(int i=0;i+2<s.size();i++){
        ans=min(ans,abs((s[i]-'0')*100+(s[i+1]-'0')*10+s[i+2]-'0'-753));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

ans  = 0
n = int(ri())
a = Ri()

maxx = -1
for i in a:
    if  i >= maxx:
        maxx = i
    else:
        ans+= (maxx- i)
print(ans)

Measured memory_bytes: 95588
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

//
void solve(long long N){
  ll sum=0;
 repf(i,1,N+1){
    ll tmp=0;
    ll j=i;
    while(100000){
      tmp++;
      j/=10;
      if(j<=0)break;
    }
    
    if(tmp%2==1) sum++;
  }
  op(sum)
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int n; ll K;
vll w, d;

bool check(ll x){
    ll ret = 0;
    rep(i, n){
        if(x >= w[i]){
            ret += (x - w[i]) / d[i] + 1;
        }
        if(ret >= K) return true;
    }
    return false;
}

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

    cin >> n >> K;
    w = vll(n), d = vll(n);
    rep(i, n) cin >> w[i] >> d[i];

    ll lb = -1, ub = inf;
    while(ub - lb > 1){
        ll mid = (lb + ub) / 2; 

        if(check(mid)){
            ub = mid;
        }
        else {
            lb = mid;
        }
    }
    cout << ub << endl;

    return 0;
}


Measured memory_bytes: 1792
n = gets.chomp.to_i
order = []
i = 1
while i <= n
  arr = gets.chomp.split(' ')
  order << [arr[0],arr[1].to_i,i]
  i += 1
end
# p order

# 順番を作る
i = 0
while i < order.size
  j = i+1
  while j < order.size
    if order[i][0] > order[j][0]
      tmp = order[i]
      order[i] = order[j]
      order[j] = tmp
    elsif order[i][0] == order[j][0] && order[i][1] < order[j][1]
      tmp = order[i]
      order[i] = order[j]
      order[j] = tmp
    end
    #  puts "i:#{order[i]}, j:#{order[j]}, j+1:#{order[j+1]}, a<b#{"kaqqqqqzan"<"moscow"}"
    j += 1
  end
  i += 1
end
# p order
order.each {|x| puts x[2]}

Measured memory_bytes: 13944
S = input()
count = 0
list = []

for c in S:
  if c == 'A' or c == 'C' or c == 'G' or c == 'T':
    count+=1
  else:
    list.append(count)
    count = 0
list.append(count)

if len(list)==0:
    print('0')
else:
    print(max(list))

Measured memory_bytes: 3060
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()
s = accumulate(a)

d = defaultdict(int)
for x in s:
    d[x] += 1

ans = d[0]
for x in d:
    ans += d[x]*(d[x]-1)//2

print(ans)

Measured memory_bytes: 43304
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n, A[100], ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> A[i];
	}
	for (int i = 0; i < n - 1; i++)
	{
		for (int j = n - 1; j > i; j--)
		{
			if (A[j] < A[j - 1])
			{
				swap(A[j], A[j - 1]);
				ans++;
			}
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (i)
		{
			cout << ' ';
			
		}
		cout << A[i];
	}
	cout << endl << ans << endl;

}


Measured memory_bytes: 3088
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

var y []int

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	n := nextInt()
	p := make([]int, n)
	q := make([]int, n)
	for i := 0; i < n; i++ {
		p[i] = nextInt()
	}
	for i := 0; i < n; i++ {
		q[i] = nextInt()
	}
	y = make([]int, n)
	for i := 0; i < n; i++ {
		y[i] = i + 1
	}
	p_num := -1
	q_num := -1
	i := 0
	for {
		// log.Println(y, p, q)
		if equal(p, y) {
			// log.Println("equal", p, y)
			p_num = i
		}
		if equal(q, y) {
			// log.Println("equal", q, y)
			q_num = i
		}
		i++
		if !next_permutation(sort.IntSlice(y), len(y)) {
			break
		}
	}
	// log.Println(p_num, q_num)
	fmt.Println(abs(p_num - q_num))
}

func equal(a []int, b []int) bool {
	if len(a) != len(b) {
		return false
	}
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func reverse(a sort.Interface, start int, size int) {
	for end := start + size - 1; start < end; start++ {
		a.Swap(start, end)
		end--
	}
}
func next_permutation(a sort.Interface, n int) bool {
	if n < 0 || a.Len() < n {
		return false
	}
	reverse(a, n, a.Len()-n)
	i := 0
	for i = a.Len() - 2; i >= 0; i-- {
		if a.Less(i, i+1) {
			break
		}
	}
	if i < 0 {
		reverse(a, 0, a.Len())
		return false
	}
	k := i
	for i = a.Len() - 1; i >= k+1; i-- {
		if a.Less(k, i) {
			break
		}
	}
	l := i
	a.Swap(k, l)
	reverse(a, k+1, a.Len()-(k+1))
	return true
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
using namespace std;

int main()
{
    int d;
    cin >> d;
    string ans = "Christmas Eve Eve Eve";
    int size = ans.size();
    for(int i = 0; i <= d - 22; ++i){
        ans = ans.substr(0, size);
        size -= 4;
    }
    cout << ans;

    return 0;
}

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

int main() {
    long long a, b, c, d, x, y;
    cin >> a >> b >> c >> d;
    x = max( a*c, b*d );
    y = max( a*d, c*b );
    x = max(x,y);
    cout << x << endl;


    return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  std::string X;
  std::cin >> X;
  const i64 N = X.size();

  i64 answer = N;
  i64 nest = 0;
  for (i64 i = 0; i < N; ++i) {
    if (X[i] ==  'S') {
      ++nest;
    } else if (X[i] == 'T') {
      if (nest > 0) {
        --nest;
        answer -= 2;
      }
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val dList = readIntegerList()
    val dMap = elementCountMap(dList)

    val m = readInteger()
    val tList = readIntegerList()
    val tMap = elementCountMap(tList)

    for (e in tMap) {
        val dCount = dMap.getOrDefault(e.key, 0)
        if (dCount < e.value) {
            out.print("NO")
            return
        }
    }
    out.println("YES")
}

/** O(n) */
fun <T>elementCountMap(list: List<T>): Map<T, Int> {
    val countMap = mutableMapOf<T, Int>()
    for (e in list) {
//        countMap[e] = (countMap[e] ?: 0) + 1
        countMap.merge(e, 1) { oldValue, value -> oldValue + value }
    }
    return countMap
}


fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 88184
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	
	while(1){
		int n;
		cin >> n;
		if(n==0)
			break;

		int c[100000];

		int m1[100000];
		int m2[100000];
		int m3[100000];
		int m4[100000];
	
		int s1[100000];
		int s2[100000];
		int s3[100000];
		int s4[100000];
		
		int ans[100000];
		int ans2[100000];
		int ans3[100000];
		for(int i=0;i<n;i++){
			cin >> c[i] >> m1[i] >> s1[i] >> m2[i] >> s2[i] >> m3[i] >> s3[i] >> m4[i] >> s4[i];
			ans[i] = (m1[i]+m2[i]+m3[i]+m4[i])*60+s1[i]+s2[i]+s3[i]+s4[i];
			ans2[i] = (m1[i]+m2[i]+m3[i]+m4[i])*60+s1[i]+s2[i]+s3[i]+s4[i];
			ans3[i] = (m1[i]+m2[i]+m3[i]+m4[i])*60+s1[i]+s2[i]+s3[i]+s4[i];
		}

		sort(ans, ans + n);
		sort(ans2, ans2 + n, greater<int>());

		for(int i=0;i<2;i++){
			for(int j=0;j<n;j++){
				if(ans[i] == ans3[j]){
					cout << c[j] << endl;
				}
			}
		}
		
		for(int i=0;i<n;i++){
			if(ans2[1] == ans3[i]){
				cout << c[i] << endl;
			}
		}

	}
		

		
	
	return 0;
}

Measured memory_bytes: 5304