akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll n,res=0;

void dfs(ll t,ll x,bool A,bool B,bool C){
	if(t>n) return;
	else if(A&&B&&C) res++;
	dfs(t+x*3,x*10,1,B,C);
	dfs(t+x*5,x*10,A,1,C);
	dfs(t+x*7,x*10,A,B,1);
}

int main(){
	cin>>n;
	dfs(0,1,0,0,0);
	cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
ll dp[20][20][2][2];
int D[25];
ll go(int s, int e, int remEnd, int reqStart) {
	if (s > e) {
		return reqStart == remEnd;
	}
	ll& ret = dp[s][e][remEnd][reqStart];
	if (ret != -1) return ret;
	ret = 0;
	if (s == e) {
		for (int a = 0; a <= 9; ++a) {
			if (!s && !a) continue;
			int diff = 0;
			if (remEnd) --diff;
			if (diff < 0 && !reqStart) continue;
			if (diff >= 0 && reqStart) continue;
			if (diff < 0) diff += 10;
			assert(diff >= 0 && diff < 10);
			if (diff != D[s]) continue;
			++ret;
		}
		return ret;
	}
	// Try all values for a[s] = a and a[e] = b.
	for (int a = 0; a <= 9; ++a) {
		for (int b = 0; b <= 9; ++b) {
			if (!s && (!a || !b)) continue;
			for (int newReqStart = 0; newReqStart < 2; ++newReqStart) {
				int diffEnd = b - a;
				if (remEnd) --diffEnd;
				int newRemEnd = 0;
				if (diffEnd < 0) {
					diffEnd += 10;
					newRemEnd = 1;
				}
				int diffStart = a - b;
				if (newReqStart) --diffStart;
				if (diffStart >= 0 && reqStart) continue;
				if (diffStart < 0 && !reqStart) continue;
				if (diffStart < 0) diffStart += 10;
				assert(diffStart >= 0 && diffStart < 10);
				assert(diffEnd >= 0 && diffEnd < 10);
				if (diffEnd != D[s] || diffStart != D[e]) continue;
				ret += go(s + 1, e - 1, newRemEnd, newReqStart);
			}
		}
	}
	return ret;
}
int main() {
	int d;
	scanf("%d", &d);
	string s = to_string(d);
	reverse(s.begin(), s.end());
	for (int i = 0; i < s.size(); ++i) D[i] = s[i] - '0';
	ll ans = 0;
	for (int len = s.size(); len <= 18; ++len) {
		memset(dp, -1, sizeof(dp));
		ll t = go(0, len - 1, 0, 0);
		ans += t;
	}
	printf("%lld\n", ans);
}


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

int main(void){
    string s;
	string ans = "Yes";
	int div;
    cin >> s;
	for(int i=0;i<(signed int)s.size();i++){
		div = (i+1) % 2;
		if(div == 1){
			if(s[i] == 'R' || s[i] == 'U' || s[i] == 'D'){
				continue;
			}
			else{
				ans = "No";
				break;
			}		
		}
		else{
			if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D'){
				continue;
			}
			else{
				ans = "No";
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;


int a[112345];
int use[112345];

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int>> v;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    v.emplace_back(i, i, 0);
    v.emplace_back(a[i], i, 1);
  }
  sort(rbegin(v), rend(v));
  for(int i = 0; i < n; i++) {
    int x, id, type;
    tie(x, id, type) = v[i];
    use[id]++;
  }
  priority_queue<tuple<int, int>> pq;
  priority_queue<tuple<int, int>> pq2;
  for(int i = 0; i < n; i++) {
    if(use[i] == 2) {
      int mi = min(i, a[i]);
      pq.emplace(mi, i);
    } else if(use[i] == 0) {
      int ma = max(i, a[i]);
      pq2.emplace(-ma, i);
    }
  }
  while(pq.size() && pq2.size() && m) {
    int x = 0, y = 0;
    tie(ignore, x) = pq.top();
    tie(ignore, y) = pq2.top();
    pq.pop();
    pq2.pop();
    swap(a[x], a[y]);
    m--;
  }
  ll ans = 0;
  for(int i = 0; i < n; i++) ans += abs(a[i] - i);
  cout << ans << endl;
  return 0;
}



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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int n;

int main(){
	cin >> n;
	cout << int(sqrt(n))*int(sqrt(n))<< endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> m(N);
    rep(i, N) cin >> m.at(i);

    sort(all(m));
    int rem = X - accumulate(all(m), 0);
    dump(rem);
    cout << N + rem / m.at(0) << endl;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using T = std::tuple<ll,ll,ll>;

ll N, X, D;

ll sgn(ll x){
    if(x < 0){
        return -1;
    }
    return +1;
}

std::set<T> se;

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

    std::cin >> N >> X >> D;

    if(D == 0){
        ll res = N + 1;
        if(X == 0){
            res = 1;
        }

        std::cout << res << std::endl;

        return 0;
    }

    for(int i=0;i<=N;++i){
        ll a = X * i, b = a / D, c = a % D;
        if(c < 0){
            b -= sgn(D);
            c += std::abs(D);
        }

        ll m = b + 1ll * i * (i - 1) / 2, M = b + 1ll * i * (N - 1) - 1ll * i * (i - 1) / 2;
        se.emplace(c, m, M);
    }

    ll res = 0;

    until(se.empty()){
        ll r, m, M;
        std::tie(r, m, M) = *se.begin();
        se.erase(se.begin());

        until(se.empty()){
            ll r2, m2, M2;
            std::tie(r2, m2, M2) = *se.begin();
            
            if(r2 != r || M < m2){
                break;
            }
            
            se.erase(se.begin());

            M = std::max(M, M2);
        }

        res += M - m + 1;
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll n,x;
	ll a[101];
	ll e=0,t=0,ans=0;

	cin>>n>>x;

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

		e+=a[i];
	}

	if(e==x){
		ans=n;
	}

	if(e>x){
		sort(a, a + n);
		rep(i,n){
			if(x-a[i]>=0){
				t++;
				x=x-a[i];
			}
		}
		ans=t;
	}

	if(e<x){
		ans=n-1;


	}

	cout<<ans<<endl;

	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;
int L[222222],R[222222];
vint lis[222222];

int sum[4444444];

bool C(int x){

}

signed main(){
    cin>>N>>M;
    rep(i,N)cin>>L[i]>>R[i];

    rep(i,N)lis[L[i]].pb(R[i]);


    priority_queue<int,vint,greater<int>>que;

    vint v;

    rep(i,M+1){
        for(auto r:lis[i])que.push(r);
        while(que.size()>i){
            v.pb(que.top());
            que.pop();
        }
    }

    rep(i,v.size())v[i]=M+1-v[i];
    memset(sum,0,sizeof(sum));
    rep(i,v.size())sum[v[i]]++;

    int ans=N-M;
    rep(i,444444){
        if(i)sum[i]+=sum[i-1];
        chmax(ans,sum[i]-i);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 49260
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<iomanip>
#include<set>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;

int main() {
    int n; cin >> n;
    string s, t; cin >> s >> t;
    int end = (int)min(s.size(), t.size());
    rep(i, s.size()) if (s[i] == t[0]) rrep(j, i + 1, end) {
        if (s[j] != t[j - i]) break;
        if (j == end - 1) {
            cout << 2 * n - (end - i) << endl;
            return 0;
        }
    }
    if (s[n - 1] == t[0]) cout << 2 * n - 1 << endl;
    else cout << 2 * n << endl;
}




Measured memory_bytes: 256
import sys
#from collections import defaultdict, deque, Counter
#from bisect import bisect_left
#import heapq
#import math
#from itertools import groupby as gb
#from itertools import permutations as perm
#from itertools import combinations as comb
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#w = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(n)]
ab = [list(map(int, stdin.readline().rstrip().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
now = 0

for i in range(n):
    now += ab[i][0]
    if now > ab[i][1]:
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 53688
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
#include <string>
#include <limits>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc
{
    // 宣言
    long long a;

    public:
        // 素因数分解
        void decompositPrime(long long a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long n)
{
    // 割る数の初期値
    a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
            //printf("%d * ", a);
             v.push_back(a);
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    v.push_back(n);
    //printf("%d\n", n);
}

int main(){
    //std::stack<int> stack;
    int x,y;
    cin >> x >> y;
    string ans = "Yes";
    if(y%2  == 1){
        ans = "No";
    }else if(y < 2*x || y > 4*x){
        ans = "No";
    }
    
    
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 3628
N = int(input())
A = list(map(int,input().split()))
state = "APPROVED"
for i in range(N):
    if A[i] % 2 == 0 and A[i] % 3 != 0 and A[i] % 5 != 0:
        state = "DENIED"
        break
print(state)

Measured memory_bytes: 2940
#include<stdio.h>
#include<math.h>



int main(){

long long point = 0;

long long n;
scanf("%lli",&n);

if(n>=500){
	int val = n/500;
	point = val * 1000;
	int rem = n%500;

	if(rem>=5){
		rem = rem/5;
		point += rem * 5;
	}
}
else{
	int val = n/5;
	point = val * 5;
}

printf("%lli\n",point);
	return 0;
}


Measured memory_bytes: 128
def fib(n,memo={}):
    if n==0 or n==1:
        return 1
    elif n in memo:
        return memo[n]
    else:
        memo[n]= fib(n-1,memo)+fib(n-2,memo)
        return memo[n]
n=int(input())
print(fib(n))


Measured memory_bytes: 5608
n = int(input())
a = [0] + list(map(int, input().split()))
ans = [0] * (n+1)
for i in range(n,0,-1):
  SUM = 0
  for j in range(i,n+1,i):
    SUM += ans[j]
  ans[i] = (SUM + a[i]) % 2
m = 0
b = []
for key,i in enumerate(ans):
  if i:
    m += 1
    b.append(key)
print(m)
print(*b)

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

using namespace std;
typedef long long ll;

int main()
{
    int N, W;
    cin >> N >> W;
    ll w[100] = {};
    int v[100] = {};
    for (int i = 0; i<N;i++){
        cin >>w[i]>>v[i];
    }
    ll dp[2][100001];
    for(int i=0;i<2;i++){
        for (int j=0;j<100001;j++){
            dp[i][j] = 1e10;
        }
    }

    dp[0][0] = 0;
    dp[0][v[0]] = w[0];
    for (int i=1;i<N;i++){
        for(int j=0;j<100001;j++){
            if(j >= v[i]){ 
                dp[1][j] = min(dp[0][j],dp[0][j-v[i]]+w[i]);
            }else{
                dp[1][j] = dp[0][j];
            }
        }
        for(int j=0;j<100001;j++){
            dp[0][j] = dp[1][j];
        }
    }
    ll ans = 0;
    for (int j=100000;j>=0;j--){
        if (dp[0][j]<=W){
            ans = j;
            break;
        }
    }
    cout << ans << endl;

    // system("pause");
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 998244353;

int N = 550000 - 1; // 必要な数よりも大きい2^nよりも大きい数を入れるとよい
long long int BIT[550000];

void init(){
	for(int i = 0; i < N; i++){
		BIT[i] = 0;
	}
}

void add(int a, long long int w){
	
	// a番目の要素にwを足す O(log N)
	
	for(int x = a; x <= N; x += x & -x){
		BIT[x] += w;
	}
}

long long int sum(int a){
	
	// 1からaまでの要素の合計を返す O(log N)
	
	long long int ret = 0;
	for(int x = a; x > 0; x -= x & -x){
		ret += BIT[x];
	}
	return ret;
}

long long int P1[210000], P2[210000], P3[210000], P4[210000];
long long int p2[210000];

int main(){
    p2[0] = 1;
    for(int i = 1; i < 210000; i++){
        p2[i] = p2[i - 1] * 2 % MOD;
    }
    int N;
    cin >> N;
    set<P> mx, my;
    vector<P> v;
    for(int i = 0; i < N; i++){
        long long int x, y;
        cin >> x >> y;
        mx.insert(P(x, i));
        my.insert(P(y, i));
        v.push_back(P(x, y));
    }
    int cnt = 1;
    for(P p : mx){
        v[p.second].first = cnt;
        cnt += 1;
    }
    cnt = 1;
    for(P p : my){
        v[p.second].second = cnt;
        cnt += 1;
    }
    sort(v.begin(), v.end());
    
    init();
    for(int i = 0; i < N; i++){
        int num = sum(v[i].second);
        P4[i] = num;
        P1[i] = i - num;
        add(v[i].second, 1);
    }
    init();
    for(int i = N - 1; i >= 0; i--){
        int num = sum(v[i].second);
        P2[i] = num;
        P3[i] = (N - 1 - i) - num;
        add(v[i].second, 1);
    }
    long long int ans = p2[N - 1] * N % MOD;
    for(int i = 0; i < N; i++){
        long long int S1 = (p2[P1[i]] - 1) * (p2[P2[i]] - 1) % MOD * p2[P3[i] + P4[i]] % MOD;
        long long int S2 = (p2[P3[i]] - 1) * (p2[P4[i]] - 1) % MOD * p2[P1[i] + P2[i]] % MOD;
        long long int S3 = (p2[P1[i]] - 1) * (p2[P2[i]] - 1) % MOD * (p2[P3[i]] - 1) % MOD * (p2[P4[i]] - 1) % MOD;
        ans += S1 + S2 - S3 + MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
  int n, l;
  cin >> n >> l;
  int ans = -1;
  int abss = 1000;
  int ss = 0;
  for (int i = 0; i < n; i++) {
    int d = abs(l+i);
    if (d < abss) {
      ans = l+i;
      abss = d;
    }
    ss += l+i;
  }
  cout << ss-ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (true) {
            int H = sc.nextInt();
            int W = sc.nextInt();

            if (H == 0 && W == 0)
                break;

            p('#', W);
            pln();
            for (int n = H - 2; n > 0; n--) {
                p('#');
                p('.', W - 2);
                p('#');
                pln();
            }
            p('#', W);
            pln();
            pln();
        }
    }
    private static void p(char c, int n) {
        while (n-- > 0)
            System.out.print(c);
    }
    private static void p(char c) {
        p(c, 1);
    }
    private static void pln() {
        System.out.println();
    }
}


Measured memory_bytes: 36220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

ll dp[60][6000];

int main()
{
  string x;
  cin >> x;
  stack<char> st;
  for (int i = 0; i < x.size(); ++i)
  {
    if (x[i] == 'S')
      st.push('S');
    else
    {
      if (!st.empty() && st.top() == 'S')
        st.pop();
      else
        st.push('T');
    }
  }
  cout << st.size() << endl;

  return 0;
}

Measured memory_bytes: 644
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define LL long long
#define int LL
#define P pair<int, int>
const LL N = 2e3 + 10;
const LL mod = 1e9 + 7;
const LL inf = 0x3f3f3f3f;
using namespace std;
template <typename tp>
inline void read(tp &x)
{
    x = 0;char c = getchar();bool f = 0;
    for (; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}
int n,x[2000],sum;
signed main()
{
    read(n);
    for(int i=1;i<=n*2;i++) read(x[i]);
    sort(x+1,x+2*n+1);
    for(int i=0;i<n;i++) sum+=x[i*2+1];
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const int MAX = 100000;
static const int NIL = -1;
using namespace std;


int main() {
    string s; cin >> s;
    ll q; cin >> q;
    int cmd;
    char c;
    int f;
    bool flip = false;

    for(int i = 0; i < q; i++){
        cin >> cmd;
        if(cmd == 1) flip = !flip;
        else{
            cin >> f >> c;
            if(flip) f = (f == 1)?2:1;
            if(f == 2) s += c;
            else s = c+s;
        }
    }

    if(flip) reverse(s.begin(),s.end());
    cout << s;

    return 0;
}


Measured memory_bytes: 4656
def solve(s, t):
    ls = len(s)
    nxt = {}
    follow = [{} for _ in range(ls + 1)]
    for i, c in enumerate(s[::-1]):
        i = ls - i
        follow[i] = nxt.copy()
        nxt[c] = i
    follow[0] = nxt.copy()
    ans = 0
    i = 0
    for c in t:
        if c not in follow[i]:
            if c not in follow[0]:
                return -1
            ans += len(s)
            i = follow[0][c]
            continue
        i = follow[i][c]
    return ans + i


s = input()
t = input()
print(solve(s, t))


Measured memory_bytes: 169588
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>

//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
int h, w, n, m, k, t, s, q, last;
double cnt, sum[10000], ans, dp[10000][10000], a[10000], b[10000];
string str, ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<LL>vec[100100];
vector<Pll>v[200000];
map<Pll, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	sort(a, a + n);
	rep(i, n - 3) {
		if (i + 1 < n - 2)
			ans = max(ans, (a[n - 1] + a[n - 2]) / abs(a[i + 1] - a[i]));
	}
	ans = max(ans, (a[n - 1] + a[n - 4]) / abs(a[n - 2] - a[n - 3]));
	ans = max(ans, (a[n - 3] + a[n - 4]) / abs(a[n - 1] - a[n - 2]));
	printf("%.15f\n",ans);
	return 0;
}



Measured memory_bytes: 10320
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    int a,b,c;
    cin>>a>>b>>c;
    if(b-a==c-b)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#define int long long
#define REP(i,n) for(int i=0; i<n; i++)
using namespace std;
signed main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    if (a < b) {
        REP(i,b) cout << a;
    } else {
        REP(i,a) cout << b;
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
#define mp make_pair
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
    ll n,k;
    cin >> n >> k;
    vl a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    ll ans=0;
    rep(i,k){
        ans+=a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	string s;
	cin >> s;
	int sum = 0;
	for(int i = 0;i < s.size();i++){
		sum += s[i] - '0';
		sum %= 9;
	}

	if(sum == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3752
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.array;

void main() {
    auto l = readln.chomp.split.map!(to!int).array;

    int a = l[0], b = l[1];
    int ans;

    for (int i = a; i <= b; ++i) {
        auto s = i.to!(string), t = s.map!(to!char).array.reverse;

        if (s == t) {
            ans++;
        }
    }

    writeln(ans);

    return;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define f first
long long const mod = 1000000007; 
#define inf 1000000000000000000
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod)+mod)%mod;}
inline ll mul(ll a, ll b){ return (((a%mod)*(b%mod))%mod+mod)%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<pair<ll,ll>, null_type,less<pair<ll,ll> >, rb_tree_tag,tree_order_statistics_node_update> */

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

ll power(ll x,ll y,ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m; 
    return (y%2 == 0)? p : (x * p) % m; 
}

ll modInv(ll x)
{
    return power(x,mod-2,mod)%mod;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
	
    ll k;
    cin>>k;
    ll x=0;
    map<ll,ll>mp;
    ll i=1;
    while(true)
    {
        ll newx= ((x*10)%k+7)%k;
        if(newx==0)
        {
            cout<<i<<endl;
            return 0;
        }
        if(mp[newx]>0)
        {
            cout<<"-1\n";
            return 0;
        }
        mp[newx]++;
        x=newx;
        i++;
    }
    return 0;
}

Measured memory_bytes: 66128
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>

#define rep(i,n) for(int i=0;i<n;i++)
#define llint long long int
#define vvint vector<vector<int>>
#define vint vector<int>

using namespace std;

int main() {
	llint  a, b, c;
	cin >> a >> b >> c;
	llint ans = b / c - a / c;
	if (a % c == 0)ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math
n = [int(input()) for i in range(5)]
# 最後の注文だけ決めれば良い。
m = list(map(lambda x:(x-1)%10,n))
min_m_idx = m.index(min(m))

l = list(map(lambda x:math.ceil(x/10)*10,n))
del l[min_m_idx]
print(n[min_m_idx] + sum(l))


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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    
    vector<int>N(3);
    N.at(0) = a;
    N.at(1) = b;
    N.at(2) = c;
    
	sort(N.begin(), N.end());
	
	cout << N.at(0) << ' ' << N.at(1) << ' ' << N.at(2) << endl;
}


Measured memory_bytes: 3144
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define INF 10000000000

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

	long long int N;
	long long int a[5]={0};
	cin>>N;
	REP(i,N){
		string s;
		cin>>s;
		if(s[0]=='M')a[0]++;
		else if(s[0]=='A')a[1]++;
		else if(s[0]=='R')a[2]++;
		else if(s[0]=='C')a[3]++;
		else if(s[0]=='H')a[4]++;
	}
	
	long long int ans=0;
	ans+=a[0]*a[1]*a[2];
	ans+=a[0]*a[1]*a[3];
	ans+=a[0]*a[1]*a[4];
	ans+=a[0]*a[2]*a[3];
	ans+=a[0]*a[2]*a[4];
	ans+=a[0]*a[3]*a[4];
	ans+=a[1]*a[2]*a[3];
	ans+=a[1]*a[2]*a[4];
	ans+=a[1]*a[3]*a[4];
	ans+=a[2]*a[3]*a[4];
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;
	cout << (H2*60+M2)-(H1*60+M1)-K << endl;
}


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(void){
    int A,B,C,D,E,Q,x,y,z,u,v,n,m;
    cin >> A >> B >> C >> D >> E;
    Q=B-A;
    if(A<0){
        x=0-A;
        y=x*C;
        z=Q-x;
        u=z*E;
        n=y+D+u;
        cout << n << endl;
    }
    else if(A>0){
        v=Q*E;
        m=v;
        cout << m << endl;
        
    }
}



Measured memory_bytes: 3032
#include<bits/stdc++.h>
using namespace std;
int i,j,k,l,s,n,m,x;
int main() {
	scanf("%d",&n);
	int gt=0,gtw=0;
	for (i=1;i<=n;i++) {
		scanf("%d",&x);
		if (abs(x)>=abs(gtw)) gtw=x,gt=i;
	}
	printf("%d\n",2*(n-1));
	for (i=1;i<=n;i++) if (i!=gt) printf("%d %d\n",gt,i);
	if (gtw>0)	for (i=2;i<=n;i++) printf("%d %d\n",i-1,i);
	else for (i=n;i>1;i--) printf("%d %d\n",i,i-1);
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll __int128

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

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> p(n);
    for(int &x:p)cin>>x;
    vector<int> c(n);
    for(int &x:c)cin>>x;
    ll ans=0;
    for(int i=0;i<n;i++)p[i]--;
    for(int i=0;i<n;i++){
        vector<ll> temp;
        int j=p[i];
        while(j!=i){
            temp.push_back(c[j]);
            j=p[j];
            //debug(j);
        }
        temp.push_back(c[i]);
        //debug(temp);
        ll len=temp.size();
        for(int m=1;m<len;m++){
            temp[m]=temp[m]+temp[m-1];
        }
        //debug(temp);
        ll sum=ll(-1e18);
        if(len>=k){
            sum=temp[k-1];
            ll sum_2=temp[0];
            for(int m=1;m<k;m++){
                sum_2=max(temp[m],sum_2);
            }
            sum=max(sum_2,sum);
        }
        else{
            ll t=(k/len);
            ll sum_2=temp[0];
            int max_pos=0;
            for(int m=1;m<len;m++){
                if(sum_2<temp[m]){
                    max_pos=m;
                    sum_2=temp[m];
                }
            }
            //take only the first sum occur
            sum=max(sum_2,sum);
            //reduce t by 1 and take the sum to that position
            for(int m=0;m<len;m++){
                sum=max(sum,(t-1)*temp[len-1]+temp[m]);
            }
            //debug(sum_2);
            int f;
            if(k%len==0){
                t-=1;
                f=len-1;
            }
            else{
                f=k%len-1;
            }
            for(int m=0;m<=f;m++){
                sum=max(sum,temp[len-1]*(t)+temp[m]);
            }
        }
        //debug(sum);
        ans=max(ans,sum);
        if(i==0)ans=sum;
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a,b;
cin>>a>>b;
if((a*b)%2==0)cout<<"Even"<<endl;
else cout<<"Odd"<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
l=[list(map(int,input().split())) for _ in range(3)]
for i in range(2):
	if len(set([l[i+1][j]-l[i][j] for j in range(3)]))!=1 or len(set([l[j][i+1]-l[j][i] for j in range(3)]))!=1:
		print('No')
		break
else:print('Yes')

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func main() {
	solve(NewScanner())
}

func solve(s *Scanner) {
	wtr := bufio.NewWriter(os.Stdout)
	K, S := s.nextInt(), s.nextInt()

	zs := map[int]bool{}

	for i := 0; i <= K; i++ {
		zs[i] = true
	}

	ansCount := 0

	for x := 0; x <= K; x++ {
		for y := 0; y <= K; y++ {
			_, ok := zs[S-x-y]
			if ok {
				ansCount++
			}
		}
	}
	fmt.Fprintln(wtr, ansCount)
	wtr.Flush()
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=300005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int x,y;cin>>x>>y;
    bool ok=false;
    for(int i=0;i<=x;i++){
        for(int j=0;j<=x;j++){
            if(i+j==x&&2*i+4*j==y) ok=true;
        }
    }
    
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 3652
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    n, k = map(int, input().split())
    p = [int(i) for i in input().split()]
    p.sort()
    ans = sum(p[:k])
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 62256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        final long d = scanner.nextInt();
        final long answer = IntStream.range(0, n)
            .mapToObj(i -> {
                final long x = scanner.nextInt();
                final long y = scanner.nextInt();
                return x * x + y * y;
            })
            .filter(l -> l <= d * d)
            .count();
        System.out.println(answer);
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

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

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int conv[4][4] = {
	{1, 2, 3, 4},
	{2, -1, 4, -3},
	{3, -4, -1, 2},
	{4, 3, -2, -1}
};

int main() {
	int n;
	while (cin >> n, n) {
		while (n--) {
			int d[2][4];
			REP(i, 2) REP(j, 4) scanf("%d", &d[i][j]);
			
			int ans[4] = {};
			REP(i, 4) REP(j, 4) {
				int pro = d[0][i] * d[1][j];
				int c = conv[i][j];
				ans[abs(c) - 1] += pro * (c < 0 ? -1 : 1);
			}
			
			REP(i, 4) printf("%d%c", ans[i], i == 3 ? '\n' : ' ');
		}
	}
	return 0;
}

Measured memory_bytes: 3180
n = int(input())
st = input()

c = [0] * (n+1)
ans = []
#c[i] == i番目がreaderの時のc[i]より左のEの数
for i in range(len(st)):#i == num_reader
  c[i+1] = c[i]
  if st[i] == "E":
    c[i+1] += 1
for i in range(n):
  e_left = c[i]
  e_right = c[n] - c[i+1]
  ans.append(i-e_left + e_right)
print(min(ans))


Measured memory_bytes: 27292
z = input().split()
a=int(z[0])
b=int(z[1])
c=int(z[2])
k=int(z[3])
res=0

if k>=a:
 res=res+a
 if k-1>=b:
   res=res+b-b
   if k-(a+b)>=c:
    res=res+c-2*c
   else:
    res=res+(k-a-b)-2*(k-a-b)
 else:
   res=res+(k-a)-(k-a)
else:
 res=res+k
print(res)

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int n; cin >> n;

	bool ans = true;

	for (int i = 0;i < n;i++){
		int a;
		cin >> a;
		if(a%2 != 0) ans = false;
	}

	cout << (ans?"second":"first") << endl;

	return 0;

}


Measured memory_bytes: 256
MAX = 10**4+1
N = gets.to_i

ans = Array.new(MAX, 0)

for x in 1..100
    for y in 1..100
        for z in 1..100
            n = x*x + y*y + z*z + x*y + y*z + z*x
            if n < MAX
                ans[n] += 1
            end
        end
    end
end
            
for i in 1..N
    puts ans[i]
end


Measured memory_bytes: 14420
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int l[105];

int main() {
  int n;
  scanf("%d", &n);
  int ret = 0;
  for(int i = 1; i <= n; i++) {
    scanf("%d", &l[i]);
    ret += l[i];
  }
  int m;
  scanf("%d", &m);
  while(m--) {
    int i, d;
    scanf("%d%d", &i, &d);
    printf("%d\n", ret - l[i] + d);
  }
}


Measured memory_bytes: 256
A,B,K = map(int,input().split())

#s = [i for i in range(A,B+1)]


if 2 * K >= B - A + 1:
    for j in range(A,B+1):
        print(j)

    exit()

#l = [s[i] for i in range(0,K)]
#k = [s[h] for h in range(len(s) - K, len(s))]

for a in range(A,A+K):
    print(a)
for b in range(B-K+1,B+1):
    print(b)

#for t in range(0,K):
#    print(s[t])

# s.reverse()

#for h in range(len(s) - K,len(s)):
#    print(s[h])



Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
char buf[20000];sz;
inline int rd()
{
	int ret=buf[sz++]-'0';
	if(buf[sz]>='0')
	{
		ret=ret*10+buf[sz++]-'0';
		if(buf[sz]>='0')
		{
			ret=ret*10+buf[sz++]-'0';
			if(buf[sz]>='0')
			{
				ret=ret*10+buf[sz++]-'0';
				if(buf[sz]>='0')
				{
					ret=ret*10+buf[sz++]-'0';
				}
			}
		}
	}
	sz++;
	return ret;
}
int d[3001],d2[3001];
const int mod=998244353;
main()
{
	read(0,buf,20000);
	int N=rd();
	int S=rd();
	int ans=0;
	for(int i=1;i<=N;i++)
	{
		d[S]=i;
		int A=rd();
		for(int j=A;j<=S;j++)d2[j]=d[j];
		for(int j=0;j<=S-A;j++)
		{
			d[j]+=d2[j+A];
			d[j]-=mod*(d[j]>=mod);
		}
		ans+=d[0];
		ans-=mod*(ans>=mod);
	}
	printf("%d",ans);
}

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

int main(){
    int dp[31] = {1, 1, 2};
    for(int i = 3; i <= 30; i++)    dp[i] = dp[i-1] + dp[i-2] + dp[i-3];

    while(1){
        int n;
        cin >> n;
        if(n == 0)  break;
        int ans = (((dp[n]+9) / 10) + 364) / 365;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int n,m,p;
	int x[105];
	long long ans=0;
	while(true){
		cin>>n>>m>>p;
		if(n+m+p==0) return 0;
		ans=0;
		//cout<<ans<<" "<<n<<" "<<m<<" "<<" "<<p<<endl;
		for(int i=0;i<n;i++){
			cin>>x[i];
			ans+=x[i]*100;
		}
		for(int i=0;i<n;i++){
			if(i+1==m){
				if(x[i]!=0){
					ans=ans/100;
					ans=ans*(100-p);
					ans=ans/x[i];
					break;
				}
				else{
					ans=0;
					break;
				}
			}
		}
		cout<<ans<<endl;


	}
}

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

int main() {
  int h, w;
  cin >> h >> w;
  //終点を与えると始点を返す
  map<int, int> s;
  multiset<int> vals;
  rep(i, w) s[i] = i;
  rep(i, w) vals.insert(0);
  rep(i, h) {
    int l, r;
    cin >> l >> r;
    l--;
    auto it = s.lower_bound(l);
    int mr = -1;
    while (it != s.end() && it->first <= r) {
      mr = max(mr, it->second);
      vals.erase(vals.find(it->first - it->second));
      s.erase(it++);
    }
    if (mr != -1 && r < w) {
      vals.insert(r - mr);
      s[r] = mr;
    }
    int ans = -1;
    if (!vals.empty()) {
      ans = *vals.begin() + i + 1;
    }
    cout << ans << endl;
  }

  return 0;
}


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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}


vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != 0) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}
// Combination
ll modcomb(ll n, ll r)
{
  if(n < r) return 0;
  ll res = fact(n);
  (res *= ppow(fact(r), M-2)) %= M;
  (res *= ppow(fact(n-r), M-2)) %= M;
  return res;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find
// Find()
int parent[N], ran[N];
int find(int x)
{
    if(parent[x]==x)return x;
    else return parent[x]=find(parent[x]);
}
// Union()
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;

    if(ran[x]<ran[y])
        parent[x]=y;
    else{
        parent[y]=x;
        if(ran[x]==ran[y])ran[x]++;
    }
}

// Main Code
ll arr[N];
ll sum[N];
ll n;
int main()
{
  cin>>n;
  repn(i, 1, n) {cin>>arr[i];
  sum[i] = sum[i-1] + arr[i];
}
ll ans = INF;
rep(i, 1, n)
{
  ll x = sum[i];
  ll y = sum[n] - sum[i];
  if(abs(x-y) < ans) ans = abs(x-y);
}
cout<<ans<<endl;
 return 0;
}


Measured memory_bytes: 21376
#include <iostream>
using namespace std;
int main(void){
    int w,h,x,y,r;
    cin >>w>>h>>x>>y>>r;
    
    if(x-r < 0 || x+r > w || y-r <0 || y+r>h){
    cout << "No" << endl;
    }else{
    cout << "Yes" << endl;
    }
}

Measured memory_bytes: 1160