akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(void){
  int i,j,l,r,t=2,n,p,tmp;
  int s[200000],a[200000],b[200000]; 
  scanf("%d",&n);
  for(i=0;i<n;i++){
  	scanf("%d",&a[i]);
	b[i]=a[i];
  }
  s[0]=0;
  s[1]=n-1;
  while(t>0){
  	t-=2;
	i=l=s[t];
	j=r=s[t+1];
	p=a[i];
	while(i<=j){
		while(a[i]<p&&i<r) i++;
		while(a[j]>p&&j>l) j--;
		if(i<=j){
			tmp=a[i];
			a[i]=a[j];
			a[j]=tmp;
			i++;
			j--;
		}
	}
	if(j>l){
		s[t]=l;
		s[t+1]=j;
		t+=2;
	}
	if(r>i){
		s[t]=i;
		s[t+1]=r;
		t+=2;
	}
  }
  for(i=0;i<n;i++){
  	printf("%d\n",b[i]<=a[n/2-1]?a[n/2]:a[n/2-1]);
  }

return 0;
}


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

int main(){
    string s1,t;
    cin >> s1 >> t;
    bool frag1 = false;
    for (int i = s1.size() - t.size(); i >= 0; i--){
        bool frag2 = true;
        for(int j = 0; j < t.size(); j++){
            char a = s1.at(i+j);
            char b = t.at(j);
            if (a != b and a != '?'){
                frag2 = false;
            }
        }
        if (frag2 == true){
            for(int n = 0; n < t.size();n ++){
                s1.at(i+n) = t.at(n);
            }
            frag1 = true;
            break;
        }
    }
    for(int i = 0; i < s1.size(); i ++){
        if(s1.at(i) == '?'){
            s1.at(i) = 'a';
        }
    }
    if(frag1 == true){
        cout << s1 <<  endl;
    }else{
        cout << "UNRESTORABLE" << endl;
    }
}



Measured memory_bytes: 256
#include <cstdio>

const int maxn=200000;

int read()
{
  int x=0,f=1;
  char ch=getchar();
  while((ch<'0')||(ch>'9'))
    {
      if(ch=='-')
        {
          f=-f;
        }
      ch=getchar();
    }
  while((ch>='0')&&(ch<='9'))
    {
      x=x*10+ch-'0';
      ch=getchar();
    }
  return x*f;
}

int n,p[maxn+10],f[maxn+10],ans;

int main()
{
  n=read();
  for(int i=1; i<=n; ++i)
    {
      p[i]=read();
      f[p[i]]=f[p[i]-1]+1;
    }
  for(int i=1; i<=n; ++i)
    {
      if(f[i]>=ans)
        {
          ans=f[i];
        }
    }
  printf("%d\n",n-ans);
  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    int n = bit(N);
    vec S(n); cin >> S;
    Sort(S);
    multiset<int> s;
    REP(i, n - 1) s.insert(S[i]);
    s.insert(-INF);

    vec v({S[n - 1]});
    REP(k, N){
        REP(i, bit(k)){
            auto it = s.lower_bound(v[i]);
            it--;
            if(*it == -INF){
                Out("No");
                return 0;
            }else{
                v.pb(*it);
                s.erase(it);
            }
        }
    }
    Out("Yes");

    return 0;
}


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

using namespace std;

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

/*
 * void init(int n) // n個で初期化
 * int find(int x) // 木の中のxの深さを返す
 * void unite(int x, int y) // xとyを統合
 * bool same(int x, int y) { // xとyが等しいかどうか判定する
 */

class UF {

  vector<int> par; // 親
  vector<int> rank; // 深さ

public:

  void init(int n) { // n個で初期化
    for(int i=0;i<n;i++) {
      par.push_back(i);
      rank.push_back(0);
    }
  }

  int find(int x) { // 木の中のxの深さを返す
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
  }

  void unite(int x, int y) { // xとyを統合する
    x = find(x);
    y = find(y);
    if (x == y) return;

    if(rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }

  bool same(int x, int y) { // xとyが等しいかどうか判定する
    return find(x) == find(y);
  }
};


signed main () {
  int n, m; cin >> n >> m;
  vector<int> p(n);
  REP(i, n) cin >> p[i];
  vector<pair<int, int> > a(m);
  REP(i, m) cin >> a[i].first >> a[i].second;

  UF u;
  u.init(n);
  REP(i, m) u.unite(a[i].first, a[i].second);

  int count = 0;
  REP(i, n) if(u.same(i+1, p[i]) || i+1 == p[i]) count++;

  cout << count << endl;
}


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


using namespace std;

int main() {
	vector<char> c(5);
	int ans = 0;
	for (int i = 0; i < 4; i++) {
		cin >> c[i];
		if (c[i] == '+') ans++;
		if (c[i] == '-') ans--;
	}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    for(int i=0;i<n;i++)
    cin>>a[i];
    vector<int>dp(n);
    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        int x=INT_MAX;
        for(int j=i-1;j>=max(0,i-k);j--)
        {
            x=min(x,dp[j]+abs(a[i]-a[j]));
        }
        dp[i] = x;
    }
    cout<<dp[n-1]<<endl;
}

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

int main() {
	long long h, cnt = 1, ans = 1;
	cin >> h;
	while (h > 1) {
		h /= 2;
		cnt *= 2;
		ans += cnt;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
class Edge:
    def __init__(self, s, t, w):
        self.s = s
        self.t = t
        self.w = w

def union(x, y):
    x = findSet(x)
    y = findSet(y)
    link(x, y)


def link(x, y):
    if r[x] > r[y]:
        p[y] = x

    else:
        p[x] = y
        if r[x] == r[y]: r[y] = r[y] + 1


def findSet(x):
    if x != p[x]:
        p[x] = findSet(p[x])

    return p[x]


def same(x, y):
    return findSet(x) == findSet(y)



if __name__ == '__main__':
    p, r = [], []

    n_V, n_E = map(int, input().split())

    for i in range(n_V):
        p.append(i)
        r.append(0)

    Es = []
    for _ in range(n_E):
        s, t, w = map(int, input().split())
        Es.append(Edge(s, t, w))

    Es.sort(key=lambda e : e.w)

    sum_w = 0
    for e in Es:
        if not same(e.s, e.t):
            union(e.s, e.t)
            sum_w += e.w

    print(sum_w)



Measured memory_bytes: 34240
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<bitset>
#include<random>
#include<cstdint>
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
#define shosu setprecision(17)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<char,P> Q;
ll longinf=(1ll<<60);
ll inf=1ll<<29;
int main(){
      int N;
      cin>>N;
      int P[N];
      rep0(i,N) cin>>P[i];
      sort(P,P+N);
      int ans=0;
      rep0(i,N){
            if(i==(N-1))ans+=(P[i]/2);
            else ans+=P[i];
      }
      cout<<ans<<endl;
      return 0;
}

Measured memory_bytes: 256
#include <cstdio> 
int N; 
int main() { 
  scanf("%d",&N); 
  int res=N; for(int i=0;i<=N;i++) { int cc=0; int t=i; while(t>0)cc+=t%6,t/=6; t=N-i; while(t>0)cc+=t%9,t/=9; if(res>cc)res=cc; } printf("%d\n",res); }


Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    AB = [list(map(int, input().split())) for _ in range(n)][::-1]

    res = 0
    for i in range(n):
        a, b = AB[i]
        push = ((a + res + b - 1) // b) * b - a
        res = push
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 28148
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
int main() {
    ll a,b,c;cin >> a >> b >> c;
    if(a*b*c%2==0) {
        cout << 0 << endl;
    }
    else cout << min({a*b,b*c,c*a}) << endl;
    return 0;
    
}

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

ll a, b, x;

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

    if (a == 0) {
        cout << b/x + 1 << endl;
    }
    else {
        cout << b/x - (a-1)/x << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,p[100010],a[100010];
P fo[100010]={P(-1,-1)},ba[100010]={P(-1,-1)};

void solve(){
    cin >> n;
    set<int> s;
    rep(i,n){
        cin >> p[i];
        a[p[i]-1]=i;
        fo[i]=P(n,n);
        ba[i]=P(-1,-1);
    }
    rep(i,n){
        s.insert(p[i]-1);
        auto itr=s.begin();
        while(*itr<p[i]-1){
            //cout << p[i]-1 << " " << *itr << endl;
            //cout << fo[*itr].first << " " << fo[*itr].second << endl;
            if (fo[*itr].first==n){
                fo[*itr].first=i;
                //cout << i << endl;
                itr++;
            }
            else{
                fo[*itr].second=i;
                itr=s.erase(itr);
            }
        }
    }

    s={};

    per(i,n){
        s.insert(p[i]-1);
        auto itr=s.begin();
        while(*itr<p[i]-1){
            //cout << p[i]-1 << " " << *itr << endl;
            //cout << ba[*itr].first << " " << ba[*itr].second << endl;
            if (ba[*itr].first==-1){
                ba[*itr].first=i;
                //cout << i << endl;
                itr++;
            }
            else{
                ba[*itr].second=i;
                itr=s.erase(itr);
            }
        }
    }

    ll ans=0;

    rep(i,n){
        
        if (fo[i].first!=n){
            ans+=(ll)(i+1)*(ll)(fo[i].second-fo[i].first)*(ll)(a[i]-ba[i].first);
        }
        if (ba[i].first!=-1){
            ans+=(ll)(i+1)*(ll)(ba[i].first-ba[i].second)*(ll)(fo[i].first-a[i]);
        }
        
    }

    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

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

// for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

// abbreviati
#define PB(v) push_back(v)
#define MP(A,B) make_pair(A,B)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

// constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

// adjacency list
vector<int> to[100005];

// Graph
using Graph = vector<vector<int>>;

// Grid
int H,W;
vector<vector<int>> field;

// 4方向への移動ベクトル
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int x; cin >> x;
    if(x==0) cout << 1 ENDL;
    else cout << 0 ENDL;
    
    return 0;
}

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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  double a, b, h, m; cin >> a >> b >> h >> m;

  double ma = double(360)/60*m;
  double ha = double(360)/(12*60) * (60*h+m);

  double ang = min(360-abs(ha-ma), abs(ha-ma));
  
  ang = ang / double(180) * M_PI;

  double ans = sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(ang));

  printf("%.10lf\n", ans);
}


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

ll N, M;

void solve()
{
	if(N >= M / 2){
		cout << M / 2 << endl;
	}else{
		ll ans = N;
		M -= 2*N;
		ans += M/4;
		cout << ans << endl;
	}
}

int main()
{
	cin >> N >> M;
	solve();
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(1, n+1):
    if str(i)[-1] == '0':
        continue
    d[int(str(i)[0] + str(i)[-1])] += 1
ans = 0
for i in range(11, 100):
    ans += d[i] * d[int(str(i)[1] + str(i)[0])]
print(ans)

Measured memory_bytes: 9240
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i = m; i < n; i++)
#define printhello std::cout << "hello" << endl;
using ll=long long;
using namespace std;

int main(){
    char c;
    cin >> c;
    if((int)c <= 90){
        cout << 'A';
    }else{
        cout << 'a';
    }
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
ll n,len=1;
string s="";

signed main(){
	cin>>n;
/*	while(n){
		n--;
		s+=char('a'+n%26);
		n/=26;
	}*/
/*	while(n>pow(26,len)){
		n-=pow(26,len);
		len++;
	}n--;
	for(int i=0;i<len;i++){
		s+=char('a'+n%26);
		n/=26;
	}*/
	n--;ll p=26,d=1;
	while(n>=p){
		n-=p;
		d++;
		p*=26;
	} 
	while(d--){
		s+=char('a'+n%26);
		n/=26;
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int res = n;
    for (int i = 1; i < n; i++) {
        if (s[i] != s[i - 1]) {
            res = min(res, max(i, n - i));
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,a,b,c;
ll l[10];
ll mini=1e18;
ll rec(string s)
{
    if(s.size()==n)
    {
        ll a1=0,b1=0,c1=0;
        ll cost=0;
        for(ll i=0;i<s.length();i++)
        {
            if(s[i]=='1')
            {
                if(a1!=0)
                {
                    cost+=10;
                }
                a1+=l[i+1];
            }
            else if(s[i]=='2')
            {
                if(b1!=0)
                {
                    cost+=10;
                }
                b1+=l[i+1];
            }
            else if(s[i]=='3')
            {
                if(c1!=0)
                {
                    cost+=10;
                }
                c1+=l[i+1];
            }
        }
        if(a1!=0 && b1!=0 && c1!=0)
        {
            cost+=abs(a1-a)+abs(b1-b)+abs(c1-c);
            mini=min(mini,cost);
        }
        return 0;
    }
    for(ll i=1;i<=4;i++)
    {
        char ch='0'+i;
        rec(s+ch);
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>a>>b>>c;
    for(ll i=1;i<=n;i++)
    {
        cin>>l[i];
    }
    string s;
    rec(s);
    cout<<mini<<endl;
}

Measured memory_bytes: 256
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
ll pw[2][1000005], pr[2] = {37, 41};
string str[200005];
vector<ll>rui[2][200005];
int n;
bool cmp(const string &a, const string &b){
	return a.size() > b.size();
}
bool ex[26][200005];

int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	rep(i, n){
		cin >> str[i];
		reverse(str[i].begin(), str[i].end());
	}
	sort(str, str+n, cmp);
	int mxlen = str[0].size();
	rep(i, 2){
		pw[i][0] = 1;
		for(int j=1;j<1000005;j++) pw[i][j] = pw[i][j-1] * pr[i] % mod;
	}
	rep(i, n){
		ll R[2] = {};
		rep(j, 2) rui[j][i].resize(str[i].size() + 1, 0);
		rep(j, str[i].size()){
			rep(k, 2) {
				R[k] += pw[k][j+1] * (str[i][j]-'a'+1) % mod;
				if(R[k] >= mod) R[k] -= mod;
				rui[k][i][j+1] = R[k];
			}
		}
	}
	ll ans = 0;
	for(int i=mxlen-1;i>=0;i--){
		vector<ll>za;
		rep(j, n){
			if(str[j].size() < i+1) break;
			za.pb(rui[0][j][i] * mod + rui[1][j][i]);
		}
		SORT(za); ERASE(za);
		vector<int>M[26];
		rep(i, 26) M[i].resize(za.size(), 0);
		rep(j, n){
			if(str[j].size() < i+1) break;
			int pos = POSL(za, rui[0][j][i] * mod + rui[1][j][i]);
			if(str[j].size() == i+1){
				ans += M[str[j][i]-'a'][pos];
            }
			ex[str[j][i]-'a'][j] = 1;
			rep(k, 26){
				if(ex[k][j]) M[k][pos] ++;
			}
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 72672
import scala.io.StdIn._

object Main extends App {
  type Cost = Int
  type Boxes = Int
  val Array(n, m) = readLine.split(" ").map(_.toInt)
  val boxPatterns = 1 << n
  val allKeys: Seq[(Cost, Boxes)] = (1 to m).map { i =>
    val Array(a, b) = readLine.split(" ").map(_.toInt)
    (a, readLine.split(" ").map(_.toInt).foldLeft(0){(z, bb) => z + (1 << (bb - 1))})
  }

  val Impossible = -1
  def dp(keys: List[(Cost, Boxes)], prev: Array[Int]): Int = {
    keys match {
      case Nil => prev(boxPatterns - 1)
      case (cost, boxes) :: ks =>
        val cur = new Array[Int](boxPatterns)
        (0 until boxPatterns).foreach { b =>
          cur(b) =
            if ((b & boxes) == 0) prev(b)
            else {
              (prev(b), prev(b - (b & boxes))) match {
                case (Impossible, Impossible) =>
                  if ((b | boxes) == boxes) cost
                  else Impossible
                case (Impossible, y) => y + cost
                case (x, Impossible) => Math.min(x, cost)
                case (x, y) => Math.min(x, y + cost)
              }
            }
        }
        dp(ks, cur)
    }
  }

  println(dp(allKeys.toList, Array.fill(boxPatterns)(Impossible)))
}

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

    reverse(s.begin(), s.end());

    for (int i = 0; i < 4; i++) reverse(divide[i].begin(), divide[i].end());

    bool can = true;

    for (int i = 0; i < s.size();)  {
        bool can2 = false;
        for (int j = 0; j < 4; j++) {
            string d = divide[j];
            if (s.substr(i, d.size()) == d) {
                can2 = true;
                i += d.size();
            }
        }

        if (!can2) {
            can = false;
            break;
        }
    }

    if (can) cout << "YES" << endl;
    else     cout << "NO" << endl;
}

Measured memory_bytes: 3252
/**
 * Created by hiramekun at 17:22 on 2019-10-16.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n;
    cin >> n;
    vl a(n);
    cin >> a;

    vl times(n);
    bool invalid = (a[0] != 0);
    rep(i, n - 1) {
        if (a[i + 1] - a[i] > 1) invalid = true;
    }
    if (invalid) cout << -1 << '\n';
    else {
        rep(i, n) times[i - a[i]] = a[i];
        cout << accumulate(all(times), 0LL) << '\n';
    }
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 3456
icase=0
if icase==0:
    from itertools import permutations, combinations,combinations_with_replacement,product
    a=[0]*5
    for i in range(5):
        a[i]=int(input())
    tmin=130*5+1
    alist=list(permutations(a))
    for ai in alist:
        t=ai[0]
        t=int((t-1)//10+1)*10+ai[1]
        t=int((t-1)//10+1)*10+ai[2]
        t=int((t-1)//10+1)*10+ai[3]
        t=int((t-1)//10+1)*10+ai[4]
        tmin=min(t,tmin)
    print(tmin)        

Measured memory_bytes: 3064
#include <stdio.h>
 
int main()
{
    for(int i = 0; i < 10000; ++i){
        int Input = 0;
        scanf("%d", &Input);
        if(Input == 0) return 0;
        printf("Case %d: %d\n", 1 + i, Input);
        fflush(stdout);
    }
    return 0;
}


Measured memory_bytes: 1952
/* 
    Author : Jeff Ahn
    Sun 02 Aug 2020 08:56:58 PM PDT 
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define uint unsigned long long
#define endl '\n'

int n, k;
const int mn = 2e5+1;
int a[mn];
signed main() {
  fastio;
  cin >> n >> k;
  int r = 1e9+10;
  rep(i,n) {
    int ai;
    cin >> ai;
    a[i] = ai;
    r = max(r, ai);
  }

  int l = 1;
  while (l <= r) {
    int mid = l + (r - l) / 2;
    int cuts = 0;
    rep(i,n) {
      int ai = a[i];
      cuts += (ai - 1) / mid;
    }
    if (cuts <= k) {
      r = mid - 1;
    }
    else l = mid + 1;
  }
  cout << l << endl;
}


Measured memory_bytes: 5192
import sys
readline = sys.stdin.buffer.readline

def main():
    A, B, C, X, Y = map(int, readline().rstrip().split())
    if A + B <= 2 * C:
        print(X * A + Y * B)
        return
    
    m = min(X, Y)
    ans = m * 2 * C
    X -= m
    Y -= m
    ans += min(X * A + Y * B, max(X, Y) * 2 * C)
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define SORT(a) sort(a.begin(),a.end())
 
int main() {
	
	//string ans="";
	//vector<int> c(30,0);
	//cout << a << b << endl;
	
	
	int ans=0;
	
	int a,b;
	
	cin >> a >> b;
	
	//vector<int> a(n);
	
	if(a>9 || b>9){
		ans=-1;
		cout << ans << endl;
		return 0;
	} 
	
	ans=a*b;
	
    cout << ans << endl;
    
    return 0;

}

Measured memory_bytes: 256
while True:
    m,f,r=map(int,input().split())
    if m==f==r and m==-1:
        break
    if m==-1 or f==-1:
        print('F')
    elif m+f>=80:
        print('A')
    elif m+f>=65:
        print('B')
    elif m+f>=50:
        print('C')
    elif m+f>=30:
        if r>=50:
            print('C')
        else:
            print('D')
    else:
        print('F')


Measured memory_bytes: 5592
class EndLoop(Exception):
    pass


def solve():
    N = int(input())
    try:
        for h in range(1, 3501):
            for n in range(1, 3501):
                if 4 * h * n - n * N - h * N > 0:
                    if (h * n * N) % (4 * h * n - n * N - h * N) == 0:
                        w = int((h * n * N) / (4 * h * n - n * N - h * N))
                        print(h, n, int(w))
                        raise EndLoop
    except:
        pass


solve()

Measured memory_bytes: 3064
///not today

#include<bits/stdc++.h>
using namespace std;

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair< int, pair<int, int> >
#define plpll pair< ll, pair<ll, ll> >

using namespace std;

int32_t main(){
      int a, b, c;
      cin >>a >>b >>c;
      a -= b;
      cout <<max(c - a, (ll)0) <<endl;
      return false;
}


Measured memory_bytes: 256
s=input()
l=['k','e','y','e','n','c','e']
flag=False
cnt=0
for i in range(7):
    if flag==False and s[i]==l[i]:
        cnt+=1
    else:
        flag=True
        if s[-(7-i)]==l[i]:
            cnt+=1
if cnt==7:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

using namespace std;
using ll=long long;
using Vec = vector<ll>;
using P = pair<ll, ll>;
using VecP = vector<P>;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)

//static const ll MOD = 1000000007;
//static const ll INF = 1000000000000000000;
//#define PI 3.14159265358979323846
//
//int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
//
//int findSumDigits(int s) {
//    int num = 0;
//    int temp = 0;
//    while (s) {
//        temp = s % 10;
//        num += temp;
//        s = s / 10;
//    }
//    return num;
//}
//
//int countDivisorNum(int n) {
//    int count = 0;
//    for (int i = 1; i <= n; i++) {
//        if (n % i == 0) {
//            count++;
//        }
//    }
//    return count;
//}

int main() {
    ll x;
    cin >> x;

    if(x>=30){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }




    return 0;
}

Measured memory_bytes: 3620
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

#define I 100000
#define J 100

int M[I][J], group[I], cnt[I], id = 1;
void setID(int);

int main(void){
	int n, m, q, i, a, b;
	
	scanf("%d%d", &n, &m);
	for(i = 0; i < m; i++){
		scanf("%d %d", &a, &b);
		M[a][cnt[a]++] = b;
		M[b][cnt[b]++] = a;
	}

	for(i = 0; i < n; i++){
		if(group[i] == 0){
			setID(i);
			id++;
		}
	}

	scanf("%d", &q);
    for(i = 0; i < q; i++){
		scanf("%d%d", &a, &b);
		if(group[a] == group[b]){
			puts("yes");
		}else{
			puts("no");
		}
	}

	return 0;
}

void setID(int x){
	int i;

	group[x] = id;
	for(i = 0; i < cnt[x]; i++){
		if(group[M[x][i]] == 0){
			setID(M[x][i]);
		}
	} 
}


Measured memory_bytes: 44592
from sys import stdin
import string
import heapq
h,w = map(int,stdin.readline().rstrip().split())
s = ""
for i in range(h):
    s += stdin.readline().rstrip()
task_4 = (h//2)*(w//2)
task_2 = (h%2)*(w//2)+(w%2)*(h//2)
task_1 = (h%2)*(w%2)
alpha = string.ascii_lowercase
li = [-s.count(i) for i in alpha if s.count(i) != 0]
heapq.heapify(li)
for i in range(task_4):
    if li[0] <= -4:
        k = heapq.heappop(li)
        if k+4 == 0:
            continue
        else:
            heapq.heappush(li,k+4)
    else:
        print("No")
        exit()
for i in range(task_2):
    if li[0] <= -2:
        k = heapq.heappop(li)
        if k+2 == 0:
            continue
        else:
            heapq.heappush(li,k+2)
    else:
        print("No")
        exit()
for i in range(task_1):
    if li[0] <= -1:
        k = heapq.heappop(li)
        if k+1 == 0:
            continue
        else:
            heapq.heappush(li,k+1)
    else:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3772
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    static int N;
    static int M;
    static int[][] graph;
    static int INF = Integer.MAX_VALUE;

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        M = scanner.nextInt();

        graph = new int[N][N];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                graph[i][j] = INF;
            }
        }

        for (int i = 0; i < M; i++) {
            int from = scanner.nextInt() - 1;
            int to = scanner.nextInt() - 1;
            graph[from][to] = to;
            graph[to][from] = from;
        }

        scanner.close();

        HashSet<Integer> passed = new HashSet<>();
        passed.add(0);
        System.out.println(dfs(0, passed));
    }

    private static int dfs(int i, HashSet<Integer> passedVertexes) {
        if (N <= passedVertexes.size()) return 1;

        int ret = 0;
        for (int to: graph[i]) {
            if (to != INF && !passedVertexes.contains(to)) {
                passedVertexes.add(to);
                ret += dfs(to, passedVertexes);
                passedVertexes.remove(to);
            }
        }

        return ret;
    }
}

Measured memory_bytes: 21844
/**
 *    author:  tourist
 *    created: 12.12.2019 19:05:50       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  const int MAX = 301;
  vector<int> cost(MAX);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    cost[x] = y;
  }
  int ans = 0;
  vector<bool> is_prime(MAX, true);
  for (int i = 2; i < MAX; i++) {
    if (is_prime[i]) {
      for (int j = i + i; j < MAX; j += i) {
        is_prime[j] = false;
      }
    }
  }
  function<void(int, long long)> Dfs = [&](int v, long long num) {
    if (v * v > MAX) {
      int cur = 0;
      vector<int> delta(MAX);
      for (int i = 2; i < MAX; i++) {
        int z = i / __gcd(i, (int) (num % i));
        if (z == 1) {
          cur += cost[i];
        } else {
          if (z >= v && is_prime[z]) {
            delta[z] += cost[i];
          }
        }
      }
      for (int i = 2; i < MAX; i++) {
        cur += max(delta[i], 0);
      }
      ans = max(ans, cur);
      return;
    }
    if (!is_prime[v]) {
      Dfs(v + 1, num);
      return;
    }
    int c = 1;
    while (c <= MAX) {
      Dfs(v + 1, num * c);
      c *= v;
    }
  };
  Dfs(2, 1);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 384
using System;

class Program
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    int[] items = new int[N];
    int sum = 0;
    for(int i = 0; i < N; i++)
    {
      items[i] = int.Parse(Console.ReadLine());
    }
    Array.Sort(items);
    Array.Reverse(items);
    
    for(int i = 0; i < N; i++)
    {
      if(i == 0) items[i] /= 2;
      sum += items[i];
    }
    Console.WriteLine(sum);
  }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
#define debug(x) cerr << x << endl
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1<<30;
const ll LINF = 1LL<<61;
const ll MOD = 1000000007;

int main()
{
    int s;
    cin >> s;
    vector<ll> dp(s+1);
    dp[0] = 1;
    rep(i,s)
    {
        for(int j = i+3; j <= s; j++)
            dp[j] = (dp[j] + dp[i]) % MOD;
    }
    cout << dp[s] % MOD << endl;
}


Measured memory_bytes: 3652
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;

set<int>s;
long long int a[100010];
long long int b[100010];

int main () {

int n;
cin>>n;
for (int i=0; i<n; i++) {
    cin>>a[i];
}
sort(a,a+n);
int m1=0,m2=0;
int koji=0;
for (int i=n-1; i>0; i--) {
    if (a[i]==a[i-1]) {
        b[koji]=a[i];
        koji++;
        i--;
    }
}
long long int maxi=0;
for (int i=0; i<koji; i++) {
    for (int j=i+1; j<koji; j++) {
        if (b[i]*b[j]>maxi) {maxi=b[i]*b[j];}
    }
}
cout<<maxi;

return 0;
}

Measured memory_bytes: 1408
#pragma GCC optimize("-Ofast")

#include <bits/stdc++.h>

#define ll long long

#define TEST

using namespace std;

/* Dijkstra法 */
template <typename T>
vector<T> dijkstra(int s,vector<vector<pair<int, T>>> & G){  
  const T INF = numeric_limits<T>::max();    
  using P = pair<T, int>;
  int n=G.size();
  vector<T> d(n,INF);
  vector<int> b(n,-1);
  priority_queue<P,vector<P>,greater<P> > q;
  d[s]=0;
  q.emplace(d[s],s);
  while(!q.empty()){
    P p=q.top();q.pop();
    int v=p.second;
    if(d[v]<p.first) continue;
    for(auto& e:G[v]){
      int u=e.first;
      T c=e.second;
      if(d[u]>d[v]+c){
        d[u]=d[v]+c;
        b[u]=v;
        q.emplace(d[u],u);
      }
    }
  }
  return d;
}

signed main(){
    int n,m;
    cin >> n >> m;
    /*
    グラフを構築する. ただし、
        頂点i -> 3 * i ～　3 * i + 2
    と一つの頂点を3つに分ける.
    それぞれ ぱ　けん1 けん2 でたどり着いたことを区別する.
     */
    vector<vector<pair<int,int>>> g(3 * n); // グラフ
    for (int i = 0;i < m;++i){
        int u,v;
        cin >> u >> v;
        u--; v--; // 頂点は0-indexedで管理
        for (int j = 0;j < 3;++j)
                g[3*u+j].emplace_back(3*v+(j+1)%3,1);
    }
    /*
    Dijkstra法で答えを求める.
     */
    int s,t;
    cin >> s >> t;
    s = (s - 1) * 3;
    t = (t - 1) * 3;
    ll ans = dijkstra(s,g)[t];
    if (ans == numeric_limits<int>::max()){ // 到達不能
        cout << -1 << endl;
    } 
    else{ // 到達可能
        cout << ans / 3 << endl;
    }
    return 0;
}

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

#ifndef ONLINE_JUDGE
	#define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y;
#else
	#define W(x, y)
#endif


#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define vl vector<ll>
#define vll vector<pll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi acos(-1)
#define ld long double
#define prime 1000000007

using namespace std;

#define INF 1000000000

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	ll n, m;
	cin >> n >> m;
	vl vet(m);
	for(auto&p: vet){
		cin >> p;
	}
	sort(vet.begin(), vet.end());
	if(m == 1){
		cout << 0 << endl;
	} else{
		vl vet2;
		ll sum = vet.back() - vet.front();
		for(int i = 1; i < m; ++i){
			vet2.push_back(vet[i]-vet[i-1]);
		}
		sort(vet2.rbegin(), vet2.rend());
		for(int i = 0; i < min(n-1, m-1); ++i){
			sum -= vet2[i];
		}
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 2168
def read():
    N = int(input().strip())
    return N,

def solve(N):
    table = [[0 for i in range(0, 10)] for j in range(0, 10)]
    for i in range(1, N+1):
        strn = str(i)
        head, tail = int(strn[0]), int(strn[-1])
        table[head][tail] += 1
    count = 0
    for i in range(1, N+1):
        strn = str(i)
        head, tail = int(strn[0]), int(strn[-1])
        count += table[tail][head]
    return count


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    string s;
    cin >> s;

    cout << string(s.size(), 'x');
    nl;

    return 0;
}




Measured memory_bytes: 3652
import java.util.*
import java.math.*
import java.lang.Math.*

private val readString: ()->String = {readLine()!!}
private val readInt: ()->Int = { readLine()!!.toInt() }
private val readLong: ()->Long = { readLine()!!.toLong() }
private val readListInt: ()->List<Int> = { readLine()!!.split(' ').map(String::toInt) }
private val readListLong: ()->List<Long> = { readLine()!!.split(' ').map(String::toLong) }
private val errPrintln: (String)->Unit = { msg -> System.err.println(msg) }
private val MOD = 1e9.toLong()+7
private val INF = Int.MAX_VALUE/2
private val LINF = Long.MAX_VALUE/2


class CumSum(val A: List<Long>) {
    private var csum: LongArray = LongArray(A.size + 1)
    init {
        for (i in 1..A.size) {
            this.csum[i] = this.csum[i-1] + A[i-1]
        }
    }
    fun sum(L: Int, R: Int): Long {
        val r = min(R, A.size);
        val l = max(L, 0)
        if (l >= r) return 0
        return this.csum[r] - this.csum[l];
    }
}


fun solveB(N: Int, K: Int, A: List<Long>): Long {
    val plus = A.map {if (it >= 0) it else 0}
    val minus = A.map { if (it < 0) it else 0 }

    val plSum = CumSum(plus)
    val miSum = CumSum(minus)

    val Max = plus.sum()
    var res = 0L
    for (left in 0 .. N-K) {
            res = max(res, Max - plSum.sum(left, left+K))
            res = max(res, Max + miSum.sum(left, left+K))
    }

    return res
}


fun main(args: Array<String>) {
    val (N,K) = readListInt()
    var A = readListLong()

    val ans = solveB(N, K, A.toList())

    println(ans)
}


Measured memory_bytes: 73792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];

    ll m = A[0];
    ll ans = -INF;
    repe(i, 1, N){
        chmax(ans, A[i] - m);
        chmin(m, A[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 4408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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 ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

int main(){
    int k; cin>>k;
    queue<ll> que;
    for (int i = 1; i <=9; i++) que.push(i);
    int cnt=0;
    while(cnt<=k-2){
        if(que.front()%10 == 0){
            que.push(que.front()*10 + que.front()%10);
            que.push(que.front()*10 + que.front()%10+1);
            que.pop();
            cnt++;
            continue;
        }
        if(que.front()%10 == 9){
            que.push(que.front()*10 + que.front()%10-1);
            que.push(que.front()*10 + que.front()%10);
            que.pop();
            cnt++;
            continue;
        }
        que.push(que.front()*10 + que.front()%10-1);
        que.push(que.front()*10 + que.front()%10);
        que.push(que.front()*10 + que.front()%10+1);
        que.pop();
        cnt++;
    }
    cout<<que.front()<<endl;
}

Measured memory_bytes: 1792
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

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;
#define EPS 1e-9

int main() {
	int n;
	cin >> n;
	vector<int> d(n);
	rep(i, n) cin >> d[i];
	sort(d.begin(), d.end());
	int target = n / 2;
	if (d[target] == d[target - 1]) cout << 0 << endl;
	else cout << d[target] - d[target - 1] << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, m; cin >> n >> m;
    string s, t; cin >> s >> t;
    ll diff = gcd(n, m);
    ll dn = n / diff, dm = m / diff;
    int idx = 0;
    while (dn * idx < n && dm * idx < m) {
        if (s[dn * idx] != t[dm * idx]) {
            cout << -1 << endl;
            return 0;
        }
        idx++;
    }
    cout << n * m / diff << endl;
    return 0;
}

Measured memory_bytes: 640