akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

string s;
int x, y;
int main()
{
  cin >> s >> x >> y;
  bitset< 2 * 8000 > dpx, dpy;
  int cnt = 0, first = 0, N = s.size();
  while (s[first++] == 'F');
  dpx[8000 + --first] = dpy[8000] = 1;

  bool isX = true;
  for (int i = first; i < N; ++i) {
    if (s[i] == 'F') cnt++;
    if (s[i] == 'T' || i == N - 1) {
      bitset< 2 * 8000 > pd;
      if (isX) {
	pd = (dpx << cnt) | (dpx >> cnt);
	swap(dpx, pd);
      } else {
	pd = (dpy >> cnt) | (dpy << cnt);
	swap(dpy, pd);
      }
      isX = !isX;
      cnt = 0;
    }
  }

  cout << (dpx[x + 8000] && dpy[y + 8000] ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;

int main()
{
    fastio;
    int N;
    vector<int> As;
    cin >> N;
    copy_n(istream_iterator<int>(cin), N, back_inserter(As));
    bool odd_found = false;

    int count = 0;
    while (!odd_found)
    {
        for (auto &&a : As)
        {
            if ((a % 2) == 1)
            {
                odd_found = true;
                break;
            }
            a /= 2;
        }
        if (!odd_found)
        {
            count++;
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main() {
	int n, m, j, suu;
	while ((cin >> m >> n) && m != 0 || n != 0) {
		int check[1001] = { 0 };
		for (int i = 1; i <= m; i++)check[i] = i;
		j = 1;
		suu = m;
		for (int i = 1; i <= n; i++) {
			string str;

			cin >> str;
			if (suu > 1) {
				if (i % 15 == 0) {
					if (str != "FizzBuzz") {
						check[j] = 0;
						suu--;
					}
				}
				else if (i % 3 == 0) {
					if (str != "Fizz") {
						check[j] = 0;
						suu--;
					}
				}
				else if (i % 5 == 0) {
					if (str != "Buzz") {
						check[j] = 0;
						suu--;
					}
				}
				else {
					char buf[10] = { NULL };
					sprintf(buf, "%d", i);
					if (str != buf) {
						check[j] = 0;
						suu--;
					}
				}
				j++;
				int x;
				if (suu>1)
					for (x = j; check[x] == 0;) {
						x++;
						if (x > m)x = 1;
					}
				j = x;
			}
		}
		int las;
		for (int i = m; i > 0; i--) if (check[i] != 0) {
			las = i; break;
		}
		for (int i = 1; i <= m; i++)
		{
			if (check[i] != 0)
			{
				cout << i;
				if (i<las)
					cout << " ";
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 3212
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
  let mut line: String = String::new();
  io::stdin().read_line(&mut line);
  line.trim().parse().ok().unwrap()
}

fn input_i32_vec() -> Vec<i32> {
  let mut line: String = String::new();
  io::stdin().read_line(&mut line);
  line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn calc_exponent(n: i32) -> i32 {
  let mut i: i32 = 0;
  let mut div = 2;
  loop {
    if n % div == 0 {
      i += 1;
      div *= 2;
    } else {
      return i
    }
  }
}

fn main() {
  let n: i32 = input();
  let a = input_i32_vec();
  let mut sum = 0;
  for i in a {
    sum += calc_exponent(i);
  }
  println!("{}", sum);
}


Measured memory_bytes: 4352
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
using vi = vector<int>;
using vpii = vector<pii>;
template<class T, class T2> using umap = unordered_map<T, T2>;
template<class T> using uset = unordered_set<T>;
#define ALL(a) a.begin(),a.end()
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a) for(int i=1;i<=a;i++)
int main() {
	int n;
	while (cin >> n,n) {
		vector<vector<int>> buf(n);
		for (auto &a : buf) {
			int m;
			cin >> m;
			while (m--) {
				int b;
				cin >> b;
				a.push_back(b);
			}
			sort(ALL(a));
		}
		vi l;
		int m;
		cin >> m;
		while (m--) {
			int b;
			cin >> b;
			l.push_back(b);
		}
		int cnt = 0;
		int ans;
		rep(i, buf.size()) {
			auto &a = buf[i];
			bool f = 1;
			for (auto b : l) {
				if (!binary_search(ALL(a), b)) {
					f = 0;
					break;
				}
			}
			if (f) {
				cnt++;
				ans = i;
			}
		}
		cout << (cnt == 1 ? ans + 1 : -1) << endl;
	}
}

Measured memory_bytes: 3196
#include<stdio.h>

int main()
{

bool num[1001]={};
int N,M;
int ii=0,L=0,nn=0;
int cou=0;
while(1){
scanf("%d %d",&N,&M);
if(N==0&&M==0)break;
for(int i=0;i<1000;i++)
num[i]=true;

while(1){
	if(cou==(M-1)&&num[ii]==true){cou=0;num[ii]=false;nn++;}
	else if(num[ii]==true){cou++;}

L=(ii+1);
ii=L%N;
if(nn==(N-1))break;


}

for(int i=0;i<N;i++){int t=i+1;
if(num[i]==true)printf("%d\n",t);}
ii=0;cou=0;nn=0;
for(int i=0;i<1000;i++)
num[i]=true;}
return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define int ll
#define For(a, b, c) for(int a = b; a <= c; ++a)
#define Ford(a, b, c) for(int a = b; a >= c; --a)
#define All(a, b) for(auto &a : b)
#define Rep(a, b, c) for(int a = b; a < c; ++a)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(),a.end()
#define reset(a, b) memset(a, b, sizeof(a))
#define bit(x, i) (x >> (i - 1) & 1ll)
#define onbit(x, i) (x | (1ll << (i - 1)))
#define offbit(x, i) (x & ~(1ll << (i - 1)))
#define bitone(i) __builtin_popcountll(i)
#define bitl(i) __builtin_clz(i)
#define bitr(i) __builtin_ctz(i)
#define vll vector<ll>
/********************************************************

Digvijay Bahadur Singh
MNNIT

*********************************************************/


const int MOD=998244353;
const int N = 1e6+100;
/********************************************************************/
                 /* GRAPH*/
//vector<vector<ll>> g;
//vector<bool> vis1,vis2;
/*******************************************************************/
ll power(ll a,ll b)
{
   ll ans =1;
   while(b>0){
   if(b&1) ans = (ans%MOD * a%MOD)%MOD;
   a = (a%MOD * a%MOD)%MOD;
   b=b>>1;
   }
   return ans%MOD;
}
struct triple
{
  int f,s,t;
};
bool comp(triple x,triple y)
{
  if(x.f==y.f)
  {
    return x.s>y.s;
  }
  return x.f<y.f;
}
signed main(){
  ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
  
  
  ll T=1;
 //cin>>T;
  
   // T=1;
    
    while(T--)
  {
     int n,m;
     cin>>n>>m;
     int ans;
     ans= (n)*(n-1)/2 +(m)*(m-1)/2;
     cout<<ans<<"\n";
       
   
  

   
 


      

  }

  
}


Measured memory_bytes: 256
#include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
#include <math.h>
#include <sstream>

using namespace std;
int main(void){
    while(true){
        int n,a,b,c,x;
        cin>>n>>a>>b>>c>>x;
        if(n==0&&a==0&&b==0&&c==0&&x==0)break;
        int in[n];
        for(int i=0;i<n;i++)cin>>in[i];
        int cnt=0,sw=0;
        while(true){
            if(x==in[sw])sw++;
            if(sw==n)break;
            x=(a*x+b)%c;
            if(cnt==10001)break;
            cnt++;
        }
        if(cnt==10001)cout<<"-1\n";
        else cout<<cnt<<endl; 
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
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;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n; cin >> n;
    vector<long long> vec(n);
    for(long long i = 0; i < n; i ++){
        cin >> vec[i];
    }
    sort(all(vec),greater<ll>());

    priority_queue<ll> pq;
    ll ans = 0;
    rep(i, n){
        if(i == 0){
            pq.push(vec[i]);
            continue;
        }

        ans += pq.top();
        pq.pop();
        pq.push(vec[i]);
        pq.push(vec[i]);
        //cout << ans << endl;
    }

    cout << ans << endl;

}

Measured memory_bytes: 6904
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

void ARC083D()
{
	int N;
	cin >> N;
	vector<vector<ll> > A(N, vector<ll>(N));
	priority_queue<pair<ll, pair<int, int> >, vector<pair<ll, pair<int, int> > >, greater<pair<ll, pair<int, int> > > >  qu;
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < N; ++j)
		{
			ll x;
			cin >> x;
			A[i][j] = x;
			if (j > i)
				qu.push({ x, {i,j} });
		}
	}

	struct Edge {
		int to_;
		ll dist_;
	};
	vector<vector<Edge> > graph(N);
	vector<vector<ll> > dist(N, vector<ll>(N, 100000000000000000));
	for (int i = 0; i < N; ++i)
	{
		dist[i][i] = 0;
	}

	ll total = 0;
	while (!qu.empty())
	{
		auto p = qu.top();
		qu.pop();
		int x1 = p.second.first;
		int x2 = p.second.second;

		if (dist[x1][x2] <= p.first)
			continue;
		graph[x1].push_back({ x2, p.first });
		graph[x2].push_back({ x1, p.first });
		total += p.first;
		for (int i = 0; i < N; ++i)
		{
			for (int j = 0; j < i; ++j)
			{
				dist[i][j] = min(dist[i][j], min(dist[i][x1] + dist[x2][j], dist[i][x2] + dist[x1][j]) + p.first);
				dist[j][i] = dist[i][j];
				if (dist[i][j] < A[i][j])
				{
					cout << -1 << endl;
					return;
				}
			}
		}
	}
	cout << total << endl;
}

int main()
{
	ARC083D();
	return 0;
}

Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr<<x<<END;
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i) 
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 1e18;
int calc(int n) 
{  
    int r = 7;  
    loop(i,1,1e7+1)
    { 
        r = (r * 10 + 7) % n; 
        if(r == 0) 
         return i+1;
    }  
    return -1; 
}
void solve()
 {
  int n;
  cin>>n; 
  if(n == 1 || n==7)
   cout<<1;
  else
	cout<<calc(n);  
 }  
signed main()
 {   
  ios_base::sync_with_stdio(false);
  cin.tie(0); 
  cout.tie(0); 
   /*int t;
   cin>>t;
   loop(i,1,t+1)*/
      solve();
      
  //cerr<<END<<1.0*clock();
  return 0;
} 


Measured memory_bytes: 3644
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=1e9+7;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=2e6+5;
int fac[N],ifac[N];
void init(int n=2e6){
	fac[0]=ifac[0]=1;fp(i,1,n)fac[i]=mul(fac[i-1],i);
	ifac[n]=ksm(fac[n],P-2);fd(i,n-1,1)ifac[i]=mul(ifac[i+1],i+1);
}
inline int C(R int n,R int m){return m>n?0:1ll*fac[n]*ifac[m]%P*ifac[n-m]%P;}
inline int calc(R int x,R int y,R int xx,R int yy){
	return x>xx||y>yy?0:C(xx-x+yy-y,xx-x);
}
int x[15],y[15],res;
inline int get(int sx,int sy,int tx,int ty){
	R int res=0;
	fp(i,x[3],x[4]){
		upd(res,1ll*(P-y[3]-i)*calc(sx,sy,i,y[3]-1)%P*calc(i,y[3],tx,ty)%P);
		upd(res,1ll*(y[4]+1+i)*calc(sx,sy,i,y[4])%P*calc(i,y[4]+1,tx,ty)%P);
	}
	fp(j,y[3],y[4]){
		upd(res,1ll*(P-x[3]-j)*calc(sx,sy,x[3]-1,j)%P*calc(x[3],j,tx,ty)%P);
		upd(res,1ll*(x[4]+1+j)*calc(sx,sy,x[4],j)%P*calc(x[4]+1,j,tx,ty)%P);
	}
	return res;
}
int solve(int sx,int sy){
	R int res=0;
	upd(res,get(sx,sy,x[5],y[5])),
	upd(res,get(sx,sy,x[6]+1,y[6]+1)),
	upd(res,P-get(sx,sy,x[5],y[6]+1)),
	upd(res,P-get(sx,sy,x[6]+1,y[5]));
	return res;
}
int main(){
//	freopen("testdata.in","r",stdin);
	init();
	fp(i,1,6)scanf("%d",&x[i]);
	fp(i,1,6)scanf("%d",&y[i]);
	upd(res,solve(x[1]-1,y[1]-1)),
	upd(res,solve(x[2],y[2])),
	upd(res,P-solve(x[2],y[1]-1)),
	upd(res,P-solve(x[1]-1,y[2]));
	printf("%d\n",res);
	return 0;
}

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

int cnt[252521];

int main() {
	int n, a, b, i;
	
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> a >> b;
		cnt[a + b]++;
	}
	
	for (i = 0; i < 252500; i++) {
		cnt[i + 1] += cnt[i] / 2;
		cnt[i] %= 2;
	}
	
	for (i = 0; i < 252500; i++) {
		if (cnt[i]) {
			cout << i << " " << 0 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 4076
fun main(args: Array<String>) {
    // Your code here!
    val (k,x) = readLine()!!.split(" ").map{it.toInt()}
    val max = 1000000
    val min = -1000000
    var sta = Math.max(x-(k-1),-1000000)
    var fin = Math.min(x+(k-1),1000000)
    
    for(i in sta..fin){
        print(i)
        print(" ")
    }
}


Measured memory_bytes: 37956
n = gets.chomp.to_i

a, b = gets.chomp.split(" ").map(&:to_i)

q1 = 0
q2 = 0
q3 = 0

q = gets.chomp.split(" ").map(&:to_i)

q.each do |x|
  if x > b
    q3 += 1
  elsif x > a
    q2 += 1
  else
    q1 += 1
  end
end

puts [q1, q2, q3].min


Measured memory_bytes: 1788
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

using namespace std;


double Distance[4];

int main() {
	int n;
	int x[101], absxy[101];

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < n; i++) {
		int y;
		cin >> y;
		absxy[i] = abs(x[i] - y);
	}

	for (int p = 0; p < 3; p++) {
		for (int i = 0; i < n; i++) {
			Distance[p] += pow(absxy[i], p + 1);
		}
			Distance[p] = pow(Distance[p], (double)1.0f / (p + 1));
	}
	Distance[3] = absxy[0];
	for (int i = 1; i < n; i++) {
		if (Distance[3] < absxy[i])
			Distance[3] = absxy[i];
	}

	for (int p = 0; p < 4; p++) {
		printf("%f\n", Distance[p]);
	}

	return 0;
}

Measured memory_bytes: 1248
X=int(input())
#X=615
DP=[0 for i in range(X+1)]
DP[0]=1
C=[100,101,102,103,104,105]
for i in range(6):
    for j in range(X+1):
        if DP[j]==1 and j+C[i]<=X:
            DP[j+C[i]]=1
print(DP[X])

Measured memory_bytes: 3864
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
int const M=2e5+10,mod=1e9+7,inf=1e9+10;
vector<string>ans;
main()
{
	string x;
	cin>>x;
	int k;
	cin>>k;
	for(int i=0;i<x.size();i++)
	{
		string now="";
		for(int j=i;j<=i+k;j++)
		{
			if(j==(int)x.size())break;
			now+=x[j];
			ans.pb(now);
		}
	}
	sort(ans.begin(),ans.end());
	int cnt=0;
	for(int i=0;i<ans.size();i++)
	{
		if(i==0 || ans[i]!=ans[i-1])cnt++;
		if(cnt==k)return cout<<ans[i],0;
	}
}

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

int mod = 1000000007;

int main()
{
    int N, M, x, y, sum = 0;
    cin >> N;
    vector<int> list(N);
    for (int i = 0; i < N; i++)
    {
        cin >> list[i];
        sum += list[i];
    }
    cin >> M;
    for (int i = 0; i < M; i++)
    {
        cin >> x >> y;
        cout << sum - list[x - 1] + y << endl;
    }
}

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

#define mp                  make_pair
#define pb                  push_back
#define f                   first
#define s                   second
#define F                   first
#define S                   second
#define clr(a, b)           memset(a, b, sizeof(a))
#define fore(i, b, e)       for(ll i = b; i < e; i++)
#define forr(i, b, e)       for(ll i = b; i < e; i++)
#define forg(i, b, e,au)    for(ll i = b; i < e; i+=au)
using namespace std;


typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
const ll tam = 4000;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1);
int sum[tam],nxt[tam];
int dp[tam][tam];
void MODUL(int &num)
{
    while(num>=MOD)num-=MOD;
}
int main()
{
    int n,m;
    cin>>n>>m;
    string txt;
    cin>>txt;
    sum[0]=0;
    forr(i,0,txt.size())
    {
        sum[i+1]=sum[i]+txt[i]-'0';
    }
    sum[n+1]=sum[n];
    int iz,der;
    forr(i,0,tam)
        nxt[i]=i;
    forr(i,0,m)
    {
        cin>>iz>>der;
        forr(j,iz,der+1)
        {
            nxt[j]=max(nxt[j],der);
        }
    }
    /*forr(i,1,n+1)
    cout<<nxt[i]<<' ';
    cout<<endl;*/
    int cantini=sum[nxt[1]],R,newR,nuevo;
    //cout<<cantini<<' ';
    dp[1][cantini]=1;
    int c0,c1;
    forr(L,1,n+1)
    {
        R=nxt[L];
        newR=nxt[L+1];
        nuevo=sum[newR]-sum[R];
        forr(c,0,n+1)
        {
            c0=R-L+1-c;
            c1=c;
            if (c0>0)
                dp[L+1][c+nuevo]+=dp[L][c],MODUL(dp[L+1][c+nuevo]);
            if (c1>0)
                dp[L+1][c+nuevo-1]+=dp[L][c],MODUL(dp[L+1][c+nuevo-1]);
        }
    }
    cout<<dp[n+1][0]<<endl;
}


Measured memory_bytes: 47360
def resolve():
    N = int(input())
    t = dict()
    ans = 0
    for i in range(N):
        n = int(input())
        is_exists = t.get(n, False)
        if not is_exists:
            ans += 1
            t[n] = True
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 38256
// https://atcoder.jp/contests/abc087/tasks/abc087_b

#include <iostream>
using namespace std;
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))

int main() {
  int a, b, c, x, t, cnt = 0;
  cin >> a >> b >> c >> x;

  // 500円玉の枚数ループ
  for (int i = 0; i <= a; i++) {
    // 100円玉の枚数ループ
    for (int j = 0; j <= b; j++) {
      // 手持ちの50円玉の枚数で合計金額を満たせるか
      t = (x - (i * 500 + j * 100)) / 50;
      if (t < 0)
        break;
      else if (t <= c)
        cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<char,int> pci;
typedef vector<pair<int,int>> vpii;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
#define sci(a) scanf("%d",&a)
#define scii(a,b) scanf("%d %d",&a,&b)
#define sciii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sciiii(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld %lld",&a,&b)
#define sclll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c
#define scllll(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define print(a) printf("%d ",a)
#define println(a) printf("%d\n",a)
#define ln printf("\n")
#define pb(a) push_back(a)
#define m_p(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define rep(i,s,n) for(int i=s;i<=n;i++)
#define rrep(i,e,s) for(int i=e;i>=s;i--)
#define repv(i,m) for(auto i = m.begin();i != m.end();i++)
#define FileIO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const long long INF = 4000000000000000000LL;
/************************************* Chocolate *************************************/
const int mod = 1e9+7;
#define white 0
#define black 1
vvi dp,grp;
void dfs(int node,int par){
    dp[node][white] = dp[node][black] = 1;
    for(int v:grp[node]){
        if(v == par) continue;
        dfs(v,node);
        dp[node][black] = (1LL * dp[node][black] * dp[v][white])%mod;
        dp[node][white] = (1LL * dp[node][white] * (dp[v][white] + dp[v][black])%mod)%mod;
    }
}
int main(){
    int n;
    sci(n);
    grp.resize(n+1);
    dp.resize(n+1,vi(2));
    rep(i,1,n-1){
        int u,v;
        scii(u,v);
        grp[u].pb(v);
        grp[v].pb(u);
    }
    dfs(1,-1);
    cout << (dp[1][white]+dp[1][black])%mod << endl;
}

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

using namespace std;
int visited[1000001];

bool printDivisors(int n) 
{ 
    if (visited[n] > 1) {
        return false;
    }
     
    for (int i=2; i<=sqrt(n); i++) { 
        if (n%i == 0) { 
            if(visited[i] > 0 || visited[n/i] > 0) {
                return false;
            } 
        } 
        
    }
    
    return true;
} 

int main()
{
    int n;
    cin>>n;
    int arr[n];
    int ans=0;
    
    for(int i=0;i<1000001;i++){
        visited[i]=0;
    }
    
    for(int i=0;i<n;i++){
        cin>>arr[i];
        visited[arr[i]]++;
    }
    
    if(visited[1]==1){
        cout<<"1";
        return 0;
    }
    
    if(visited[1]>1){
        cout<<"0";
        return 0;
    }
    
    for(int i=0;i<n;i++){
        if(printDivisors(arr[i])){
            ans++;
        }
    }
    
    cout<< ans;
    return 0;
}



Measured memory_bytes: 8364
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <stdlib.h>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==0) break;
		int m,mm;
		cin>>m;
		int x[m],y[m];
		for(int i=0;i<m;i++){
			cin>>x[i]>>y[i];
		}
		for(int i=0;i<n;i++){
			cin>>mm;
			int xx[mm],yy[mm];
			for(int j=0;j<mm;j++){
				cin>>xx[j]>>yy[j];
			}
			if(m!=mm){
				goto end;
			}
			int h1,h2,k1,k2;
			int sa;
			if(x[1]-x[0]>0){
				h1=0;
				k1=x[1]-x[0];
			}
			else if(y[1]-y[0]>0){
				h1=1;
				k1=y[1]-y[0];
			}
			else if(x[1]-x[0]<0){
				h1=2;
				k1=x[0]-x[1];
			}
			else if(y[1]-y[0]<0){
				h1=3;
				k1=y[0]-y[1];
			}
			if(xx[1]-xx[0]>0){
				h2=0;
				k2=xx[1]-xx[0];
			}
			else if(yy[1]-yy[0]>0){
				h2=1;
				k2=yy[1]-yy[0];
			}
			else if(xx[1]-xx[0]<0){
				h2=2;
				k2=xx[0]-xx[1];
			}
			else if(yy[1]-yy[0]<0){
				h2=3;
				k2=yy[0]-yy[1];
			}
			sa=(h2+4-h1)%4;
			if(k1!=k2){
				goto aida;
			}
			for(int j=1;j<m-1;j++){
				if(x[j+1]-x[j]>0){
					h1=0;
					k1=x[j+1]-x[j];
				}
				else if(y[j+1]-y[j]>0){
					h1=1;
					k1=y[j+1]-y[j];
				}
				else if(x[j+1]-x[j]<0){
					h1=2;
					k1=x[j]-x[j+1];
				}
				else if(y[j+1]-y[j]<0){
					h1=3;
					k1=y[j]-y[j+1];
				}
				if(xx[j+1]-xx[j]>0){
					h2=0;
					k2=xx[j+1]-xx[j];
				}
				else if(yy[j+1]-yy[j]>0){
					h2=1;
					k2=yy[j+1]-yy[j];
				}
				else if(xx[j+1]-xx[j]<0){
					h2=2;
					k2=xx[j]-xx[j+1];
				}
				else if(yy[j+1]-yy[j]<0){
					h2=3;
					k2=yy[j]-yy[j+1];
				}
				if(k2!=k1||(h1+sa)%4!=h2){
					goto aida;
				}
			}
			cout<<i+1<<endl;
			goto end;
			aida:;
			if(x[m-2]-x[m-1]>0){
				h1=0;
				k1=x[m-2]-x[m-1];
			}
			else if(y[m-2]-y[m-1]>0){
				h1=1;
				k1=y[m-2]-y[m-1];
			}
			else if(x[m-2]-x[m-1]<0){
				h1=2;
				k1=x[m-1]-x[m-2];
			}
			else if(y[m-2]-y[m-1]<0){
				h1=3;
				k1=y[m-1]-y[m-2];
			}
			if(xx[1]-xx[0]>0){
				h2=0;
				k2=xx[1]-xx[0];
			}
			else if(yy[1]-yy[0]>0){
				h2=1;
				k2=yy[1]-yy[0];
			}
			else if(xx[1]-xx[0]<0){
				h2=2;
				k2=xx[0]-xx[1];
			}
			else if(yy[1]-yy[0]<0){
				h2=3;
				k2=yy[0]-yy[1];
			}
			sa=(h2+4-h1)%4;
			if(k1!=k2){
				goto end;
			}
			for(int j=1;j<m-1;j++){
				if(x[m-j-2]-x[m-j-1]>0){
					h1=0;
					k1=x[m-j-2]-x[m-j-1];
				}
				else if(y[m-j-2]-y[m-j-1]>0){
					h1=1;
					k1=y[m-j-2]-y[m-j-1];
				}
				else if(x[m-j-2]-x[m-j-1]<0){
					h1=2;
					k1=x[m-j-1]-x[m-j-2];
				}
				else if(y[m-j-2]-y[m-j-1]<0){
					h1=3;
					k1=y[m-j-1]-y[m-j-2];
				}
				if(xx[j+1]-xx[j]>0){
					h2=0;
					k2=xx[j+1]-xx[j];
				}
				else if(yy[j+1]-yy[j]>0){
					h2=1;
					k2=yy[j+1]-yy[j];
				}
				else if(xx[j+1]-xx[j]<0){
					h2=2;
					k2=xx[j]-xx[j+1];
				}
				else if(yy[j+1]-yy[j]<0){
					h2=3;
					k2=yy[j]-yy[j+1];
				}
				if(k2!=k1||(h1+sa)%4!=h2){
					goto end;
				}
			}
			cout<<i+1<<endl;
			end:;
		}
		cout<<"+++++"<<endl;
	}
    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#include <vector>
#include <string>
using namespace std;
#define FL(i,a,b) for(int i = a;i<b;i++)
typedef vector<int> vi;
typedef long long int lli;
const int inf = numeric_limits<int>::max();




int main(){
    int n;int k;
    cin>>n>>k;
    
    unordered_set<int> s;
    for(int snak = 0;snak<k;snak++){
        int d;
        cin>>d;
        for(int j = 0;j<d;j++){
            int a;
            cin>>a;
            s.insert(a);
        }
    }
    int z = s.size();
    cout<<n-z;
}




Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A,B,i;
    string S;
    cin >> A >> B;
    cin >> S;
    if(S.size() == A + B + 1){
        for(i = 0; i < S.size(); i++){
            if(S[i] == '-' && i != A){
                cout << "No" << endl;
                return 0;
            }
            
        }
    }
    else{
        cout << "No" << endl;
    }
   if(S[A] == '-'){
        cout << "Yes" << endl;
        return 0;
   }
   cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
        char c[8][8];
        for(int i = 0; i < 8; i++){
                for(int j = 0; j < 8; j++){
                        cin >> c[i][j];
                }  
        }  
        cout << 90 << endl;
        for(int i = 0; i < 8; i++){
                for(int j = 0; j < 8; j++){
                        cout << c[7-j][i];
                }  
                cout << endl;
        }  
        cout << 180 << endl;
        for(int i = 0; i < 8; i++){
                for(int j = 0; j < 8; j++){
                        cout << c[7-i][7-j];
                }  
                cout << endl;
        }  
        cout << 270 << endl;
        for(int i = 0; i < 8; i++){
                for(int j = 0; j < 8; j++){
                        cout << c[j][7-i];
                }  
                cout << endl;
        }  
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

double x[1010], y[1010];
int main()
{
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    cout << fixed << setprecision(3);

    string s;
    while (cin >> s)
    {
        int n = s.size();
        string ans = "";
        for (int i = 0; i < n; ++i)
        {
            if (s[i] == '@')
            {
                i++;
                for (int j = 0; j < s[i] - '0'; ++j)
                {
                    ans += s[i + 1];
                }
                i++;
            }
            else
            {
                ans += s[i];
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3152
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int main()
{
	long N, M;
	cin >> N >> M;
	
	vector<long> P(M);
	vector<pair<pair<long, long>, long>> cities(M);
	
	for (long i = 0; i < M; i++)
	{
		long Y;
		cin >> P[i] >> Y;
		
		cities[i] = make_pair(make_pair(Y, P[i]), i);
	}
	
	// 昇順にソート
	sort(cities.begin(), cities.end());
	
	vector<long> number(M);
	vector<long> count(N + 1);
	for (long i = 0; i < cities.size(); i++)
	{
		// 県に属した市iのカウントを割り振る
		count[cities[i].first.second]++;
		// 入力時に割り当てた順番で並んだ番号の配列に県に属した市iのカウント数を代入する
		number[cities[i].second] = count[cities[i].first.second];
	}
	
	for (long i = 0; i < M; i++)
	{
		// ゼロ埋め対応
		cout << setfill('0') << right << setw(6) << P[i];
		cout << setfill('0') << right << setw(6) << number[i];
		// 改行
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 6272
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TemplateAlgorithm
{
    class Program
    {
        public const long Inf = (long)1e18;
        public const double eps = 1e-6;
        public const string alfa = "abcdefghijklmnopqrstuvwxyz";
        public const string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        public const int MOD = 1000000007;
        
        // c ot i
        static int ToInt(char c) => c - '0';

        static void Main(string[] args)
        {
            int n = IO.ReadInt();
            var s = IO.ReadStr();
            int max = 0;
            int x = 0;
            for (var i = 0; i < n; i++)
            {
                if (s[i] == 'I') x++;
                else x--;
                max = Max(x, max);
            }
            WriteLine(max);
        }

        #region  範囲

        public static bool InRange<T>(T begin, T end, T value) where T : IComparable<T> 
            => value.CompareTo(begin) >= 0 && value.CompareTo(end) <= 0;

        #endregion

        #region MIN,MAX

        /// <summary>
        /// 最大値を返す
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="vals"></param>
        /// <returns></returns>
        public static T MaxValue<T>(params T[] vals) => vals.Max();

        /// <summary>
        /// 最小値を返す
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="vals"></param>
        /// <returns></returns>
        public static T MinValue<T>(params T[] vals) => vals.Min();
        #endregion
    }

    #region IO

    /// <summary>
    /// IO
    /// </summary>
    public class IO
    {
        public static string ReadStr(bool isTrim = false) => (isTrim) ? ReadLine().Trim() : ReadLine();
        public static int ReadInt() => int.Parse(ReadStr());

        public static long ReadLong() => long.Parse(ReadStr());

        public static decimal ReadDecimal() => decimal.Parse(ReadStr());
        public static double ReadDouble() => double.Parse(ReadStr());
        public static string[] ReadStrArr(char separator = ' ') => ReadLine().Split(separator);
        public static int[] ReadIntArr() => Array.ConvertAll(ReadStrArr(), int.Parse);
        public static long[] ReadLongArr() => Array.ConvertAll(ReadStrArr(), long.Parse);

        public static decimal[] ReadDecimalArr() => Array.ConvertAll(ReadStrArr(), decimal.Parse);
        public static double[] ReadDoubleArr() => Array.ConvertAll(ReadStrArr(), double.Parse);        
    }

    #endregion    
}


Measured memory_bytes: 11092
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			int[] etimes = new int[1000];
			int[] times = new int[1000];
			String currentDay = "";
			for (int i = 0; i < n; i++) {
				String day = sc.next();
				String time = sc.next();
				char io = sc.next().charAt(0);
				int id = sc.nextInt();
				if (!day.equals(currentDay)) {
					currentDay = day;
					for (int j = 1; j < 1000; j++)
						if (etimes[i] != 0) {
							etimes[i] = 0;
							if (etimes[0] != 0)
								etimes[i] += 24 * 60 - 1 - etimes[i];
						}
					etimes[0] = 0;
				}
				if (io == 'I') {
					String[] s = time.split(":");
					int t = Integer.parseInt(s[0]) * 60
							+ Integer.parseInt(s[1]);
					etimes[id] = t;
				} else {
					String[] s = time.split(":");
					int otimes = Integer.parseInt(s[0]) * 60
							+ Integer.parseInt(s[1]);
					if (id == 0) {
						for (int j = 1; j < 1000; j++)
							if (etimes[j] != 0)
								times[j] += otimes
										- Math.max(etimes[0], etimes[j]);
					} else if (etimes[0] != 0)
						times[id] += otimes - Math.max(etimes[0], etimes[id]);
					etimes[id] = 0;
				}
			}
			int result = 0;
			for (int i = 1; i < 1000; i++) {
				result = Math.max(result, times[i]);
			}
			System.out.println(result);
		}
		sc.close();
	}
}

Measured memory_bytes: 51048
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def check(i):
        i = str(i)
        for j in range(n):
            if d[j] >= 0:
                if int(i[j]) != d[j]:
                    return 0
        return 1
    n,m = LI()
    s = LIR(m)
    d = defaultdict(lambda : -1)
    for i,j in s:
        i -= 1
        if d[i] != -1 and d[i] != j:
            print(-1)
            return
        d[i] = j
    for i in range(10**(n-1) if n > 1 else 0, 10**n):
        if check(i):
            print(i)
            return
    print(-1)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ll long long
#define fir first
#define sec second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define MOD (1000000007ll)
using namespace std;

int main(){
    ll n,m;
    cin>>n>>m;
    ll a[n];
    ll b[m];
    bool chka[n];
    bool chkb[m];
    rep(i,n) {
        chka[i]=false;
        cin>>a[i];
    }
    rep(i,m){
        chkb[i]=false;
        cin>>b[i];
    }
    sort(a,a+n,greater<ll>());
    sort(b,b+m,greater<ll>());
    if(a[0]!=b[0]){
        cout<<0<<endl;
        return 0;
    }
    ll free[n]={};
    ll ans=1;
    rep(i,n) free[i]=m;
    for (ll i=m*n;i>0;i--){
        ll px=-1,py=-1;
        rep(y,n){
            if (i>a[y]) break;
            py=y;
        }
        rep(x,m){
            if (i>b[x]) break;
            px=x;
        }
        if (px==-1 or py==-1) {
            cout<<0<<endl;
            return 0;
        }
        if(b[px]==i and a[py]==i) {
            chka[py]=true;
            chkb[px]=true;
            ans*=1;
            ans%=MOD;
        }else if (b[px]==i){
            chkb[px]=true;
            ans*=(py+1);
            ans%=MOD;
        }else if (a[py]==i){
            chka[py]=true;
            ans*=(px+1);
            ans%=MOD;
        }else{
            ll j=m*n-i;
            ans*=((px+1)*(py+1) -j );
            ans%=MOD;
        }

    }


    rep(i,n)if (chka[i]==false){
        cout<<0<<endl;
        return 0;
    }
    rep(i,m)if (chkb[i]==false){
        cout<<0<<endl;
        return 0;
    }
    cout<<ans<<endl;
    return 0;


}

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

using namespace std;

int main(void){

  int n,m,p;
  while( cin >> n >> m >> p , n || m || p ){

    int a,b = 0;
    int total = 0;

    for( int i = 1 ; i <= n ; i++ ){
      cin >> a; 
      if(i == m) b = a;
      total += a;
    }
    if(b){
      total = total * 100 * (100 - p)/ (b * 100);
      cout << total << endl;
    }else cout << "0" << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int d[120][120];
int memo[120][120];
int main(){
	int n;
	cin>>n;
	for(int i =1;i <= n;i++){
		for(int j =1;j <= n;j++){
			int x;
			cin>>x;
			d[i][j]=d[i-1][j]+d[i][j-1]-d[i-1][j-1]+x;
		}
	}
	int ans =-INF;
	for(int i =1;i <=n;i++){
		for(int j =1;j <=n;j++){
			for(int y =1;y <=i;y++){
				for(int x =1;x <=j;x++){
					ans =max(ans,d[i][j]-d[y-1][j]-d[i][x-1]+d[y-1][x-1]);
				}
			}
		}
	}
	cout <<ans<<endl;
	return 0;
}

Measured memory_bytes: 1212
#include<iostream>
#include<string>
using namespace std;
int main(){
   string s;
   cin >> s;
   int i;
   int p = 700;
   for(i=0;i<3;i++){
     if(s[i]=='o')p=p+100;
   }
   cout << p;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
			using namespace std;
			#define ll long long
			#define INF 100000000LL
			#define mod 1000000007
			#define pll pair<long,long>
			#define se second
			#define fi first
			#define pb push_back
			#include <ext/pb_ds/assoc_container.hpp>
			#include <ext/pb_ds/tree_policy.hpp>
			using namespace __gnu_pbds;

			typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
			typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update>pllordered_set;
			
			ll cache[3000][3000];
			vector<ll> v1;
			vector<ll> v2;
			
			ll dp(ll i,ll j)
			{
				if(i<0 || j<0)
					return 0;
				if(cache[i][j]!=-1)	
					return cache[i][j];
				
				ll ans=dp(i-1,j)+dp(i,j-1);
				ans%=mod;
				ans=(ans-dp(i-1,j-1)+mod)%mod;
				if(v1[i]==v2[j])
				{
					ans+=1+dp(i-1,j-1);
					ans%=mod;
				}
				return cache[i][j]=ans;
			}
			
			int main()
			{
				ll n,m;
				cin>>n>>m;
				v1.resize(n);
				v2.resize(m);
				for(ll i=0;i<n;i++)
				{
					cin>>v1[i];
				}
				for(ll i=0;i<m;i++)
				{
					cin>>v2[i];
				}
				for(ll i=0;i<=n;i++)
				{
					for(ll j=0;j<=m;j++)
						cache[i][j]=-1;
				}
				cout<<dp(n-1,m-1)+1;
				
						
			}


Measured memory_bytes: 47360
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int main(){
  ull n, q, h, s, d;
  scanf("%llu %llu %llu %llu", &q, &h, &s, &d);
  scanf("%llu", &n);
  h = min(h, 2*q);
  s = min(s, h*2);
  d = min(d, s*2);
  if(n&1) {
    printf("%llu\n", n>1?min(((n-1)>>1)*d+s, n*s) : s);
  } else {
    printf("%llu\n", (n>>1)*d);
  }
  return 0;
}


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

using namespace std;
using ll = long long;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, std::vector<long long> A){
  ll ans = 0;
  map<ll, ll> m;
  m[0] = 1;
  ll sum = 0;
  
  for(int i=0; i<N; i++) {
    sum += A[i];
    ans += m[sum];
    m[sum]++;
  }
  std::cout << ans << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 14336
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

signed main()
{
	ll N;
	cin >> N;
	bool approved=true;
	REP(i, N){
		ll A;
		cin >> A;
		if(A%2==0 and (A%5!=0 and A%3!=0)){
			approved=false;
		}
	}
	if(approved){
		cout << "APPROVED";
	}else{
		cout << "DENIED";
	}
	cout << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)
ll INF = 1LL << 50;

void solve(long long N){
    ll ans = INF, tmp;
    for(ll i=1; i*i<=N; i++){
        if(N % i == 0){ 
            tmp = i + N/i;
            ans = min(ans, tmp);
        }
    }
    cout << ans-2<< endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

//[l, r)
ll calc(string &S, int l, int r) {
	ll ans = 0;
	ll cnt = 0;
	char prev = S[l];
	for (int i = l; i < r; i++) {
		if (prev == S[i]) {
			cnt++;
		} else {
			ans += cnt / 2;
			cnt = 1;
		}
		prev = S[i];
	}
	ans += cnt / 2;
	return (ans);
}

void Main() {
	string S; cin >> S;
	ll K; cin >> K;
	ll N = S.size();
	if (count(begin(S), end(S), S[0]) == N) {
		cout << (N * K) / 2 << endl;
		return;
	}
	if (K == 1) {
		cout << calc(S, 0, N) << endl;
		return;
	}
	char c = S[0];
	ll left, right;

	for (left = N-1; left >= 0 && c == S[left]; left--);
	left++;
	for (right = 1; right < N && c == S[right]; right++);
	
	ll cnt = (right+N - left) / 2 * (K-1);

	cnt += calc(S, right, left) * (K-2);
	cnt += calc(S, 0, left) + calc(S, right, N);

	cout << cnt << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;

inline int read()
{
    register int x = 0 , ch = getchar();
    while( !isdigit( ch ) ) ch = getchar();
    while( isdigit( ch ) ) x = x * 10 + ch - '0' , ch = getchar();
    return x;
}

void print(int x)
{
    if(x < 0)
    {
        putchar('-');
        x =- x;
    }
    if(x > 9)
        print(x / 10);
    putchar(x % 10 + '0');
}

string str;

int main()
{
	cin >> str;
	int len = str.size();
	len -= 2;
	cout << str[0] << len << str[len + 1] << endl;
	return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn._
import scala.annotation.tailrec

object Main {

  object Dice{
    private val north = List(2,6,3,4,1,5).map(_-1)
    private val east = List(4,2,1,6,5,3).map(_-1)
    private val ccw = List(3,2,6,1,5,4).map(_-1)
  }

  case class Dice(pip: List[Int]) {
    private def north = Dice(Dice.north.map(pip))
    private def east = Dice(Dice.east.map(pip))
    private def south = north.north.north
    private def west = east.east.east

    def rotate(com: Char):Dice = com match {
      case 'N' => north
      case 'E' => east
      case 'S' => south
      case 'W' => west
      case _ => this
    }
  }

  @tailrec
  def loop(com: String, dice: Dice):Dice = {
    if(com.isEmpty)dice
    else loop(com.tail,dice.rotate(com.head))
  }

  def main(args: Array[String]): Unit = {
    val pip = readLine.split(" ").map(_.toInt).toList
    println(loop(readLine,Dice(pip)).pip(0))
  }
}

Measured memory_bytes: 41192