akhauriyash/Code-Regression huggingface dataset:
//“ In order to be irreplaceable, one must always be different”
#include <bits/stdc++.h>
using namespace std;
# define ll long long
#define endl "\n"
# define pi 3.14159265359
#define mod 1000000007
# define str string
# define vll vector<ll>
# define vstr vector<str>
# define vchar vector<char>
# define pb push_back
# define mll map<ll,ll>
#define mchar map<char, ll>
# define mstr map<str,ll>
# define vp vector< pair<ll,ll> >
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
# define f(x,y) for(int x=0;x<y;x++)
# define r(x,y) for(int x=y;x>=0;x--)
# define loop(x,y,z) for(int x=y;x<z;x++)
ll power(ll a , ll b){ll res=1;for(ll i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll gcd(ll a, ll b){
    if(b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a, b);
}
void print(vll a){
    for(int i=0;i<a.size();i++){
        cout<<a[i]<<' ';
    }
    cout<<endl;
}
vll inp(int n){
    vll a;
    ll x;
    f(i,n){
        cin>>x;
        a.pb(x);
    }
    return a;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll x,y;
    cin>>x>>y;
    ll a[x];
    f(i,x){
        cin>>a[i];
    }
    vll v;
    v.pb(1);
    mll m;
    m[1]++;
    m[a[0]]++;
    v.pb(a[0]);
    ll k2;
    while(true){
        ll k=v[v.size()-1];
        m[a[k-1]]++;
        if(m[a[k-1]]>1){
            k2=a[k-1];
            break;
        }
        v.pb(a[k-1]);
    }
    ll c=0;
    f(i,v.size()){
        if(v[i]!=k2){
            c++;
        }
        else{
            break;
        }
    }
    ll c1=v.size()-c;
    if(y<v.size()){
        cout<<v[y]<<endl;
    }
    else{
         y-=c;
        cout<<v[c+ y%c1];
    }
    return 0;
}

Measured memory_bytes: 18592
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("board.in");ofstream out("board.out");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

int main() {
    fast;
    ll a; cin>>a;
    cout<<3*a*a;
}

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


typedef long long ll;
ll s,c;

int main()
{
	cin >> s >> c;
	ll res = 0;

	ll us = min(s,c / 2);

	res += us;

	s -= us;
	c -= 2 * us;

	res += c / 4;

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e9+7;

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

int main()
{
    ll n;
    cin >> n;
    vector<ll> p(n*n);
    ll sum=0;
    vector<vector<pll>> ans(n,vector<pll>(n,make_pair(0,1)));
    rep(i,n*n){
        cin >> p[i];
        p[i]--;
    }
    rep(i,n){
        rep(j,n){
            ans[i][j].fi=min(min(i,n-1-i),min(j,n-1-j));
            //cout << ans[i][j].fi << " ";
        }
        //cout << endl;
    }
    rep(k,n*n){
        ll i=p[k];
        sum+=ans[i/n][i%n].fi;
        queue<pll> que;
        que.push(make_pair(i/n,i%n));
        ans[i/n][i%n].se=0;
        //vector<vector<ll>> s(n,vector<ll>(n));
        while(!que.empty()){
            pll x=que.front();
            que.pop();
            //s[x.fi][x.se]=1;
            if(ans[x.fi][x.se].se==0){
                rep(j,4){
                    ll nx=x.fi+dx[j];
                    ll ny=x.se+dy[j];
                    if(0<=nx && nx<=n-1 && 0<=ny && ny<=n-1 &&  ans[nx][ny].fi>ans[x.fi][x.se].fi){
                        ans[nx][ny].fi=ans[x.fi][x.se].fi;
                        que.push(make_pair(nx,ny));
                    }
                    
                }
            }
            else{
                rep(j,4){
                    ll nx=x.fi+dx[j];
                    ll ny=x.se+dy[j];
                    if(0<=nx && nx<=n-1 && 0<=ny && ny<=n-1 &&  ans[nx][ny].fi>ans[x.fi][x.se].fi+1){
                        ans[nx][ny].fi=ans[x.fi][x.se].fi+1;
                        que.push(make_pair(nx,ny));
                    }
                    
                }
            }
        }
    }
    /*cout << endl;
    rep(i,n){
        rep(j,n){
            //ans[i][j].fi=min(min(i,n-1-i),min(j,n-1-j));
            cout << ans[i][j].fi << " ";
        }
        cout << endl;
    }
    cout << endl;
    rep(i,n){
        rep(j,n){
            //ans[i][j].fi=min(min(i,n-1-i),min(j,n-1-j));
            cout << ans[i][j].se << " ";
        }
        cout << endl;
    }*/
    cout << sum << endl;
    return 0;
} 

Measured memory_bytes: 9000
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int q, k;
    cin >> q;
    rep(i, q) {
        cin >> k;
        cout << binary_search(a.begin(), a.end(), k) << "\n";
    }
}


Measured memory_bytes: 3288
#include <stdio.h>

int main(){
	int n;
	int i;
	int m;
	long long int a=0;
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d", &m);
		a+=m;
	}
	a/=n;
	printf("%lld\n", a);
	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
 
typedef long long ll;
typedef pair<int, int> ii;

int main() {
	int n;
	cin >> n;
	vector<int> d(n);
	int maxi = 0;
	rep(i, n) cin >> d[i];
	rep(i, n){
		if(maxi < i) continue;
		maxi = max(maxi, i + d[i]/10);
	}
	
	if(maxi < n-1){
		cout << "no" << endl;
		return 0;
	}
	int mini = n-1;
	for(int i = n-1; i >= 0; --i){
		if(i < mini) continue;
		mini = min(mini, i - d[i]/10);
	}
	cout << (mini <= 0?"yes":"no") << endl;
}

Measured memory_bytes: 3876
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var X = parseInt(input[0].split(" ")[1]);
  input.shift();
  var L = input[0].split(" ").map(i=>parseInt(i));
  var ans=1;
  var tmp=0;
  for(var i=0;i<N;i++){
    tmp+=L[i];
    if(tmp<=X){
      ans++;
    }else{
      break;
    }
  }
  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  ll ans = a.front()-1;
  int now = 2;
  rep2(i, 1, n){
    // cerr << ans << endl;
    if(a.at(i) == now){
      now++;
    }else{
      ans += (a.at(i)-1)/now;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3768
import time
import random


class TreapNode:
    def __init__(self, key, pri):
        self.left = None
        self.right = None
        self.key = key
        self.pri = pri


class Treap:
    def __init__(self):
        self.root = None

    def search_lower(self, key):
        if key == None:
            return None
        ptr = self.root
        ret = None
        while ptr is not None:
            pk = ptr.key
            if pk < key:
                ret = pk
                ptr = ptr.right
            else:
                ptr = ptr.left
        return ret

    def search_higher(self, key):
        if key == None:
            return None
        ptr = self.root
        ret = None
        while ptr is not None:
            pk = ptr.key
            if pk > key:
                ret = pk
                ptr = ptr.left
            else:
                ptr = ptr.right
        return ret

    def insert(self, key):
        pri = random.randrange(0, 2**32)
        ptr = self.root
        elem = TreapNode(key, pri)
        if ptr is None or ptr.pri < pri:
            self.root = elem
        else:
            while True:
                if key < ptr.key:
                    left = ptr.left
                    if left is None or left.pri < pri:
                        ptr.left = elem
                        ptr = left
                        break
                    ptr = left
                else:
                    right = ptr.right
                    if right is None or right.pri < pri:
                        ptr.right = elem
                        ptr = right
                        break
                    ptr = right
        left = elem
        right = elem
        while ptr is not None:
            if key < ptr.key:
                right.left = ptr
                right = ptr
                ptr = ptr.left
            else:
                left.right = ptr
                left = ptr
                ptr = ptr.right
        left.right = None
        right.left = None
        elem.left, elem.right = elem.right, elem.left

# デバッグ用
    def dump(self):
        self.__dump(self.root, 0)

    def __dump(self, idx, dep):
        if idx is not None:
            self.__dump(idx.right, dep + 1)
            for _ in range(0, dep):
                print("   ", end="")
            print([idx.key, idx.pri])
            self.__dump(idx.left, dep + 1)

def main():
    n = int(input())
    p = list(map(int, input().split()))
    idx = [0] * n
    for i in range(0, n):
        idx[i] = i
    idx.sort(key=lambda i: - p[i])
    t = Treap()
    t.insert(-1)
    t.insert(n)
    ans = 0
    for i in idx:
        nex = t.search_higher(i)
        nexnex = t.search_higher(nex)
        pre = t.search_lower(i)
        prepre = t.search_lower(pre)
        if prepre != None:
            ans += p[i] * (pre - prepre) * (nex - i)
        if nexnex != None:
            ans += p[i] * (i - pre) * (nexnex - nex)
        t.insert(i)
    print(ans)


main()


Measured memory_bytes: 83432
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
int main() {
  int n, q, i, l, r;
  std::string s;
  std::cin >> n >> q >> s;
  std::vector<int> v(n, 0);
  for(i=1; i < n; ++i) {
    v[i] = (s[i-1]=='A'&&s[i]=='C'?v[i-1]+1:v[i-1]);
  }
  while(std::cin >> l >> r) {
    std::cout << v[r-1] - v[l-1] << "\n";
  }
}

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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;

//---------------------------------------------------------------

int main(){
  int N,P,ans;
  cin>>N;
  vec X(N);
  P=0;
  rep(i,N){
    cin>>X.at(i);
    P+=X.at(i);
  }
  if(((double)P/N-(int)P/N)>0.5)
  { P/=N;
    P++;
  }else{
    P/=N;
  }
  ans = 0;
  rep(i,N){
    ans+=(X.at(i)-P)*(X.at(i)-P);
  }
  cout<<ans<<endl;

}


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

int main(){
  int h,w;
  while(true){
    cin >> h >> w;
    if(h == 0 && w == 0)break;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        if(i % 2 == 0 && j % 2 == 1){
          cout << '.';
          continue;
        }
        if(i % 2 == 1 && j % 2 == 0){
           cout << '.';
          continue;
        }
        cout << '#';
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3096
def To_Infinity(s , k):

    ans = ""

    s1 = s.lstrip("1")

    if k - (len(s) - len(s1)) > 0:
        ans = s1[0]
    else:
        ans = "1"

    return ans
def main():
    s = str(input())
    k = int(input())
    print(To_Infinity(s , k))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n, k, q;
  cin >> n >> k >> q;
  map<int, int> mp;
  for (int i=0; i<q; i++) {
    int a;
    cin >> a;
    a--;
    mp[a]++;
  }
  for (int i=0; i<n; i++) {
    if (q-mp[i]<k) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 5376
#include <stdio.h>
int main(void){
	char day[4];
	int i;
	scanf("%s",day);
	if(day[0]=='S'){
		if(day[1]=='U'){
			i=7;
		}else{
			i=1;
		}
	}else if(day[0]=='M'){
		i=6;
	}else if(day[0]=='T'){
		if(day[1]=='U'){
			i=5;
		}else{
			i=3;
		}
	}else if(day[0]=='W'){
		i=4;
	}else{
		i=2;
	}
	printf("%d",i);
}

Measured memory_bytes: 128
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int k,q;
	std::cin >> k >> q;
	std::vector<int> d(k);
	rep(i,k) std::cin >> d[i];
	rep(qq,q) {
		int n,x,m;
		std::cin >> n >> x >> m;
		n--;
		int zeros = 0;
		int sum = x%m;
		int xx = 0;
		rep(i,k) {
			xx+=d[i]%m;
			if(d[i]%m==0) zeros++;
		}
		sum+=xx*(n/k);
		zeros*=(n/k);
		int lastzero = false;
		rep(i,n%k) {
			sum+=d[i]%m;
			if(d[i]%m==0) zeros++;
		}
		print(std::max(n-sum/m-zeros,0ll));
	}
	return 0;
}


Measured memory_bytes: 384
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    g1 = a[0]
    g2 = sum(a[1:n])
    ans = abs(g1 - g2)
    if n > 2:
        for i in range(1, n-1):
            g1 += a[i]
            g2 -= a[i]
            tmp = abs(g1 - g2)
            if tmp < ans:
                ans = tmp

    print(ans)


Measured memory_bytes: 24832
#include <cstdio>

char sq[100][100];
bool ok, start;

int main()
{
	int A, B;
	int x, y;
	
	for(y=0; y<100; y++)
		for(x=0; x<100; x++)
			sq[y][x] = '.';
	
	scanf("%d %d", &A, &B);
	
	A--;
	
	for(y=0; y<100; y+=2)
	{
		for(x=0; x<100; x+=2)
		{
			if(!A && !B)
			{
				ok = true;
				break;
			}
			else if(A && B && !start)
			{
				start = true;
				sq[y][x+1] = '#';
				sq[y+1][x] = '#';
				sq[y+1][x+1] = '#';
				
				A--;
				B--;
			}
			else if(A)
			{
				sq[y][x+1] = '#';
				sq[y+1][x] = '#';
				sq[y+1][x+1] = '#';
				
				A--;
			}
			else if(B)
			{
				sq[y+1][x+1] = '#';
				
				B--;
			}
		}
		
		if(ok) break;
	}
	
	puts("100 100");
	
	for(y=0; y<100; y++,puts(""))
		for(x=0; x<100; x++)
			printf("%c", sq[y][x]);
	
	return 0;
}

Measured memory_bytes: 128
"""
半ば強引に二分探査で書いた。
"""
#入力
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
h_not_sorted = h
h = sorted(h)
x = abs((t - a) / 0.006)

#二分探査
l = 0
r = n - 1
x_index = 0
while l + 1 != r :
    middle = (l + r) // 2
    if h[middle] == x:
        x_index = middle
        break
    elif h[middle] < x:
        x_index = middle + 1
        l = middle
    else:
        x_index = middle - 1
        r = middle


#x_indexが両橋の場合とそれ以外で場合わけ。
res = abs(a - (t - 0.006 * h[x_index]))
ans = x_index
flag_r = True 
flag_l = True
if x_index == n - 1:
    flag_r = False
elif x_index == 0:
    flag_l = False
else:
    pass

#x_indexの両橋と比較。x_indexが際数値でない可能性があるため。
if flag_r:
    if abs(a - (t - 0.006 * h[x_index + 1])) < res:
        res = abs(a - (t - 0.006 * h[x_index + 1]))
        ans += 1
if flag_l:
    if abs(a - (t - 0.006 * h[x_index - 1])) < res:
        res = abs(a - (t - 0.006 * h[x_index - 1]))
        ans -= 1

print(h_not_sorted.index(h[ans]) + 1)

Measured memory_bytes: 9292
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int mod=1e9+7;
const int INF =LONG_LONG_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
vector<int>adj[100001];
vector<int>visited(100001,0);
vector<int>ans;
void dfs(int s)
{
    visited[s]=1;
    for(int i=0;i<adj[s].size();i++)
    {
        int child=adj[s][i];
        if(!visited[child])dfs(child);
    }
    ans.push_back(s);
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m;
    cin>>n>>m;
    vector<int>degree(n+1,0);
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        degree[y]++;
        adj[x].push_back(y);
    }
   for(int i=1;i<=n;i++)
   {
       if(!visited[i]&&degree[i]==0)
        dfs(i);
   }
    vector<int>dp(n+1,0);
    for(int i=ans.size()-1;i>=0;i--)
    {
        int node=ans[i];
        for(int j=0;j<adj[node].size();j++)
        {
            int child=adj[node][j];
            dp[child]=max(dp[child],dp[node]+1);
        }
    }
    int max1=-1;
    for(int i=1;i<=n;i++)
    {
        max1=max(max1,dp[i]);
    }
    cout<<max1<<endl;
    return 0;
}


Measured memory_bytes: 12148
#include<stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{

        int i;
        int j;
        int k;
        int cnt5;
        int cnt7;

	// 個数のの入力
        cnt5 = 0;
        cnt7 = 0;
        scanf("%d %d %d",&i,&j,&k);

        if (i == 5) {
           cnt5 = cnt5 + 1;
        }
        if (i == 7) {
           cnt7 = cnt7 + 1;
        }
 

        if (j == 5) {
           cnt5 = cnt5 + 1;
        }
        if (j == 7) {
           cnt7 = cnt7 + 1;
        }


        if (k == 5) {
           cnt5 = cnt5 + 1;
        }
        if (k == 7) {
           cnt7 = cnt7 + 1;
        }


        if (cnt5 == 2) {
           if (cnt7 == 1) {
               printf("YES\n");
           }
           else {
               printf("NO\n");
           }
        }
        if (cnt5 != 2) {
               printf("NO\n");
        }
        
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    int minus = 0;
    ll sum = 0;
    ll abs_min = 10e9+1;
    for (int i = 0; i < N; i++){
        cin >> A.at(i);
        ll ab = abs(A.at(i));
        sum += ab;
        abs_min = min(ab, abs_min);
        if (A.at(i) < 0) minus++;
    }
    if (minus % 2 == 0) cout << sum << endl;
    else cout << sum - abs_min*2  << endl;
}

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

const int maxn = 200010;
pair<int, int> p[maxn];

int main() {
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		cin >> p[i].first >> p[i].second;
		if (p[i].first == 1 && p[i].second == n) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	sort(p + 1, p + m + 1);
	for (int i = 1; i <= m; i++) {
		if (p[i].first == 1) {
			if (binary_search(p + 1, p + m + 1, make_pair(p[i].second, n))) {
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 1792
N = int(input())

A = list(map(int, input().split()))

S = 0
for i in range(N):
  S += A[i]

c = S
d = 0
for j in range(N):
  c -= A[j]
  c = c%(10**9+7)
  d += A[j]*c
  d = d%(10**9+7)
  
print(d)

Measured memory_bytes: 31548
#include <iostream>
int main(){
	int m[12];
	char q;
	m[1]=31,m[2]=29,m[3]=31,m[4]=30,m[5]=31,m[6]=30,m[7]=31,m[8]=31,m[9]=30,m[10]=31,m[11]=30,m[12]=31;
	int mm,d;
	while(std::cin>>mm>>d&&mm!=0&&d!=0){
		int y=0;
		for(int a=1;a<mm;a++){
			y=y+m[a];
		}
		
		if((y+d)%7==1){
			std::cout<<"Thursday"<<std::endl;
		}if((y+d)%7==2){
		std::cout<<"Friday"<<std::endl;
		}
		if((y+d)%7==3){
		std::cout<<"Saturday"<<std::endl;
		}
		if((y+d)%7==4){
		std::cout<<"Sunday"<<std::endl;
		}
		if((y+d)%7==5){
		std::cout<<"Monday"<<std::endl;
		}
		if((y+d)%7==6){
		std::cout<<"Tuesday"<<std::endl;
		}
		if((y+d)%7==0){
			std::cout<<"Wednesday"<<std::endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef unsigned long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;

int main(){
    string s;cin >> s;
    int ans=INF;
    for (int i = 0; i <= s.length()-3; i++) {
        ans=min(ans,abs(753-stoi(s.substr(i,3))));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
using namespace std;

int main(void)
{
	int N, T; cin >> N >> T;
	vector<int> t(N);
	rep(i, 0, N)cin >> t[i];
	lli ans = 0;
	rep(i, 1, N) {
		if (t[i] - t[i - 1] < T)ans += (t[i] - t[i - 1]);
		else ans += T;
	}
	ans += T;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
from collections import Counter
n, m = map(int, input().split())

a = []
for i in range(n):
    a.extend(list(map(int, input().split()))[1:])

c = Counter(a)

ans = 0
for k, v in c.most_common():
    if v == n:
        ans += 1
    else:
        break
print(ans)

Measured memory_bytes: 38512
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int hour = scan.nextInt();
    int minute = scan.nextInt();
    int Hour = scan.nextInt();
    int Minute = scan.nextInt();
    int K = scan.nextInt();
    int start, finish, sum;
    start = hour * 60 + minute;
    finish = Hour * 60 + Minute;
    sum = finish - start - K;
    System.out.println(sum);
  }
}


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

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

int main(){
	int N, X;
	int x[100005];
	cin >> N >>X;
	int tmp;
	for(int i = 0; i <N; i++){
		cin >> tmp;
		x[i] = abs(tmp - X);
	}
	tmp = x[0];
	for(int i = 1; i < N; i++){
		tmp = gcd(tmp, x[i]);
	}
	cout << tmp;
	return 0;
}


Measured memory_bytes: 640
import math

N=int(input())
A = list(map(int,input().split()))	

Money=1000
Kabu=0

def MoneyWar(Money,Kabu,A,N):
  for i in range(N-1):
    if A[i]<A[i+1]:
      Kounyu=math.floor(Money/A[i])
      Money-=A[i]*Kounyu
      Kabu+=Kounyu

    if A[i]>A[i+1]:
      Money+=Kabu*A[i]
      Kabu=0

      
  if Kabu>0:
    Money+=Kabu*A[-1]
    
  return Money

print(MoneyWar(Money,Kabu,A,N))


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

int main(){
  ll a,b,ans;
  cin>>a>>b;
  if(a+b==3)ans=3;
  else if(a+b==5)ans=1;
  else ans=2;
  cout<<ans<<endl;
}


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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
ll inf = 1e18;

ll T, D, L;
ll x[100010];
int main(){
	while(cin >> T >> D >> L && T > 0){
		REP(i,0,T) cin >> x[i];
		ll now = 0;
		ll ans = 0;
		REP(i,0,T){
			if(now > 0){
				ans++;
			}
			if(x[i] >= L){
				now = D;
			}else{
				now--;
			}

		}
		p(ans);
	}

	return 0;
}


Measured memory_bytes: 3868
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

void solve()
{
	int n;
	cin >> n;
	double res = 0;
	for(int i = 0; i < n; ++i){
		double x;
		string s;
		cin >> x >> s;
		if(s == "BTC") res += x * 380000;
		else res += x;
	}		
	cout << fixed << setprecision(6) << res;
}


 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};

int main(){
  int n; cin >> n;
  string s; cin >> s;
  int ans = 0;
  for(int i = 0; i+2 < n; i++) {
    string t = s.substr(i,3);
    if(t == "ABC") ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//Coded by dst
#include<iostream>
#include<cstdio>
using namespace std;
int n,cnt,ans;
bool a[200005],b[200005];
int main(){
	int i,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(i=n;i;i--){
		cnt=0;
		for(j=i;j<=n;j+=i)
			cnt+=b[j];
		if(cnt%2!=a[i])
			b[i]=1,++ans;
	}
	printf("%d\n",ans);
	for(i=1;i<=n;i++)
		if(b[i])
			printf("%d ",i);
	return 0;
}

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

#define cnd(c, a, b) (c ? a : b);
#define fl(x,y,z) for(int x=y;x<z;x++)
#define fe(x,y,z) for(int x=y;x<=z;x++)
#define fge(x,y,z) for(int x=y;x>=z;x--)

#define debug(x) std::cerr << #x << " --> " << x << "\n";
#define fastIO std::ios_base::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
#define pb push_back
#define pob pop_back
 
#define ln '\n'
typedef long long int ll;

ll mod=1e9+7;

void decrypt() {
	ll n, x, y, ans;
	vector<ll> v1, v2;
	cin>>n;
	fl(i,0,n) {
		cin>>x>>y;
		v1.pb(x+y);
		v2.pb(x-y);
	}
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	ans = max(abs(v1[n-1]-v1[0]), abs(v2[n-1]-v2[0]));
	cout<<ans<<ln;
}

int main() {
    fastIO
    int t = 1;
    // cin >> t;
    fl(i,0,t) {
    	// cout << "Case #"<< i+1 <<": ";
    	decrypt();
    }
    return 0;
}

Measured memory_bytes: 6684
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pb push_back
#define f first
#define s second
#define MOD 998244353
 
using namespace std;

ll U[200002];
ll pp[10000];

int main(){
 
	ios_base::sync_with_stdio(false);
	//cin.tie(0);
	cout<<fixed<<setprecision(12);
	//memset(dp,-1,sizeof(dp));
	int n, p;
	string s;
	cin>>n>>p>>s;
	
	ll ans = 0;
	if(p == 5 || p ==2){
		
		for(int i=0; i<n; i++){
			if((int)(s[i] - '0')%p == 0) ans += i+1;
		}
		cout<<ans;
		return 0;
	}
	reverse(s.begin(),s.end());

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

		if(i == 0){
			U[i] = ((int)(s[i] - '0'))%p;
			mt = 10;
		}
		else{
			U[i] = (U[i-1] + ((int)(s[i]-'0')*mt)%p)%p;
			mt = (10*mt)%p;
		}
		
		ans += pp[U[i]%p];
		pp[U[i]]++;
		if(U[i]%p ==0) ans++;
		//cout<<U[i]<<" ";
	}


	cout<<ans;
	

	return 0;
}
 

Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
int main()
{
 int64_t A,B,N,n;
  cin >> A >> B >> N ;
  if(N>B-1)
  {
    n=B-1;
  }
  else
  {
    n=N;
  }
  cout << (A*n)/B << endl;
  
  

}


Measured memory_bytes: 3604
package main

import "fmt"

func main() {
	var x, y int

	var a = [] int{1, 3, 5, 7, 8, 10, 12}
	var b = [] int{4, 6, 9, 11}
	var c = [] int{2}

	//fmt.Println(a, b, c)
	fmt.Scanf("%d%d", &x, &y)
	//x, y = 1, 3
	//fmt.Println(x, y, )

	if nInStr(a, x) && nInStr(a, y) {
		fmt.Println("Yes")
	}else {

	if nInStr(b, x) && nInStr(b, y) {
		fmt.Println("Yes")
	} else  {
		if nInStr(c, x) && nInStr(c, y) {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}}
}

func nInStr(m[] int, n int) bool {
	for i := 0; i < len(m); i++ {
		if n == m[i] {
			return true
		}
	}
	return false
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
long long i,j,n,m,a,b,c,a1,b1,c1;
long long M=1e18;
int main()
{
    std::cin.sync_with_stdio(false);
    std::cin.tie(0);
    cin >> a >> b >> c >> n;
    i=0;
    while (i<n%2)
    {
        a1=b+c;
        b1=a+c;
        c1=a+b;
        a=a1;
        b=b1;
        c=c1;
        i++;
        //cout << a << " " << b << " " << c << "\n";
    }
    if (abs(a-b)>M)
    {
        cout << "Unfair";
        return 0;
    }
    cout << a-b;
    return 0;
}


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



int main() {
    using vi = vector<int>;
    
    int64_t n;
    int64_t k;
    cin >> n >> k;
    int64_t s = 0;
    for(int64_t i = k; i < n+2;i++){
        if(i == n+1){
            s++;
        }else{
            //cout << i << endl;
            int64_t x = n*(n+1)/2-(n-i)*(n-i+1)/2;
            int64_t y = i*(i-1)/2;
            s = (s+x-y+1) % 1000000007;
            //cout << s << endl;
        }
    }
    //cout << "\n";
    cout << s << endl;
}

Measured memory_bytes: 3636
#include <cmath>
#include <cstdint>
#include <cstdio>

int main(void) {
    int n, k;
    std::scanf("%d %d", &n, &k);

    double prob = 0.0;

    for (int i = 1; i <= n; i++) {
        int point = i;
        double prob_1 = 1.0 / n;
        while (point < k) {
            point *= 2;
            prob_1 /= 2.0;
        }
        prob += prob_1;
    }

    printf("%.15f", prob);

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <ostream>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  vll a(n), b(n);

  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];

  vi c;
  ll sum = 0, ans = 0;

  rep(i, n) {
    ll d = a[i] - b[i];

    if (d < 0) sum += abs(d), ++ans;
    else c.eb(d);
  }

  sort(all(c),greater<int>());

  rep(i, si(c)) {
    if (sum <= 0) {
      cout << ans << endl;
      return (0);
    }

    sum -= c[i];
    ++ans;
  }
  
  if (sum > 0) cout << -1 << endl;
  else cout << ans << endl;

  return (0);
}


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

int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);

  int n, a, b;
  cin >> n >> a >> b;
  int p1 = 0, p2 = 0, p3 = 0;
  for (int i = 0; i < n; ++i) {
    int d;
    cin >> d;
    if (d <= a) {
      ++p1;
    } else if (d <= b) {
      ++p2;
    } else {
      ++p3;
    }
  }
  cout << min(min(p1, p2), p3) << "\n";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(void){
	char a;
	int mae,sum,i;
	while(1){
		mae=0;sum=0;i=0;
		while(1){
			a=getchar();
			if(a=='\n') break;
			sum+=atoi(&a);
			mae=atoi(&a);
			i++;
		}
		if(i==1&&mae==0) break;
		printf("%d\n",sum);
	}
	return 0;
}

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

#define UN unsigned
#define ll long long
#define mod 1000000007
#define pii pair<int, int>
#define pb push_back
//~ #define x first
//~ #define y second
// const int N = 1e6 + 5;

int main(void) {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);
	
	int a;
	cin >> a;
	int ans = (a + a*a + a*a*a);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
#define INF (1<<29)
#define INFLL (1ll<<58)
#define EPS (1e-10)
static const int MAX=1e5;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int N,a,b;
string s;
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin>>N>>a>>b>>s;
    int  cunt=0,cunt_foreign=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='a'&&cunt<a+b) {
            cout<<"Yes"<<"\n";
            cunt++;
        }else if(s[i]=='b'&&cunt<a+b&&cunt_foreign<b) {
            cout<<"Yes"<<"\n";
            cunt++; cunt_foreign++;
            
        }else cout<<"No"<<"\n";
    }
    return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);

void gen(LL N, LL S, LL W, VI& a){
  int g = S;
  for(int i=0; i<N; i++) {
	a[i] = (g/7) % 10;
	if( g%2 == 0 ) { g = (g/2); }
	else           { g = (g/2) ^ W; }
  }
}

LL powm(LL x, LL y, LL m){
  if(y == 0) return 1;
  return powm(x*x%m, y/2, m) * (y%2?x:1) % m;
}
LL inv(LL x, LL m){
  return powm(x, m-2, m);
}

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

  LL N, S, W, Q;
  while(cin>>N>>S>>W>>Q,N){
	VI as(N);
	gen(N, S, W, as);

	if(Q == 2){
	  LL ans = 0;
	  LL z = 0;
	  for(int i=N-1;i>=0;--i){
		if(as[i]){
		  ans += z + 1 - as[i] % 2;
		}
		z += 1 - as[i] % 2;
	  }
	  cout<<ans << endl;
	  continue;
	}
	else if(Q == 5){
	  LL ans = 0;
	  LL z = 0;
	  for(int i=N-1;i>=0;--i){
		if(as[i]){
		  ans += z + (as[i]%5==0? 1: 0);
		}
		z += as[i]%5==0? 1: 0;
	  }
	  
	  cout<<ans<<endl;
	  continue;
	}

	LL p = 1;
	VL xs(N);
	for(int i=N-1;i>=0;--i){
	  xs[i] = as[i] * p % Q;
	  (p *= 10) %= Q;
	}
	VL acc(N+1);
	REP(i,N)
	  acc[i+1] = (acc[i] + xs[i]) % Q;

	LL ans = 0;
	map<LL,LL> cnt;
	cnt[acc.back()]++;
	for(int l=N-1;l>=0;--l){
	  if(as[l] && cnt.count(acc[l])){
		ans += cnt[acc[l]];
	  }
	  cnt[acc[l]]++;
	}
	
	cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 10392
#include <stdio.h>
long long int gcd(long long int a, long long int b){
    long long int r;
    while((r=a%b)!=0){
        a=b;
        b=r;
    }
    return b;
}
int main(void){
    long long int a, b, c, d;
    scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
    long long int l=c*d/gcd(c, d);
    long long int ans=(b-b/c-b/d+b/l)-(a-1-(a-1)/c-(a-1)/d+(a-1)/l);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1732
h,n=map(int,input().split())
a=[]
b=[]
for _ in range(n):
  x,y=map(int,input().split())
  a.append(x)
  b.append(y)
a_=max(a)
dp=[10**8]*(h+1+a_)
dp[0]=0
for i in range(1,len(dp)):
  for j in range(n):
    if 0<=i-a[j]<=len(dp)-1-a[j]:
      dp[i]=min(dp[i],dp[i-a[j]]+b[j])
print(min(dp[h:]))

Measured memory_bytes: 74140
//  cd Desktop/Prog_Contest
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define rep(i,n) for(i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
#define MOD 1000000007

int main(){
    int l,r,d,i,ans=0;
    scanf("%d%d%d",&l,&r,&d);
    for(i=l;i<=r;i++){
        if(i%d==0) ans++;
    }
    printf("%d",ans);
    return 0;
}

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

#define MAX 100

int G[MAX + 1][MAX + 1];

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

  for ( int i = 1; i <= n; i++ ) {
    int m; cin >> m;
    int n; cin >> n;
    for ( int j = 1; j <= n; j++ ) {
      int k; cin >> k;
      G[i][k] = 1;
    }
  }

  for ( int i = 1; i <= n; i++ ) {
    for ( int j = 1; j <= n; j++ ) {
      if ( j != 1 ) cout << " ";
      cout << G[i][j];
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 3124
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define inf 1e9
#define INF 1000000000000000000
#define PI 3.14159265359

int main() {
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    double tansin = H * 30 + 0.5 * M;
    double tyosin = M * 6;
    double diff1 = max(tansin, tyosin) - min(tansin, tyosin);
    double diff2 = 360 - diff1;
    double diff = min(diff1, diff2);
    diff = M_PI * diff / 180;
    double ans = sqrt(A * A + B * B - 2 * A * B * cos(diff));
    cout << fixed << setprecision(12) << ans << endl;
}

Measured memory_bytes: 4216
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<class T> class Dijkstra {
public:
	int N;
	T inf;
	vector<T> cost;
	vector<vector<pair<T, int>>> edge;

	Dijkstra(const int N, T inf) : N(N), inf(inf),cost(N), edge(N) {
	}

	void make_edge(int from, int to, T w) {
		edge[from].push_back({ w,to });
	}

	void solve(int start) {
		for(int i = 0; i < N; ++i) cost[i] = inf;

		priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> pq;
		cost[start] = 0;
		pq.push({ 0,start });

		while (!pq.empty()) {
			T v = pq.top().first;
			int from = pq.top().second;
			pq.pop();
			for (auto u : edge[from]) {
				T w = v + u.first;
				int to = u.second;
				if (w < cost[to]) {
					cost[to] = w;
					pq.push({ w,to });
				}
			}
		}
		return;
	}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, X, Y;
    cin >> N >> X >> Y;
    --X, --Y;
    Dijkstra<int> d(N, INF);
    d.make_edge(X, Y, 1);
    d.make_edge(Y, X, 1);
    REP(i,N-1){
        d.make_edge(i, i+1, 1);
        d.make_edge(i+1, i, 1);
    }
    vector<int> ans(N);
    REP(i,N-1){
        d.solve(i);
        for(int j=i+1;j<N;j++) ans[d.cost[j]]++;
    }
    for(int i=1;i<N;i++) cout << ans[i] << endl;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define regsiter register
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
const int M=1000000007;
int x,y,z,sum;
int f[44][133333];
int next[133333][11];
int lg[133333];
void init()
{
	for(register int i=1,j=0;i<=131072;i<<=1,++j)lg[i]=j;
	for(register int i=1;i<=10;++i)
		if(i<=x)next[0][i]=1<<i-1;
	for(register int s=1;s<(1<<sum);++s)
	{
		int t=s-(s&-s);
		int l=lg[s&-s]+1;
		for(register int i=1;i<=10;++i)
		{
			next[s][i]=next[t][i];
			if(l<x)
			{
				if(l+i<=x)next[s][i]|=1<<l+i-1;
			}
			else if(l<x+y)
			{
				if(l+i<=x+y)next[s][i]|=1<<l+i-1;
			}
			else if(l<sum)
			{
				if(l+i<=sum)next[s][i]|=1<<l+i-1;
			}
			else next[s][i]|=1<<sum-1;
		}
	}
}
int main()
{
	int n=io::F();
	x=io::F(),y=io::F(),z=io::F();
	sum=x+y+z;
	f[0][0]=1;
	init();
	for(register int i=0;i<n;++i)
		for(register int j=0;j<(1<<sum);++j)
			for(register int k=1;k<=10;++k)
				(f[i+1][next[j][k]]+=f[i][j])%=M;
	int ans=0;
	for(register int j=1<<sum-1;j<(1<<sum);++j)ans=(ans+f[n][j])%M;
	printf("%d\n",ans);
	return 0;
}




Measured memory_bytes: 28288
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Node
    {
        internal List<int> children;
        internal int parent, preorder, lowest;
        internal bool isVisit;

        public Node()
        {
            children = new List<int>();
            parent = -1;
        }
    }

    class Program
    {
        static int timer;

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int V = int.Parse(input[0]);
            int E = int.Parse(input[1]);

            Node[] NL = Enumerable.Range(0, V).Select(a => new Node()).ToArray();

            for (int i = 0; i < E; i++)
            {
                input = Console.ReadLine().Split(' ');
                int s = int.Parse(input[0]);
                int t = int.Parse(input[1]);

                NL[s].children.Add(t);
                NL[t].children.Add(s);
            }

            ArtPoints(NL);
        }

        static void ArtPoints(Node[] NL)
        {
            timer = 1;

            DFS(NL, 0, -1);

            int len = NL.Length;
            int[] result = new int[len];
            for (int i = 1; i < len; i++)
            {
                int p = NL[i].parent;
                
                if (NL[p].preorder <= NL[i].lowest) result[p]++;
            }
            result[0]--;

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < len; i++)
            {
                if (result[i] > 0) sb.AppendLine(i.ToString());
            }
            Console.Write(sb);
        }

        static void DFS(Node[] NL, int current, int prev)
        {
            NL[current].preorder = timer;
            NL[current].lowest = timer;
            timer++;

            NL[current].isVisit = true;

            int len = NL[current].children.Count;
            for (int i = 0; i < len; i++)
            {
                int next = NL[current].children[i];

                if (!NL[next].isVisit)
                {
                    NL[next].parent = current;

                    DFS(NL, next, current);

                    NL[current].lowest = Math.Min(NL[current].lowest, NL[next].lowest);
                }
                else if (next != prev)
                {
                    NL[current].lowest = Math.Min(NL[current].lowest, NL[next].preorder);
                }
            }
        }
    }
}

Measured memory_bytes: 12904