akhauriyash/Code-Regression huggingface dataset:
a, b, q = map(int, input().split())
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]

s = sorted(s)
t = sorted(t)
st = []
(i, j) = (0, 0)
while i < len(s) or j < len(t):
    if j == len(t) or (i < len(s) and s[i] < t[j]):
        st.append((s[i], min(abs(s[i] - t[max(j - 1, 0)]),
                             abs(s[i] - t[min(j, len(t) - 1)]))))
        i += 1
    else:
        st.append((t[j], min(abs(t[j] - s[max(i - 1, 0)]),
                             abs(t[j] - s[min(i, len(s) - 1)]))))
        j += 1

def doit(x):
    lo, hi = 0, len(st) - 1
    while hi - lo > 1:
        mid = (lo + hi) // 2
        if st[mid][0] < x:
            lo = mid
        else:
            hi = mid
    mid = (lo + hi) // 2
    return min(abs(st[mid][0] - x) + st[mid][1], abs(st[mid + 1][0] - x) + st[mid + 1][1])

for _ in range(q):
    print(doit(int(input())))

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

int main(){
    int N; cin >> N;
    vector<long long> A(N+1);
    for(int i=0; i < N+1; i++){
        long long a; cin >> a;
        A[i] = a;
    }
    vector<long long> B(N);
    for(int i=0; i < N; i++){
        long long b; cin >> b;
        B[i] = b;
    }
    long long ans = 0;
    for(int i=0; i < N; i++){
        ans += min({A[i], B[i]});
        B[i] = max({B[i] - A[i], (long long)0});
        ans += min({A[i+1], B[i]});
        A[i+1] = max({A[i+1] - B[i], (long long)0});
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
N = int(input())
W = [input() for _ in range(N)]
s = set(W)
if len(s) != N:
    print("No")
    exit()
for i in range(N - 1):
    if W[i][-1] != W[i + 1][0]:
        print("No")
        exit()
print("Yes")

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

int main () {
    string s; cin >> s;
	
    int A = s[0]-'0', B = s[1]-'0', C = s[2]-'0', D = s[3]-'0';
    if (A+B+C+D == 7) cout << s[0] << '+' << s[1] << '+' << s[2] << '+' << s[3] << '=' <<  '7' << endl;
    else if (A+B+C-D == 7) cout << s[0] << '+' << s[1] << '+' << s[2] << '-' << s[3] << '=' << '7' << endl;
    else if (A+B-C+D == 7) cout << s[0] << '+' << s[1] << '-' << s[2] << '+' << s[3] << '=' << '7' << endl;
    else if (A+B-C-D == 7) cout << s[0] << '+' << s[1] << '-' << s[2] << '-' << s[3] << '=' << '7' << endl;
    else if (A-B+C+D == 7) cout << s[0] << '-' << s[1] << '+' << s[2] << '+' << s[3] << '=' << '7' << endl;
    else if (A-B+C-D == 7) cout << s[0] << '-' << s[1] << '+' << s[2] << '-' << s[3] << '=' << '7' << endl;
    else if (A-B-C+D == 7) cout << s[0] << '-' << s[1] << '-' << s[2] << '+' << s[3] << '=' << '7' << endl;
    else if (A-B-C-D == 7) cout << s[0] << '-' << s[1] << '-' << s[2] << '-' << s[3] << '=' << '7' << endl;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
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); }
// clang-format on

main {
  int N, S;
  cin >> N >> S;
  vector<int> a(N + 1);
  for (int i = 1; i <= N; i++) cin >> a[i];
  for (int i = 2; i <= N; i++) a[i] += a[i - 1];
  int ans = INF;
  for (int i = 0; i < N; i++) {
    int j = lower_bound(all(a), a[i] + S) - a.begin();
    if (j == N + 1) continue;
    cmin(ans, j - i);
  }
  cout << (ans == INF ? 0 : ans) << endl;
}



Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <climits>
#include <math.h>
#include <bitset>

#define P pair
#define X first
#define Y second
#define VSORT(v) sort(v.begin(), v.end())
#define VREV(v) reverse(v.begin(), v.end())
#define VMAX_P(v) max_element(v.begin(), v.end())
#define VMIN_P(v) min_element(v.begin(), v.end())
#define VMAX_IDX(v) distance(v.begin(), VMAX_P(v))
#define VMIN_IDX(v) distance(v.begin(), VMIN_P(v))
#define VCOPY(src, dst) copy(src.begin(), src.end(), back_inserter(dst))
#define SUPPER(src, dst) transform(src.begin(), src.end(), dst.begin(), toupper);
#define SLOWER(src, dst) transform(src.begin(), src.end(), dst.begin(), tolower);

using namespace std;
using ll = long long;

void displayVec(vector<int> v)
{
    for (int i = 0; i < v.size(); i++)
    {
        cout << v[i] << endl;
    }
    cout << endl;
}

int binarySearch(vector<int> v, int target)
{
    int left = -1;
    int right = v.size();

    while (right - left > 1)
    {
        int mid = left + (right - left) / 2;

        if (v[mid] >= target)
        {
            right = mid;
        }
        else
        {
            left = mid;
        }
    }

    if (right < v.size() && v[right] == target)
    {
        return right;
    }
    return -1;
}

int main(int argc, const char *argv[])
{
    string s;
    cin >> s;
    VSORT(s);
    if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

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

int main() {
    char s[200000],t[200000];
    int n,m,sw=0,g,sidx=0,tidx=0;
    scanf("%d %d %s %s",&n,&m,s,t);
    g=gcd(n,m);

    while(sidx<n && tidx<m) {
        if(s[sidx]!=t[tidx]) {sw=1; break;}
        sidx+=n/g;
        tidx+=m/g;
    }
    if(sw) printf("%d",-1);
    else printf("%lld",(long long)n/g*m);
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int N, M;
    cin >> N >> M;
    pair<uint64_t,int> store[100'000];
    for(int i=0;i<N;i++){
        int a, b;
        cin >> a >> b;
        store[i] = {a, b};
    }
    sort(store, store+N);
    int64_t ans = 0;
    for(int i=0;i<N && M>0;i++){
        if(store[i].second <= M){
            ans += store[i].first * store[i].second;
            M -= store[i].second;
        }else{
            ans += store[i].first * M;
            M = 0;
        }
    }

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

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int n;
    cin >> n;
    string t;
    cout << "?";
    for (int i=1; i<=n; i++) cout << ' ' << i;
    cout << endl;
    cin >> t;
    char f = t[0];
    int l = 1, r = n+1, m;
    while (r - l > 1) {
        m = (l + r) / 2;
        cout << "?";
        for (int i=m; i<m+n; i++) cout << ' ' << i;
        cout << endl;
        cin >> t;
        if (t[0] == f) l = m;
        else r = m;
    }
    string ans = "";
    for (int i=1; i<=2*n; i++) {
        cout << "? " << i;
        if (i < r || i >= r+n-1)
            for (int j=r; j<r+n-1; j++) cout << ' ' << j;
        else  {
            for (int j=1; j<=2*n; j++)
                if (j < r-1 || j >= r+n)
                    cout << ' ' << j;
        }
        cout << endl;
        cin >> t;
        ans += t[0];
    }
    cout << "! " +  ans << endl;
    return 0;
}


Measured memory_bytes: 724
#include <iostream>
#include <cmath>
#include <cassert>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <type_traits>
#include <fstream>
//#include <bits/stdc++.h>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// print(x, y, z);
// printVec(va.begin(), va.end());
void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}
template<typename Iterator> void printVec(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << it - begin << "] " << *it << " ";
    if ((it - begin) % 20 == 19 || it == end - 1) { std::cout << std::endl; }
  }
}
template<typename Iterator> void printVecPair(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << it - begin << "] " << it->first << " " << it->second << " ";
    if ((it - begin) % 10 == 9 || it == end - 1) std::cout << std::endl;
  }
}


int main(int argc, char* argv[])
{

  //std::ifstream ifs("input.txt");
  //std::cin.rdbuf(ifs.rdbuf());

  // Speed Up
  // http://tatanaideyo.hatenablog.com/entry/2014/10/24/214714
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll N, M, X, Y;
  std::cin >> N >> M >> X >> Y;
  std::vector< ll > vx(N+1, 0LL);
  std::vector< ll > vy(M+1, 0LL);
  vx[0] = X;
  for (ll i = 1; i <= N; i++) {
    std::cin >> vx[i];
  }
  vy[0] = Y;
  for (ll i = 1; i <= M; i++) {
    std::cin >> vy[i];
  }
  ll max_x = *std::max_element(vx.begin(), vx.end());
  ll min_y = *std::min_element(vy.begin(), vy.end());
  if (min_y <= max_x) {
    print("War");
  } else {
    print("No War");
  }

  return 0;
}


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

int main(){
  int W,H,N;
  cin >> W >> H >> N;
  int x_u,x_d,y_u,y_d,area;
  x_u = W;
  x_d = 0;
  y_u = H;
  y_d = 0;
  for(int i = 0; i < N; i++){
    int x,y,a;
    cin >> x >> y >> a;
    if(a == 1) x_d = max(x,x_d);
    else if(a == 2) x_u = min(x,x_u);
    else if(a == 3) y_d = max(y,y_d);
    else if(a == 4) y_u = min(y,y_u);
  }
  area = (x_u - x_d) * (y_u - y_d);
  if(x_u - x_d < 0 || y_u - y_d < 0 ) area = 0;
  cout << area << endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[105],b[105],c[105],d[105],n,st,ed;
int head[205],nxt[50005],v[50005],w[50005],tot=1;
int lev[205];
inline void add(int a,int b,int val)
{tot++;nxt[tot]=head[a];head[a]=tot;v[tot]=b;w[tot]=val;}
inline bool bfs()
{memset (lev,0x7f,sizeof(lev));
queue <int> q;int i;
lev[st]=1;q.push(st);
while (!q.empty())
{int t=q.front();q.pop();
for (i=head[t];i;i=nxt[i])
{if (w[i]>0&&lev[v[i]]>lev[t]+1)
{lev[v[i]]=lev[t]+1;q.push(v[i]);}
}
}
return lev[ed]<100000000;
}
int dfs(int pos,int f)
{if (pos==ed) {return f;}
int cost=0,tmp,i;
for (i=head[pos];i;i=nxt[i])
{if (w[i]>0&&lev[v[i]]==lev[pos]+1)
{tmp=dfs(v[i],min(w[i],f-cost));
if (tmp)
{w[i]-=tmp;w[i^1]+=tmp;
cost+=tmp;
if (cost==f) {return cost;}
}
}
}
lev[pos]=-1;
return cost;
}
int main (){
	int i,j,k,ans=0;
	scanf ("%d",&n);
	st=2*n+1;ed=2*n+2;
	for (i=1;i<=n;i++)
	{scanf ("%d%d",&a[i],&b[i]);}
	for (i=1;i<=n;i++)
	{scanf ("%d%d",&c[i],&d[i]);}
	for (i=1;i<=n;i++)
	{for (j=1;j<=n;j++)
	{if (a[i]<c[j]&&b[i]<d[j])
	{add(i,j+n,1);add(j+n,i,0);}
	}
	add(st,i,1);add(i,st,0);
	add(i+n,ed,1);add(ed,i+n,0);
	}
	while (bfs()) ans+=dfs(st,10000);
	printf ("%d",ans);
	return 0;
}
	
	

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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;
const long double PI = (acos(-1));
const ull MOD = 1000000007;


struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main(){
    int N;
    ll T;
    cin >> N >> T;
    vector<ll> t(N);
    for(int i = 0; i < N; i++) cin >> t[i];
    ull ans = T;
    for(int i = 0; i < N - 1; i++) ans += min(T, t[i + 1] - t[i]);
    cout << ans << endl;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    int X;
    cin >> X;

    int ans = 0;
    if (400 <= X && X < 600) ans = 8;
    if (600 <= X && X < 800) ans = 7;
    if (800 <= X && X < 1000) ans = 6;
    if (1000 <= X && X < 1200) ans = 5;
    if (1200 <= X && X < 1400) ans = 4;
    if (1400 <= X && X < 1600) ans = 3;
    if (1600 <= X && X < 1800) ans = 2;
    if (1800 <= X && X < 2000) ans = 1;

    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

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;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

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

	int x;
	cin >> x;

	int f = 1;
	for (int f = 1; f <= 1000; ++f) {
		for (int i = 100 * f; i <= 105 * f; ++i) {
			if (x % i == 0) {
				cout << "1\n";
				return 0;
			}
		}
	}

	cout << "0\n";

	return 0;

}

Measured memory_bytes: 256
//Belief yourself,Respect yourself

#include<bits/stdc++.h>
using namespace std;
#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search;
#define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Lower value search;
#define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
#define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
#define rep(i,intial,n) for(int i=intial; i<(n) ; i++)
#define REP(i,intial,n) for(int i=intial; i<=(n) ; i++)
#define PI acos(-1.0)//PI Calculation
#define LL long long
#define MP make_pair
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007

//Bit Operation
bool checkBit(LL n, int i) { return n&(1LL<<i); }  //AND
LL setBit(LL n, int i) { return n|(1LL<<i);; }     //OR
LL resetBit(LL n, int i) { return n&(~(1LL<<i)); } //OFF

template<typename T> T POW(T b,T p)          //Pow calculation
{
    T r=1;
    while(p)
    {
        if(p&1)r=(r*b);
        b=(b*b);
        p>>=1;
    }
    return r;
}

LL big_mod(LL n, LL p)
{
    if(p==0) return 1;
    if(!(p&1))
    {
        LL r = big_mod(n,p/2) % MOD;
        return ( (r%MOD) * (r%MOD) ) % MOD;
    }
    else return ( ( n%MOD) * (big_mod(n,p-1) %MOD)) % MOD;
}

long long gcd(long long a, long long b) {
  while (b != 0) {
    long long t = a % b;
    a = b;
    b = t;
  }
  return a;
}

//||--------------------------->||Main_Code_Start_From_Here||<---------------------------------||
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    LL a,b;
    while(cin>>a>>b)
    {
        LL keep=a-b;
        if(keep<=0) cout<<"0"<<endl;
        else cout<<keep<<endl;
    }

}



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

vector<pair<long long, long long> > prime_factorize(long long N) {
	vector<pair<long long, long long> > res;
	for (long long a = 2; a * a <= N; ++a) {
		if (N % a != 0) continue;
		long long ex = 0; // 指数

		 // 割れる限り割り続ける
		while (N % a == 0) {
			++ex;
			N /= a;
		}

		// その結果を push
		res.push_back({ a, ex });
	}

	// 最後に残った数について
	if (N != 1) res.push_back({ N, 1 });
	return res;
}

int main() {

	ll n, p; cin >> n >> p;
	vector<pair<long long, long long>> a_prime;  // a^x ならば { a, x }

	a_prime = prime_factorize(p);
	ll tmp = 1;
	for (ll i = 0; i < a_prime.size(); i++) {
		ll quo = a_prime[i].second / n;
		for (int j = 0; j < quo; j++) {
			tmp *= a_prime[i].first;
		}	
	}
	cout << tmp << endl;
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	long long a,b;
	cin>>a>>b;
	vector<int>arr(n);
	for(int i=0; i<n; i++) cin>>arr[i];
	long long ret = 0;
	for(int i=0; i<n-1; i++){
		long long d = arr[i+1]-arr[i];
		long long walk = d*a;
		ret+=min(walk,b);
	}
	cout<<ret;
}

Measured memory_bytes: 3716
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int[] a=new int[n];
		int ans=0;
		for(int i=0;i<n;i++){
			a[i]=scan.nextInt();
		}
		
		Arrays.sort(a);
		
		for(int i=0;i<n;i++){
			if(a[i]>=n-i && n-i>ans){
				ans=n-i;
				break;
			}
		}
		System.out.println(ans);
	}
}



Measured memory_bytes: 26464
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n;
string s;
map<pair<string, string>, int> mp;
int ans;

signed main() {
	cin >> n >> s;
	for (int i = 0; i < (1 << n); i++) {
		string t1 = "", t2 = "";
		for (int j = 0; j < n; j++)if (i&(1 << j))t1 += s[j];
		for (int j = n - 1; j >= 0; j--)if (!(i&(1 << j)))t2 += s[j];
		mp[make_pair(t1, t2)]++;
	}
	for (int i = 0; i < (1 << n); i++) {
		string t1 = "", t2 = "";
		for (int j = 0; j < n; j++)if (i&(1 << j))t1 += s[n + j];
		for (int j = n - 1; j >= 0; j--)if (!(i&(1 << j)))t2 += s[n + j];
		ans += mp[make_pair(t2, t1)];
	}
	cout << ans << endl;
}

Measured memory_bytes: 91904
#include <vector>
#include <iostream>

int main() {
	int lx = 0, rx, by = 0, ty;
	int w, h;
	int n;
	std::cin >> w >> h >> n;
	rx = w;
	ty = h;
	for (int i = 0; i < n; i++) {
		int x, y;
		std::cin >> x >> y;
		int mode;
		std::cin >> mode;

		if (mode == 1 && lx < x) {
			lx = x;
		}
		if (mode == 2 && rx > x) {
			rx = x;
		}
		if (mode == 3 && by < y) {
			by = y;
		}
		if (mode == 4 && ty > y) {
			ty = y;
		}
	}

	

	int ans = (rx - lx) * (ty - by);
	if (rx - lx < 0 || ty - by < 0) {
		ans = 0;
	}
	std::cout << ans << std::endl;


}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using static System.Math;

class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < 100; i++)
        {
            for (int j = 0; j < 100; j++)
            {
                if(i * 4 + j * 7 == n)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
        }
        Console.WriteLine("No");
    }
}

Measured memory_bytes: 13140
from operator import mul
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
mul_all = reduce(mul, a)
sum_all = 0
ans = 0
for i in range(n):
  sum_all += ( mul_all / a[i] )
ans = mul_all / sum_all

print(ans)



Measured memory_bytes: 3700
K, N = map(int, input().split())
A = list(map(int, input().split()))
sa = [A[i + 1] - A[i] for i in range(N - 1)]
sa.append((K - A[N - 1]) + A[0])

s = sa.index(max(sa))
del sa[s]

print(sum(sa))

Measured memory_bytes: 25840
N = int(input())
a = list(map(int, input().split()))

def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)

def lcm(a, b):
  return a*b//gcd(a,b)

alcm = a[0]
for i in a[1:]:
  alcm = lcm(alcm, i)

res = 0

for i in range(N):
  res += (alcm-1) % a[i]

print(int(res))

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,c;
    cin >> a >> b >> c;
    //    if(((double)sqrt(a) + (double)sqrt(b)) < (double)sqrt(c)) cout << "Yes" << endl;
    //    if((a + b - c +2*((double)sqrt((ll)a*b))) < 0) cout << "Yes" << endl;
    ll d = c-a-b;
//    if(((c-a-b) > 0)&&((c-a-b)^2 - 4*a*b) > 0) cout << "Yes" << endl;
    if(d > 0 && d * d > 4*a*b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
//#pragma region ALL(include define etc)
#include <iostream>   // swap(a, b)
#include <string>
#include <cmath>      // abs(絶対値) sin cos tan(角度 / 180.0 * 3.141592)
#include <vector>     // vec.push_back(a) vec.pop_back()
#include <algorithm>  // max(a, b) min(a, b) reverse() sort()
#include <functional> // sort(a, a + N, greater<型>());
#include <math.h>
#include <iomanip>
#define int long long
#define ll long long
#define double long double
using namespace std;
//#pragma endregion

signed main()
{
	//int x;

	//int h1, h2, m1, m2, k;
	//int box, box1,box2;

	//int N;
	//int n;
	int a;
	double b;
	//int m;
	//int k;
	//string s;
	//string t;
	//int m1, m2;
	//int a, b, c, k;

	//int box[1000000000000000000];
	double box;

	//long double aaa;

	//int k, d;
	int all = 0;
	//double all;
	//double a, b;
	//double h, m;
	//int a[30000] = { 0 };
	//double c, d, e;

	//double mbox, hbox;
	//double box, box2;

	//int b = 0;

	//int box[10000] = { 0 };

	//bool flag = true;

	//string str;

	//cin >> h1 >> m1 >> h2 >> m2 >> k;
	//cin >> n;
	cin >> a >> b;

	box = (double)a * b;

	all = box;

	//n = t.length();

	//cout << b << "\n";
	/*for (int i = 0; i < n; i++)
	{
		if (t[i] == '?')
		{
			t[i] = 'D';
		}
	}*/

	/*if (flag == true)
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";
	}*/
	//if (all > 1000000000000000000)//1000000000000000000
	//{
	//	cout << "-1\n";
	//}
	//else
	//{
	//	cout << all << "\n";
	//}

	cout << all << "\n";

	//cout << fixed << setprecision(111) << all;
}


Measured memory_bytes: 3728
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#define MOD 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;

signed main(){
    string s,t;
    cin>>s>>t;
    vector<int> w[26];
    for(int i=0;i<s.size();i++)w[s[i]-'a'].push_back(i);
    int now=0;
    int cnt=0;
    for(int i=0;i<t.size();i++){
        if(w[t[i]-'a'].empty()){
            cout<<-1<<endl;
            return 0;
        }else if(lower_bound(w[t[i]-'a'].begin(),w[t[i]-'a'].end(),now)-w[t[i]-'a'].begin()==w[t[i]-'a'].size()){
            now=w[t[i]-'a'][0]+1;
            cnt++;
        }else{
            now=*lower_bound(w[t[i]-'a'].begin(),w[t[i]-'a'].end(),now)+1;
        }
    }
    cout<<cnt*s.size()+now<<endl;
    return 0;
}


Measured memory_bytes: 1724
//gauravsinghh
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 1000000000
#define lim 100005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
 
int main(){
    IOS
    //io_set();
    cout << fixed << setprecision(10);
 	ll n;
 	cin >> n;
 	ld x[n], y[n], ans = 0;
 	rep(i, n){
 		cin >> x[i] >> y[i];
 	}
 	ll power = pow(2, n-1);
 	rep(i, n){
 		fo(j, i+1, n-1){
 			ans += (sqrtl(abs((x[i] - x[j])*(x[i] - x[j])) + abs((y[i] - y[j])*(y[i] - y[j]))));

 		}
 	}
 	ll fact = 1;
 	fo(i, 1, n){
 		fact *= i;
 	}
 	ld op = ans * 2;
 	op /= n;
 	cout << op << endl;
    return 0;
} 


Measured memory_bytes: 256
from itertools import product

n, m, x = map(int, input().split())
ci = []
aij = []

for _ in range(n):
    c, *a = map(int, input().split())
    ci.append(c)
    aij.append(a)

min_used_money = float("inf")
for i in product([True, False], repeat=n):
    used_money = 0
    skills = [0] * m
    for j in range(n):
        if i[j]:
            used_money += ci[j]
            for k in range(m):
                skills[k] += aij[j][k]
    for k in range(m):
        if skills[k] < x:
            break
    else:
        min_used_money = min(min_used_money, used_money)

print(min_used_money if min_used_money != float("inf") else - 1)

Measured memory_bytes: 9124
#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 LOCAL
    ~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__) << "] "
 
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<long double> vld;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846
#define sqr(a) ((a) * (a))
#define len(V) (int)V.size()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define fix(a) fixed << setprecision(a)
#define readv(x) for(auto &_ : (x)) {cin >> _;}
#define printv(x) for(auto &_ : (x)) {cout << _ << ' ';} cout << endl
#define EPS 1e-6
#define MAXN 100047

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n; cin >> n;
	vi a(n); readv(a);
	sort(all(a));
	cout << (a[n/2] - a[n/2-1] > -1 ? a[n/2] - a[n/2-1] : 0) << endl;
	
	return 0;
}


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

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;
    cin>>n>>k;
    vector<ll> arr(n+1);
    for(ll i=1;i<=n;i++)
        cin>>arr[i];
    vector<ll> vis(n+1);
    ll cur=1;
    ll cnt =1;
    while(vis[cur]==0){
        vis[cur] = cnt++;
        cur = arr[cur];
    }
    ll cur2=cur;
    vector<ll> loop;
    do{
        loop.push_back(cur2);
        cur2 = arr[cur2];
    }while(cur2!=cur);
    ll dist = vis[cur]-1;
    if(k<dist){
        cur=1;
        while(k--)
            cur = arr[cur];
        cout<<cur<<endl;
    }
    else 
        cout<<loop[(k-dist)%loop.size()]<<endl;
    
    return 0;
}



Measured memory_bytes: 8424
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n;cin>>n;
    vector<vector<ll>> v(n, vector<ll> (3));
    REP(i,n)REP(j,3)cin>>v[i][j];
    string ans="Yes";
    ll dt,dx,dy;
    dt=v[0][0], dx=v[0][1], dy=v[0][2];
    while(dt>=0){
        if(dx+dy==dt){
            break;
        }else{
            dt-=2;
            continue;
        }
    }
    if(dt<0)ans="No";
    REP(i,n-1){
        dt=v[i+1][0]-v[i][0];
        dx=abs(v[i+1][1]-v[i][1]);
        dy=abs(v[i+1][2]-v[i][2]);
        while(dt>=0){
            if(dx+dy==dt){
                break;
            }else{
                dt-=2;
                continue;
            }
        }
        if(dt<0)ans="No";
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8712
S = input()
s_set = set(S)
ind = len(S)

if len(S) == 26:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
        exit()
    for i in range(24, -1, -1):
        if ord(S[i]) <= ord(S[i+1]):
            ind = i
            break
    ans = S[:ind]
    for s in reversed(S[ind+1:]):
        if ord(s) > ord(S[ind]):
            print(ans + s)
            exit()

else:        
    for i in range(26):
        if chr(i+97) in s_set:
            continue
        else:
            print(S + chr(i+97))
            break

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

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

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

vector<int> p;
vector<int> r;

void init(int n) {
  p.reserve(n);
  r.reserve(n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 0;
  }
}

int root(int x) { return p[x] == x ? x : p[x] = root(p[x]); }

bool same(int x, int y) { return root(x) == root(y); }

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if (x == y)
    return;

  if (r[x] < r[y])
    p[x] = y;
  else {
    p[y] = x;
    if (r[x] == r[y])
      r[x]++;
  }
}

int main() {
  int N;
  cin >> N;
  map<string, int> W;
  string tmp = "";
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    W[s]++;
    if (W[s] > 1) {
      cout << "No" << endl;
      return 0;
    }
    if (tmp != "") {
      int n = tmp.size() - 1;
      if (s[0] != tmp[n]) {
        cout << "No" << endl;
        return 0;
      }
    }
    tmp = s;
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#define INF 1LL<<60
#define MAX_N 120000
#define MAX_M 320000
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
struct edge{
	int t;
	ll dist;
	edge(){}
	edge(int tt,ll dd){
		t=tt;
		dist=dd;
	}
};

int n,m;
ll x,h[MAX_N];
vector<edge> G[MAX_N];
ll dp[MAX_N];

ll dijk(){
	for(int i=0;i<MAX_N;i++){
		dp[i]=INF;
	}
	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0,0));
	dp[0]=0;
	while(que.size()){
		P p=que.top();
		que.pop();
		ll cost=p.first;
		int v=p.second;
		if(cost>dp[v])continue;
		if(v==n-1){
			if(cost>x)return cost+h[n-1];
			else return cost+h[n-1]-(x-cost);
		}
		for(int i=0;i<G[v].size();i++){
			edge e=G[v][i];
			ll ncost=cost+e.dist;
			ll ph=max(x-cost,0LL);
			if(ph-e.dist<0LL)ncost+=e.dist-ph;
			if(ph-e.dist>h[e.t])ncost+=ph-e.dist-h[e.t];
			if(ncost<dp[e.t]){
				dp[e.t]=ncost;
				que.push(P(ncost,e.t));
			}
		}
	}
	return -1;
}

int main(void){
	scanf("%d%d%lld",&n,&m,&x);
	for(int i=0;i<n;i++){
		scanf("%d",&h[i]);
	}
	for(int i=0;i<m;i++){
		int a,b;
		ll d;
		scanf("%d%d%lld",&a,&b,&d);
		a--;
		b--;
		if(h[a]>=d)G[a].push_back(edge(b,d));
		if(h[b]>=d)G[b].push_back(edge(a,d));
	}
	printf("%lld\n",dijk());
	return 0;
}

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

int main() {
	int n, l;
	string ans;
	cin >> n >> l;
	vector<string> str(n);
	for (int i = 0; i<n; i++) {
		cin >> str.at(i);
	}
	sort(str.begin(), str.end());
	ans = str.at(0);
	for (int i = 1; i<n; i++) {
		ans += str.at(i);
	}

	cout << ans << endl;
}

Measured memory_bytes: 3644
N = int(input())
A = [int(input()) for i in range(N)]
array = []
ans = 0
j = 0

for i in range(N):
  if i+1 == N:
    ans += sum(A[j:i+1])//2
    j = i+1
  elif A[i+1] == 0:
    ans += sum(A[j:i+1])//2
    j = i+1
    
print(ans)

Measured memory_bytes: 7840
#include <cstdio>

const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;

int x[maxn], y[maxn];

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &x[i]);
        if (x[i] < 0)
            x[i] += mod;
    }
    for (int i = 0; i < m; ++i)
    {
        scanf("%d", &y[i]);
        if (y[i] < 0)
            y[i] += mod;
    }
    long long X = 0;
    long long Y = 0;
    long long sum;
    sum = 0;
    for (int i = 0; i < n; ++i)
    {
        X = (X + 1ll * i * x[i] % mod + mod - sum) % mod;
        sum = (sum + x[i]) % mod;
    }
    sum = 0;
    for (int i = 0; i < m; ++i)
    {
        Y = (Y + 1ll * i * y[i] % mod + mod - sum) % mod;
        sum = (sum + y[i]) % mod;
    }
    printf("%lld\n", X * Y % mod);
    return 0;
}

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

int main() {
  long N;
  cin >> N;
  int sqn = sqrt(N);
  //cout<<sqn<<endl;
  int minimum =9999;
  for(int i=1;i<sqn+1;i++){
    if(N%i==0){
      long di=0, dn=0, tmpi=i,tmpn=N/i;
      while(tmpi>0){
        tmpi/=10;
        di++;
      }
      while(tmpn>0){
        tmpn/=10;
        dn++;
      }
      //cout<<i<<" "<<N/i<<" "<<di<<" "<<dn<<endl;
      int f = max(di,dn) ;
      minimum = min(minimum,f) ;
    }
  }
cout<<minimum<<endl;
}


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

void solve(){
    string s; cin >> s;
    if(s == "Sunny") cout << "Cloudy" << endl;
    if(s == "Cloudy") cout << "Rainy" << endl;
    if(s == "Rainy") cout << "Sunny" << endl;
}

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

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }


int main(){
    ll N; cin >> N;
    vll A(N); REP(i, N) cin >> A[i];
    vll B(N); REP(i, N) B[i] = i - A[i];
    map<ll, vll> Rec;
    REP(i, N){
        if(!Rec.count(B[i])) Rec[B[i]] = vll(1, i);
        else Rec[B[i]].push_back(i);
    }
    ll ans = 0;
    REP(i, N){
        ll tmp = A[i]+i;
        if(!Rec.count(tmp)) continue;
        ans += Rec[tmp].end() - upper_bound(ALL(Rec[tmp]), i);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 26284
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
typedef pair<int, int> P;
typedef struct{
  int first;
  int second;
  int third;
}T;

//昇順
bool comp_Se(T& l, T& r){
  return l.second < r.second;
}

int main(void){
  string s;
  cin >> s;
  replace(s.begin(),s.end(),'1','*');
  replace(s.begin(),s.end(),'9','1');
  replace(s.begin(),s.end(),'*','9');
  cout << s << endl;
  return 0;
}

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

#define ll long long int
#define ld long double
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back

using namespace std;
typedef pair<int, int> pii;

#define MOD 998244353

int main() {
    fastIO;
    int n, k;
    cin >> n >> k;

    ll a[n + 1];
    ll pref[n + 1];
    memset(pref, 0, sizeof(pref));
    memset(a, 0, sizeof(a));
    a[1] = pref[1] = 1;
    vector<pii> segments(k);
    for (int i = 0; i < k; i++) {
        int l, r;
        cin >> l >> r;
        segments[i] = {l, r};
    }

    for (int i = 2; i <= n; i++) {
        for (pii seg : segments) {
            int l = max(0, i - seg.second - 1);
            int r = max(0, i - seg.first);
            a[i] += ((pref[r] - pref[l]) + MOD) % MOD;
            a[i] %= MOD;
        }
        pref[i] = ((pref[i - 1] % MOD) + (a[i] % MOD)) % MOD;
    }

    cout << a[n];
}


Measured memory_bytes: 6724
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <set>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <unordered_map>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#define ll long long
#define read(x) scanf("%d",&x);
#define readll(x) cin>>x;
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define MP make_pair
#define PB push_back
#define pii pair<int,int>
#define readN(N,X) for(int i=0;i<N;i++) cin>>X[i];
#define pff pair<double,double>
using namespace std;

void no(){
	cout<<"NO"<<endl;
	exit(0);
}


void yes(){
	cout<<"YES"<<endl;
	exit(0);
}

int N;
string S;
int dp[30][30][30][30];

int solve(int l, int r, char kir, char kan) {
  int KIR = kir - 'a';
  int KAN = kan - 'a';
  if (kir == '?') KIR = 29;
  if (kan == '?') KAN = 29;

  cout<<l<<" "<<r<<" "<<kir<<" "<<kan<<endl;
  if (l > r) {
  	int ret = 0;
    if (kir == '?' && kan == '?') return 1;
    else return 0;
  	return ret;
  }
  if (dp[l][r][KIR][KAN] != -1) return dp[l][r][KIR][KAN];
  int tmp = 0;

  if (kir == '?') {
  	tmp += solve(l + 1, r, S[l], kan);
  } else if (kir == S[r]){
  	tmp += solve(l, r - 1, '?', kan);
  }
  if (kan == '?') {
  	tmp += solve(l + 1, r, kir, S[l]);
  } else if (kan == S[r]) {
  	tmp += solve(l, r - 1, kir, '?');
  }

  dp[l][r][KIR][KAN] = tmp;
  return tmp;
}

map<string, int> poss[19];

int main(){
	ios_base::sync_with_stdio(false);

	cin>>N;
	cin>>S;

	for (int i=0;i<(1<<N);i++) {
		string red = "";
		string blue = "";
		int K=0;
		for (int j=0;j<N;j++){
			if (i & (1<<j)) {K++; red += S[j];}
			else blue += S[j];
		}
		string baca = red + blue;
		//cout<<baca<<" "<<K<<endl;
		poss[K][baca]++;
	}

	long long ret = 0;
	for (int i=0;i<(1<<N);i++) {
		string red = "";
		string blue = "";
		int K=0;
		for (int j=N-1;j>=0;j--){
			if (i & (1<<j)) {K++; red += S[N + j];}
			else blue += S[N + j];
		}
		//cout<<baca<<endl;
		string baca = blue + red;
		ret += poss[N - K][baca];
	}
	cout<<ret<<endl;

	
}

Measured memory_bytes: 70656
#include<algorithm>
using namespace std;

#define MAXN 100000

int AC[MAXN] = {};
int WA[MAXN] = {};

int main()
{
    int ACCount = 0;
    int WACount = 0;
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i = 0; i < m; i++)
    {
        int curNum;
        char first, second;
        scanf("%d %c%c", &curNum, &first, &second);
        if(AC[curNum - 1] != 0)
        {
            continue;
        }
        if(first == 'A')
        {
            AC[curNum - 1] = 1;
            WACount += WA[curNum - 1];
            ACCount += 1;
        }
        else
        {
            WA[curNum - 1] += 1;
        }
    }
    printf("%d %d",ACCount, WACount);
}

Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


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

    int ans = 0;
    rep(i, 4) {
        if (s[i] == '+') ans++;
        else ans--;
    }

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

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<cstring>
using namespace std;
long int n,m;
int a[1000][1000];
void function()
{
    long int i,j,dp[n][m];
    memset(dp,0,sizeof(dp));
    for(i=0;i<n;i++)
    {
        if(a[i][0]==0){dp[i][0]=1;}
        else{break;}
    }
    for(i=0;i<m;i++)
    {
        if(a[0][i]==0){dp[0][i]=1;}
        else{break;}
    }
    for(i=1;i<n;i++)
    {
        for(j=1;j<m;j++)
        {
            if(a[i][j]==0)
            {
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
            }
        }
    }
    printf("%ld",dp[n-1][m-1]%1000000007);
}
int main()
{
    char s[1000];
    long int i,j;
    memset(a,0,sizeof(a));
    scanf("%ld%ld",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%s",s);
        for(j=0;j<m;j++)
        {
            if(s[j]=='#'){a[i][j]=1;}
        }
    }
    function();
    return 0;
}

Measured memory_bytes: 11904
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int a[3];
int dp[105][105][105];

int main(void){
	scanf("%d%d%d",&a[0],&a[1],&a[2]);
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			for(int k=0;k<=100;k++){
				dp[i][j][k]=1000;
			}
		}
	}
	dp[a[0]][a[1]][a[2]]=0;
	for(int i=0;i<100;i++){
		for(int j=0;j<100;j++){
			for(int k=0;k<100;k++){
				dp[i+1][j+1][k]=min(dp[i+1][j+1][k],dp[i][j][k]+1);
				dp[i+1][j][k+1]=min(dp[i+1][j][k+1],dp[i][j][k]+1);
				dp[i][j+1][k+1]=min(dp[i][j+1][k+1],dp[i][j][k]+1);

				dp[i+2][j][k]=min(dp[i+2][j][k],dp[i][j][k]+1);
				dp[i][j][k+2]=min(dp[i][j][k+2],dp[i][j][k]+1);
				dp[i][j+2][k]=min(dp[i][j+2][k],dp[i][j][k]+1);
			}
		}
	}
	int ans=1000;
	for(int i=0;i<100;i++){
		ans=min(ans,dp[i][i][i]);
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
  double n;
  cin >> n;
  for(double i=1.0; i<=3500; i+=1.0){
    for(double j=1.0; j<=3500; j+=1.0){
  	  double w = (n*i*j)/(4*i*j-n*i-n*j);
      if(w == (int)w && w > 0){
        cout << (int)i << " " << (int)j << " " << (int)w;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
priority_queue<int> que;
int a, b, k;
int main()
{
    cin >> a >> b >> k;
    for (int i = 1; i <= min(a, b); i++)
    {
        if (a % i == 0 && b % i == 0)
        {
            que.push(i);
        }
    }
    for (int i = 1; i < k; i++)
    {
        que.pop();
    }
    cout << que.top() << endl;
    return 0;
}

Measured memory_bytes: 256
def gcd(a, b):
    while b: a, b = b, a % b
    return a
def lcm(a, b):
    return b//gcd(a, b)*a

P = 10**9+7
N = int(input())
A = [int(a) for a in input().split()]
L = 1
s = 0
for a in A:
    L = a // gcd(L, a) * L
    s += pow(a, P-2, P)
print(s * L % P)

Measured memory_bytes: 41836