akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    for(int i=0; i<K; i++){
        if(i%2==0){
            if(A%2==0){
                B += A / 2;
                A /=2;
                
            }
            else{
                A--;
                B += A/2;
                A /=2;
                
            }
        }
        else{
            if(B%2==0){
                A += B / 2;
                B /=2;   
            }
            else{
                B--;
                A += B/2;
                B /=2;
            }
        }
    }
    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
#define Max 1000001
#define inf INT_MAX
#define llinf LONG_LONG_MAX
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define endl '\n'
const ll N=2e5+5,mod=1000000007,bit=60;
signed main()
{
    fast;
    ll pro=1,temp,t,i,j,l,r,n,m,mid,z,k,x,y,rem,carry=0,ind,ans=0,mx=-llinf,mn=llinf,cnt=0,curr=0,prev,next,sum=0,flag=1,i1=-1,i2=-1,u,v;
    cin>>n>>k;
    while(n--)
    {
    	cin>>x;
    	if(x>=k)
    	{
    		ans++;
    	}
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <climits>
#include <set>

#define DEBUG(x) cout << "> " << #x << ": " << x << "\n";

using std::cout;
using std::cin;
using std::endl;
using std::vector;
using std::string;

constexpr int pb_size = 501;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {

	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";

    return out;

}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, m, q;
	cin >> n >> m >> q;

	vector<vector<int>> trains(pb_size);
	int l, r;
	for (int i = 0; i < m; ++i) {
		cin >> l >> r;
		trains[l].push_back(r);
	}

	for (int i = 1; i <= n; ++i) {
		std::sort(trains[i].begin(), trains[i].end());
	}

	int res;
	for (int i = 0; i < q; ++i) {
		cin >> l >> r;
		res = 0;
		for (int j = l; j <= r; ++j) {
			res += std::lower_bound(trains[j].begin(), trains[j].end(), r + 1) - trains[j].begin();
		}
		cout << res << "\n";
	}


	return 0;

}

Measured memory_bytes: 2176
<?php
  
  fscanf(STDIN, "%d", $n);
  $array = str_split($n);
  $hon = [2, 4, 5, 7, 9];
  $pon = [0, 1, 6, 8];
  $bon = [3];
  $cnt = count($array);
  if(in_array($array[$cnt - 1], $hon)){
  echo "hon";
  }elseif(in_array($array[$cnt - 1], $pon)){
  echo "pon";
  }else{
  echo "bon";
  }

Measured memory_bytes: 16148
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC058A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a,b,c;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);
            if (b-a==c-b)
                Console.Write("YES");
            else
                Console.WriteLine("NO");
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main() {
    string s; cin >> s;
    int n = s.size();
    int count = 0;
    int max_count = 0;
    for (int i = 0; i < n; ++i) {
        if(s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G'){
            count++;
        }else{
            max_count = max(max_count,count);
            count = 0;
        }
    }
    print(max(count,max_count));
}


Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N;
    cin >> N;

    string s, t;
    cin >> s >> t;

    FOR(i, 0, N+1){
        string a = s.substr(i);
        string b = t.substr(0, N-i);

        if(a==b){
            ll kasanari = N-i;
            p(2*N - kasanari);
            return 0;
        }
    }
   
    return 0;
}

Measured memory_bytes: 256
s=list(input())
t=list(input())
S=[0 for i in range(len(s)-len(t)+1)]
for i in range(len(s)-len(t)+1):
  for j in range(len(t)):
    if t[j]==s[j+i]:
      S[i]+=1
      
S_0=max(S)
print(len(t)-S_0)

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

using namespace std;

long long fac(long long num)
{
    long long res = 0;
    long long unit = 5;
    while(num >= unit){
        res += num/unit;
        unit *= 5;
    }
    return res;
}

long long qmi(long long n)
{
    long long res = n / 10;
    res += fac(res);
    return res;
}

int main(){
    long long n;
    cin >> n;
    if((n & 1)== 1) cout << 0 << endl;
    else cout << qmi(n) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <functional>  
#include <algorithm>  
#include <iostream>  
#include <fstream>  
#include <sstream>  
#include <iomanip>  
#include <numeric>  
#include <cstring>  
#include <cassert>  
#include <cstdio>  
#include <string>  
#include <vector>  
#include <bitset>  
#include <queue>  
#include <stack>  
#include <cmath>  
#include <ctime>  
#include <list>  
#include <set>  
#include <map>  

using namespace std;

#define PB push_back  
#define MP(A, B) make_pair(A, B)  
#define fi first  
#define se second  

#define gcd(a,b) __gcd(a,b)
#define pi acos(-1.0)
#define pii pair<int,int>
#define ll long long  
#define MAX 1000005  
#define MOD 1000000007  
#define INF 0x3f3f3f3f  
#define EXP 1e-8  
#define lowbit(x) (x&-x)  
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

int main()
{
    int k , a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; ++i) {
        if (i % k == 0){cout << "OK" << endl;return 0;}
    }
    cout << "NG" << endl;
    return 0;
}

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

int main(void){
    char c;
    cin>>c;
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
        cout<<"vowel"<<endl;
    }
    else
    {
        cout<<"consonant"<<endl;
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
double dp[3005];
long mod=1000000007;
#define deb(x,j) cout<<j<<'\t'<<x<<endl;
int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    double p;
    cin>>n;
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for (int i = 1; i <=n ; ++i) {
        cin>>p;
        for (int j = i; j >=0 ; --j) {
            if (j==0) {
            dp[j]=dp[j]*(1-p);

            } else {
                dp[j]=dp[j-1]*p+dp[j]*(1-p);

            }
        }

    }
    double ans=0.0;
    for (int k = (n/2)+1; k <=n ; ++k) {
        ans+=dp[k];
    }
    printf("%.10lf",ans);


    return 0;
}

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

vector<string> parse(string s) {
  s += " ";
  vector<string> res;
  string str;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == ' ') {
      res.push_back(str);
      str = "";
    } else str += s[i];
  }

  return res;
}

int main() {
  string s;
  while (getline(cin, s)) {
    vector<string> v = parse(s);

    // cout << s << endl;
    // for (string u : v) cout << u << endl;

    stack<double> st;
    for (string u : v) {
      if (u.size() == 1 && !('0' <= u[0] && u[0] <= '9')) {
        double b = st.top(); st.pop();
        double a = st.top(); st.pop();
        double x;
        if (u == "+") x = a + b;
        if (u == "-") x = a - b;
        if (u == "*") x = a * b;
        if (u == "/") x = a / b;
        st.push(x);
        // cout << a << " " << b << " " << x << endl;
      } else {
        double x = 0, num = 1;
        for (int i = 0; i < u.size(); ++i) {
          if ('0' <= u[i] && u[i] <= '9') {
            x = 10 * x + (u[i] - '0');
          } else num = -1;
        }

        st.push(x * num);
      }
    }

    printf("%.10f\n", st.top());
  }
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

const int N = 1e5+1;
int n, dp[N], a[N];

int main()
{
  fastio;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) dp[i] = INF;
  dp[1] = 0; a[0] = -INF;
  for (int i = 2; i <= n; i++){
    dp[i] = min(dp[i], dp[i - 1] + abs(a[i] - a[i - 1]));
    dp[i] = min(dp[i], dp[i - 2] + abs(a[i] - a[i - 2]));  
  }
  cout << dp[n];
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    ll n,a,b;
    cin>>n>>a>>b;
    ll A=0,B=0;
    A+=n/(a+b)*a;
    B+=n/(a+b)*b;
    n-=(A+B);
    if(n>a){
        A+=a;
        n-=A;
        B+=n;
    } else {
        A+=n;
    }
    fin(A);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
   int i, h, m, s;
   cin >> i;
   h = i / 3600;
   m = i % 3600 / 60;
   s = i % 3600 % 60;
   cout << h << ":" << m << ":" << s << endl; 
   
   return 0;
}


Measured memory_bytes: 3080
n = int(input())
lis  = [0] * 4
for i in range(n):
    a = input()
    if a == "AC":
        lis[0] += 1
    elif a == "WA":
        lis[1] += 1
    elif a == "TLE":
        lis[2] += 1
    elif a == "RE":
        lis[3] += 1

tmp = ["AC x", "WA x", "TLE x", "RE x"]

for i in range(4):
    print(tmp[i], lis[i])


Measured memory_bytes: 9208
import sys
from collections import deque


def input():
    return sys.stdin.readline().rstrip()


def main():
    H, W, M = map(int, input().split())
    lh = [0] * H
    lw = [0] * W
    s = set()
    for _ in range(M):
        h, w = map(int, input().split())
        lh[h - 1] += 1
        lw[w - 1] += 1
        s.add((h-1, w-1))

    maxh = max(lh)
    maxw = max(lw)
    wlist=[]
    for j in range(W):
        if maxw==lw[j]:
            wlist.append(j)



    for i in range(H):
        if lh[i] !=maxh:
            continue
        for j in wlist:
            if (i,j) not in s:
                print(maxh+maxw)
                exit()

    print(maxh+maxw-1)



if __name__ == "__main__":
    main()


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

int main()
{
  vector<int> c(3);
  int i = 0;
  for (int i = 0; i < 3; i ++)
    cin >> c.at(i);
  
  sort(c.begin(), c.end(), greater<>());
  cout << c.at(0) * 10 + c.at(1) + c.at(2) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define P(x) cout << x << endl
#define D(x) P(#x << ": " << x)
#define F(i,n) for (int i=0; i<(int)(n); i++)
#define DEC(i,n) for (int i=(int)(n); --i>=0;)
#define S(s) (int)((s).size())
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,(v))
#define MA(a,v) a = max(a,(v))
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m; cin>>n>>m;
    bool ok1[n], ok2[n];
    F(i,n) ok1[i] = ok2[i] = false;
    F(i,m) {
        int a,b; cin>>a>>b;
        a--, b--;
        if (a>b) swap(a,b);
        if (a == 0) ok2[b] = true;
        if (b == n-1) ok1[a] = true;
    }
    bool ok=false;
    F(i,n) if (ok1[i] && ok2[i])
        ok = true;
    if (!ok) printf("IM");
    printf("POSSIBLE\n");
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string str;
    std::cin >> str;
    
    std::reverse(str.begin(), str.end());
    // cout << str << endl;
    ll ans = 0;
    ll cnt = 0;
    bool horyu = false;

    for (int i = 0; i < str.length(); i++) {
        if (str[i] == 'B') {
            if (horyu) {
                cnt += 1;
            }
            else
            {
                cnt = 0;
            }
            horyu = false;
        }
        else if (str[i] == 'A')
        {
            if (horyu) {
                cnt = 0;
            }
            ans += cnt;
            horyu = false;
        }
        else if (str[i] == 'C')
        {
            if (horyu) {
                cnt = 0;
            }
            horyu = true;
        }
        // cout << ans << endl;
    }
    // cout << "ans: " << ans << endl;
    cout << ans << endl;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int A,B,C;cin>>A>>B>>C;
  
  if(B-A==C-B){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

int main()
{
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> input(N, vector<int>(M, 0));
  for (int i = 0; i < N; i++)
  {
    cin >> C[i];
    for (int j = 0; j < M; j++)
      cin >> input[i][j];
  }
  int maxim = 1 << 25;
  int ans = maxim;
  for (int bit = 0; bit < (1 << N); bit++)
  {
    vector<int> score(M, 0);
    int cost = 0;
    for (int i = 0; i < N; i++)
      if ((bit >> i) & 1)
      {
        cost += C[i];
        for (int j = 0; j < M; j++)
          score[j] += input[i][j];
      }
    bool ok = true;
    for (int i = 0; i < M; i++)
      if (score[i] < X)
        ok = false;
    if (ok && ans > cost)
    {
      ans = cost;
    }
  }
  if (ans == maxim)
    ans = -1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
    return ans;
}
int main() {
    string S,T;
    cin>>S>>T;
    int ans=100000;
    int a=S.size();
    int b=T.size();
    for(int i=0; i<a-b+1; i++ ){
        int c=0;
        for(int j=0; j<b; j++){
            if(S.at(j+i)!=T.at(j)){
                c++;
            }
        }
        if(c<ans){
            ans=c;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,k,pcnt=0,ncnt=0; cin>>n>>k;
    vector<ll> p,ne;
    rep(i,n){
        ll a; cin>>a;
        if(a>0){
            pcnt++; p.push_back(a);
        }
        else{
            ncnt++; ne.push_back(a);
        }
    }
    if(pcnt+ncnt<k){
        cout<<0<<endl;
        return 0;
    }
    if(pcnt==0){
        sort(al(ne)); 
        if(k%2) reverse(al(ne));
        ll ans=1;
        rep(i,k) ans=ans*(ne[i]+MOD)%MOD;
        cout<<(ans+MOD)%MOD<<endl;
        return 0;
    }
    if(ncnt==0){
        sort(al(p)); reverse(al(p));
        ll ans=1;
        rep(i,k) ans=ans*p[i]%MOD;
        cout<<(ans+MOD)%MOD<<endl;
        return 0;
    }
    ll pr=min(pcnt,k),nr=max(0LL,k-pcnt);
    if(nr%2){
        if(nr==ncnt){
            ll ans=1;
            rep(i,pr) ans=ans*p[i]%MOD;
            rep(i,nr) ans=ans*(ne[i]+MOD)%MOD;
            cout<<(ans+MOD)%MOD<<endl;
            return 0;
        }
        else{
            pr--; nr++;
        }
    }
    sort(al(ne));
    sort(al(p)); reverse(al(p));
    while(1){
        if(pr<2 || nr+2>ncnt) break;
        if(ne[nr]*ne[nr+1]>p[pr-1]*p[pr-2]){
            pr-=2; nr+=2;
        }
        else break;
    }
    ll ans=1;
    rep(i,pr) ans=ans*p[i]%MOD;
    rep(i,nr) ans=ans*(ne[i]+MOD)%MOD;
    cout<<(ans+MOD)%MOD<<endl;
}

Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string s="AKIHABARA",r;
  R r;
  rep(t,1<<4) {
    int k=0;
    string ss="";
    rep(j,s.size()) {
      if(s[j]=='A') {
        if(t&(1<<k)) {
          k++;
          continue;
        }
        k++;
      }
      ss+=s[j];
    }
    if(ss==r) {
      pr("YES");
      return;
    }
  }
  pr("NO");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = [deque(list(STR())) for _ in range(3)]
i = 0
arr = ['a', 'b', 'c']
while True:
    tmp = s[i].popleft()
    i = arr.index(tmp)
    if len(s[i]) == 0:
        print(arr[i].upper())
        exit()


Measured memory_bytes: 5272
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef DEBBY
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define ll long long
#define rep(i,a,b) for(int i=int(a); i<=int(b); i++)
#define sz(v)  (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pi>
#define fs first
#define sd second
#define pb push_back

ll comb(ll n){
    return n*(n-1)/2;
}


void solve(){
    int n; cin >> n;
    map<string,int> m;
    rep(i,1,n){
        string s;
        cin >> s;
        sort(all(s));
        m[s]++;
    }
    ll count = 0LL;
    for(auto q: m){
            count += comb(q.second);
    }
    cout << count;
    debug() << imie(m);
    
} 

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





Measured memory_bytes: 11264
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    function<bool(int)>f = [&](int n) ->bool{
        for(int i = 2;i*i<=n;i++){
            if(n%i==0)return false;
        }
        return true;
    };
    int a; cin >> a;
    int ans = 0;
    int b[100000]; rep(i,a)scanf("%lld",b+i);
    rep(i,a){
        if(b[i]>1 and f(b[i]))ans++;
    }
    cout << ans << endl;
    
}





Measured memory_bytes: 3312
import java.io.*;

public class Main{
public static void main(String[] args){
try{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String[] str = br.readLine().split(" ");

	int W = Integer.parseInt(str[0]);
	int H = Integer.parseInt(str[1]);
	int x = Integer.parseInt(str[2]);
	int y = Integer.parseInt(str[3]);
	int r = Integer.parseInt(str[4]);
		
		if( -100 <= x && x <= 100 && -100 <= y && y<= 100){
			if(0 <= W && W <= 100 && 0 <= H && H <= 100 && 0 <= r && r<= 100){
			int circle_max_X = x + r;
			int circle_min_X = x - r;
			int circle_max_Y = y + r;
			int circle_min_Y = y - r;

				if (circle_max_X <= W && circle_min_X >= 0 && circle_max_Y <= H && circle_min_Y >= 0){
				System.out.println("Yes");
				}else{
				System.out.println("No");
				}
			}else{
			System.out.println("Input Error");
			}
	}else{
	System.out.println("Input Error");
	}
}catch(IOException e){
System.out.println(e);
}
}
}

Measured memory_bytes: 17088
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ii pair<int,int> 
#define f first
#define s second
#define pb push_back

int r,c;
int v[999][18278];
map<ii,string> m;

ii id(string s){
    int ten=1;
    int ts=1;
    int x=0,y=0;
    for(int i=s.length()-1;i>=0;i--){
        if(isdigit(s[i])){
           x+= (s[i]-48)*ten;
           ten*=10;
        }
        else if(isalpha(s[i])){
            y+= (s[i]-65)*ts;
            ts*=26;
        }
    }
    x--;
    y--;
    return make_pair(x,y);
}
int cal(int i,int j){
    
    if(v[i][j]!=INT_MAX)return v[i][j];
    string s = m[{i,j}];
    string ip;
    istringstream iss(s);
    int ans=0;
    while(getline(iss,ip,'+')){
        ii loc = id(ip);
        ans+=cal(loc.f,loc.s);
    }
    v[i][j]=ans;
    return ans;
    
}
int32_t main(){
    int n;
    cin>>n;
    int d;
    cin>>d;
    int ans=0;
    d*=d;
    for(int i=1;i<=n;i++){
        int x,y;
        cin>>x>>y;
        if(x*x+y*y<=d)ans++;
        
    }
    cout<<ans;
    
}

Measured memory_bytes: 3632
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a = sorted(a)[::-1]
b = sorted(b)[::-1]
c = sorted(c)[::-1]

a_smaller_b = [0]*n
b_smaller_c = [0]*n
n_a, n_b = 0, 0
j, k = 0, 0
for i in range(n):
    a_tar = a[i]
    b_tar = b[i]
    while True:
        if j == n:
            a_smaller_b[i] = n_a
            break
        if b[j] > a_tar:
            n_a += 1
            j += 1
        else:
            a_smaller_b[i] = n_a
            break

    while True:
        if k == n:
            b_smaller_c[i] = n_b
            break
        if c[k] > b_tar:
            n_b += 1
            k += 1
        else:
            b_smaller_c[i] = n_b
            break
# print(a_smaller_b)
# print(b_smaller_c)

bsc_cumsum = [0]*(n+1)
for i in range(n):
    bsc_cumsum[i+1] = bsc_cumsum[i]+b_smaller_c[i]

ans = 0
for i in range(n):
    ans += bsc_cumsum[a_smaller_b[i]]
print(ans)


Measured memory_bytes: 27424
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	int N;
	cin >> N;
	vector<int>A(N), B(N), C(N);
	rep(i, N)cin >> A[i];
	rep(i, N)cin >> B[i];
	rep(i, N)cin >> C[i];
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());
	int ans = 0;
	rep(i, N) {
		int a = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
		int c = C.end() - upper_bound(C.begin(), C.end(), B[i]);
		ans += a * c;
	}
	cout << ans;
}

Measured memory_bytes: 2560
S = input()
s = list(S)
p = []
q = []
ans = [0 for i in range(len(s))]
for i in range(len(s)-1):
    if s[i] == 'L' and s[i+1] == 'R':
        p.append(i)
for i in range(len(s)-1):
    if s[i] == 'R' and s[i+1] == 'L':
        q.append(i)
if len(p) > 0:
    if (p[0]-q[0])%2 == 0:
        ans[q[0]] = -(-(p[0]+1)//2)
    else:
        ans[q[0]] = (p[0]+1)//2
    ans[q[0]+1] = p[0]+1-ans[q[0]]
    for i in range(len(p)-1):
        if (p[i+1]-q[i+1])%2 == 0:
            ans[q[i+1]] = -(-(p[i+1]-p[i])//2)
        else:
            ans[q[i+1]] = (p[i+1]-p[i])//2
        ans[q[i+1]+1] = p[i+1]-p[i]-ans[q[i+1]]
    if (len(s)+1-q[-1])%2 == 0:
        ans[q[-1]] = -(-(len(s)-p[-1]-1)//2)
    else:
        ans[q[-1]] = (len(s)-p[-1]-1)//2
    ans[q[-1]+1] = len(s) - p[-1] -1 - ans[q[-1]]
else:
    if (len(s)+1-q[-1])%2 == 0:
        ans[q[-1]] = -(-(len(s))//2)
    else:
        ans[q[-1]] = (len(s))//2
    ans[q[-1]+1] = len(s) - ans[q[-1]]
for i in range(len(ans)):
    print(ans[i],end=' ')

Measured memory_bytes: 14556
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		loop: while (true) {
			w = scanner.nextInt();
			h = scanner.nextInt();
			if ((w | h) == 0)
				break;
			count = 0;
			visited = new boolean[h][w];
			sx = -1;
			sy = -1;
			boolean isworstpatt = (w == 7 && h == 7);
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					int now = scanner.nextInt();
					if (now == 0) {
						count++;
						if (sx == -1) {
							sy = i;
							sx = j;
						}
					} else {
						isworstpatt = false;
						visited[i][j] = true;
					}
				}
			}
			if (isworstpatt) {
				System.out.println("No");
				continue;
			}
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (visited[i][j])
						continue;
					int count = 0;
					for (int k = 0; k < 4; k++) {
						int x = j + vx[k];
						int y = i + vy[k];
						if (!isOK(x, y))
							continue;
						if (!visited[y][x])
							count++;
					}
					if (count < 2) {
						System.out.println("No");
						continue loop;
					}
				}
			}

			System.out.println(dfs(sx, sy, 0) ? "Yes" : "No");
		}

	}

	private boolean dfs(int x, int y, int deep) {
		if (count - deep < Math.abs(x - sx) + Math.abs(y - sy))
			return false;
		
		for (int i = 0; i < 4; i++) {
			int nx = x + vx[i];
			int ny = y + vy[i];
			if (!isOK(nx, ny))
				continue;
			if (ny == sy && nx == sx && deep + 1 == count)
				return true;
			if (visited[ny][nx])
				continue;
			boolean res = check(nx, ny);
			if (!res)
				continue;
			visited[ny][nx] = true;
			if (dfs(nx, ny, deep + 1))
				return true;
			visited[ny][nx] = false;
		}
		return false;

	}

	private boolean check(int x, int y) {
		for (int i = 4; i < vx.length; i++) {
			int nx = x + vx[i];
			int ny = y + vy[i];
			if (!isOK(nx, ny))
				continue;
			if (nx == sx && ny == sy)
				continue;
			if (visited[ny][nx])
				continue;
			int count = 0;
			for (int j = 0; j < 4; j++) {
				int nnx = nx + vx[j];
				int nny = ny + vy[j];
				if (!isOK(nnx, nny))
					continue;
				if (visited[nny][nnx])
					continue;
				count++;
			}
			if (count <= 1)
				return false;
		}
		return true;
	}

	private boolean isOK(int x, int y) {
		if (0 <= x && x < w && 0 <= y && y < h)
			return true;
		return false;
	}

	boolean[][] visited;
	boolean ans;
	int count, w, h, sx, sy;
	int[] vx = { 0, 1, 0, -1, 1, 1, -1, -1 };
	int[] vy = { -1, 0, 1, 0, -1, 1, 1, -1 };
}

Measured memory_bytes: 50652
n = int(input())
a = [int(i) for i in input().split()]

b = [0]*10**5

for i in a:
    b[i] += 1
ans = 0
c = 0
for i in range(10**5):
    if b[i] == 0:
        continue
    if b[i] == 1:
        ans +=1
    elif b[i] % 2 == 0:
        c += 1
    elif b[i] % 2 == 1:
        ans +=1
        
d = c % 2
if d == 1:
    ans -=1
print(ans + c)

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

typedef long long ll;

ll N;
vector<ll> A;
vector<pair<ll, ll>> R;

void go(ll x, ll y) {
  A[y] += A[x];
  R.push_back(make_pair(x, y));
}
int main() {
  cin >> N;
  A.resize(N);
  for (ll i = 0; i < N; ++i) cin >> A[i];
  vector<ll>::iterator ma = max_element(A.begin(), A.end()),
                       mi = min_element(A.begin(), A.end());
  if (*ma + *mi >= 0) {
    assert(*ma >= 0);
    ll mai = ma - A.begin();
    for (ll i = 1; i < N; ++i) {
      go(mai, i);
      if (A[i - 1] > 0) go(i - 1, i);
      assert(A[i - 1] <= A[i]);
    }
  } else {
    assert(*mi <= 0);
    ll mii = mi - A.begin();
    for (ll i = N - 2; i >= 0; --i) {
      go(mii, i);
      if (A[i + 1] < 0) go(i + 1, i);
      assert(A[i] <= A[i + 1]);
    }
  }
  cout << R.size() << endl;
  for (auto r : R) {
    cout << r.first + 1 << " " << r.second + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a,b;

  scanf("%d %d",&a,&b);
  
  if(a < b)
    {
      printf("a < b\n");
    }
  if(a > b)
    {
      printf("a > b\n");
    }
  if(a == b)
    {
      printf("a == b\n");
    }
    return 0;
}



Measured memory_bytes: 2044
using System;
using System.Collections.Generic;
using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

class Program
{
    

    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());

        var Hs = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        int max = 0;
        int count = 0;

        for(int i = 0; i < Hs.Length; i++)
        {
            if(Hs[i] >= max)
            {
                max = Hs[i];
                count++;
            }
        }

        Console.WriteLine(count);
        
    }
    
}


Measured memory_bytes: 13396
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7


def main():
    n,l = list(map(int,input().split()))
    a = [input() for _ in range(n)]
    a.sort()
    return ''.join(a)



print(main())


Measured memory_bytes: 8644
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 998244353
#define all(v) (v).rbegin(),(v).rend()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 

#define M 200010


int main(){
	IOS;
	tihs;

	ll n,k;cin>>n>>k;
	ll x=n-(n/k)*k;
	cout<<min(x,abs(x-k));


	return 0;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M; cin >> N >> M;
    int A[M]; rep(i, M) cin >> A[i];
    sort(A, A+M);
    vector<int> dist;
    rep(i, M-1) dist.push_back(A[i+1]-A[i]);
    sort(dist.rbegin(), dist.rend());
    ll ans = 0;
    for(int i = N-1; i < dist.size(); i++){
        ans += dist[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1276
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = 2000000000;
// const ll MOD = 1000000007;

string S;

bool f(char c) {
  if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
    return true;
  }
  return false;
}

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

  int ans = 0;
  int last = 0;
  for (int i = 0; i < S.size(); i++) {
    if (f(S[i])) {
      last++;
    } else {
      ans = max(ans, last);
      last = 0;
    }
  }
  ans = max(ans, last);

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int x1 , y1 , x2 , y2 ;
    scanf("%d%d%d%d", &x1 , &y1 , &x2 , &y2);
    int d1 = x2 - x1 ;
    int d2 = y2 - y1 ;

    printf("%d %d %d %d ", (x2-d2),(y2 +d1) , (x1-d2) ,(y1 + d1));
}

Measured memory_bytes: 128
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    string s, t;
    cin >> s;
    cin >> t;
    unordered_map<char, vint> pos;
    rep(i, s.size()) {
        pos[s[i]].push_back(i + 1);
    }
    int now_pos = 0;
    int now_t_idx = 0;
    string substr = "";
    vector<string> subs;
    while(1) {
        if (now_t_idx == t.size()) {
            break;
        }
        auto c = t[now_t_idx];
        auto it = upper_bound(pos[c].begin(), pos[c].end(), now_pos);
        if (it == pos[c].end()) { //ない場合
            if (substr.size() == 0) { //todo 検討
                cout << -1 << endl;
                return 0;
            }
            subs.push_back(substr);
            substr = "";
            now_pos = 0;
        }
        else { //ある場合
            substr += c;
            now_pos = *it;
            now_t_idx++;
        }
    }

    if (substr.size() > 0) {
            subs.push_back(substr);
            substr = "";
    }
    ll ans = s.size() * (subs.size() - 1) + now_pos;
    cout << ans << endl;
    return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

int main(){
  int n;
  cin >> n;
  vi p(n);
  rep(i, 0, n)
    cin >> p[i];
  
  int cnt = 0;
  int mn = p[0];
  
  rep(i, 0, n){
    if(mn >= p[i]){
      cnt++;
      mn = p[i];
    }
  }
  
  cout << cnt << endl;
  
  return 0;
  
}

Measured memory_bytes: 3992
#include<iostream>
using namespace std;
int main() {
	long long a, b;
	cin >> a >> b;
	if (a * 2 > b) {
		cout << b / 2 << endl;
	}
	else {
		cout << a + (b - a * 2) / 4 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
bool exist[26];
int main(){
  string S;
  cin>>S;
  for(int i=0;i<S.size();i++){
    int n = S[i] - 'a';
    exist[n] = true;
  }
  for(int i=0;i<26;i++){
    if(!exist[i]){
      char a = 'a' + i;
      cout<<a<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int digit_sum(int n){
  int res = 0;
  while(n>0){
    res += n%10;
    n /=10;
  }
  return res;
}
int main(){
  int n;
  cin >> n;
  if(n%digit_sum(n)==0) cout << "Yes" <<endl;
  else cout << "No" <<endl;
  

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, m, x;
int main(){
  cin >> n >> m >> x;
  int a(m);
  int many = 0;
  int litt = 0;
  for(int i = 0; i < m; ++i){
    cin >> a;
    if(x > a) ++many;
    if(x < a) ++litt;
  }
  if(many < litt) cout << many << endl;
  else cout << litt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,D;
  cin >> N >> D;
  vector<vector<int>> X(N,vector<int>(D));
  for (int i = 0; i < N; i++){
    for (int j = 0; j < D; j++){
      cin >> X[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++){
    for (int j = i + 1; j < N; j++){
      int d = 0;
      for (int k = 0; k < D; k++) d += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
      if (pow((int)sqrt((double)d),2) == d) ans++;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


MOD = 1000000007

N = int(input())

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

lcm_ = 1
for a in A:
    lcm_ = lcm(lcm_, a)

ans = 0
for a in A:
    ans += lcm_ // a

ans %= MOD
print(ans)

Measured memory_bytes: 10184
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int n; cin>>n;
    itn nc2 = n*(n-1)/2;
    if(n%2 == 0){
        cout<<nc2 - (n/2)<<endl;
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                if(j == (n+1-i)) continue;
                else cout<<i<<' '<<j<<endl;
            }
        }
    }else{
        cout<<nc2 - (n-1)/2<<endl;
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                if(j == n-i) continue;
                else cout<<i<<' '<<j<<endl;
            }
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long sum=0;
long long a[1005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        sum+=a[i];
    }
    long long  MIN=1e18;
    long long pos=0;
    for(int i=1;i<=n;i++)
    {
        pos+=a[i];
        MIN=min(MIN,abs(sum-pos-pos));
    }
    printf("%lld\n",MIN);
}


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

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

int N;
string S;

int memo[300010];

int main() {
	cin >> N >> S;
	int count = 0;

	for (int i = 1; i < N; i++) {
		if (S[i] == 'E') memo[0]++;
	}
	int best = memo[0];

	for (int i = 1; i < N; i++) {
		count = memo[i - 1];
		if (S[i - 1] == 'W') count++;

		if (S[i] == 'E') count--;

		if (count < best) {
			best = count;
		}

		memo[i] = count;

	}

	cout << best << endl;

	return 0;
}

Measured memory_bytes: 1796
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

x = int(input())

def judge(p):
    j = True
    for i in range(2, int(p**0.5)):  #O(√p)
        if p%i == 0:
            j = False
            continue
    return(j)
   
c = False
while not c:
    c = judge(x) 
    x += 1
    
print(x - 1)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define rep(i, n) for (int i=0; i< (n); ++i)
typedef long long ll;
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; }

using namespace std;

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

    if (n < 10) {
        cout << 100 * (10 - n) + r << endl;
    } else {
        cout << r << endl;
    }
}


Measured memory_bytes: 256
n = int(input())
stair = input().split(' ')

for i in range(0, n - 1):
  if (int(stair[i]) < int(stair[i+1])):
    stair[i+1] = int(stair[i+1]) - 1

  if (int(stair[i]) > int(stair[i+1])):
    print("No")
    exit()


print("Yes")


Measured memory_bytes: 12020
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
//ミョ(-ω- ?)
int main() {
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m,0);
    rep(i,m)cin >> a.at(i);
    ll ac =accumulate(a.begin(),a.end(),0); 
    if(n < ac){
        cout << -1 << endl;
    }else{
        cout << n-ac << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

int n, h;

const int MAXN = 123456;



int main() {

    cin >> n >> h;
    //cout << n << endl;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        h -= a[i];
        if(h < 0) break;
        cnt++;
    }
    cout << cnt - (h > 0);
	return 0;
}


Measured memory_bytes: 256