akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll h,w;
  cin>>h>>w;
  vvll d(10,vll(10));
  vvll c(h,vll(w));
  rep(i,10)rep(j,10){
    cin>>d[i][j];
  }
  rep(i,h)rep(j,w)cin>>c[i][j];
  rep(k,10)rep(i,10)rep(j,10){
    d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
  }
  ll ans=0;
  rep(i,h){
    rep(j,w){
    if(c[i][j]==1||c[i][j]==-1) continue;
    ans+=d[c[i][j]][1];

  }
  }
  COUT(ans);
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;

int main(int argc, char* argv[])
{

	int a,b,c,d;

	cin >> a >> b >> c >> d;

	cout << (((abs(b-a) <= d && abs(c-b)<=d) || abs(c-a) <= d) ? "Yes" : "No" ) << endl;

	return 0;

}

Measured memory_bytes: 256
from math import sqrt
x1, y1, x2, y2 = map(int, raw_input().split())
dx = x2 - x1
dy = y2 - y1
for i in xrange(input()):
    x, y = map(int, raw_input().split())
    a = float(dx*(x - x1) + dy*(y - y1)) / (dx**2 + dy**2)
    print "%.09f %0.09f" % (x1 + a*dx, y1 + a*dy)

Measured memory_bytes: 6480
console.log((args=>{
  const [[N],...task] = args.trim().split('\n').map(r=>r.split(' ').map(v=>v|0));
  task.sort((a,b)=>a[1]-b[1]);
  let t = 0;
  for ( let i = 0; i < N; i++ ) {
    t += task[i][0];
    if ( task[i][1] < t ) return 'No';
  }
  return 'Yes';
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 101040
s=input()
t={'R','L','U','D'}
s_odd=''.join(x for i,x in enumerate(s) if i%2==0)
s_even=''.join(x for i,x in enumerate(s) if i%2!=0)
print('No' if len(set(s)-t) or 'L' in s_odd or 'R' in s_even else 'Yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define ff first
#define ss second
typedef pair<int,int> pii;

const int N = 1e6 + 8 ;
int32_t main()
{
	int n ;
	cin >> n ;

	int have[N] ;
	int a[n] ;
	memset(have , 0 , sizeof(have)) ;

	for(int i = 0 ; i < n ; i++){
		int x ;
		cin >> x ;
		a[i] = x ;
		have[x]++ ;
	}

	int ans = n ;

	for(int i = 0 ; i < n ; i++){
		int number = a[i] ;
		int fg = 0;
		for(int fact = 1 ; fact * fact <= number && !fg ; fact++){
			if(number % fact == 0){
				int f1 = fact , f2 = number / fact ;
				if(f1 != number && have[f1]){ans--; fg = 1 ;}
				else if(f1 == number && have[f1] > 1){ans--; fg = 1; }
				else if(f2 != number && have[f2]){ans-- ; fg = 1 ;}
				else if(f2 == number && have[f2] > 1){ans--; fg = 1;}
			}
		}
	}

	cout << ans <<" ";
	return 0;
}        

Measured memory_bytes: 12996
import java.awt.geom.Point2D;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		Point2D.Double p[];
		int start;
		int count;

		n = sc.nextInt();
		while (n != 0) {
			p = new Point2D.Double[n];
			start = 0;
			count = 0;
			for (int i = 0; i < n; i++) {
				String s[] = sc.next().split(",");
				p[i] = new Point2D.Double(Double.valueOf(s[0]), Double.valueOf(s[1]));
				if (p[i].x < p[start].x) {
					start = i;
				}
			}
			int pre = start;
			while (true) {
				for (int i = 0; i < n; i++) {
					if (i != pre) {
						boolean flag = true;
						for (int j = 0; j < n && flag; j++) {
							if (j != i && j != pre) {
								flag = isLeft(p[pre], p[i], p[j]);
							}
						}
						if (flag) {
							count++;
							pre = i;
							break;
						}
					}
				}
				if (pre == start) {
					break;
				}
			}
			System.out.println(n - count);
			n = sc.nextInt();
		}
	}

	public static boolean isLeft(Point2D.Double p, Point2D.Double q, Point2D.Double x) {
		double dx1 = q.x - p.x;
		double dy1 = q.y - p.y;
		double dx2 = x.x - p.x;
		double dy2 = x.y - p.y;
		if (0 < dx1 * dy2 - dx2 * dy1) {
			return true;
		} else {
			return false;
		}
	}
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int a, b;
  char op; cin >> a >> op >> b;
  if(op == '+') cout << a+b << endl;
  else cout << a-b << endl;

  return 0;
}




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

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;

 main()

{
    fast
    int l,r,d;
    cin>>l>>r>>d;
    int cnt=0;
    f(i,l,r)
    {
        if(i%d==0)cnt++;
    }
    cout<<cnt<<endl;
    return 0;

}





































Measured memory_bytes: 3608
#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 ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m,a,b,c,d;
	set<string>st;
	cin >> t;
	while(t--)
	{
		string s;
		cin >> s;
		st.insert(s);

	}
	cout<<sz(st)<<endl;
}

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

ll N, Q, A[100000], X[100000];
ll sum[100001], se[100001], so[100001];

bool check(ll x, ll a, ll b) {
  if (abs(A[b] - x) < abs(A[a] - x)) return true;
  if (abs(A[b] - x) == abs(A[a] - x)) return b < a;
  return false;
}

ll solve(ll x) {
  ll l = 1, h = N + 1;
  while (h - l > 1) {
    ll m = (l + h) / 2;
    ll p = (m + 1) / 2;
    ll q = m / 2;
    if (check(x, N - m, N - p)) h = m;
    else l = m;
  }
  return (sum[N] - sum[N - (l + 1) / 2]) + (N % 2 == 0 ? so[N - l] : se[N - l]);
}

int main(void) {
  cin >> N >> Q;
  REP(i, 0, N) cin >> A[i];
  REP(i, 0, Q) cin >> X[i];

  REP(i, 0, N) sum[i + 1] = sum[i] + A[i];
  REP(i, 0, N) se[i + 1] = se[i] + (i % 2 == 0 ? A[i] : 0);
  REP(i, 0, N) so[i + 1] = so[i] + (i % 2 == 1 ? A[i] : 0);

  REP(i, 0, Q) cout << solve(X[i]) << endl;
}

Measured memory_bytes: 5632
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);
	      	  
	      	  int N;
	      	  cin >> N;
	      	  
	      	  vector<int> v(N);
	      	  int S=0;
	      	  REP(i,N){
	      		  cin >> v[i];
	      		  S+=v[i];
	      	  }
	      	  
	      	  sort(v.begin(),v.end());
	      	  reverse(v.begin(),v.end());
	      	  
	      	  int x=0;
	      	  for(i=0;i<N;i+=2){
	      		  x+=v[i];
	      	  }
	      	  
	      	  cout << x-(S-x) << endl;
	      	  

	          return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, X, M;
    cin >> N >> X >> M;

    vec R;
    vec F(M+1, 0);
    ll p = 0, cnt = 1;
    R.pb(X%M);
    F[X%M] = 1;
    while(true) {
        ll r = R.back() % M;
        r = (r * r) % M;
        if(F[r] == 0) {
            ++cnt;
            F[r] = cnt;
            R.pb(r);
        }
        else {
            p = F[r];
            break;
        }
    }

    ll sum = 0, sum1 = 0, sum2 = 0, sum3 = 0;
    ll L = SZ(R) - p + 1;
    REP(i,0,p-1) sum1 += R[i];
    REP(i,p-1,SZ(R)) sum2 += R[i];
    REP(i,p-1,p-1+((N-p+1)%L)) sum3 += R[i];
    sum = sum1 + sum2 * ((N-p+1)/L) + sum3;
    PR(sum);
    
    return 0;
}

/*



*/

Measured memory_bytes: 4676
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def nCr(com_n, com_r):
    if com_n < com_r: return 0
    return fac[com_n] * ifac[com_r] % md * ifac[com_n - com_r] % md

# combinationの準備
# md>n_maxの条件
md = 10 ** 9 + 7
n_max = 200005
fac = [1]
for i in range(1, n_max + 1): fac.append(fac[-1] * i % md)
ifac = [1] * (n_max + 1)
ifac[n_max] = pow(fac[n_max], md - 2, md)
for i in range(n_max - 1, 1, -1): ifac[i] = ifac[i + 1] * (i + 1) % md
half=[1]*n_max
half[n_max-1]=pow(pow(2,n_max-1,md),md-2,md)
for i in range(n_max-2,0,-1):half[i]=half[i+1]*2%md

memo={}
# 色c（代入するのは個数）がt回でなくなる確率
def p0(t,c):
    if t<c:return 0
    if (t,c) in memo:return memo[t,c]
    res=p0(t-1,c)+half[t]*nCr(t-1,c-1)
    res=memo[t,c]=res%md
    return res

def main():
    b,w=MI()
    for i in range(b+w):
        ans=p0(i,w)+(1-p0(i,b)-p0(i,w))*half[1]
        print(ans%md)

main()

Measured memory_bytes: 67564
import javax.management.MBeanRegistration;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.StringTokenizer;
import java.util.Scanner;
import java.lang.*;
import java.io.*;
import java.util.*;
import java.lang.Integer;
import java.util.HashMap;

public class Main {
    // driver function to test the above functions
    public static void main(String args[]) throws IOException {
        Reader.init(System.in);
        int n =Reader.nextInt();
        long ans = 0;
        for(int i=1; i<=n; i++){
            if (!(i%3==0 || i%5==0)){
                ans=ans+i;
            }
        }
        System.out.println(ans);

    }
}

class Node{
    char val;
    Node nxt = null;
    Node prev=null;


}



class solu{

}

/** Class for buffered reading int and double values */
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }

    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }

    static String line() throws IOException {
        return reader.readLine();
    }
}

Measured memory_bytes: 32664
N,Y=map(int,input().split())
for i in range(N+1):
    for j in range(N+1):
        A,B,C=i*10000,j*5000,(N-i-j)*1000
        if A+B+C==Y and i+j+(N-i-j) and -1<N-i-j:
            print(i,j,N-i-j)
            exit()
print(-1,-1,-1)

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

using namespace std;
#define ll long long
#define pb push_back

int main()
{	
	string str;
	cin >> str;
	int cnt=0;
	for(int i=0; i<3; i++) {
		if(str[i]=='1') cnt++;
	}
	cout << cnt << endl;
	return 0;
}


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

int main()
{
    int N;
    cin >> N;
    int C[N + 1] = {};
    int S[N + 1] = {};
    int F[N + 1] = {};

    for (int i = 1; i <= N - 1; i++)
    {
        cin >> C[i] >> S[i] >> F[i];
    }

    for (int i = 1; i <= N; i++)
    {
        int ans = S[i];
        for (int j = i; j <= N - 1; j++)
        {
            if (ans <= S[j])
            {
                ans = S[j] + C[j];
            }
            else
            {
                if (ans % F[j] == 0)
                {
                    ans += C[j];
                }
                else
                {
                    ans += F[j] - (ans % F[j]) + C[j];
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
from collections import Counter


def main():
    n = int(input())
    s = [input() for _ in range(n)]
    counter = Counter(s)
    most_common = counter.most_common()
    max_num = most_common[0][1]
    values, counts = zip(*most_common)
    for i, cnt in enumerate(counts):
        if cnt != max_num:
            last_index = i
            break
    else:
        last_index = len(counter)
    ans = list(values[:last_index])
    ans.sort()
    print("\n".join(ans))


if __name__ == "__main__":
    main()


Measured memory_bytes: 63760
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var np=Arr.shift();
   if(np=="0 0")break;
   np=np.split(" ").map(Number);
   var n=np[0];
   var p=np[1];
   var sum=p;
   var arr=[];
   for(var i=0;i<n;i++)arr.push(0);
   var j=0;
   for(var i=0;i<1000000;i++){
      if(j==arr.length)j=0;
      if(p>0){
         p--;
         arr[j]++;
         if(p==0 && sum==arr[j]){console.log(j);break;}
      }else{
         p=arr[j];
         arr[j]=0;
      }
      j++;
   }
}

Measured memory_bytes: 8512
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vi2;
const int INF = 1 << 30;

int solve();

int main(void) {

	while (solve()){}

	return 0;

}

int solve() {

	int n, m, s, g1, g2;

	cin >> n >> m >> s >> g1 >> g2;
	if (!(n | m | s | g1 | g2)){ return 0; }

	s--;
	g1--;
	g2--;

	//Adjacency matrix
	vi2 v(n, vi(n, -1));

	//distance
	vi2 d(n, vi(n, INF));

	//input
	for (int i = 0; i < m; i++) {

		int b1, b2, c;

		cin >> b1 >> b2 >> c;
		v[b1 - 1][b2 - 1] = c;

	}

	//Floyd???Warshall algorithm
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (v[i][j] > 0) {
				d[i][j] = v[i][j];
			}
			if (i == j) {
				d[i][j] = 0;
			}
		}
	}

	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if ( d[i][k] < INF && d[k][j] < INF )
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}

	//s??????i,g1,g2????????°???
	int ans = INF;
	for (int i = 0; i < n; i++) {
		if (d[s][i] == INF || d[i][g1] == INF || d[i][g2] == INF) 
		{
			continue;
		}
		ans = min(d[s][i] + d[i][g1] + d[i][g2], ans);
	}

	//s->g1->g2
	if (d[s][g1] < INF && d[g1][g2] < INF)
		ans = min(d[s][g1] + d[g1][g2], ans);

	//s->g2->g1
	if (d[s][g2] < INF && d[g2][g1] < INF)
		ans = min(d[s][g2] + d[g2][g1], ans);

	cout << ans << endl;

	return 1;
	
}

Measured memory_bytes: 3172
#include <iostream>
#include <string.h>
#include <vector>

using namespace std;

typedef unsigned long long ull;
typedef pair<int, int> P;

int main() {

	string S, T, U;
	cin >> S >> T;

	int A, B;
	cin >> A >> B;

	cin >> U;

	if (U == S)
		A--;
	else
		B--;

	cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int k,a,b;
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
    return 0;
}

Measured memory_bytes: 3008
if __name__ == "__main__":
    n = int(input())
    for _ in range(n):
        count = 0
        y,m,d = list(map(int,input().strip().split()))
        if y %3 == 0:count += 20 - d +1
        elif m &1: count +=20 -d + 1
        else :count += 19-d+1
        for i in range(m + 1,11):
            if y % 3 ==0: count +=20
            elif i &1: count += 20
            else:count += 19
        for i in range(y + 1,1000):
            if i %3 ==0: count+= 20* 10
            else:count += 20 * 5 + 19 * 5
        print(count)

Measured memory_bytes: 7592
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a) begin(a),end(a)
#define FOR(x,val,to) for(int x=(val);x<int((to));++x)
#define FORE(x,val,to) for(auto x=(val);x<=(to);++x)
#define FORR(x,arr) for(auto &x: arr)
#define FORS(x,plus,arr) for(auto x = begin(arr)+(plus); x != end(arr); ++x)
#define FORREV(x,plus,arr) for(auto x = (arr).rbegin()+(plus); x !=(arr).rend(); ++x)
#define REE(s_) {cout<<s_<<'\n';exit(0);}
#define GET(arr) for(auto &i: (arr)) sc(i)
#define whatis(x) cerr << #x << " is " << (x) << endl;
#define e1 first
#define e2 second
#define INF 0x7f7f7f7f
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::vector<std::string> vs;
typedef int64_t ll;
typedef uint64_t ull;
#define umap unordered_map
#define uset unordered_set
using namespace std;
using namespace __gnu_pbds;

#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
template<class L, class R> ostream& operator<<(ostream &os, map<L, R> P) { for(auto const &vv: P)os<<"("<<vv.first<<","<<vv.second<<")"; return os; }
template<class T> ostream& operator<<(ostream &os, set<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) { os<<"("<<P.first<<","<<P.second<<")"; return os; }
inline int fstoi(const string &str){auto it=str.begin();bool neg=0;int num=0;if(*it=='-')neg=1;else num=*it-'0';++it;while(it<str.end()) num=num*10+(*it++-'0');if(neg)num*=-1;return num;}
inline void getch(char &x){while(x = getchar_unlocked(), x < 33){;}}
inline void getstr(string &str){str.clear(); char cur;while(cur=getchar_unlocked(),cur<33){;}while(cur>32){str+=cur;cur=getchar_unlocked();}}
template<typename T> inline bool sc(T &num){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){if(c == EOF) return false;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; return true;}template<typename T, typename ...Args> inline void sc(T &num, Args &...args){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; sc(args...); }
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //s.find_by_order(), s.order_of_key() <- works like lower_bound
template<typename T> using ordered_map = tree<T, int, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 1000001

bool xd(int n){
    bool k = 0;
    while(n){
        n /= 10;
        k ^= 1;
    }
    return k;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    sc(n);
    int ret = 0;
    FORE(i,1,n){
        ret += xd(i);
    }
    cout << ret;
}



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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

vvint edges;

ll solve(ll cur){
    priority_queue<ll, vint, greater<ll>> pq;
    for(auto child:edges[cur]){
        pq.push(solve(child)+1);
    }
    ll rtn = 0;
    while(not pq.empty()){
        rtn++;
        chmax(rtn, pq.top());
        pq.pop();
    }

    // cout<<"cur: "<<cur<<", rtn: "<<rtn<<endl;

    return rtn;
}

int main() {
    cout<<fixed<<setprecision(10);

    ll n; cin>>n;
    vint a(n-1);
    rep(i,n-1) cin>>a[i];

    edges.resize(n);
    rep(i,n-1){
        edges[a[i]-1].push_back(i+1);
    }

    cout<<solve(0)<<endl;


    return 0;

}

Measured memory_bytes: 14336
#include<stdio.h>
int main(void) {
        char ST[200001];
        int T=0;
        int count=0;
        int n;
        scanf("%s", ST);
                for(n=0; ST[n]!='\0'; n++) {
                        if(T==0 && ST[n]=='T') {
                                count++;
                        }else if(T>0 && ST[n]=='T') {
                                T--;
                        }
                        if(ST[n]=='S') {
                                T++;
                        }
                }
                count+=T;
                printf("%d\n", count);
        return 0;
}


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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a,b) ((a)>(0)?(a):-(a))

int main(void){
    int A,B,X;
    scanf("%d %d %d",&A,&B,&X);
    if(A<=X && X<=A+B){
        printf("YES");
    }else{printf("NO");
    }
            
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll=std::int_fast64_t;
using u64=std::uint_fast64_t;

void solve(){
  ll n,a,b,c,d;
  std::cin>>n>>a>>b>>c>>d;

  constexpr ll INF=1e18;

  std::map<ll,ll> memo;
  auto dp=[&](auto f,ll num)->ll{
    if(num==0)return 0;
    if(memo[num]!=0)return memo[num];

    ll val=INF;
    ll arr[3]={2,3,5};
    ll cost[3]={a,b,c};
    rep(i,0,3){
      ll down=num/arr[i];
      ll up=(num+arr[i]-1)/arr[i];
      if(down!=num)chmin(val,f(f,down)+d*std::abs(num-down*arr[i]) + (down>0 ? cost[i]:0));
      if(up!=num)chmin(val,f(f,up)+d*std::abs(num-up*arr[i]) + (up>0?cost[i]:0));
    }

    if(d<=val/num)chmin(val,d*num);

    return memo[num]=val;
  };

  dp(dp,n);

  std::cout<<dp(dp,n)<<"\n";

  for(const auto& [key,val]:memo)debug(key,val);
}

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

  ll test;
  std::cin>>test;

  while(test--)solve();
  
  return 0;
}

Measured memory_bytes: 4440
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, m, k = map(int, input().split())


class UnionFind:
    def __init__(self, n):
        self.p = [-1]*n
        # union by rank
        self.r = [1]*n

    def find(self, x):
        if self.p[x] < 0:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]

    def union(self, x, y):
        rx, ry = self.find(x), self.find(y)

        if rx != ry:
            if self.r[rx] > self.r[ry]:
                rx, ry = ry, rx
            if self.r[rx] == self.r[ry]:
                self.r[ry] += 1
            self.p[ry] += self.p[rx]
            self.p[rx] = ry

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def count_member(self, x):
        return -self.p[self.find(x)]


uf = UnionFind(n)
ab = []
cd = []

for _ in range(m):
    a, b = map(lambda x: int(x)-1, input().split())
    ab.append((a, b))
    uf.union(a, b)

for _ in range(k):
    c, d = map(lambda x: int(x)-1, input().split())
    cd.append((c, d))

ans = [uf.count_member(i)-1 for i in range(n)]

for a, b in ab:
    if uf.same(a, b):
        ans[a] -= 1
        ans[b] -= 1

for c, d in cd:
    if uf.same(c, d):
        ans[c] -= 1
        ans[d] -= 1

print(*ans)


Measured memory_bytes: 37952
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
#include <queue>
#include <cstdio>
#include <stack>
#include <list>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;
template <class T> T gcd(T n, T m){return m ? gcd(m, n%m):n;}

int main(){
    int n,k;cin>>n>>k;
    if (n < 10 && k < 10){cout << n*k <<endl;}
    else{cout << -1 << endl;}
}

Measured memory_bytes: 256
import os, sys, re, math

(N, K, Q) = [int(n) for n in input().split()]

answer_count = [K - Q] * N
for i in range(Q):
    answer_count[int(input()) - 1] += 1

for a in answer_count:
    print('Yes' if a > 0 else 'No')


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

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

point = A[0]
maxlen = A[0] + (K-A[N-1])
for i in range(1,N):
    maxlen = max(A[i]-A[i-1],maxlen)
    #print(str(A[i]-A[i-1]) + "max="+str(maxlen))


print(K-maxlen)


Measured memory_bytes: 26100
N , L = map(int,input().split())
alpha='abcdefghijklmnopqrstuvwxyz'
def which(a,b):
    l=len(a)
    for i in range(l):
        x=alpha.index(a[i])
        y=alpha.index(b[i])
        if x<y:return True
        if x>y:return False
        
S = []
S.append(str(input()))
for i in range(1,N):
    Si=str(input())
    for j in range(len(S)):
        vs=S[j]
        if which(Si,vs):
            Slist=[]
            Slist.append(Si)
            if j==0:
                S=Slist+S
            else:S = S[:j]+Slist+S[j:]
            break
        if j==len(S)-1:S.append(Si)
        
result=''
for i in range(N):
    result+=S[i]
print(result)

Measured memory_bytes: 3064
def solve():
    from sys import stdin
    f_i = stdin
    
    mod = 10 ** 9 + 7
    
    N, K = map(int, f_i.readline().split())
    A = sorted(map(int, f_i.readline().split()))
    
    comb = 1
    ans = A[K-1] - A[N-K]
    for i, j in zip(range(K, N), range(1, N)):
        comb = comb * i * pow(j, mod - 2, mod) % mod
        ans += (A[i] - A[N-i-1]) * comb
        ans %= mod
    
    print(ans)

solve()

Measured memory_bytes: 14044
#include <bits/stdc++.h>
#define endl "\n"
#define int long long
using namespace std;


int N , Q ;

void replaceSum(){
	
	int sum = 0;
	cin >> N ;
	vector<int> freq(100001 , 0);
	for(int i , inp ; i < N ; i++){
		
		cin >> inp ;
		freq[inp]++;
		sum += inp ;
	}
	
	cin >> Q ;
	
	for(int Query=0, B ,C ; Query < Q ; Query++){
		
		cin >> B >> C ;
		sum -= freq[B] * B ;
		sum += freq[B] * C ;
		freq[C] +=  freq[B];
		freq[B] = 0 ;
		
		cout << sum << endl ;
	}
	
}







int32_t main() {
	
	ios_base::sync_with_stdio(false) ,cin.tie(nullptr);
	replaceSum();
	
	return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
#define MAX_B 1001001
#define NIL -1
const int MOD = 1e9+7;
const int INF = 1 << 29;
const ll INFTY=1000000000000000000LL;

int main(){
    int n,q,l,r;
    string s;
    cin>>n>>q>>s;
    vector<bool>a(n+1,0);
    rep(i,n-1){
        if(s.substr(i,2)=="AC"){
            a[i]=1;
        }
    }
    int sum[n+1];//累積和
    sum[0]=0;
    rep(i,n){
        sum[i+1]=sum[i]+a[i];
    }
    rep(i,q){
        cin>>l>>r;
        l--;r--;
        cout<<sum[r]-sum[l]<<endl;
    }
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
    string s;
  cin>>s;
  int t=s.length();
  cout<<s[0]<<(t-2)<<s[t-1];
    return 0;
}

Measured memory_bytes: 256
def main():
    import numpy as np
    n, k = map(int, input().split())
    a = np.array(input().split(), np.int64)
    f = np.array(input().split(), np.int64)
    a.sort()
    a = a[::-1]
    f.sort()
    right = np.max(a*f)
    left = 0
    while right > left:
        middle = (right + left)//2
        if np.sum(np.maximum(a-middle//f, 0)) <= k:
            right = middle
        else:
            left = middle+1
    print(right)
if __name__ == '__main__':
    main()

Measured memory_bytes: 37260
def read():
    return [int(x) for x in str.split(raw_input())]

n, m = read()
st = []
cnt = 0

for i in range(n):
    st.append(raw_input())
    for j in range(m):
        if (st[i][j] == '#'):
            cnt = cnt+1
            
def can_down(st, x, y):
    return x+1 < n and st[x+1][y] == '#'

def can_right(st, x, y):
    return y+1 < m and st[x][y+1] == '#'

def dfs(st, x, y, c):
    if (x == n-1 and y == m-1):
        return c == cnt
    down, right = can_down(st, x, y), can_right(st, x, y)
    if (down and right):
        return 0
    if ((not down) and (not right)):
        return 0
    if (down):
        return dfs(st, x+1, y, c+1)
    if (right):
        return dfs(st, x, y+1, c+1)

if (dfs(st, 0, 0, 1) == 1):
    print("Possible")
else:
    print("Impossible");


Measured memory_bytes: 2696
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#define N 500005
#define lowbit(o) o&(-o)
using namespace std;
int i,j,k,l,s,n,m,last,tot,a[N],ans,b[N],f[N][4];
char c[N];
inline void getans() {
	if (tot<=1) return ;
	for (int i=1;i<tot;i++) for (int j=0;j<=3;j++) for (int k=0;k<=3;k++) {
		if (f[i-1][j]==-1) continue;
		if (!k) f[i][k]=max(f[i][k],f[i-1][j]);
		else {
			if (((j==1&&b[i]==1)||j==2)) continue;
			if (k==1&&j<=1) f[i][k]=max(f[i][k],f[i-1][j]+b[i]-j);
			else if (k==1&&j==3) f[i][k]=max(f[i][k],f[i-1][j]+1);
			else if (k==2) f[i][k]=max(f[i][k],f[i-1][j]+b[i+1]);
			else f[i][k]=max(f[i][k],f[i-1][j]+b[i+1]-1);
		}
	}
	ans+=max(f[tot-1][0],max(max(f[tot-1][1],f[tot-1][2]),f[tot-1][3]));
	for (int i=1;i<tot;i++) for (int j=0;j<=3;j++) f[i][j]=-1;
}
inline void work() {
	for (i=1;i<=n;i++) {
		if (!a[i]&&!last) getans(),tot=0;
		else if (a[i]&&!last) last=1,b[++tot]=1;
		else if (a[i]&&last) b[tot]++;
		else last=0;
	}
	getans();
}
int main() {
	scanf("%d",&n);
	scanf("%s",c);
	memset(f,-1,sizeof(f));
	f[0][0]=0;
	for (i=0;i<n;i++) a[i+1]=c[i]-48;
	work();
	printf("%d\n",ans);
}


Measured memory_bytes: 12416
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoder
{
    internal class Program
    {
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
        static long[] ReadLongs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); }
        static string[] ReadStrings() { return Console.ReadLine().Split(); }

        static void Main(string[] args)
        {
            var n = ReadLong();
            Solve(n);
        }


        internal static void Solve(long n)
        {
            var ans = n.ToString().Length;
            var root = Math.Sqrt(n);
            for (var i = 2; i <= root; ++i)
            {
                if (n % i == 0)
                {
                    var div = (n / i).ToString().Length;
                    if (div < ans)
                    {
                        ans = div;
                    }
                }
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13140
#include<stdio.h>

int main(void){
  int n,tmp;
  int ans;

  while(1){
    scanf("%d",&n);
    if(!n)break;

    ans = 0;

    tmp = 5;
    while(tmp <= n){
      ans += n/tmp;
      tmp *= 5;
    }

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

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

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

using ll = long long;
using lb = long double;
using P = pair<int,int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    ll D,T,S;
    cin>>D>>T>>S;
    if((lb)D/S<=T) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}


//{{{ Segment Tree
template <class T>
struct segment_tree {
	int n;
	vector<T> x;
	segment_tree(int n_) {
		n=1;
		while(n < n_)n*=2;
		x.assign(n*2,init_val());
	}

	T init_val(){
		return 0;
	}
	T f(const T &a, const T &b){
		return a+b;
	}
	T range(int a,int b,int i,int l,int r){
		if(r<=a or b<=l)return init_val();
		if(a<=l and r<=b)return x[i];
		else{
			int m = (l+r)/2;
			return f(range(a,b,i*2+1,l,m),range(a,b,i*2+2,m,r));
		}
	}
	T range(int a,int b){
		return range(a,b,0,0,n);
	}
	void add(int a,const T &v,int i,int l,int r){
		if(r-l==1){
			x[i] += v;
		}else{
			int m = (l+r)/2;
			if(a<m)add(a,v,i*2+1,l,m);
			else add(a,v,i*2+2,m,r);
			x[i] = f(x[i*2+1],x[i*2+2]);
		}
	}
	void add(int a,const T &v){
		add(a,v,0,0,n);
	}
};
//}}}

int N,K;
Int a[200010];
Int s[200010];



int main(){
	cin>>N>>K;
	REP(i,N)cin>>a[i], a[i]-=K;
	vector<Int> id;
	Int sum = s[0] = 0;
	id.push_back(0);
	REP(i,N)sum+=a[i], s[i+1] = sum, id.push_back(sum);
	sort(ALL(id));
	id.erase(unique(ALL(id)),id.end());
	segment_tree<Int> st(id.size());
//	multiset<Int> st;
	Int ans = 0;
	for(int i=N-1;i>=0;i--){
		int j = distance(id.begin(),lower_bound(ALL(id),s[i+1]));
		st.add(j,1);
//		st.insert(s[i+1]);
		j = distance(id.begin(),lower_bound(ALL(id),s[i]));
		ans += st.range(j,id.size()+1);
//		ans += distance(st.lower_bound(s[i]),st.end());
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <tuple>
#include <bitset>
#include <random>
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 1000000007
using namespace std;
using pii=pair<int,int>;



vector<int> Dijkstra(vector<vector<pii>> adj_list,int start){
  int n=adj_list.size();
  /*初期化*/
  vector<int> distance(n,INF);
  vector<int> pre(n);
  distance.at(start)=0;
  priority_queue<pii,vector<pii>,greater<pii>> unsettled;/*未確定の頂点*/
  REP(u,n){
    unsettled.push(make_pair(distance.at(u),u));
  }

  /*本計算*/
  while(!unsettled.empty()){
    int u;
    tie(ignore,u)=unsettled.top();
    unsettled.pop();/*uを確定*/
    /*uから伸びている辺の先へ書き込み*/

    for(auto vpair : adj_list.at(u)){
      int weight_u_to_v,v;
      tie(v,weight_u_to_v)=vpair;
      int alt=distance.at(u)+weight_u_to_v;
      /*更新*/
      if(distance.at(v)>alt){
        distance.at(v)=alt;
        pre.at(v)=u;
        unsettled.push(make_pair(alt,v));

      }
    }

  }
  return distance;

}

int main() {
  int V,E,r;
  cin>>V>>E>>r;
  vector<vector<pair<int,int>>> adj_list(V);
  
  REP(i,E){
    int s,t,d;
    cin>>s>>t>>d;
    adj_list.at(s).push_back(make_pair(t,d));

  }

  vector<int> distance=Dijkstra(adj_list,r);
  REP(i,V){
    if(distance.at(i)==INF){
      cout<<"INF"<<endl;
    }else{
      cout<<distance.at(i)<<endl;
    }
  }


  return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;

  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
  cout << endl << "#";
  string a;
  for (int i = 0; i < H; i++) {
    cin >> a;
    cout << a << "#" << endl;
    if (i == H - 1) {
      break;
    }
    cout << "#";
  }
  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
  cout << endl;
}

Measured memory_bytes: 256
import sys
from operator import itemgetter

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

class UnionFind:
    def __init__(self, N):
        self.root = list(range(N + 1))

    def __getitem__(self, x):
        root = self.root
        while root[x] != x:
            root[x] = root[root[x]]
            x = root[x]
        return x

    def merge(self, x, y):
        x = self[x]
        y = self[y]
        if x == y:
            return
        # 番号の大きい頂点を根にする
        if x < y:
            x, y = y, x
        self.root[y] = x

N = int(readline())
m = map(int, read().split())
ABC = sorted(zip(m, m, m), key=itemgetter(2), reverse=True)

uf = UnionFind(N + N)
parent = [0] * (N + N)
value = [0] * (N + N)
for n, (a, b, c) in enumerate(ABC, N + 1):
    ra = uf[a]
    rb = uf[b]
    parent[ra] = n
    parent[rb] = n
    value[n] = c
    uf.merge(ra, n)
    uf.merge(rb, n)

size = [0] + [1] * N + [0] * (N - 1)
for n in range(N + N):
    p = parent[n]
    size[p] += size[n]

for n in range(N + N):
    p = parent[n]
    value[n] = 0
    if not p:
        continue
    value[n] = value[p] * (size[p] - size[n])
for n in range(N + N - 2, 0, -1):
    p = parent[n]
    value[n] += value[p]

print('\n'.join(map(str, value[1:N + 1])))

Measured memory_bytes: 57432
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int K, A, B;

  std::cin >> K >> A >> B;

  for (int i = A; i <= B; i ++)
    if (i % K == 0) {
      std::cout << "OK" << std::endl;

      return 0;
    }

  std::cout << "NG" << std::endl;

  return 0;
}


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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

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

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(exp, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)1e5+1;
int N, A[21], B[21], C[21];


int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    int ans = 0;
    for(int i=0; i<N; i++)
    {
        cin >> A[i];
        A[i]--;
    }
    for(int i=0; i<N; i++)
    {
        cin >> B[i];
    }
    for(int i=0; i<N-1; i++)
    {
        cin >> C[i];
    }

    int prev = -1;
    for(int i=0; i<N; i++)
    {
        ans += B[A[i]];
        if(prev != -1 && A[i] == prev + 1)
        {
            ans += C[prev];
        }
        prev = A[i];
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;


int main(){
    int m, d;
    cin >> m >> d;

    int res = 0;
    int d1;
    int d2;

    for(int month=4;month<=m;month++){
        for(int day=22;day<=d;day++){
            int tmp = day;
            d1 = day % 10;
            if(d1 < 2) continue;
            tmp -= d1;
            d2 = tmp/10;

            if(month == d1*d2)res++;
        }
    }
  cout << res << endl;
}

Measured memory_bytes: 256