akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;
using namespace std;

int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  for(int i = 1; i <= n; i++){
    if((i % 3 != 0) && (i % 5 != 0)){
      ans += i;
    } 
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main(void){
    int A,B;
    cin >> A >> B;
    for(int i=1;i<=10000;i++){
        if((int)(i*0.08)==A && (int)(i*0.1) == B) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools
def main():
    N, M, Q = map(int, input().split())
    abcd = []
    for _ in range(Q):
        a, b, c, d = map(int, input().split())
        abcd.append((a-1, b-1, c, d))
    score = 0
    for ones in list(itertools.combinations([i for i in range(N+M-1)], M-1)):
        temp = [0] * (N + M -1)
        for idx in ones:
            temp[idx] = 1
        A = [0] * N
        idx = 0
        sum_ = 0
        for i in temp:
            if i == 0:
                A[idx] = sum_ + 1
                idx += 1
            else:
                sum_ += 1
        score_temp = get_score(A, abcd)
        if score_temp > score:
            score = score_temp
    print(score)
            
def get_score(A, abcd):
    score = 0
    for a, b, c, d in abcd:
        if A[b] - A[a] == c:
            score += d
    return score

if __name__ == '__main__':
    main()

Measured memory_bytes: 19880
def main():
	'''
	メイン関数
	'''
	# a
	N = int(input())
	
	SPList = []
	SPList_reverse = []

	for n in range(0,N):
		SP = input().split()
		sp_tuple = SP[0], int(SP[1])
		sp_tuple_reverse = SP[0], (100-int(SP[1]))
		SPList.append(sp_tuple)
		SPList_reverse.append(sp_tuple_reverse)


	sortedSPList = sorted(SPList_reverse)


	for ssp in sortedSPList :
		ori = ssp[0], int(ssp[1])
		print(SPList_reverse.index(ori)+1)



if __name__ == '__main__':
	main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long int
signed main()
{
    string s;
    cin>>s;
    deque<char> dq;
    for(char c:s)
        dq.push_back(c);
    bool flag=true;
    int q;
    cin>>q;
    while(q--)
    {
        int t;
        cin>>t;
        if(t==1)
            flag=!flag;
        else
        {
            int f;
            char c;
            cin>>f>>c;
            if(f==1)
            {
                if(flag)
                dq.push_front(c);
                else
                dq.push_back(c);
            }
            else
            {
                if(flag)
                dq.push_back(c);
                else
                dq.push_front(c);
            }
        }
        
    }
    if(!flag)
        reverse(dq.begin(),dq.end());
        for(auto c:dq)
        cout<<c;
}

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

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

	string ans = "Yes";
	if (n % 2) ans = "No";
	else {
		rep(i, 0, n / 2) {
			if (s[i] != s[i + n / 2]) ans = "No";
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main()
{
	ll N,K;
	cin >> N >> K;
	rep(i,N)
	{
		cin >> A[i];
	}
	rep(i,N-K)
	{
		if (A[i] < A[K+i]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 5152
#include <iostream>
#include <algorithm>
#include <vector>

typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int main() {
    int X;
    vector<int> pv = {1};
    cin >> X;
    FOR(i, 2, 33) {
        int p = i * i;
        while (p <= 1000) {
            pv.push_back(p);
            p *= i;
        }
    }
    sort(ALL(pv));
    pv.push_back(1 << 30);
    REP(i, pv.size()) {
        if (pv[i] > X) {
            cout << pv[i - 1] << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll N;
    cin >> N;

    if (N & 1) print(2 * N);
    else print(N);
    
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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



void solve() {
	vec N(3);
	rep(i, 3){
		cin >> N[i];
	}
	swap(N[0], N[1]);
	swap(N[0], N[2]);
	cout << N[0] << " " << N[1] << " " << N[2] << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
N = int(input())
div_num = [0]*(N+1)
for i in range(2,N+1):
    cur = i
    for j in range(2,i+1):
        while cur % j == 0:
            div_num[j] += 1
            cur = cur // j
MAX_VALUE = 80
dp = [0]*(MAX_VALUE)
dp[1] = 1
for i in range(2,N+1):
    for j in range(MAX_VALUE-1,-1,-1):
        for k in range(1,div_num[i]+1):
            next_ = j * (k+1)
            if next_ >= MAX_VALUE:
                break
            dp[next_] += dp[j]
print(dp[75])

Measured memory_bytes: 41584
#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;

#define INF (i64)(1e18)
#define MOD (i64)(1e9+7)
#define REP(i, n) for(i64 i = 0; i < (n); i++)
#define RREP(i, n) for(i64 i = (n)-1; i >= 0; i--)
#define RANGE(i, a, b) for(i64 i = (a); i < (b); i++)
#define RRANGE(i, a, b) for(i64 i = (b)-1; i >= (a); i--)
#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) ((i64)(v).size())
template<class T> inline void chmax(T &a, const T &b) { if (a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if (a > b) a = b; }

int main() {
  i64 n;
  cin >> n;
  i64 ans = INF;
  RANGE(i, 1, sqrt(n)+1) {
    if (n%i == 0) {
      chmin(ans, SIZE(to_string(n/i)));
    }
  }
  cout << ans << endl;
  return 0;
}


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

void countBomb(vector<vector<int>>& bombs, int i, int j, int& h, int& w) {
    if(i >= 0 && i < h && j >= 0 && j < w) bombs.at(i).at(j)++;
}

int main() {
    int h, w;
    cin >> h >> w;

    vector<vector<char>> cell(h, vector<char>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> cell.at(i).at(j);
        }
    }

    vector<vector<int>> bombs(h, vector<int>(w, 0));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (cell.at(i).at(j) == '#') {
                countBomb(bombs, i-1, j-1, h, w);
                countBomb(bombs, i-1, j  , h, w);
                countBomb(bombs, i-1, j+1, h, w);
                countBomb(bombs, i  , j-1, h, w);
                countBomb(bombs, i  , j+1, h, w);
                countBomb(bombs, i+1, j-1, h, w);
                countBomb(bombs, i+1, j  , h, w);
                countBomb(bombs, i+1, j+1, h, w);
            }
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if(cell.at(i).at(j) == '#') cout << '#';
            else cout << bombs.at(i).at(j);
        }
        cout << endl;
    }
}

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

using namespace std;

int main( void )
{
    int array[3];

    for( auto& val : array)
    {
        scanf("%d", &val);
    }

    sort(&array[0], &array[2 + 1]);

    if( array[1] != array[0] )
        printf("%d", array[0]);
    else
        printf("%d", array[2]);

    return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**9)
from functools import lru_cache
mod=1000000007

def judge(last4):
    for i in range(4):
        t=list(last4)
        if i:
            t[i-1],t[i]=t[i],t[i-1]
        if ''.join(t).count('AGC'):
            return False
    return True

@lru_cache(maxsize=None)
def dfs(cur,last3):
    if cur==0:
        return 1
    ret=0
    for c in 'ACGT':
        if judge(last3+c):
            ret+=dfs(cur-1,last3[1:]+c)
            ret%=mod
    return ret

n=int(input())
print(dfs(n,'TTT'))

Measured memory_bytes: 52444
N,Y = map(int,(input()).split())

res10000 =res5000 = res1000 = -1

for x in range(N+1):
    for y in range(N+1-x):
        z = N-x-y # zは決まっているので、ループを減らして、計算量を減らす！
        if 10000*x + 5000*y + 1000*z == Y:
            res10000 = x
            res5000 = y
            res1000 = z

print(res10000, res5000, res1000)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int N; cin >> N;
    vector<int>v(N);
    for(auto& e : v)
        cin >> e;
    sort(all(v));
    int ans = 0;
    for(int i = N - 1; i >= 0; --i){
        for(int j = i - 1; j >= 0; --j){
            auto itr = lower_bound(all(v),v[i] + v[j]);
            int invalid = distance(itr,v.end());
            ans += (N - 1 - i) - invalid;
        }
    }
    cout << ans << endl;
}


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


int main(){
 
  int H1,H2,M1,M2,K;
 
    cin >> H1 >> M1 >> H2 >> M2 >> K;
  
 cout << (H2-H1-1)*60+60-M1+M2-K << endl;

 
  
  
  
}

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

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pli = std::pair<long long, int> ;

using namespace std;

const long long MOD = 1000000007;

template<typename T>
constexpr std::pair<T, T> eea(T a, T b) noexcept {
	T x = 1, y = 0, p = 0, q = 1;
	while (b != 0) {
		T s = a;
		a = b;
		T t = s / b;
		b = s % b;

		T i = x, j = y;
		x = p;
		y = q;
		p = i - t * p;
		q = j - t * q;
	}

	return pair<T, T>(x, y);
}

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

	int n;
	ll k;
	cin >> n >> k;
	ll* a;
	a = new ll[n];
	rep(i, n) cin >> a[i];
	sort(a, a + n);

	ll ans = a[k-1] - a[n-k];
	ll count = 1;
	REP(i, k-1, n-1) {
		ll g = eea(i - k + 2, MOD).first;
		if (g < 0) g += MOD;

		count *= ((i + 1)*g) % MOD;
		count %= MOD;

		ans += a[i + 1] * count - a[n - i - 2] * count;
		ans %= MOD;
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,s,n) for(ll i=(s);i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int v,e,r;cin>>v>>e>>r;
    vector<tuple<int,int,int>> edge(e);
    vin d(v,inf);
    rep(i,e){
        int s,t,w;cin>>s>>t>>w;
        edge[i]=make_tuple(s,t,w);
    }
    d[r]=0;
    bool update;
    int res=0;
    while(1){
        res++;
        update=false;
        for(auto hen:edge){
            if(d[get<0>(hen)]!=inf&&d[get<1>(hen)]>d[get<0>(hen)]+get<2>(hen)){
                d[get<1>(hen)]=d[get<0>(hen)]+get<2>(hen);
                update=true;
            }
        }
        if(!update)break;
        if(res==v){
            cout<<"NEGATIVE CYCLE"<<endl;
            return 0;
        }
    }
    rep(i,v){
        if(d[i]==inf)cout<<"INF"<<endl;
        else cout<<d[i]<<endl;
    }
}


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

//#define DEBUG

#define INF INT_MAX

using namespace std;

//左、上、右、下
int dy[4] = {0,1,0,-1};
int dx[4] = {-1,0,1,0};
char dir[4] = {'L','U','R','D'};
//右、下、左、上
int rdy[4] = {0,1,0,-1};
int rdx[4] = {1,0,-1,0};
char rdir[4] = {'R','D','L','U'};   
//マンハッタン距離を計算
int getManhattanDistance(int x1, int y1, int x2, int y2) {
    //return abs(x1 - x2) + abs(y1 - y2);
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}

bool memo[3000][3000];

int main(void){
    int sy,sx,gy,gx;
    cin >> sx >> sy >> gx >> gy;
	sx += 1500,sy += 1500, gx += 1500, gy += 1500;

    vector<char> root;

	int rx = sx,ry = sy;
	for(int i = 0; i < 2;i++){
		memo[gy][gx] = false;
		memo[sy][sx] = true;
		while(true){
			//cout << ry << " " << rx << endl;
			vector< pair<int,int> > rank;
			for(int i = 0;i < 4;i++){
				rank.push_back(make_pair(getManhattanDistance(rx+dx[i],ry+dy[i],gx,gy),i));
			}
			sort(rank.begin(),rank.end());
			// for(int i = 0;i < 4;i++){
			// 	cout << rank[i].first << " " << rank[i].second << endl;
			// }
			for(int i = 0;i < 4;i++){
				int index = rank[i].second;
				if(!memo[ry+dy[index]][rx+dx[index]]){
					//cout << "index:" << index << endl;
					ry += dy[index],rx += dx[index];
					memo[ry][rx] = true;
					root.push_back(dir[index]);
					break;
				}
			}
			if(ry == gy && rx == gx){
				break;
			}
		}
		//cout << "aaa" << endl;
		memo[sy][sx] = false;
		memo[gy][gx] = true;
		while(true){
			vector< pair<int,int> > rank;
			for(int i = 0;i < 4;i++){
				rank.push_back(make_pair(getManhattanDistance(rx+dx[i],ry+dy[i],sx,sy),i));
			}
			sort(rank.begin(),rank.end());
			for(int i = 0;i < 4;i++){
				int index = rank[i].second;
				if(!memo[ry+dy[index]][rx+dx[index]]){
					ry += dy[index],rx += dx[index];
					memo[ry][rx] = true;
					root.push_back(dir[index]);
					break;
				}
			}
			if(ry == sy && rx == sx){
				break;
			}			
		}
	}
	for(int i = 0;i < root.size();i++){
		cout << root[i];
	}
	cout << endl;
    return 0;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 105
#define INF 1000000001
typedef pair< double ,int> P;

struct edge {
  int to;
  int cap;
  int rev;
  double cost;
};

int V;
vector<edge> G[MAX_V];
double h[MAX_V];
double dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void init_edge(){
  for(int i=0;i<MAX_V;i++)G[i].clear();
}

void add_edge(int from,int to,int cap,double cost){
  G[from].push_back((edge){to,cap,(int)G[to].size(),cost});
  G[to].push_back((edge){from,0,(int)G[from].size()-1,-cost});
}

double min_cost_flow(int s,int t,int f){
  double eps = 1e-5;
  double res = 0;
  fill(h,h+V,0.0);
  
  while(f>0){
    
    priority_queue< P, vector<P>, greater<P> >  que;
    fill( dist, dist+V , (double)INF );
    dist[s]=0;
    que.push(P(0,s));

    // fill ( prevv , prevv + V , s );
    
    while(!que.empty()){
      P p = que.top(); que.pop();
      int v = p.second;
      if(dist[v]+eps < p.first)continue;
      for(int i=0;i<(int)G[v].size();i++){
        edge &e = G[v][i];
        if(e.cap>0&&dist[e.to] > eps+dist[v]+e.cost+h[v]-h[e.to]){
          dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
          prevv[e.to]=v;
          preve[e.to]=i;
          que.push(P(dist[e.to],e.to));
        }
      }
    }

        
    if(dist[t] == INF){
      return -1;
    }
    for(int v=0;v<V;v++)h[v]+=dist[v]; 

    int d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,G[prevv[v]][preve[v]].cap);
    }
    assert( d > 0 );
    f-=d;

    res+=d*h[t];

    for(int v=t;v!=s;v=prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }

  }
  return res;
}

typedef vector< double > vec;
typedef vector<vec> mat;


vec gauss_jordan(const mat&A,const vec&b){
  int n=A.size();
  mat B(n,vec(n+1));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)B[i][j]=A[i][j];
  for(int i=0;i<n;i++)B[i][n]=b[i];
  for(int i=0;i<n;i++){
    int pivot=i;
    for(int j=i;j<n;j++)
      if(abs(B[j][i])>abs(B[pivot][i]))pivot=j;
    swap(B[i],B[pivot]);
    if(abs(B[i][i])< 0.0000001 )return vec();
    for(int j=i+1;j<=n;j++)B[i][j]/=B[i][i];
    for(int j=0;j<n;j++){
      if(i!=j)
        for(int k=i+1;k<=n;k++)B[j][k]-=B[j][i]*B[i][k];
    }
  }
  vec x(n);
  for(int i=0;i<n;i++)x[i]=B[i][n];
  return x;
}

int N,si,ti,F;
int M;

int main(){
  int T;
  cin>>T;
  while(T--){

    init_edge();
    cin>>N>>si>>ti>>F;
    
    mat A( N , vec(N) );
    vec B( N );
    
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++)scanf("%lf",&A[i][j]);
      scanf("%lf",&B[i]);
    }
    
    vec C=gauss_jordan(A,B);
    
    for(int i=0;i<N;i++){
      
      cin>>M;
      vector<int> d(M);
      vector<int> f(M);
      for(int j=0;j<M;j++)scanf("%d",&d[j]);
      for(int j=0;j<M;j++)scanf("%d",&f[j]);
      
      for(int j=0;j<M;j++){
        add_edge(i,d[j],f[j], abs(C[i]-C[d[j]]) );
        
      }
    }
    V=N;
    double ans=min_cost_flow(si,ti,F);
    if(ans<=-1.0){
      cout<<"impossible"<<endl;
    }else{
      printf("%.10f\n",ans);
    }
  }
  return 0;
}

Measured memory_bytes: 2116
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){

    ll m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(d2 == 1)cout << 1 << endl;
    else cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 256
from sys import stdin

def main():
    N = int(input())
    B = list(map(int, input().split()))

    ans = []
    for n in range(N, 0, -1):
        for i in range(N-1, -1, -1):
            if not B[i]:
                continue
            if B[i] == n:
                ans.append(n)
                B[i] = 0
                break
            n -= 1
        else:
            print(-1)
            return
    print(*ans[::-1], sep='\n')

input = lambda: stdin.readline()
main()


Measured memory_bytes: 3064
#include <stdio.h>

int main(void){

  int h,w;
  scanf("%d %d", &h, &w);
  char a[h][w+1];
  for (int i = 0; i < h; i++) {
    scanf("%s", a[i]);
  }
  for (int i = 0; i < w+2; i++) {
    printf("#");
  }
  printf("\n#");
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] < 'a' || a[i][j] > 'z') {
        break;
      }
      printf("%c", a[i][j]);
    }
    printf("#\n#");
  }
  for (int i = 0; i < w+1; i++) {
    printf("#");
  }
  printf("\n");

  return 0;
}

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

int main() {
  int n;
  
  cin >> n;
  vector<int> val(n);
  rep(i, n) cin >> val.at(i);
  
  rep(i, n) {
    if (0 != val.at(i) % 2) continue;
    if (0 != val.at(i) % 3 && 0 != val.at(i) % 5) {
      cout << "DENIED" <<endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int x;
    cin>>x;
    x=x%7;
    for(int i=0;i<7;i++){
        if(x==i){
            if(i==0){
                cout<<"thu"<<endl;
            }
            if(i==1){
                cout<<"fri"<<endl;
            }
            if(i==2){
                cout<<"sat"<<endl;
            }
            if(i==3){
                cout<<"sun"<<endl;
            }
            if(i==4){
                cout<<"mon"<<endl;
            }
            if(i==5){
                cout<<"tue"<<endl;
            }
            if(i==6){
                cout<<"wed"<<endl;
            }
        }    
    }
}



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

#define FORN(i, j, k) for(int i=j;i<k;i++)
#define FORR(i, j, k) for(int i=j;i>=k;i--)
#define REP(i, n) FORN(i, 0, n)
#define int long long
#define pii pair<int, int>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define endl '\n'

const int MODO = 1e+9 + 7;
const int INF = 1e18L;
const int MAX = 1e+5 + 5;
const int nax = 3e+3 + 5;

int n;
int a[MAX];
int dp[nax][nax];
int pref[MAX];

int solRec(int l, int r){
	if(dp[l][r]!=-1){
		return dp[l][r];
	}
	if(l==r){
		return dp[l][r] = 0;
	}
	int tempres = INF;
	for(int i=l;i<=r-1;i++){
		tempres =  min(tempres, solRec(l,i) + solRec(i+1,r) + pref[r]-pref[l]+a[l]);
	}
	return dp[l][r] = tempres;
}

void solve(){
	REP(i,n){
		cin >> a[i];
		if(i==0){
			pref[i] = a[i];
		}
		else{
			pref[i] = pref[i-1]+a[i];
		}
	}
	memset(dp, -1, sizeof(dp));
	
	cout << solRec(0,n-1) << endl;
	return;
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	solve();
	return 0;
}


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

using namespace std;

int main(){
    long long n, maxi = 0, ans = 0;
    cin >> n;
    vector <long long>v;
    for(long long i = 0; i < n; ++i){
        long long tmp; cin >> tmp;
        v.push_back(tmp);
    }
    for(long long i = 0; i < n - 1; ++i){
        if(v[i] >= v[i + 1]){
            ans += 1;
        }
        else ans = 0;
        maxi = max(maxi, ans);
    }
    cout << maxi;
    return 0;

}


Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main()
{
	int ans=0;
	string s;
	cin >> s;
	rep(i,4){
		if(s[i] == '+') ans++;
		else ans--;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[]){
    int i, n;
    double one = 0, two = 0, three = 0, max = 0, x[1000], y[1000], cat;
    scanf("%d",&n);
    for( i = 0 ; i < n ; i++ ) {
        scanf("%lf",&x[i]);
    }
    for( i = 0 ; i < n ; i++ ) {
        scanf("%lf",&y[i]);
    }
    for( i = 0 ; i < n ; i++ ){
        cat = fabs(x[i] - y[i]);
        one += cat;
        two += cat * cat;
        three += pow( cat , 3.0 );
        if( max < cat ) {
            max = cat;
        }
    }
    printf("%f\n%f\n%f\n%f\n",one,sqrt(two),cbrt(three),max);
    return 0;
}

Measured memory_bytes: 740
#include <stdio.h>

main(){
  int data[11][11];
  int i, j, n, sum;


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

    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	scanf("%d", &data[i][j]);
      }
    }

    for(i=0;i<n;i++){
      sum=0;
      for(j=0;j<n;j++){
	sum+=data[j][i];
      }
      data[n][i]=sum;
    }
    

    for(i=0;i<n;i++){
      sum=0;
      for(j=0;j<n;j++){
	sum+=data[i][j];
      }
      data[i][n]=sum;
    }

    sum=0;
    for(i=0;i<n;i++){
      sum+=data[n][i];
    }
    data[n][n]=sum;

    for(i=0;i<n+1;i++){
      for(j=0;j<n+1;j++){
       	printf("%5d", data[i][j]);
      }
      printf("\n");
    }
  }
  return 0;
}

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

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    ll sum=0;
    rep(i,n-1){
        if(a.at(i)>a.at(i+1)){
            ll tmp=a.at(i)-a.at(i+1);
            a.at(i+1)+=tmp;
            sum+=tmp;
        }
    }
    cout << sum << endl;
}

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

int main() {
    int n;
    int a[100];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];

    int ans = 0;
    for (int i = 0; i < n; i = i + 2) {
        if (a[i] % 2 != 0) ans++;
    }

    cout << ans << endl;
}

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

using namespace std;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9+7;
const LL INF = LLONG_MAX;
const LL N = 1e6+1;

#define F first
#define S second

LL binpow (LL x, LL p , LL m) {
	x %= m;
	LL res = 1;
	while (p) {
		if (p&1) {
			res = res * x % m;
		}
		x = x* x % m;
		p >>= 1;
	}
	return res;
}

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

	if (n ==1) cout << "0\n";
	else {
		LL ans = binpow(10, n, MOD);
		ans = (ans - 2*binpow(9, n, MOD) + binpow(8, n, MOD));
		ans %= MOD;
		ans = (ans + MOD) % MOD;
		cout << ans << "\n";
	}

}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main(){
int n;
cin>>n;
int a[n];
map<int,ll>m;
rep(i,n){
    cin>>a[i];
    m[a[i]]++;
}
ll ans=0;
for(int i=1;i<=n;i++){
    ans+=m[i]*(m[i]-1)/2;
//cout<<"ans=="<<ans<<endl;    
}

rep(i,n){
    if(m[a[i]]>1){
        ll w=m[a[i]],A=ans;
        A-=w*(w-1)/2;
        A+=(w-1)*(w-2)/2;
        cout<<A<<endl;
    }else{
        cout<<ans<<endl;
    }

}

  return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
string place[20];
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int serch(int n,int m,int y,int x)
{
	int ans=0;
	place[y][x]='#';
	for(int i=0,ax,ay;i<4;i++)if((ay=dy[i]+y)<m&&(ax=dx[i]+x)<n&&ay>=0&&ax>=0&&place[ay][ax]=='.')ans+=serch(n,m,ay,ax)+1;
	return ans;
}
int main() {
	int n,m;
	while(cin>>n>>m,n,m){
		for(int i=0;i<m;i++)cin>>place[i];
		for(int i=0;i<m;i++)for(int j=0;j<n;j++)if(place[i][j]=='@')cout<<serch(n,m,i,j)+1<<endl;
	}
}

Measured memory_bytes: 1240
#coding:utf-8
import numpy as np
n,k = map(int,input().split())
ls = list(map(int,input().split()))

# n, k = 5, 3
# ls = [-30,-10,10,20,50]
#
# n,k = 3,2
# ls=[10,20,30]

# n,k = 1,1
# ls = [0]

# n,k=8,5
# ls=[-9,-7,-4,-3,1,2,3,4]
if not (0 in ls):
    ls.append(0)
    k+=1
#print (ls)

ls = np.array(ls)
ls.sort()
#print (ls)

idx = np.where(ls==0)[0][0]
#print (idx,k)
#print (idx+k)
start = max(0,idx-k)
goal = min(idx+k,len(ls)-1)

#print (start,goal)
answer = []
for i in range(goal-(k-1)+1):
    #print (i,i+k-1)
    mi = min(abs(ls[i]),abs(ls[i+k-1]))
    ma = max(abs(ls[i]),abs(ls[i+k-1]))
    #print (mi,ma)
    answer.append(2*mi+ma)
print (min(answer))
# def set_max(ls):
#     if len(ls)>0:
#         return set([max(ls)])
#     else:
#         return set()
# def set_min(ls):
#     if len(ls)>0:
#         return set([min(ls)])
#     else:
#         return set()
#
#
# plus = list(filter(lambda n:n>=0, ls))
# minus = list(filter(lambda n:n<=0, ls))
#
# neighbor = set_max(minus) | set_min(plus)
#
# #print (neighbor)
# answer = []
# cnt = 0
# for i in range(n-k+1):
#     if len(set(ls[i:i+k])&neighbor)>0:
#
#         #print (ls[i:i+k])
#         #print (np.sign(ls[i]*ls[i+k-1]))
#         temp = [abs(ls[i]),abs(ls[i+k-1])]
#         if np.sign(ls[i]*ls[i+k-1])<0:
#
#             answer.append(2*min(temp)+max(temp))
#         else:
#             answer.append(max(temp))
#         cnt += 1
#         if cnt == k + 1:
#             break
# print (min(answer))

# first = -1
# for i,point in enumerate(ls):
#     if point >= 0:
#         first = i
#         break
# size=k+1
# ans = []
# for i in range(size):
#     if first-size+i+1>=0 and first+i-1< len(ls):
#         temp = [0,ls[first-size+i+1],ls[first+i-1]]
#         temp = [abs(min(temp)),abs(max(temp))]
#         ans.append((2*min(temp)+max(temp)))
# print (min(ans))


Measured memory_bytes: 23048
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))
n=n_in()
A=l_in()

if n == 0:
    if A[0] == 1:
        print(1)
    else:
        print(-1)
    exit()


if A[0] != 0:
    print(-1)
    exit()
    
B=[0]*(n+1)
B[0] = 1

upper = max(A)

S=[0]*(n+1)
S[0] = A[0]

for i in range(1,n+1):
    S[i] = S[i-1]+A[i]



for i in range(1, n):
    B[i] = min(B[i-1]*2-A[i], S[n]-S[i])
    if B[i] <= 0:
        print(-1)
        exit()

if A[n] > B[n-1]*2:
    print(-1)
    exit()
        
print(sum(A)+sum(B))
    


Measured memory_bytes: 83596
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll X;
  cin >> X;

  ll result = 0;
  result += (X / 500) * 1000;
  X -= (X / 500) * 500;

  result += (X / 5) * 5;
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define mp make_pair
#define fi first
#define se second
#define pb push_back

int a,b,c;

int main(){
	
	cin >> b;
	int can = true;
	for ( int i = 0; i < b; i++ ){
		cin >> a;
		if ( a % 2 == 0 ){
			if ( a %3 == 0 || a % 5 == 0 ) continue;
			can = false;
		}
	}
	
	if ( can ) cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;
	return 0;
}

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

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

typedef long long LL;
typedef unsigned long UL;

using namespace std;


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

	int a, b, t;
	cin >> a >> b >> t;

	cout << t / a * b << endl;

	return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  vector<int> elat(1000010, 1);
  elat[0] = elat[1] = 0;
  for (int i = 2; i <= 1000000; i++) {
    if (!elat[i]) continue;
    for (int j = i * 2; j <= 1000000; j += i) {
      elat[j] = 0;
    }
  }
  rep(i, 1000000) elat[i + 1] += elat[i];

  int n;
  while (cin >> n) {
    cout << elat[n] << '\n';
  }
}



Measured memory_bytes: 6564
#include <bits/stdc++.h>
#define ll long long
#define ld long double 
#define For(i, a, n) for(long long i = a; (a < n) ? (i < n) : (i > n); (a < n) ? (i++) : (i--))
#define ee 1000000007
#define pb push_back
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
using namespace std;

void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a * c, max(b * d, max(a * d, b * c)));
}

int main() {
    fio;
    solve();
}

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

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pvec;



typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector<string> svec;
typedef vector< vector<string> > smat;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    double v;
    dvec vv(n);
    for (int i=0; i<n; i++) cin >> vv[i];
    sort(vv.begin(), vv.end());
    ll m=1;
    long double s = vv[0];
    for (int i=1; i<n; i++) {
        s += (double) m * vv[i];
        m *= 2;
    }
    cout << setprecision(10) << s/(double)m << endl;
    return 0;
}

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

#define rep(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int,int> pii;

main(){
  string s; cin >> s;
  int apos,zpos;
  rep(i,s.size())
    if(s[i] == 'A'){
      apos = i;
      break;
    }
  ROF(i,s.size()-1,0)
    if(s[i] == 'Z'){
      zpos = i;
      break;
    }

  cout << s.substr(apos,zpos-apos+1).size() << endl;
}


Measured memory_bytes: 772
#include <bits/stdc++.h>
using namespace std;
#define ll long long int


int main(){
    ll n;
    cin>>n;
    n = n * 2;
    ll a[n];
    for(ll i = 0;i<n;i++){
        cin>>a[i];
    }
    sort(a, a+n);
    ll ans = 0;
    for(ll i = 0;i<n;i+=2){
        ans += min(a[i], a[i+1]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
   ll N,W,TS=0;
   cin>>N>>W;
   ll w[N+1],v[N+1];
   for(ll i=1;i<=N;i++)
   {
       cin>>w[i]>>v[i];
       TS+=v[i];
   }
   //dp[i]=min weight required to reach value i
   
    vector<ll>V(TS+1,INT_MAX);
    V[0]=0;
    for(ll i=1;i<=N;i++)
    {
        for(ll j=TS-v[i];j>=0;j--)
        {
            V[j+v[i]]=min(V[j+v[i]],V[j]+w[i]);            
        }
    }
    
    int K=0;
    for(int i=0;i<=TS;i++)
    {
        if(V[i]<=W)
        {
            K=i;
        }
    }
    cout<<K;
    
    return 0;
}

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

using namespace std;

const long long mod = 1e9 + 7;

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector < int > c(n);
	for (int i = 0; i < n; i++)
		cin>>c[i];
	
	sort(c.rbegin(), c.rend());
	
	long long st = 1;
	for (int i = 0; i < n - 1; i++)
		st = st * 4LL % mod;
	long long res = 0;
	for (int i = 0; i < n; i++) {
		res += st * (long long)(i + 2) % mod * (long long)c[i];
		res %= mod;
	}
	cout<<res;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}

signed main(){
    string s,t;
    cin >> s >> t;
    ll DP[s.size()+1][t.size()+1];
    FOR(i,0,s.size()+1)FOR(j,0,t.size()+1)DP[i][j] = 0;
    FOR(i,0,s.size())FOR(j,0,t.size()){
        if(s[i] == t[j])chmax(DP[i+1][j+1],DP[i][j]+1);
        chmax(DP[i+1][j+1],DP[i+1][j]);
        chmax(DP[i+1][j+1],DP[i][j+1]);
    }
    ll n = s.size();
    ll m = t.size();
    vector<char> ans;
    while(n && m){
        if(DP[n][m] == DP[n-1][m]){
            n--;
        }
        else if(DP[n][m] == DP[n][m-1]){
            m--;
        }
        else{
            ans.pb(s[n-1]);
            n--;
            m--;
        }
    }
    reverse(ALL(ans));
    for(auto c:ans)cout << c;
}

Measured memory_bytes: 70656
#include<stdio.h>
int main()
{
    int x,i,j,t,ys,jg;
    scanf("%d",&x);
    ys=0;jg=0;
    if(x==2||x==3)
        printf("1\n");
    else
    {
        for(i=x;i>=1;i--)
        {
            for(j=2;j<i;j++)
            {
                t=i;
                while(t!=0)
                {
                    ys=t%j;
                    if(ys!=0)
                        t=0;
                    else
                    {
                        t=t/j;
                        if(t==1)
                            break;
                    }
                }
                if(ys==0)
                    break;
            }
            if(ys==0)
            {
                jg=i;break;
            }
        }
        if(jg!=0)
            printf("%d\n",jg);
    }
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1000000009;

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < n; ++i) cin >> l[i];

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      for (int k = j + 1; k < n; ++k) {
        if (l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) continue;
        vector<int> rect(3);
        rect[0] = l[i];
        rect[1] = l[j];
        rect[2] = l[k];
        sort(rect.begin(), rect.end());
        //        cout << rect[0] << " " << rect[1] << " " << rect[2] << endl;
        if (rect[0] + rect[1] <= rect[2]) continue;
        ++ans;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3192
H,W,K = map(int, input().split())

c = []
for i in range(H):
    c.append(input())


ans = 0
for paint_h in range(2**H):
    for paint_w in range(2**W):
        cnt = 0
        for i in range(H):
            for j in range(W):
                if(paint_h>>i)&1==0 and (paint_w>>j)&1==0:
                    if c[i][j]=='#':
                        cnt+=1
        if cnt == K:
            ans += 1
print(ans)


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

const int nm = 2e5;
int n, a[nm];
ll ans = 0;

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 1; i < n; ++i) {
		if (a[i - 1] > a[i]) {
			ans += a[i - 1] - a[i];
			a[i] = a[i - 1];
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 4372
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x*=i;
    return x;
}

ll gcd(ll a,ll b) { return b ? gcd(b, a%b) : a; }

ll func(ll a,ll b,ll& ans_x,ll& ans_y){
    if(b == 0){
        ans_x = 1;
        ans_y = 0;
        return a;
    }else{
        ll ret = func(b,(a%b),ans_y,ans_x);
        ans_y -= (a/b)*ans_x;
        return ret;
    }
}

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; 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;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];

ll dp[50010];

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

    ll n,m,ans=0,t=-INF;
    cin>>n>>m;;
    pair<ll,ll> itv[m];
    rep(i,m){
        ll x,l;
        cin>>x>>l;
        itv[i].first=l;
        itv[i].second=x;
    }
    sort(itv,itv+m);
    
    rep(i,m){
        if(t<=itv[i].second){
            ans++;
            t=itv[i].first;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5196