akhauriyash/Code-Regression huggingface dataset:
//includes
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#include<assert.h>
#include<cstring>
#include<unordered_map>
#include<bitset>

//macros and consts
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define FORE(i,a) for(auto &i : a)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define accm accumulate
#define Fi first
#define Se second
#define INF 1e9
#define llINF (1LL<<60)
#define mINF -1e9
#define mllINF -(1LL<<60)
#define endl "\n"
#define CONT continue
#define BRK break
#define modulo(n, m) (((n)%(m)+(m))%m)

//shorter types
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vc = std::vector<char>;
using vll = std::vector<long long>;
using vs = std::vector<string>;
using Mi = map<int,int>;
using Mll = map<ll,ll>;
using UMi = unordered_map<int,int>;
using UMll = unordered_map<ll,ll>;
using Pi = pair<int,int>;
using Pll = pair<ll,ll>;
using vPi = vector<Pi>;
using vPll = vector<Pll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pqgi = priority_queue<int,vector<int>,greater<int>>;
using pqsi = priority_queue<int,vector<int>,less<int>>;
using pqgll = priority_queue<int,vector<int>,greater<int>>;
using pssll = priority_queue<int,vector<int>,less<int>>;
template<class T>
using vec = vector<T>;
#define int long long
//here begins your code
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int N,K;
  cin >> N >> K;

  vector<int> H;
  H.resize(N);
  for(int i = 0 ; i < N ; i++){
  	cin >> H[i];
  }

  sort(H.begin(),H.end());
  if(K >= N){
  	cout << 0 << endl;
  }
  else{
  	int sum = 0;
  	for(int i = 0 ; i < N-K ; i++){
  		sum += H[i];
  	}
  	cout << sum << endl;
  }



  //check types
  //do not eb if you resize
  //resize before you access by idx
  return 0;
} 

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

#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(5e3 + 10)

using namespace std;

int n, k;
int a[N], b[N];

void dfs(int nd, vector<int> &v) {
	v.pb(nd);
	if (v.size() and v.front() != a[nd])
		dfs(a[nd], v);
}

void solve() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= n; i++)
		cin >> b[i];

	int ma = -inf;

	for (int i = 1; i <= n; i++) {
		vector<int> v;
		dfs(i, v);
		int m = v.size();
		int cy = k / m;
		int rem = k % m;
		int ans = -inf, val1 = -inf, val2 = -inf;
		int tot = 0;
		for (int i = 1; i < m; i++) {
			tot += b[v[i]];
			val2 = max(val2, tot);
			if (i <= rem)
				val1 = max(val1, tot);
		}
		tot += b[v[0]];
		val2 = max(val2, tot);
		if (!cy)
			ans = val1;
		else
			ans = max((tot * cy) + val1, max(0ll, (tot * (cy - 1))) + val2);
		// dbg(tot, val1, val2, ans);

		ma = max(ma, ans);
	}

	cout << ma << endl;
}
// you should probably see down .. believe me it would help
int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
//	cin >> t_c;
	while (t_c--)
		solve();
}

/*
 * COME ON DUDE .... DONT GET UP UNTIL U GET THE SOLUTION
 * GIVING UP NOT GONNA HELP .. JUST GET YOUR ASS TO WORK ALREADY ..
 * AND FOR FUCKING SAKE ... DONT PANIC !!
*/


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

using namespace std;

template<typename T>void read(T&x){x=0;int fl=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')
fl=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}x*=fl;}
template<typename T,typename...Args>inline void read(T&t,Args&...args){read(t);read(args...);}

typedef long long LL;
typedef pair<int, int> pii;
#define mp(x, y) make_pair(x, y)
#define pb(x) emplace_back(x)

LL n, cnt;
map<LL, bool> exist;

void check(LL k){
	LL t = n;
	if(k == 1)	return;
	while(t % k == 0)
		t /= k;
	t %= k;
	if(t == 1){
		if(exist[k] == 0)	cnt++;
		exist[k] = 1;
	}
}

int main(){
	read(n);
	for(LL i = 1; i * i <= n; i++)
		if(n % i == 0)
			check(i), check(n / i);
	for(LL i = 1; i * i <= n - 1; i++)
		if((n - 1) % i == 0)
			check(i), check((n - 1) / i);
	printf("%lld\n", cnt);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(ll, n, k);
    Cins(int, n, a);
    
    vc<int> v(n, -1);
    int i = 0;
    v[i] = 0;
    while(true){
        int j = a[i] - 1;
        if(v[j] == -1){
            v[j] = v[i] + 1;
            i = j;
            continue;
        }
        
        // 1st: v[j]
        // 2nd: v[i] + 1
        int p = v[i] + 1 - v[j];
        if(k > v[j]) k = (k - v[j]) % p + v[j];

        int ans = 0;
        Rep(k) ans = a[ans] - 1;
        Return(ans + 1);
    }
    
}



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

const long long int MOD = 1000000007;
const int MAX_K = 404040;

long long int fac[MAX_K], finv[MAX_K], inv[MAX_K];

void com_init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX_K; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long int com(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
  com_init();
  int n, k;
  cin>>n>>k;
  vector<ll> a(n), b(n);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  
  rep(i,n) b[i] = com(i,k-1);
  
  ll res = 0;
  rep(i,n)
  {
    res += (a[i]*b[i])%MOD;
    res = ((MOD+res)-(a[i]*b[n-i-1])%MOD)%MOD;
  }
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 11264
N=int(input())
#75=3*5*5
#  =15*5
#  =3*25
#  =1*75

#N以下の素数
prime=[]
is_prime=[True]*(N+1)
is_prime[0]=is_prime[1]=False
for i in range(2,N+1):
    if is_prime[i]==False: continue
    prime.append(i)
    for j in range(i*i,N+1,i):
        is_prime[j]=False

#N!を素因数分解
import collections
pfac=collections.defaultdict(int)
for n in range(1,N+1):
    while n>1:
        for p in prime:
            if n%p==0:
                pfac[p]+=1
                n//=p

pfac2=sum([1 for n in pfac.values() if n>=2])
pfac4=sum([1 for n in pfac.values() if n>=4])
pfac14=sum([1 for n in pfac.values() if n>=14])
pfac24=sum([1 for n in pfac.values() if n>=24])
pfac74=sum([1 for n in pfac.values() if n>=74])

#3*5*5
ans=pfac4*(pfac4-1)*(pfac2-2)//2
#5*15
ans+=pfac14*(pfac4-1)
#3*25
ans+=pfac24*(pfac2-1)
#1*75
ans+=pfac74

print(ans)


Measured memory_bytes: 38768
use std::collections::HashSet;

fn main() {
    let n = read_vec::<usize>()[0];
    let mut s = HashSet::new();
    for i in (0..n) {
        s.insert(read_vec_to_str());
    }

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec_to_str() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().to_string()
}

Measured memory_bytes: 15300
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	long long x;
	cin >> x;
  	for(long long a = 1; a <= 100LL; a++) {
    	for(long long b = -a; b < a; b++) {
        	if(a*a*a*a*a - b*b*b*b*b == x) {
            	cout << a << " " << b << endl;
            	return 0;
            }
        }
    }
  	for(long long a = 101; a <= 200LL; a++) {
    	for(long long b = 0; b < a; b++) {
        	if(a*a*a*a*a - b*b*b*b*b == x) {
            	cout << a << " " << b << endl;
            	return 0;
            }
        }
    }
  	cout << endl;
}


Measured memory_bytes: 3632
(defun dis (x y)
  (let ((r 0))
       (loop for i in x for j in y do
             (incf r (expt (- i j) 2)))
       r))

(let ((n (read))
      (k (read))
      (arr (make-array 0 :element-type 'list
                         :adjustable t
                         :fill-pointer 0))
      (temp ())
      (ans 0))
     (dotimes (i n)
       (setf temp ())
       (dotimes (j k)
         (setf temp (append temp (list (read)))))
       (vector-push-extend temp arr))
     (loop for i from 0 below (1- n)
           do (loop for j from (1+ i) upto (1- n)
                    do (setf temp (sqrt (dis (aref arr i) (aref arr j))))
                       (if (zerop (- temp (floor temp))) (incf ans))))
     (princ ans))

Measured memory_bytes: 8288
#include<cstdio>
#include<vector>
#include<algorithm>
#include<iterator>
#include<cstring>
#include<cctype>
using namespace std;
typedef vector<int>V;
V a[5],u;
int x;
V F(char*s)
{
	vector<V>v;
	V m;
	v.reserve(x);
	m.reserve(u.size());
	for(char*p=s;*p;++p)
	{
		if(isupper(*p))v.push_back(a[*p-'A']);
		else
		{
			#define A(L,R) L.begin(),L.end(),R.begin(),R.end(),back_inserter(m)
			m.clear();
			if(*p-'c')
			{
				V r(v.back());v.pop_back();
				V l(v.back());v.pop_back();
				if(*p=='u')set_union(A(l,r));
				if(*p=='i')set_intersection(A(l,r));
				if(*p=='d')set_difference(A(l,r));
				if(*p=='s')set_symmetric_difference(A(l,r));
			}
			else
			{
				V r(v.back());v.pop_back();
				set_difference(A(u,r));
			}
			v.push_back(m);
		}
	}
	return v[0];
}
void I(V&v)
{
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
}
int main()
{
	char*p,c,s[8193];
	int n,i,t;
	for(;;)
	{
		for(x=i=0;i<5;++i)a[i].clear();
		u.clear();
		for(;;)
		{
			if(scanf(" %c%d",&c,&i)<2)return 0;
			if(c=='R')break;
			n=c-'A';
			while(i--)scanf("%d",&t),a[n].push_back(t);
			I(a[n]);
			u.insert(u.end(),a[n].begin(),a[n].end());
		}
		I(u);
		scanf("%s",s);
		vector<char>v,u;
		for(p=s;*p;++p)
		{
			c=*p;
			if(isupper(c))
			{
				++x;
				v.push_back(c);
				while(u.size()&&strchr("uidsc",u.back()))v.push_back(u.back()),u.pop_back();
			}
			else
			{
				if(c==')')
				{
					while(u.back()!='(')
					{
						v.push_back(u.back());
						u.pop_back();
					}
					u.pop_back();
					while(u.size()&&strchr("uidsc",u.back()))v.push_back(u.back()),u.pop_back();
				}
				else u.push_back(c);
			}
		}
		while(u.size())v.push_back(u.back()),u.pop_back();
		v.push_back(0);	
		V r(F(&v[0]));
		if(r.empty())puts("NULL");
		else for(i=0;i<r.size();++i)printf("%d%c",r[i],i+1-r.size()?' ':'\n');
	}
}

Measured memory_bytes: 0
# numpy使うときは、PyPyは不可
import numpy as np

N, K = map(int, input().split())
P = (np.array(list((map(int, input().split())))) + 1)

# ans = 0
#
# for num in range(len(P)):
#     tmp = P[num:num+K].sum()
#     if ans < tmp:
#         ans = tmp
#
# print(ans/2)


# 回答
Pcum = np.zeros(N + 1, np.int32)
Pcum[1:] = P.cumsum()

length_K_sums = Pcum[K:] - Pcum[0:-K]
print(length_K_sums.max() / 2)

Measured memory_bytes: 33996
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  vector<int> p;
  set<int> q;
  rep(i,m){
    int x,y;
    cin>>x>>y;
    x--;y--;
    if(x==0) p.pb(y);
    if(y==n-1) q.insert(x);
  }

  bool ok=false;
  rep(i,p.size()){
    if(q.count(p[i])) ok=true;
  }

  cout << (ok?"POSSIBLE":"IMPOSSIBLE") << endl;

}

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

int main(void)
{
	int a,b,c;
	
	cin >> a >> b >> c;
	
	if(a < b) {
		if(b < c) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3080
//Patwari26
//#include template<t> as mine
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n,m;
    cin>>n>>m;
    ll a,b,x,y;
    cin>>a>>b;
    a--,b--;
    cin>>x>>y;
    x--,y--;
    string s[n];
    rep(i,0,n-1) cin>>s[i];
    using T=pair<ll,pii>;
    priority_queue<T,vector<T>,greater<T>> q;
    q.push({0,{a,b}});
    ll ans[n][m];
    bool vis[n][m];
    memset(vis,0,sizeof(vis));
    memset(ans,-1,sizeof(ans));
    // vis[a][b]=1;
    while(!q.empty()){
        T top=q.top();
        q.pop();
        if(vis[top.y.x][top.y.y]) continue;
        ans[top.y.x][top.y.y]=top.x;
        vis[top.y.x][top.y.y]=1;
        rep(i,-1,1){
            rep(j,-1,1){
                if(abs(i)==abs(j)) continue;
                if(top.y.x+i>=0 && top.y.x+i<n && top.y.y+j>=0 && top.y.y+j<m && !vis[top.y.x+i][top.y.y+j] && s[top.y.x+i][top.y.y+j]=='.'){
                    q.push({top.x,{top.y.x+i,top.y.y+j}});
                }
            }
        }
        rep(i,-2,2){
            rep(j,-2,2){
                if(top.y.x+i>=0 && top.y.x+i<n && top.y.y+j>=0 && top.y.y+j<m && !vis[top.y.x+i][top.y.y+j] && s[top.y.x+i][top.y.y+j]=='.'){
                    q.push({top.x+1,{top.y.x+i,top.y.y+j}});
                }
            }
        }
    }
    // cout<<ans[1][1]<<endl;
    cout<<ans[x][y]<<endl;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    // time
    return 0;
}

Measured memory_bytes: 16088
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <bitset>
#include <numeric>

using namespace std;

typedef long long li;

const int BITSIZE = 2000 * 2000;
typedef bitset<BITSIZE> bits;

int main() {
    li n;
    cin >> n;
    vector<li> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    bits possible(1);
    for (auto &&x : a) {
        possible |= possible << x;
    }
    const li total = accumulate(a.begin(), a.end(), 0LL);
    for (li ans = (total + 1) / 2; ans <= total; ++ans) {
        if (possible[ans]) {
            cout << ans << endl;
            break;
        }
    }
    return 0;
}

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

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

int main(){
    string s;
    cin >> s;
    //int size = s.size();
    ll ans=0;
    
    for(int tmp=0; tmp < (1 << (s.size() -1)); tmp++){
        //cout << tmp << endl;
        bitset<10> bit(tmp);
        ll sum = 0;
        ll ret = ctoi(s[0]);
        for(int i=0; i< s.size() -1 ; i++){
            if(bit.test(i)){
                sum += ret;
                ret = ctoi(s[i+1]);
            }else{
                ret *=10;
                ret += ctoi(s[i+1]);
                
            }
            //cout << sum << endl;
            //cout << ret << endl;
            
        }
        if(ret != 0){
                sum += ret;
        }
        //cout << sum << endl;
        ans += sum;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

// 自力で解こうとしたがうまくいかなかったので答えを見た
// 2次元累積和を使うO(Q + N^2)解法

fn main() {
    input! {
        N: usize,
        M: usize,
        Q: usize,
        tmpLRs: [(usize, usize); M],
        tmpPQs: [(usize, usize); Q],
    }

    // 0-origin
    let LRs: Vec<(usize, usize)> = tmpLRs.iter().map(|&(l, r)| (l - 1, r - 1)).collect();
    let PQs: Vec<(usize, usize)> = tmpPQs.iter().map(|&(p, q)| (p - 1, q - 1)).collect();

    // O(10^5)のループの内側でクエリに回答する
    // つまり、クエリへの回答はO(1)でできる必要がある (← 注: これ嘘です。10^7までは食えるので今回はO(NQ)までいけます)
    // ある「領域」に属する個数の総和を高速で求める → 累積和
    // ここで、領域は幅を持っている → 2次元累積和

    // imos[l][r] : 「[0, l),[0, r) の区間に含まれる電車の数」
    let mut acc: Vec<Vec<i64>> = vec![vec![0i64; N + 1]; N + 1];

    for &(l, r) in LRs.iter() {
        acc[l + 1][r + 1] += 1;
    }

    // 横方向の和
    for l in 0..N + 1 {
        for r in 1..N + 1 {
            acc[l][r] += acc[l][r - 1];
        }
    }

    // 縦方向の和
    for r in 0..N + 1 {
        for l in 1..N + 1 {
            acc[l][r] += acc[l - 1][r];
        }
    }

    for &(p, q) in PQs.iter() {
        // ループの中はほぼO(1)じゃないと間に合わない (← 注: これ嘘です。10^7までは食えるので今回はO(NQ)までいけます)
        // 区間、O(1)と来れば累積和でしょう

        let ans = acc[q + 1][q + 1] - acc[q + 1][p] - acc[p][q + 1] + acc[p][p];
        println!("{}", ans);
    }
}


Measured memory_bytes: 15492
#include <cstdio>
using lli=long long int;
const lli mod=1000000007;
int main(){
  int N;
  scanf("%d",&N);

  lli dp[100][256]={};
  for(int i=0;i<256;i++) dp[0][i]=(i/4==0);
  for(int i=1;i<N;i++){
    for(int j=0;j<1024;j++) dp[i][j%256]=(dp[i][j%256]+dp[i-1][j/4])%mod;
    if(i>1) for(int j=0;j<4;j++) dp[i][j*64+0*16+1*4+2]=dp[i][j*64+1*16+0*4+2]=dp[i][j*64+0*16+2*4+1]=0; //*AGC,*GAC,*ACG
    if(i>2) dp[i][0*64+1*16+1*4+2]=dp[i][0*64+3*16+1*4+2]=dp[i][0*64+1*16+3*4+2]=0; //AGGC,ATGC,AGTC
  }

  lli ans=0;
  for(int i=0;i<256;i++) ans+=dp[N-1][i];
  printf("%ld\n",ans%mod);
  return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	int n,m;
	cin>>n>>m;
	string s;
	cin>>s;
	if(s==a)cout<<n-1<<" "<<m;
	else cout<<n<<" "<<m-1; 
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int r,c;
    int matrix[101][101] = {{0}};
    scanf("%d %d",&r,&c);
    for(int i = 0;i < r;i++) {
        for(int j = 0;j < c;j++) {
            scanf("%d",&matrix[i][j]);
            matrix[i][c] += matrix[i][j];
            matrix[r][j] += matrix[i][j];
            }
        }
    for(int i = 0;i < r;i++) matrix[r][c] += matrix[i][c];  
    for(int i = 0;i <= r;i++){
        for(int j = 0;j <= c;j++){
            printf("%d",matrix[i][j]);
            if(j != c)printf(" ");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2780
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main()
{
    int K, S, Z = 0, ans = 0;
    std::cin >> K >> S;

    for (int X = 0; X <= K; X++)
    {
        for (int Y = 0; Y <= K; Y++)
        {
            Z = S - X - Y;
            if (0 <= Z && Z <= K) { ans++; }
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

long long check(long long x, long long count) {
  if (x % 2 == 0) {
    return check(x / 2, count + 1);
  } else {
    return count;
  }
}

int main(int argc, char* argv[]) {
  long long N;
  cin >> N;

  vector<long long> a(N);

  int ret = 0;

  for (int i = 0; i < N; ++i) {
    long long a;
    cin >> a;
    ret += check(a, 0);
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 384
import java.util.*;


public class Main {
    public static void main(String[] args){

        Scanner s = new Scanner(System.in);
        
        int a = s.nextInt();
        int array[] = new int[a];

        for (int i = 0; i < a; i++) {
            array[i] = s.nextInt();
        }

        Arrays.sort(array);

        System.out.println(array[a-1] - array[0]);
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int n, m, c, b[] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
string dp[10004];
bool a[10];

int main(){
  scanf("%d%d", &n, &m);
  for(int i = 0; i < m; i++){
    scanf("%d", &c); a[--c] = true;
  }
  for(int i = 1; i <= n; i++){
    for(int j = 0; j < 9; j++){
      if(a[j] &&  i - b[j] >= 0 && (dp[i-b[j]] != "" || i-b[j] == 0)){
        string tm = dp[i-b[j]] + (char)('1'+j);
        if(dp[i] == "") dp[i] = tm;
        else if(dp[i].size() < tm.size()) dp[i] = tm;
        else if(dp[i].size() == tm.size() && dp[i] < tm) dp[i] = tm;
      }
    }
  }
  cout << dp[n] << "\n";
}

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

int main() {

  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;

  if(A + B <= 2 * C) {
    cout << A * X + B * Y;
  }else {
    if(X > Y) cout << min(2 * C * X, 2 * C * Y + A * (X - Y)) << endl;
    else if(X == Y) cout << 2 * C * X << endl;
    else cout << min(2 * C * Y, 2 * C * X + B *(Y - X)) << endl;
  }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    a,b,q=map(int,input().split())
    S=[-INF]+[int(input()) for _ in range(a)]+[INF]
    T=[-INF]+[int(input()) for _ in range(b)]+[INF]
    X=[int(input()) for _ in range(q)]
    from bisect import bisect
    for x in X:
        i=bisect(S,x)
        j=bisect(T,x)
        sleft=x-S[i-1]
        sright=S[i]-x
        tleft=x-T[j-1]
        tright=T[j]-x
        LL=max(sleft,tleft)
        RR=max(sright,tright)
        LR=sleft+tright+min(sleft,tright)
        RL=sright+tleft+min(sright,tleft)
        print(min(LL,RR,LR,RL))

resolve()

Measured memory_bytes: 131548
import heapq

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

left = [0] * (N+1)
right = [0] * (N+1)

left[0] = sum(an[:N])
right[-1] = -sum(an[2*N:])

l = an[:N]
heapq.heapify(l)
m = an[N:2*N]
r = [-i for i in an[2*N:]]
heapq.heapify(r)

for k in range(N):
    heapq.heappush(l, m[k])
    left[1+k] = left[k] + m[k] - heapq.heappop(l)

    heapq.heappush(r, -m[-1-k])
    right[-2-k] = right[-1-k] - heapq.heappop(r) - m[-1-k]

ans = -float('inf')
for i in range(N+1):
    ans = max(ans, left[i]+right[i])

print(ans)

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

int main() {
	
	int n;
	cin >> n;
	vector<int> d(n);
	rep(i, n) cin >> d[i];
	
	sort(d.begin(), d.end());
	int a = d[n/2 - 1];
	int b = d[n/2];
	cout << b - a << endl;
	
	return 0;
}

Measured memory_bytes: 640
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    f = [list(map(int, readline().split())) for _ in range(n)]
    p = [list(map(int, readline().split())) for _ in range(n)]

    ans = -INF

    from itertools import product, chain

    for bit in range(1, 1 << 10):
        c = [0] * n
        for time in range(10):
            if bit >> time & 1:
                for shopnum, shopopen in enumerate(f):
                    if shopopen[time]:
                        c[shopnum] += 1

        prof = 0

        for shopnum in range(n):
            prof += p[shopnum][c[shopnum]]

        ans = max(ans, prof)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41456
#include<string>
#include<iostream>
#include<stdio.h>

using namespace std;
int main(){

string str1,str2,e,v;

int n,m,size;
char ch[1]={};
while(1)
{
cin>>str1;
ch[0]=str1[0];
if(ch[0]=='-')break;
size=str1.size();
scanf("%d",&n);


for(int i=0;i<n;i++){
scanf("%d",&m);
str2=str1.substr(0,m);
//cout<<str2<<endl;
e=str1.erase(0,m);
//printf("%s\n",str1);
str1=e+str2;
}
cout<<str1<<endl;
}
return 0;
}

Measured memory_bytes: 1252
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
g,h,i=map(int,input().split())
if a+e==b+d:
  if b+f==c+e:
    if d+h==e+g:
      if e+i==f+h:
        print('Yes')
        exit()
print('No')

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

int main(void)
{
    int N;
    cin >> N;
    int v[N];
    for (int i = 0; i < N; i++) {
        cin >> v[i];
    }

    // 低い価値のものから合成する
    sort(v, v+N);
    double combined = v[0];
    for (int i = 1; i < N; i++) {
        combined = (combined + v[i]) / 2.0;
    }

    cout << setprecision(15) << combined << endl;
}

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

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define REVREP(i, n)      for(ll i = n - 1; i >= 0 ; i--)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define VC                vector<char>
#define VVC               vector<vector<char>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
//#define MOD             998244353
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }

void Solve()
{
	ll N, D;
	cin >> N >> D;
	VL X(N), Y(N);
	REP(i, N) cin >> X[i] >> Y[i];

	D = D * D;
	ll ans = 0;
	REP(i, N) {
		ll ansOne = X[i] * X[i] + Y[i] * Y[i];
		if (ansOne <= D) {
			ans++;
		}
	}
	
	cout << ans << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


Measured memory_bytes: 6364
#include <iostream>
using namespace std;
typedef long long ll;
int n;
ll a[300][300],d[300][300],ans=0;

int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
            d[i][j]=a[i][j];
        }
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            bool f=true;
            for(int k=0;k<n;k++){
                if(k!=i&&k!=j){
                    if(d[i][k]+d[k][j]<a[i][j]){
                        cout<<-1<<endl;
                        return 0;
                    }else if(d[i][k]+d[k][j]==a[i][j]){
                        f=false;
                    }
                }
            }
            if(f){
                ans+=a[i][j];
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main(void) {
    const int N = 26;
    const int C = 'a';
    int map[N] = {};
    string s;
    cin>>s;
    int len = s.size();
    for (int i=0; i<len; ++i) {
        int c = s[i] - C;
        map[c] = 1;
    }
    bool hit = false;
    for (int i=0; i<N; ++i) {
        if (map[i] == 0) {
            char c = i + C;
            cout<<c<<endl;
            hit = true;
            break;
        }
    }
    if (!hit) {
        cout<<"None"<<endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <iomanip>
using namespace std;

struct City {
    int prefecture;
    int year;
    int x;
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<City> city(M + 1);
    map<int, map<int, int>> mp;
    for (int i = 1; i <= M; i++) {
        int Pi, Yi;
        cin >> Pi >> Yi;
        city[i].prefecture = Pi, city[i].year = Yi;
        mp[Pi][Yi] = i;
    }

    for (int Pi = 1; Pi <= N; Pi++) {
        int x = 1;
        for (auto mp_Pi_Yi : mp[Pi]) city[mp_Pi_Yi.second].x = x++;
    }

    for (int i = 1; i <= M; i++) {
        cout << setfill('0');
        cout << setw(6) << city[i].prefecture;
        cout << setw(6) << city[i].x << endl;
    }
}

Measured memory_bytes: 15232
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

print(48-ri())















Measured memory_bytes: 26892
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
#include<utility>
using namespace std;
typedef long long ll;
int main(){
    int n,m;
    char s[11];
    vector<char> s1;
    map<vector<char> ,ll> se;
    ll ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s",s);
        m=strlen(s);
        sort(s,s+m);
        s1.clear();
        for(int j=0;j<m;j++){
            s1.push_back(s[j]);
        }
        decltype(se)::iterator it = se.find(s1);
        if(it!=se.end()){
            se[s1]++;
        }
        else{
            se.insert(make_pair(s1,1));
        }
    }
    for(auto i=se.begin();i!=se.end();i++){
        ans+=(i->second)*(i->second-1)/2;
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 11136
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;
 
public class Main {

  public static void main(String[] args) throws IOException {
    try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ) {

      String[] lines = br.readLine().split(" ");
      int n = Integer.parseInt(lines[0]);
      int m = Integer.parseInt(lines[1]);
      int l = Integer.parseInt(lines[2]);
      long[][] mA = new long[n][m];
      long[][] mB = new long[m][l];
      long[][] mC = new long[n][l];

      for(int i = 0; i < n; i++ ) {
        lines = br.readLine().split(" ");
        mA[i] = Stream.of(lines)
                      .mapToLong(Long::parseLong)
                      .toArray();
      }
      for( int i = 0; i < m; i++ ) {
        lines = br.readLine().split(" ");
        mB[i] = Stream.of(lines)
                      .mapToLong(Long::parseLong)
                      .toArray();
      }

      for( int i = 0; i < n; i++ ) {
        for( int j = 0; j < l; j++ ){
          for( int k = 0; k < m; k++ )
          mC[i][j] += mA[i][k] * mB[k][j];
        }
      }

      System.out.println(
        Stream.of(mC)
              .map( a -> Stream.of(a)
                      .collect(Collectors.mapping(b -> ArrayToString(b),
                            Collectors.joining())) )
              .collect(Collectors.joining("\n"))
      );
    }
  }
  public static String ArrayToString(long[] a) {
      if (a == null)
          return "null";
      long iMax = a.length - 1;
      if (iMax == -1)
          return "[]";

      StringBuilder b = new StringBuilder();
      for (int i = 0; ; i++) {
          b.append(a[i]);
          if (i == iMax)
              return b.toString();
          b.append(" ");
      }
  }
}


Measured memory_bytes: 39572
//Meri hr baat bs yaad hai tumhari , mera apna koi kissa nhi!!
#include<iostream>
#include<bits/stdc++.h>
#define ll long long int 
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define md 1000000007
#define fat 998244353 
double PI=3.1415926535;
const int N =  (int)(1 * 1e6 + 10);
using namespace std;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
bool fun(ll x ,ll y , ll d)
{
    double p = (double)x*x + (double)y*y;
    p = sqrt(p);
    if(p>d)return false;
    else return true;
}

int main()

{
    ll n , d ,x, y , ans= 0;
    cin>>n>>d;
    for(ll i = 0 ; i < n ; i++)
    {
        cin>>x>>y;
        if(fun(x,y,d))ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3676
N, K = map(int,input().split())
p = list(map(int,input().split()))
ex = [0]*1000
ex[0] = 1
for i in range(1,1000):
    ex[i] = ex[i-1]+(i+1)
for i in range(0,1000):
    ex[i] = ex[i]/(i+1)

ans = 0
for i in range(0,K):
    ans += ex[p[i]-1]

tmp = ans
for i in range(K,N):
    tmp -= ex[p[i-K]-1]
    tmp += ex[p[i]-1]
    ans = max(ans,tmp)
print(ans)

Measured memory_bytes: 24548
import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int gyou = sc.nextInt();
		int retu = sc.nextInt();
		int gyouSum = 0;
		int retuSum = 0;
		int sum = 0;
		int map[][] = new int[gyou][retu];

		for(int i = 0; i < gyou; i++){
			for(int j = 0; j < retu; j++){
				map[i][j] = sc.nextInt();
			}
		}

		for(int i = 0; i < gyou; i++){
			gyouSum = 0;
			for(int j = 0; j < retu; j++){
				System.out.print(map[i][j] + " ");
				gyouSum += map[i][j];
			}
			System.out.println(gyouSum);
		}
		for(int j = 0; j < retu; j++){
			retuSum = 0;
			for(int i = 0; i < gyou; i++){
				retuSum += map[i][j];
			}
			System.out.print(retuSum + " ");
			sum += retuSum;
		}
		System.out.println(sum);


	}
}

Measured memory_bytes: 40960
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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 int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

int a, b, h;

int main() {
  cin >> a >> b >> h;
  cout << (a + b) * h / 2;
}


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

int main(){
    int n,cnt=0,cnt2=0;
    cin >> n;
    map<int,int> mp;
    for(int i = 0;i < n;i ++){
        int a;
        cin >> a;
        mp[a] ++;
        if(mp[a]>=3) mp[a] -= 2,cnt ++;
    }
    for(auto ite = mp.begin();ite != mp.end();++ite){
        if(ite->second==2) cnt2 ++;
    }
    cnt += cnt2/2+cnt2%2;
    cout << n-cnt*2 << endl;
    return 0;
}

Measured memory_bytes: 4992
n = int(input())
alst = list(map(int, input().split()))
ans = 0
ave = sum(alst) / n
d = abs(ave - alst[0])

for i, num in enumerate(alst):
    d_tmp = abs(ave - num)
    if d_tmp < d:
        ans = i
        d = d_tmp
print(ans)

Measured memory_bytes: 9124
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    public static class program
    {
        public static void Main()
        {
            var input = Console.ReadLine().Split().Select(e =>int.Parse(e)).ToArray();
            var n = input[0];
            var m = input[1];
            var x = input[2];

            //二次元配列を定義
            var array = new int[n, m+1];
            var bookList = new List<int>();
            for(var bookCnt = 0; bookCnt < n;bookCnt++)
            {
                var row = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray();
                for (var algCng = 0; algCng < m + 1; algCng++)
                {
                    array[bookCnt, algCng] = row[algCng];
                }
                bookList.Add(bookCnt);
            }
            var ans = int.MaxValue;
            for (int i = 1; i < n + 1; i++)
            {
                foreach (var comb in Enumerate<int>(bookList, i))
                {
                    var check = new int[m];
                    var price = 0;
                    foreach (var c in comb)
                    {
                        for (int a = 1; a < m + 1; a++)
                        {
                            check[a - 1] = check[a - 1] + array[c, a];
                        }
                        price = price + array[c, 0];
                    }
                    bool ok = true;
                    for (int a = 1; a < m + 1; a++)
                    {
                        if (check[a - 1] < x)
                        {
                            ok = false;
                            break;
                        }
                    }
                    if (ok)
                    {
                        ans = Math.Min(ans, price);
                    }
                    else 
                    { }
                }
            }
            if (ans == int.MaxValue)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(ans);

            }
        }
        public static IEnumerable<T[]> Enumerate<T>(IEnumerable<T> book,int roopCnt)
        {
            if (roopCnt == 1)
            {
                foreach (var b in book)
                {
                        yield return new T[] { b };
                }
                yield break;
            }
            foreach (var b in book)
            {
                var left = new T[] { b };
                var used = book.SkipWhile(e => !e.Equals(b)).Skip(1).ToArray();

                foreach (var item in Enumerate(used, roopCnt - 1))
                {
                    yield return left.Concat(item).ToArray();
                }
            }
        }
    }
}

Measured memory_bytes: 41480
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  string s; cin >> s;
  ll ai=0, zi=0;
  REP(i, s.size()) {
    if (s[i] == 'A') {
      ai = i; break;
    }
  }
  for (ll i=s.size()-1; i>=0; i--) {
    if (s[i] == 'Z') {
      zi = i;
      break;
    }
  }
  cout << zi - ai + 1 << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int n, ans;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n, n)
    {
        ans = INF;
        for(int i = 0; i < 100; i++)
        {
            for(int j = 0; j < 100; j++)
            {
                int m = n - 200 * i - 300 * j;
                if(m < 0) break;
                int k;
                if(m % 500 == 0) k = m / 500;
                else continue;
                int sum = 0;
                if(i / 5 != 0) sum += 380 * (i - i % 5) * 0.8 + 380 * (i % 5);
                else sum += 380 * i;
                if(j / 4 != 0) sum += 550 * (j - j % 4) * 0.85 + 550 * (j % 4);
                else sum += 550 * j;
                if(k / 3 != 0) sum += 850 * (k - k % 3) * 0.88 + 850 * (k % 3);
                else sum += 850 * k;
                ans = min(ans, sum);
            }
        }
        cout << ans << endl;
    }
    return 0;
}




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

int main() {
    int n,m;
    cin>>n>>m;
    vector <string> vec(n);
    for(int i=0;i<n;i++){
        cin>>vec[i];
    }
    vector <vector<int>> dp(n,vector <int> (m,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            int up=(i==0)?0:dp[i-1][j];
            int back=(j==0)?0:dp[i][j-1];
            if(vec[i][j]=='#')dp[i][j]=0;
            else if(i==0&&j==0)dp[i][j]=1;
            else dp[i][j]=(up+back)%1000000007;
        }
    }
    cout<<dp[n-1][m-1]<<endl;
}

Measured memory_bytes: 5248
n = int(input())
A = [*map(int, input().split())]
S = [0] * (n+1)
for i in range(n): S[i+1] = S[i] + A[i]
MOD = (10**9)+7
ans = 0
for i in range(n): ans = (ans + A[i] * (S[-1] - S[i+1])) % MOD
print((ans + MOD) % MOD)


Measured memory_bytes: 31516
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;

int main(){
  int dp[100100][13];
  string S;cin>>S;
  rep(i,100100)rep(j,13){dp[i][j]=0;}
  rep(i,13)dp[0][i]=0;
  //if分岐
  dp[0][0]=1;
  for(int i=0;i<S.size();++i){
    if(S[i]=='?'){
      //?をjに変えた場合
      rep(j,13){
        rep(k,10){
          int f = (j*10+k)%13;
          dp[i+1][f]+=dp[i][j];
          dp[i+1][f]%=mod;
        }
      }
    }
    else{
      rep(j,13){
        int g = (j*10+(S[i]-'0'))%13;
        dp[i+1][g]+=dp[i][j];
        dp[i+1][g]%=mod;
      }
    }
  }
  cout << dp[S.size()][5] << endl;
}

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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int x, a, b;

int main(){
    cin >> x >> a >> b;
    cout << (x-a)%b << endl;
}
































Measured memory_bytes: 256
#include <iostream>

int main() {
    long long int n;
    std::cin >> n;

    long long exclude = -1, last = 1;
    for (long long i = 1; i <= n; i++) {
        long long t = i * (i + 1) / 2;
        if (t > n) {
            exclude = t - n;
            last = i;
            break;
        }
    }

    for (long long i = 1; i <= last; i++) {
        if (i != exclude) std::cout << i << std::endl;
    }

    return 0;
}

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

#define rep(i,n) for (int i = 0; i < int(n); i++)
#define all(c) (c).begin(), (c).end()

int h, w;

int main(int argc, const char * argv[]) {
    while (cin >> h >> w && h > 0 && w > 0) {
        priority_queue<pair<int, int>> pq;
        pair<int, int> p = { - w*w - h*h, - h };
        rep (x,151) rep (y,151) {
            if (x > 0 && y > 0 && x > y) {
                pair<int, int> q = { - x*x - y*y, - y };
                if (p > q) pq.push(q);
            }
        }
        pair<int, int> q = pq.top();
        cout << -q.second << " " << sqrt(-q.first-q.second*q.second) << endl;
    }
}

Measured memory_bytes: 1396
using System;
using System.IO;
using System.Text;

class Program{
    static void Main(string[] args){
        var arr = Console.ReadLine().Split();
        var sb = new StringBuilder();
        var ab = int.Parse(sb.Append(arr[0]).Append(arr[1]).ToString());
        var sqrt = Math.Sqrt(ab);
        var answer = sqrt == (int) sqrt ? "Yes" : "No";
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 27416
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

A, B = map(int, input().split())
if (A + B) % 2 != 0:
    print('IMPOSSIBLE')
else:
    print((A + B) // 2)


Measured memory_bytes: 38256