akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int max_abc(int a, int b, int c)
{
    return max(max(a, b), c);
}

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    int N;
    ist >> N;

    vector<int> a;
    vector<int> b;
    vector<int> c;

    for (int i = 0; i < N; i++)
    {
        int input_a, input_b, input_c;
        ist >> input_a >> input_b >> input_c;
        a.emplace_back(input_a);
        b.emplace_back(input_b);
        c.emplace_back(input_c);
    }

    /* ------- 計算 ------- */

    vector<int> dp_a;
    vector<int> dp_b;
    vector<int> dp_c;

    dp_a.emplace_back(a.at(0));
    dp_b.emplace_back(b.at(0));
    dp_c.emplace_back(c.at(0));

    for (int i = 1; i < N; i++)
    {
        dp_a.emplace_back(a.at(i) + max(dp_b.at(i - 1), dp_c.at(i - 1)));
        dp_b.emplace_back(b.at(i) + max(dp_c.at(i - 1), dp_a.at(i - 1)));
        dp_c.emplace_back(c.at(i) + max(dp_a.at(i - 1), dp_b.at(i - 1)));
    }

    ost << max_abc(dp_a.at(N - 1), dp_b.at(N - 1), dp_c.at(N - 1)) << endl;
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


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

using namespace std;

int main()
{
    int arr[1000];
    int n, k;
    cin >> n >> k;
    for(int i=0; i<n; i++){
        cin >> arr[i];
    }
    sort(arr, arr+n);
    int ans = 0;
    for(int i=0; i<k; i++)
        ans += arr[i];
    cout << ans;
    return 0;
}


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

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> a,b;
    int p,l;
    for(int i=0;i<m;i++){
        cin >> p >> l;
        a.push_back(p);
        b.push_back(l);
    }
    sort(a.begin(),a.end());
    int sum=0;
    for(int i=1;i<m;i++){
        if(a[i]<n) sum+=(n-a[i]);
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 3164
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    m = int(readline())
    dl = []
    cl = []
    s = 0
    for _ in range(m):
        d, c = list(map(int, readline().split()))
        dl.append(d)
        cl.append(c)
        s += d * c
    cnt = 0
    while True:
        if s >= 10:
            cnt += s // 10
            s = s // 10 + s % 10
        else:
            break
    print(sum(cl) + cnt - 1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 63836
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

template <typename T> using vec = std::vector<T>;
using vi = vec<int>;
using ll = long long;
using ld = long double;
// constexpr auto mod = 1000000007;
using namespace std;

int main() {
  string s;
  cin >> s;
  const auto size = s.size();
  vi changed = {0, 0};
  REP(i, size) {
    if (s[i] != (i % 2 == 0 ? '0' : '1')) {
      changed[0]++;
    } else {
      changed[1]++;
    }
  }
  cout << min(changed[0], changed[1]) << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if((abs(a-b) <= d && abs(b-c) <= d) || abs(a-c) <= d) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;

  int ans = 0;
  while(B <= A){
    B *= 2;
    ans++;
  }
  while(C <= B){
    C *= 2;
    ans++;
  }

  if(ans <= K) Yes;
  else No;

  return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
        if (a[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    ll res = 1;
    rep(i, n) {
        ll keep;
        res *= a[i];
        keep = 1000000000000000000 / res;
        if (i != n - 1) {
            if (keep < a[i + 1]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
using namespace std;
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

const int dy[] = { 0, 1, 0, -1 };
const int dx[] = { 1, 0, -1, 0 };
int main() {
    // input
    int h, w; cin >> h >> w;
    vector<string> code(h);
    REP (y, h) cin >> code[y];
    // solve
    auto used = vectors(h, w, array<bitset<16>, 4>());
    function<bool (int, int, int, int)> go = [&](int y, int x, int dir, int mem) {
        y = (y + h) % h;
        x = (x + w) % w;
        if (used[y][x][dir][mem]) return false;
        used[y][x][dir][mem] = true;
        switch (code[y][x]) {
            case '<': dir = 2; break;
            case '>': dir = 0; break;
            case '^': dir = 3; break;
            case 'v': dir = 1; break;
            case '_': dir = (mem ? 2 : 0); break;
            case '|': dir = (mem ? 3 : 1); break;
            case '?': {
                REP (dir, 4) {
                    if (go(y + dy[dir], x + dx[dir], dir, mem)) {
                        return true;
                    }
                }
                return false;
            }
            case '.': break;
            case '@': return true;
            case '+': mem = (mem +  1) % 16; break;
            case '-': mem = (mem + 15) % 16; break;
            default: assert (isdigit(code[y][x])); mem = code[y][x] - '0'; break;
        }
        return go(y + dy[dir], x + dx[dir], dir, mem);
    };
    bool halt = go(0, 0, 0, 0);
    // output
    cout << (halt ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 5504
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
using namespace std;
 int N, K; vector<int> d;  vector<vector<int>> A;
 void input() {  cin >> N >> K; d.resize(K);  A.resize(K, vector<int>());  for(int i = 0; i < K; i++) {  cin >> d[i];  A[i].resize(d[i]);  for(int j = 0; j < d[i]; j++) {  cin >> A[i][j];  }  }  }
 void solve() {  int ans = 0;  for(int i = 1; i <= N; i++) {  bool have = false;  for(auto v : A) { for(auto p : v) {  if(p == i) have = true;  }  }  if(!have) ans++;  }  cout << ans << endl;  }
 int main() {  input();  solve();

 return 0;  }


Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n;
    cin >> n;
    int ans = 0;
    int Min = INF;
    rep(i, n)
    {
        int p;
        cin >> p;
        if (Min >= p)
        {
            ans++;
            Min = p;
        }
    }
    cout << ans << endl;
}


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

int main(){

  long double a,b,c;
  cin >> a >> b >> c;
  
  long double aa,bb,cc;
  long double EPS = 1e-14;
  
  aa=sqrtl(a);
  bb=sqrtl(b);
  cc=sqrtl(c);
  
  if (aa + bb + EPS < cc ){
    cout << "Yes" << endl;

  }else{
    cout << "No" << endl;

  }  
  
}

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

int main() {
	int a, b;
	cin >> a >> b;

	int d, r;
	double f;

	d = a / b;
	r = a % b;
	f = (double)a / (double)b;

	cout << d << " " << r << " ";
	cout << fixed << setprecision(6) << f << endl;
}

Measured memory_bytes: 1244
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    E=[[] for _ in range(n)]
    for v in range(1,n):
        u=int(input())-1
        E[u].append(v)
        E[v].append(u)

    dp=[None]*n
    def dfs(v,p=-1)->int:
        if(dp[v] is not None): return dp[v]
        if(E[v]==[p]): # 葉のとき 0
            dp[v]=0
            return 0
        res=[]
        for nv in E[v]:
            if(nv==p): continue
            res.append(dfs(nv,v))
        dp[v]=max(1+i+x for i,x in enumerate(sorted(res,reverse=1)))
        return dp[v]

    print(dfs(0))
resolve()

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

int main () {
    int n;
    cin >> n;
    bool t = true;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if ((a % 2) == 0 && ((a % 3) != 0 && (a % 5) != 0))
            t = false;
    }
    if (t)
        cout << "APPROVED";
    else
        cout << "DENIED";
}


Measured memory_bytes: 256
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 1005;
const int mod = 1000000007;



int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='?')s[i]='D';
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 3704
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>
#include <cstdint>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const long long MOD = 1000000007;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
constexpr auto PI = 3.14159265358979323846264338327950L;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    for (int i = 1; i <= 10; ++i) {
        if (1000 * i >= N) {
            cout << 1000 * i - N << endl;
            return 0;
        }
    }
    return 0;

}


Measured memory_bytes: 3648
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
#include<limits.h>
using namespace std;

const int N=1e5+5;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;

struct Tree{
	int left,right,val;
	Tree *left_child,*right_child;
}o[N*4],e[N*4];

int n,om=1,em=1;
map<int,int> elenum;

void update(Tree *pos){
	pos->val=min(pos->left_child->val,pos->right_child->val);
}

void build(Tree *pos,Tree *root,int &m,int x,int y){
	pos->left=x;pos->right=y;pos->val=INT_MAX;
	if(x==y) return;
	int mid=(x+y)>>1;
	pos->left_child=root+m;m++;
	pos->right_child=root+m;m++;
	build(pos->left_child,root,m,x,mid);
	build(pos->right_child,root,m,mid+1,y);
}

void def(Tree *pos,int x,int val){
	if(pos->left>x||pos->right<x) return;
	if(pos->left==pos->right&&pos->left==x){
		pos->val=val;
//		printf("ok:%d\n",x);
		return;
	}
	def(pos->left_child,x,val);
	def(pos->right_child,x,val);
	update(pos);
}

int query(Tree *pos,int x,int y){
	if(pos->left>=x&&pos->right<=y) return pos->val;
	if(pos->left>y||pos->right<x) return INT_MAX;
	return min(query(pos->left_child,x,y),query(pos->right_child,x,y));
}

priority_queue<piii,vector<piii>,greater<piii> > pq;

void add(int x,int y){
	if(x>y) return;
	pq.push(make_pair(x%2==1?(query(o,x,y)):(query(e,x,y)),make_pair(x,y)));
//	printf("%d %d %d\n",query(o,x,y),x,y);
}

int main(){
	scanf("%d",&n);
	build(o,o,om,1,n);
	build(e,e,em,1,n);
	for(int i=1;i<=n/2;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		def(o,i*2-1,x);
		def(e,i*2,y);
		elenum[x]=i*2-1;
		elenum[y]=i*2;
	}
//	for(int i=1;i<=n/2;i++) printf("%d %d ",query(o,i,i),query(e,i,i));
//	puts("");
	add(1,n);
	while(!pq.empty()){
		piii now=pq.top();pq.pop();
		int B=now.second.first;
		int E=now.second.second;
		int ind1=elenum[now.first],ind2;
		int mn=(B%2==1)?(query(e,ind1,E)):(query(o,ind1,E));
		ind2=elenum[mn];
		printf("%d %d ",now.first,mn);
//		system("pause");
//		printf("%d-%d %d-%d %d-%d\n",B,ind1-1,ind1+1,ind2-1,ind2+1,E);
		add(B,ind1-1);add(ind1+1,ind2-1);add(ind2+1,E);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 36472
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>

#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; i++)
#define DOW(i, a, b) for(int i = (a), _b = (b); i >= _b; i--)

using namespace std;

long long a[222000];

int main() {
  ios::sync_with_stdio(false);
  int n;
  while (cin >> n) {
    int res = 1;
    long long sum = 0;
    FOR(i, 0, n-1) cin >> a[i];
    sort(a, a+n);
    FOR(i, 0, n-2) sum += a[i];
    DOW(i, n-2, 0) {
      if (2LL * sum < a[i+1]) break;
      res++;
      sum -= a[i];
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
var
	h,w,i,j:Longint;
	m:array[1..50]of String[50];
begin
	readln(h,w);
	for i:=1 to h do readln(m[i]);
	for i:=1 to h do begin
		for j:=1 to w do begin
			if m[i][j]='#' then begin
				if not(((i>1)and(m[i-1][j]='#'))or((i<h)and(m[i+1][j]='#'))or((j>1)and(m[i][j-1]='#'))or((j<w)and(m[i][j+1]='#')))then begin
					writeln('No');
					exit;
				end;
			end;
		end;
	end;
	writeln('Yes');
end.


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int n,ans=1e9+7,x,s,now;
int a[250];
int main()
{
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++) a[i]=x+i-1,s+=a[i];
	for(int i=1;i<=n;i++){
		if(abs(a[i])<ans) ans=abs(a[i]),now=a[i];
	}
	cout<<s-now;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {


    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        String word= s.next();
        if(word.contains("a")&&word.contains("b")&&word.contains("c")) System.out.println("Yes");
        else System.out.println("No");
    }


}


class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25328
using System;
using System.Linq;

namespace ABC098
{
    class D
    {
        static void Main(string[] args)
        {

            long N = long.Parse(Console.ReadLine());
            long[] A = Console.ReadLine().Split().Select(long.Parse).ToArray();

            long res = 0;
            long right = 0;
            long sum = 0;
            for (long left = 0; left < N; left++)
            {
                while (right < N && (sum ^ A[right]) == (sum + A[right]))
                {
                    sum += A[right];
                    right++;
                }

                res += right - left;

                if (right == left) right++;
                else { sum -= A[left]; }
            }
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 34780
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;


int main()
{
    int N,cnt=0;
    int p[100] = {0};
    int sorted[100] = {0};

    cin >> N;

    for(int i=0;i<N;i++)
    {
        cin >> p[i];
        sorted[i] = p[i];
    }

    sort(sorted,sorted+N);

    for(int i=0;i<N;i++)
    {
        if(p[i] != sorted[i]) cnt++;
    }

    if(cnt<3)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    
   
}

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

int main(){
  int n, k, q;
  cin >> n >> k >> q;
  int a[n+1], tmp;
  for ( int i = 1; i <= n; i++ ){
    a[i] = q;
  }
  for ( int i = 0; i < q; i++){
    cin >> tmp;
    a[tmp]--;
  }

  for ( int i = 1; i <= n; i++ ){
    if ( k - a[i] > 0){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s, t;
	cin >>s >>t;
	
	VI ckd(30);
	for(char z: s) ckd[z -'a'] |= 1;
	for(char z: t) ckd[z -'a'] |= 2;
	for(auto z: ckd) if(z == 2){
		puts("-1"); return 0;
	}
	
	int n = sz(s);
	vector<VI> ic(30);
	rep(i, n) ic[s[i]-'a'].push_back(i);
	rep(i, n) ic[s[i]-'a'].push_back(i+n);

	
	int ps = 0; ll  ans =0;
	rep(i, sz(t)){
		int w= t[i] - 'a';
		ps= *lower_bound(all(ic[w]), ps) + 1;
		//dbg(i, t[i], w, ps, ans);
		if(ps >= n){
			ans += n;
			ps -= n;
		}
	}
	cout << ans + ps <<"\n";
	return 0;
}


Measured memory_bytes: 1736
#include <stdio.h>
int N,C;
    int s[100005],t[100005],c[100005];
    int sm[200002];
    int tt[200002];
int main(){
    scanf("%d%d",&N,&C);
    for(int i=0; i<N; i++)scanf("%d%d%d",&s[i],&t[i],&c[i]);

    for(int i=1; i<=C; i++){
        for(int j=0; j<200002; j++)tt[j]=0;
        for(int j=0; j<N; j++){
            if(c[j]==i){
                tt[s[j]*2-1]++;
                tt[t[j]*2]--;
            }
        }
        for(int j=1; j<200002; j++){
            tt[j]+=tt[j-1];
        }
        for(int j=0;j<200002;j++){
            if(tt[j]>0)sm[j]++;
        }
    }
    int max=0;
    for(int i=0; i<200002; i++)if(sm[i]>max)max=sm[i];
    printf("%d\n",max);
    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll a, b;
    cin >> a >> b;
    cout << max(a * b, max(a + b, a - b)) << endl;
}

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

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

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

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 7;

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


/////////////////////////////////////////////////////////////////////////////////////////

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    a[0] = 0;
    int sum = 0;
    for (int i = 1;i <= n;i++){
        cin >> a[i];
        sum += abs(a[i] - a[i-1]);
    }
    
    int ans;
    for (int i = 1;i <= n;i++){
        if (i == 1){
            ans = sum - abs(a[i]) - abs(a[1] - a[2]) + abs(a[2]) + abs(a[n]);
        }
        else if (i == n){
            ans = sum - abs(a[n-1] - a[n]) + abs(a[n-1]);
        }
        else{
            ans = sum - abs(a[i] - a[i-1]) - abs(a[i] - a[i+1]) + abs(a[i-1] - a[i+1]) + abs(a[n]);
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int a = N/100;
		int b = (N%100)/10;
		int c = N%10;
		int ans = 0;
		if(a == 9) {
			ans+=100;
		}else if(a==1) {
			ans+=900;
		}else {
			ans += 100*a;
		}
		
		if(b == 9) {
			ans+=10;
		}else if(b==1) {
			ans+=90;
		}else {
			ans += 10*b;
		}
		if(c == 9) {
			ans+=1;
		}else if(c==1) {
			ans+=9;
		}else {
			ans += 1*c;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 23764
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int Y = in.nextInt()/1000;
        int[] C = {10,5,1};
        int[] used = {-1,-1,-1};

        for(int i = 0; i <= N; i++){
            for(int j = 0; j <= N-i; j++){
                for(int k = 0; k <= N-i-j; k++){
                    if(i+j+k == N && C[0]*i+C[1]*j+ C[2]*k == Y){
                        used[0] = i;
                        used[1] = j;
                        used[2] = k;
                        break;
                        
                    }
                }
            }
        }
        for(int i = 0; i < 3; i++){
            System.out.print(used[i]+" ");
        }
        in.close();
    }
}


Measured memory_bytes: 22228
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

string str[] = { "* = ****", 
				 "* =* ***",
	             "* =** **",
	             "* =*** *",
				 "* =**** ",
	             " *= ****",
	             " *=* ***",
	             " *=** **",
                 " *=*** *",
	             " *=**** "};

int main()
{
	int cnt = 0;
	string n;

	while (cin >> n) {
		if (cnt++)cout << endl;

		while (n.size() < 5)n = "0" + n;

		vector<string> s(n.size());
		rep(i, n.size()) 
			s[i] = str[n[i] - '0'];
		
		rep(i, 8) {
			rep(j, 5) {
				cout << s[j][i];
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3008
#include <iostream>
#include <cmath>

using namespace std;
int main(){
    long long n, d, x, y, cnt=0;
    cin >> n >> d;
    for(int i=0; i<n; i++){
        cin  >> x >> y;
        if(pow(x*x+y*y,0.5)<=d) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
vector<int> graph[10];
int visited[10];
int n;
int dfs(int now){
    int res = 0;
    visited[now] = 1;
    int cnt = 0;
    rep(i,n){
        if(visited[i])cnt++;
    }
    if(cnt == n)return 1;
    for(int next : graph[now]){
        if(visited[next])continue;
        res += dfs(next);
        visited[next] = 0;
    }
    



        
    return res;

}
int main()
{
    int m;
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        graph[a].push_back(b);
        graph[b].push_back(a);

    }
    cout << dfs(0) << endl;
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    int ymd=0;
    rp(i,10){
        if(i==4||i==7) continue;
        ymd=ymd*10+(s.at(i)-'0');
    }
    if(ymd<20190431) puts("Heisei");
    else puts("TBD");
    return 0;
}

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

int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    if((A + D - 1) / D >= (C + B - 1) / B){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3644
import itertools
n,m,q = map(int,input().split())
s = [list(map(int, input().split())) for _ in range(q)]
#print(s)

maxi = 0
#l = [1,2,3,4,5,6,7,8,9,10]
l = []
for i in range(m):
	l.append(i)
#print(l)
for a in itertools.combinations_with_replacement(l, n):
	#print(a)
	pnt = 0
	for i in range(q):
		#print(s[i][1]-1,s[i][0]-1)

		if a[s[i][1]-1]-a[s[i][0]-1] == s[i][2]:
			#print(a[s[i][1]-1],a[s[i][0]-1] )
			
			pnt += s[i][3]
	#print(pnt)
	if pnt >maxi:
		maxi = pnt
		#print(a)
print(maxi)

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

int main() {
  int k; cin >> k;
  rep (i,k) cout << "ACL";
  cout << endl;
  return 0;
}

Measured memory_bytes: 3624
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1000000;
const int mod = 998244353;
const int INF = 1 << 30;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
int main() {
	string s;
	cin >> s;
	int n = 700;
	rep(i, s.size()) {
		if (s[i] == 'o')n += 100;
	}
	cout << n<< endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
 
class Main {
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();
    while(true){
      String line[] = br.readLine().split(" ");
      int a = Integer.parseInt(line[0]);
      String op = line[1];
      int b = Integer.parseInt(line[2]);
           
      if(op.equals("+"))  System.out.println(a+b);
      else if(op.equals("-"))  System.out.println(a-b);
      else if(op.equals("*"))  System.out.println(a*b);
      else if(op.equals("/"))  System.out.println(a/b);
      else  break;
    }
  }
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> s(n,0);
    for (int i = 0; i < n - 1; i++) {
        int a;
        cin >> a;
        s[a-1] += 1;
    }
    for (int i = 0; i < n; i++) {
        cout << s[i] << "\n";
    }
}


Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
template<class T> inline void chmin(T &a, T b){if(a>=b)a=b;}
template<class T> inline void chmax(T &a, T b){if(a<=b)a=b;}
typedef long long ll;
const int INF = 1e9;
 
int N, notZeroH;
int X[110],Y[110],H[110];
int main(){
    cin >> N;
    REP(i,N){
        cin >> X[i] >> Y[i] >> H[i];
        if(H[i]) notZeroH = i;
    }

    // H = | X - Cx | + | Y - Cy | + h

    // 取りうるCの値について全探索
    // 全ての条件を満たした時、値を確定させる。

    // Cx, Cy : 0 ~ 100 (計101 * 101の全探索)
    REP(cx,101){
        REP(cy,101){
            // 全てのcx,cyの組みについてNを全探索
            ll th = abs(X[notZeroH] - cx) + abs(Y[notZeroH] - cy) + H[notZeroH]; // 前回のh　：　つまりこれをHと仮定
            bool isok = true;
            REP(i,N){
                ll h = abs(X[i] - cx) + abs(Y[i] - cy) + H[i];
                // H[i] = 0の時は特殊　：　条件より、th - | X - Cx | - | Y - Cy| < 0 だからである。
                // 
                if((H[i] != 0 && th != h) || (H[i]==0 && th-abs(X[i]-cx)-abs(Y[i]-cy)>0)){
                    isok = false; break;
                }
            }
            if(isok){ // 値が確定
                cout << cx << " " << cy << " " << th << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
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 FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    ll n, k;
    cin >> n >> k;
    n %= k;
    ll ans = min(n, k - n);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}


//for(int i = ; i < ; i++){}

int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i = 0; i < n; i++){
    cin>>a[i];
  }
  sort(a,a+n);
  reverse(a,a+n);
  
  ll counter1 = -1;
  ll counter2 = -1;
  int tmp = 0;
  for(int i = 0; i < n-1; i++){
    if(a[i]==a[i+1]&&counter1==-1){
      counter1 = a[i];
      i++;
    }
    else if(a[i]==a[i+1]&&counter1!=-1){
      counter2 = a[i];
      break;
    }
  }
  if(counter1==-1||counter2==-1)cout<<0<<endl;
  else cout<<counter1*counter2<<endl;
  
  return 0;
}




Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
const int N = 100005;
set<int> g[N];
int p[N];
int num = 0;
int find(int x){
    return x == p[x] ? x : p[x]=find(p[x]);
}
void merge(int u, int v){
    u = find(u), v = find(v);
    if (u == v) return;
    if (g[u].size() < g[v].size()) swap(u,v);
    //printf("merge %d to %d\n",v,u);
    set<ii> que;
    for (auto x: g[v]){
        if (x == u) continue;
        //printf("%d connected to %d\n",x,v);
        g[x].erase(v);
        if (g[x].count(u)){
            que.insert({x,u});
        }
        g[u].insert(x);
        g[x].insert(u);
    }
    g[u].erase(v);
    p[v] = u;
    for (auto cur : que){
        merge(cur.first,cur.second);
    }
}
int main(){
    int n;
    scanf("%d",&n);
    iota(p,p+N,0);
    for (int i = 1; i < n; i++){
        int a,b;
        scanf("%d%d",&a,&b);
        g[a].insert(b);
        g[b].insert(a);

    }
    for (int i = 1; i < n; i++){
        int a,b;
        scanf("%d%d",&a,&b);
        a = find(a); b = find(b);
        if (g[a].count(b)) merge(a,b);
        else{
            g[a].insert(b);
            g[b].insert(a);
        }
    }
    int c = find(1);
    for (int i = 2; i <= n; i++){
        if (c != find(i)){
            printf("NO");
            return 0;
        }
    }
    printf("YES");
}


Measured memory_bytes: 24064
#include <iostream>
#include <utility>

int main (){
	int a,b,c;

	std::cin >> a >> b >> c;

	if(a > b) std::swap(a,b);
	if(b > c) std::swap(b,c);
	if(a > b) std::swap(a,b);

	std::cout<< a <<" "<< b <<" " << c << std::endl;

	return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <cstdio>
#include <queue>
#define N 300005
using namespace std;
typedef long long ll;
ll n, mx=-1e18, a[N], b[N], c[N];
priority_queue<ll> qb, qc;
int main() {
	ll i;
	scanf("%lld", &n);
	for(i=1; i<=3*n; i++) scanf("%lld", &a[i]);
	for(i=1; i<=2*n; i++) {
		qb.push(-a[i]);
		b[i] = b[i-1] + a[i];
		if(i>n) b[i] += qb.top(), qb.pop();
	}
	for(i=3*n; i>n; i--) {
		qc.push(a[i]);
		c[i] = c[i+1] + a[i];
		if(i<=2*n) c[i] -= qc.top(), qc.pop();
		if(i<=2*n+1) mx = max(mx, b[i-1]-c[i]);
	}
	printf("%lld", mx);
	return 0;
}

Measured memory_bytes: 8308
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int P = sc.nextInt();
		int Q = sc.nextInt();
		int R = sc.nextInt();

		System.out.println(Math.min(Math.min(P+Q,Q+R), R+P));
	}

}

Measured memory_bytes: 22356
#include <iostream>

using namespace std;

//Compiler version g++ 6.3.0

int main()

{

    char str[8];

    

    for(int i=0 ; i<6;i++)

    {

    	cin>> str[i];    }

    

    if(str[2]==str[3] && str[4]== str[5])

    cout<<"Yes"<<endl;

    else

    cout<<"No"<<endl;

}


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

int main(){
    int n, T,prv=0; cin >> n >> T;
    long long ans=0;
    vector<int>t(n), en(n);
    for(int i = 0; i < n; i++)  cin >> t[i];

    for(int i = 0; i < n; i++){
        if(i){
            if(t[i]-t[i-1]>T) ans+= min(T, t[i]);
            else ans += t[i]-t[i-1];
        }
        else ans+= T;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, m, x, ans = 1e9, cnt;;
  scanf("%lld%lld%lld", &n, &m, &x);
  ll c[n], a[n][m], now[m];
  for(i = 0; i < n; ++i) {
    scanf("%lld", &c[i]);
    for(j = 0; j < m; ++j) scanf("%lld", &a[i][j]), a[i][j];
  }
  for(i = 0; i < (1 << n); ++i) {
    cnt = 0;
    for(j = 0; j < m; ++j) now[j] = 0;
    for(j = 0; j < n; ++j) if((i >> j) & 1) {
      for(k = 0; k < m; ++k) now[k] += a[j][k];
      cnt += c[j];
    }
    for(j = 0; j < m; ++j) if(now[j] < x) break;
    if(j == m && ans > cnt) ans = cnt;
  }
  printf("%lld", ans != 1e9 ? ans : -1);
  return 0;
}

Measured memory_bytes: 1728
import sys
import math

a = []
for line in sys.stdin:
    a.append(line)

for n in a:
    inl=n.split()
    num1=int(inl[0])
    check=1
    list=[]
    while check<=math.sqrt(num1):
        if num1%check==0:
            list.append(check)
            list.append(num1/check)
        check+=1
    list.sort()
    list.reverse()
    num2=int(inl[1])
    for i in list:
        if num2%i==0:
            gud=i
            break
    lcm=num1*num2/gud
    print gud,lcm

Measured memory_bytes: 6364
a,b,c = map(int,input().split())

count = 0
for i in range(100):
    if a%2==1 or b%2==1 or c%2==1:
        break

    count = count + 1
    a_new = (b+c)/2
    b_new = (a + c) / 2
    c_new = (a + b) / 2

    a = a_new
    b = b_new
    c = c_new
    if i == 99:
        count = -1
print(count)

Measured memory_bytes: 62032
#include <iostream>
#include <stdlib.h>
using namespace std;

int p[5][5],x[11]={1,2,3,0,1,2,3,4,1,2,3},y[11]={1,1,1,2,2,2,2,2,3,3,3},s,sx[2],sy[2]
    ,mx[4]={1,0,-1,0},my[4]={0,-1,0,1},lt;
int search(int t,int mx2,int my2,int mc) {
	int a,i,j,x2,y2,s2;
	if (s==0) { if (lt>t) lt=t; return 1;}
	  for (i=0;i<2;i++) for (j=0;j<4;j++) {
	  x2=sx[i]+mx[j]; y2=sy[i]+my[j];
	  if (x2<0 || x2>4 || y2<0 || y2>4) continue;
	  if (p[y2][x2]<1 || ( mc==i  && mx2==-mx[j] && my2==-my[j])) continue;
	  s2=abs(sx[i]-x[p[y2][x2]-1])+abs(sy[i]-y[p[y2][x2]-1])-(abs(x2-x[p[y2][x2]-1])+abs(y2-y[p[y2][x2]-1]));
	  if (s+s2>lt-t) continue;
	  p[sy[i]][sx[i]]=p[y2][x2]; p[y2][x2]=0;  s+=s2; 
	  sx[i]=x2; sy[i]=y2;
	  a=search(t+1,mx[j],my[j],i);
	  sx[i]=x2-mx[j]; sy[i]=y2-my[j]; 
	  p[y2][x2]=p[sy[i]][sx[i]]; p[sy[i]][sx[i]]=0; s-=s2;
	  if (a==1) return 0;
  }
  return 0;
}

int main() {
  int i,j,k;
  for (i=0;i<5;i++) for (j=0;j<5;j++) p[i][j]=-1;
  while (cin >> p[0][2] && p[0][2]!=-1) {
	  cin >> p[1][1] >> p[1][2] >> p[1][3];
	  cin >> p[2][0] >> p[2][1] >> p[2][2] >> p[2][3] >> p[2][4];
	  cin >> p[3][1] >> p[3][2] >> p[3][3];
	  cin >> p[4][2]; k=0; s=0;
	  for (i=0;i<5;i++) for (j=0;j<5;j++) {
		  if (p[i][j]==0) { sx[k]=j; sy[k]=i; k++;}
		  if (p[i][j]>0) s+=abs(j-x[p[i][j]-1])+abs(i-y[p[i][j]-1]);
		   }
	  lt=21;
	  search(0,0,0,0);
	  if (lt==21) cout << "NA" << endl; else cout << lt << endl;
  } 
 return 0;
}	

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

int main(){
    INT n, k, s=0, i;
    cin >> n >> k;
    for(i=k;i<=n+1;i++){
        //cout << (n-i+1)*i+1<<'\n';
        s=((s+(n-i+1)*i)+1)%1000000007;
    }
    cout << s;
}


Measured memory_bytes: 3648
//
// Created by yamunaku on 2019/10/19.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n;
    cin >> n;
    vi a(n);
    map<int, int> mp;
    rep(i, n){
        cin >> a[i];
        mp[a[i]]++;
    }
    vi k;
    for(auto &p:mp) k.push_back(p.second);
    sort(all(k));
    int sz = k.size();
    vl rui(sz + 1, 0);
    rep(i, sz) rui[i + 1] = rui[i] + k[i];
    cout << n << endl;
    repl(i, 2, n + 1){
        int l = 0, r = n;
        while(r - l > 1){
            ll mid = (l + r) / 2;
            ll idx = lower_bound(all(k), mid) - k.begin();
            if(rui[idx] + (sz - idx) * mid >= i * mid){
                l = mid;
            }else{
                r = mid;
            }
        }
        cout << l << endl;
    }
    return 0;
}


Measured memory_bytes: 19056
N = int(input())
A = [int(input()) for _ in range(N)]
cnt = 0
for i in range(N):
    if A[i]%2==1:
        cnt += A[i]//2
        A[i] = 1
    else:
        a = A[i]//2
        if a>0:
            cnt += a-1
            A[i] = 2
for i in range(1,N):
    if A[i-1]!=1:
        cnt += A[i-1]//2+A[i]//2
        A[i-1]=0
        A[i]=A[i]%2
    elif A[i-1]==1 and A[i]>=1:
        cnt += 1
        A[i-1]=0
        A[i] -= 1
if N==1:
    cnt = A[0]//2
print(cnt)

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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m;
  cin >> n >> m;
  VLL a(n);
  rep(i, n) cin >> a[i];
  ll sum = 0;
  rep(i, n) sum += a[i];
  ll ans = 0;
  rep(i, n) {
    if(4ll * m * a[i] >= sum)
      ans++;
  }
  if(ans >= m) {
    cout << "Yes"
         << "\n";
  } else {
    cout << "No"
         << "\n";
  }
  return 0;
}


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

int main()
{
	int n;
	cin >> n;
	vector<int> A( n + 1 );
	vector<int> B( n + 1 );
	for( int i = 1; i < n + 1; i++ ) {
		cin >> A[i];
	}

	int k = 10000 + 1;
	vector<int> C( k );
	for( int i = 1; i < n + 1; i++ ) {
		C[ A[i] ]++;
	}
	for( int i = 1; i < k + 1; i++ ) {
		C[i] += C[i - 1];
	}
	for( int i = n; i > 0; i-- ) {
		B[ C[ A[i] ] ] = A[i];
		C[ A[i] ]--;
	}
	for( int i = 1; i < n + 1; i++ ) {
		if( i > 1 ) cout << " ";
		cout << B[i];
	}
	cout << endl;
}



Measured memory_bytes: 18324