akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//約数列挙
//昇順
//#include <vector>
//#include <cmath>
std::vector<long long> div(long long n) {
  std::vector<long long> v(1, 1);
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) v.push_back(i);
  }
  if (sqrt(n) == (long long)sqrt(n)) {
    for (long long i = v.size() - 2; i >= 0; i--) v.push_back(n / v[i]);
  }
  else {
    for (long long i = v.size() - 1; i >= 0; i--) v.push_back(n / v[i]);
  }
  return v;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  vll v = div(n - 1);
  for (ll i = 0; i < v.size(); i++) {
    if (n % v[i] > 0) ans++;
  }
  vll w = div(n);
  for (ll i = 1; i < w.size(); i++) {
    ll m = n;
    while(m % w[i] == 0) m /= w[i];
    if (m % w[i] == 1) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define show(x) cout << #x << " = " << x << endl;

int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<ll>w(n),d(n);
    rep(i,n){
        cin >> w[i] >> d[i];
    }
    ll low = 0;
    ll high = 1999999999000000000LL;
    while(high-low > 1){
        ll med = (low+high)/2;
        ll c = 0;
        rep(i,n){
            if(med-w[i]>=0)c += (med-w[i])/d[i] + 1;
        }
        if(c >= k){
            high = med;
        }else{
            low = med;
        }
    }
    cout << high << endl;
}

Measured memory_bytes: 1792
MOD = 10**9+7

n = int(input())
a = list(map(int,input().split()))

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

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

LCM = 1
for v in a:
    LCM = lcm(LCM,v)

LCM %= MOD

def pow(a,n,mod):
    ret = 1
    tmp = a
    while n:
        if n & 1:
            ret *= tmp
            ret %= mod
        tmp *= tmp
        tmp %= mod
        n >>= 1
    return ret

def inv(a,mod):
    return pow(a,mod-2,mod)


ans = 0
for v in a:
    ans += LCM * inv(v,MOD)
    ans %= MOD;

print(ans)


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

int main(){
  int N;
  cin>>N;
  int work = N%10;
  
  if(work==3){
    cout << "bon" << endl;
    return 0;
  }else if(work==0||work==1||work==6||work==8){
    cout << "pon" << endl;
    return 0;
  }else{
    cout << "hon" << endl;
    return 0;
  }
}

Measured memory_bytes: 3636
#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;

// ?????¬???????????¬??????
#define REP(i,n) for(int i=0; i<(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), c.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<double> vd;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<long, long> pil;

// ??°?????????????????¬??????
typedef int Weight;

struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) {}
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight :
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;


int main() {
  int x;
  scanf("%d", &x);
  printf("%d\n", x*x*x);
  return 0;
}

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

const int MAX_N = 20;
const int MAX_Q = 200;

int a[MAX_N];
int n, q, x;

bool func(int sum, int i) {
	if (sum == x) return true;
	if (i == n) return false;
	return func(sum, i + 1) || func(sum + a[i], i + 1);
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> x;
		cout << (func(0, 0)?"yes":"no") << endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;

// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;

int main ()
{
  prep();
  long long n, a, b;
  cin >> n >> a >> b;
  long long arr[n];
  for (int i=0; i<n; i++){
      cin >> arr[i];
  }
  long long res = 0;
  for (int i=1; i<n; i++){
      long long diff = arr[i]-arr[i-1];
      res += min(diff*a, b);
  }
  cout << res;
  return 0; 
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
int main(void){
    int N;
    int *p,*q;
    scanf("%d", &N);
    p = (int *)calloc(N, sizeof(int));
    q = (int *)calloc(N, sizeof(int));
    for(int i=0;i < N;i++)
        scanf("%d", &p[i]);
    for(int i=0;i<N;i++)
        q[i] = i+1;
    int count = 0;
    for(int i=0; i<N;i++){
        if(p[i]!=q[i])
            count +=1;
    }
    if(count<=2)
        printf("YES\n");
    else
    {
        printf("NO\n");
    }
    return 0;
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
//gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builitin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique(x).begin(),(x).end()),(x).end());
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
#define F first
#define S second
#define cauto (const auto &)
template <class A, class B>
using pii = vector<pair<A, B>>;
template <class T> //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T> //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <class T>
bool chmax(T &a, const T &b) //最大値更新 返り値はbool
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) //最小値更新 返り値はbool
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr long long mod1 = 1e9 + 7;
constexpr long long mod2 = 998244353;
//} END
using P = pair<int, int>; //firstは最短距離,secondは頂点の番号

vector<vector<P>> graph;
vector<int> min_cost;

void Dijkstra(int s)
{
    //昇順でfirstを小さい方から取る
    priority_queue<P, vector<P>, greater<P>> que;
    min_cost[s] = 0;
    que.emplace(0, s);

    while (!que.empty())
    {
        int now_cost, now_node;
        tie(now_cost, now_node) = que.top();
        que.pop();

        if (min_cost[now_node] < now_cost) //queの値より新しいcostの方が小さいとき見ない
        {
            continue;
        }

        for (int i = 0; i < graph[now_node].size(); ++i)
        {
            int next_node, next_cost;
            tie(next_node, next_cost) = graph[now_node][i];

            if (chmin(min_cost[next_node], min_cost[now_node] + next_cost)) //最短経路の更新
            {
                que.emplace(min_cost[next_node], next_node);
            }
        }
    }
}

signed main(void)
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int V, E, r;
    cin >> V >> E >> r;

    min_cost.resize(V + 1, INF);
    graph.resize(V + 1);

    for (int i = 0; i < E; ++i)
    {
        int a, b, c;
        cin >> a >> b >> c;
        graph[a].emplace_back(b, c); //グラフの構築
        //graph[b].emplace_back(a, c);
    }

    Dijkstra(r);

    rep(i, 0, V)
    {
        if (min_cost[i] == INF)
        {
            cout << "INF\n";
        }
        else
        {
            cout << min_cost[i] << '\n';
        }
    }

    return 0;
}


Measured memory_bytes: 19320
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define N 100000
#define INF 10000000000
using namespace std;

typedef long long ll;

int main()
{
    int n;
    ll a[N] = {};
    cin >> n;
    FOR(i,0,n)
        cin >> a[i];
    int idx;
    do
    {
        sort(a,a+n);
        idx = upper_bound(a,a+n,0) -a ;
        if(idx == n-1)
            break;
        mFOR(i,n-1,idx)
        {
            if(a[i]==0)
                break;
            a[i] %= a[idx];
        }
        // cout << a[idx] << "\n";
    }while(a[idx]>1);
    cout << a[idx] << "\n";
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        String a=sc.next();
        String b=sc.next();
        String c=sc.next();
        System.out.println(b.charAt(0) == a.charAt(a.length() - 1) &&
                           c.charAt(0) == b.charAt(b.length() - 1) ? "YES":"NO");
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  char x, y;
  cin >> x >> y;
  if (x < y)
    cout << "<" << endl;
  else if (x > y)
    cout << ">" << endl;
  else
    cout << "=" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
long long INF = 1e18;
const int MOD = 1e9 + 7;
 
using namespace std;
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll ar[5]={};
    ll ans=0;
    cin >> n;
    vector<string> vi(n);
    REP(i,n) cin >> vi[i];
 
    REP(i,n){
        if(vi[i][0] == 'M') ++ar[0];
        else if(vi[i][0] == 'A') ++ar[1];
        else if(vi[i][0] == 'R') ++ar[2];
        else if(vi[i][0] == 'C') ++ar[3];
        else if(vi[i][0] == 'H') ++ar[4];
    }
 
    REP(i,5){
        FOR(j,i+1,5){
            FOR(k,j+1,5){
                ans += ar[i]*ar[j]*ar[k];
            }
        }
    }
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define S second
#define F first
#define ll long long

using namespace std;

const ll N = 2e5 + 5, M = 1e6 + 5;

ll a[N], b[N];

int main()
{
    ll n, mn = 1e9;
    ll ans = 0;
    scanf("%lld", &n);
    for(int i = 0 ; i <= n ; i++) scanf("%lld", a + i);
    for(int i = 0 ; i < n ; i++) scanf("%lld", b + i);
    for(int i = 0 ; i <= n ; i++)
    {
        int mn = min(a[i], b[i]);
        ans += mn;
        b[i] -= mn;
        mn = min(a[i + 1], b[i]);
        a[i + 1] -= mn;
        ans += mn;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }

    ll ans = 0;
    for(auto& p : mp) {
        int t = p.second;
        ans += (ll)t*(t-1)/2;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std; 
#define ll long long
int main()
{
    ll t=1;
    //cin>>t;
    while(t--)
    {
      ll a,b,c,d;
      cin>>a>>b>>c>>d;
      ll ans=max({a*c,a*d,b*c,b*d});
      cout<<ans<<endl;
    }
    return 0;
}

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

int main(){
    int x,a,b;
    cin>>x>>a>>b;
    if (abs(x-a)<abs(x-b))
    {
        /* code */
        cout<<'A'<<endl;
    }
    else
    {
        /* code */
        cout<<'B'<<endl;
    }
    
}

Measured memory_bytes: 256
while 1:
    N, M, C, s, g = map(int, raw_input().split())
    if N == M == 0:
        break
    es = [[] for i in xrange(C)]
    for i in xrange(M):
        x, y, d, c = map(int, raw_input().split())
        if not x < y:
            x, y = y, x
        es[c-1].append((x-1, y-1, d))
    P = map(int, raw_input().split())
    Q = []; R = []
    for i in xrange(C):
        Q.append([0] + map(int, raw_input().split()) + [10**18])
        R.append(map(int, raw_input().split()))
    def calc(c, z):
        p = P[c]; q = Q[c]; r = R[c]
        su = i = 0
        while q[i+1] < z:
            su += (q[i+1] - q[i]) * r[i]
            i += 1
        return su + (z - q[i]) * r[i]

    EA = {}
    INF = 10**18
    for c in xrange(C):
        E = {(i, i): 0 for i in xrange(N)}
        V = set()
        for x, y, d in es[c]:
            E[x, y] = min(E.get((x, y), INF), d)
            V.add(x); V.add(y)
        for k in V:
            for i in V:
                for j in V:
                    if not i < j:
                        continue
                    k1 = min((i, k), (k, i))
                    k2 = min((k, j), (j, k))
                    if k1 in E and k2 in E:
                        E[i, j] = min(E.get((i, j), INF), E[k1] + E[k2])
        for ps in E:
            EA[ps] = min(EA.get(ps, INF), calc(c, E[ps]))
    for k in xrange(N):
        for i in xrange(N):
            for j in xrange(i+1, N):
                k1 = min((i, k), (k, i))
                k2 = min((k, j), (j, k))
                if k1 in EA and k2 in EA:
                    EA[i, j] = min(EA.get((i, j), INF), EA[k1] + EA[k2])
    ps = min((s-1, g-1), (g-1, s-1))
    print -1 if ps not in EA else EA[ps]

Measured memory_bytes: 8556
#include<bits/stdc++.h>
using namespace std;
    int main(){
        string A;
            cin >> A;
                int B = A.size();
                    int C = 0;
                        if(B % 1 == 0){
                            for(int i = 0; i < B/2; i++){
                                if(A.at(i) == A.at(B -i - 1)){

                                }else{
                                    C += 1;
                                }
                            }
                        }
                            cout << C << endl;
    return 0;}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[44];
	int n, i;
	a[0] = 1;
	a[1] = 1;
	
	scanf("%d", &n);
	
	for (i = 2; i <= n; i++){
		a[i] = a[i - 2] + a[i - 1];
	}
	
	printf("%d\n", a[n]);
	
	
	return (0);
}

Measured memory_bytes: 596
/*786*/
#include<bits/stdc++.h>
#define        ll          long long int
#define        sj          200010
#define        fast        ios_base :: sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define        sc1(a)      scanf("%lld",&a)
#define        sc2(a,b)    scanf("%lld %lld",&a,&b)
#define        pb          push_back
#define        pn          printf("No\n")
#define        py          printf("Yes\n")
#define        op(a)       printf("%lld\n",a)

using namespace std;

/*
0  1  2  3  4  5 6  7  8  9  () & *  !  #  Z  z  %
*/

ll num[sj];

int main()
{

    ll a,b;

    cin>>a>>b;

    cout<<a*b<<endl;

    return 0;
}







Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define pii              pair <int,int>
#define pll              pair <long long,long long>
#define sc               scanf
#define pf               printf
#define Pi               2*acos(0.0)
#define ms(a,b)          memset(a, b, sizeof(a))
#define pb(a)            push_back(a)
#define MP               make_pair
#define db               double
#define ll               long long
#define ull              unsigned long long
#define f                first
#define s                second
#define sqr(x)           (x)*(x)
#define VI               vector <int>
#define DBG              pf("Hi\n")
#define MOD              1000000007
#define SZ(a)            (int)a.size()
#define sf(a)            scanf("%d",&a)
#define sfl(a)           scanf("%lld",&a)
#define sff(a,b)         scanf("%d %d",&a,&b)
#define sffl(a,b)        scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)      scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)
#define loop(i,n)        for(int i=0;i<n;i++)
#define loop1(i,n)       for(int i=1;i<=n;i++)
#define REP(i,a,b)       for(int i=a;i<b;i++)
#define RREP(i,a,b)      for(int i=a;i>=b;i--)
#define intlim           2147483648
#define ull              unsigned long long
#define gcd(a, b)        __gcd(a, b)
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))
#define mk(x1,y1) make_pair(x1, y1)
#define maxl 100000
#define psz 20
using namespace std;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N | (1<<pos);}
//int reset(int N,int pos){return N= N & ~(1<<pos);}
//bool check(int N,int pos){return (bool)(N & (1<<pos));}
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdin);
//ios_base::sync_with_stdio(false);
 //cin.tie(NULL);
int main(){


    string s;
    cin>>s;

    for(int i=0; i<s.size()-1; i++){

        if(s[i] == s[i+1]) { cout<<"Bad"<<endl; return 0; }
    }
    cout<<"Good"<<endl;


    return 0;
}

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

int main() {
  vector<char> S(4);
  for (int i = 0; i < 4; i++)
    cin >> S[i];

  sort(S.begin(), S.end());

  if (S.at(0) == S.at(1) && S.at(2) == S.at(3) && S.at(0) != S.at(2))
    puts("Yes");
  else
    puts("No");
}

Measured memory_bytes: 256
class Combination:
    def __init__(self, n_max, mod=10 ** 9 + 7):
        # O(n_max + log(mod))
        self.mod = mod
        f = 1
        self.fac = fac = [f]
        for i in range(1, n_max + 1):
            f = f * i % mod
            fac.append(f)
        f = pow(f, mod - 2, mod)
        self.facinv = facinv = [f]
        for i in range(n_max, 0, -1):
            f = f * i % mod
            facinv.append(f)
        facinv.reverse()

    # "n 要素" は区別できる n 要素
    # "k グループ" はちょうど k グループ

    def __call__(self, n, r):  # self.C と同じ
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def nCr(self, n, r):
        if not 0 <= r <= n:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def nPr(self, n, r):
        if not 0 <= r <= n:
            return 0
        return self.fac[n] * self.facinv[n - r] % self.mod

    def nHr(self, n, r):
        if (n == 0 and r > 0) or r < 0:
            return 0
        return self.fac[n + r - 1] * self.facinv[r] % self.mod * self.facinv[n - 1] % self.mod


def resolve():
    MOD = 10**9+7
    N, K = map(int, input().split())

    r = min(N-1, K)
    cmb = Combination(N)

    ans = 0
    for i in range(r+1):
        ans += cmb.nCr(N, i) * cmb.nHr(N-i, i)
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 24752
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define debug(x) cerr <<__LINE__<< ": " <<#x<< " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

ll dp[101][2][4];

void solve() {
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    dp[0][0][0] = 1;
    rep(i, n) {
        int x = s[i] - '0';
        rep(j, 2) {
            rep(l, 4) {
                rep(m, (j ? 10 : x + 1)) {
                    if (l + (m != 0) >= 4) continue;
                    dp[i + 1][j || m < x][l + (m != 0)] += dp[i][j][l];
                }
            }
        }
    }
    cout << dp[n][0][k] + dp[n][1][k] << endl;
}

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


Measured memory_bytes: 3648
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    System.out.print(Math.min(a,b));
    System.out.print(" ");
    System.out.println(Math.max(0,a+b-n));
  }
}

Measured memory_bytes: 21588
#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<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
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 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 pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void solve(){
	int a; string s;
	cin >> a >> s;
	if (a >= 3200)cout << s << endl;
	else cout << "red" << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(map(int, input().split()))

    section_needed = sum(a)
    ans = 0
    section_count = 1
    total_section = 1
    for i in range(n+1):
        ans += section_count
        section_count -= a[i]
        if section_count <= 0 and i != n:
            print(-1)
            return
        if i == n and total_section != section_needed:
            print(-1)
            return
        next_branch = min(max(0, section_needed - total_section), section_count)
        total_section += next_branch
        section_count += next_branch

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 20000
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
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; }
template<class T>T gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  S[K-1] = S[K-1] + 32;
  cout << S << endl;
}

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

using namespace std;

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl

int main(){
    int h,w;
    cin>>h>>w;
    REP(i,h){
        REP(j,w){
            string s;
            cin>>s;
            if(s=="snuke"){
                cout<<(char)(j+'A')<<i+1<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

const double pi = 3.141592653589793;
// -------------------------------------------------------

ll N, K;
ll A[201010];
ll ev[201010];

int main() {
  cin >> N >> K;
  repe(i, 1, N) { cin >> A[i]; }

  rep(i, 0, K) {
    repe(i, 0, N + 1) { ev[i] = 0; }
    repe(i, 1, N) {
      ev[max(0LL, i - A[i])]++;
      ev[min(N + 1, i + A[i] + 1)]--;
    }
    A[0] = ev[0];
    repe(i, 1, N) { A[i] = A[i - 1] + ev[i]; }

    bool br = true;
    repe(i, 2, N) {
      if (A[i] != N) {
        br = false;
      }
    }
    if (br) {
      break;
    }
  }

  repe(i, 1, N) {
    cout << A[i];
    if (i != N) {
      cout << " ";
    }
  }
}


Measured memory_bytes: 6696
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX
#define eps LDBL_EPSILON
#define moder 100000
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
#define ggr getchar();getchar();return 0
using namespace std;
string s;
signed main() {
	cin>>s;
	int ans=0;
	rep(i,s.size()){
		rep(j,s.size()-i+1){
			string t=s.substr(i,j);
			bool f=false;
			for(char c:t){
				if(c!='A'&&c!='C'&&c!='G'&&c!='T')f=true;
			}
			if(!f)ans=max(ans,(ll)t.size());
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int i,j=0,k,q;
	int l[100000],r[100000],a[100000];
	int prime[10000];
	int like2017[1000];
	prime[0]=2;
	like2017[0]=3;
	
	for(i=3;i<100000;i+=2){
		for(k=0;k<=j;k++){
			if(i%prime[k]==0){
				break;
			}
			if(k==j){
				j++;
				prime[j]=i;
			}
		}
	}
	prime[j+1]=-1;
	j=0;
	
	for(i=2;prime[i]!=-1;i++){
		for(k=0;k<=i;k++){
			if((prime[i]+1)/2==prime[k]){
				j++;
				like2017[j]=prime[i];
				break;
			}
		}
	}
	like2017[j+1]=100000;
	
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d%d",&l[i],&r[i]);
	}
	
	for(i=0;i<q;i++){
		j=0;
		k=0;
		while(1){
			if(l[i]<=like2017[j]){
				break;
			}
			j++;
		}
		while(1){
			if(r[i]<like2017[j]){
				break;
			}
			k++;
			j++;
		}
		a[i]=k;
	}
	
	for(i=0;i<q;i++){
		printf("%d\n",a[i]);
	}
	
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner( System.in );
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();

    if ( B > A ) {
      System.out.println("Input Error ( B > A )");
    } else {
      if ( C > (A-B) ) {
        System.out.println(C-(A-B));
      } else {
        System.out.println("0");
      }
    }
    
  }
}

Measured memory_bytes: 21972
#include <stdio.h>
#include <stdlib.h>

int min(int a, int b){
	return a <= b ? a : b;
}

int power(int a, int N){
	if(N == 0){
		return 1;
	}
	else{
		return a * power(a, N - 1);
	}
}

int main(){
	int N, i, j;
	scanf("%d", &N);
	int *dp = (int *)malloc(sizeof(int) * (N + 1));
	dp[0] = 0;
	for(i = 1; i <= N; i++){
		dp[i] = dp[i - 1] + 1;
		for(j = 1; power(6, j) <= i; j++){
			dp[i] = min(dp[i], dp[i - power(6, j)] + 1);
		}
		for(j = 1; power(9, j) <= i; j++){
			dp[i] = min(dp[i], dp[i - power(9, j)] + 1);
		}
	}
	printf("%d\n", dp[N]);
	return 0;
}

Measured memory_bytes: 512
import java.util.Set;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String... args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        Set<String> set = new HashSet<>();
        for(int i = 0;i < n;i++){
            String order = scan.next();
            String arg = scan.next();
            if(order.equals("insert"))set.add(arg);
            else{
                if(set.contains(arg))System.out.println("yes");
                else System.out.println("no");
            }
        }
        scan.close();
    }
    

}


Measured memory_bytes: 253840
import           Control.Applicative
import           Data.Functor

main :: IO ()
main = do
  [h,w] <- fmap read . words <$> getLine
  if (h,w) == (0,0)
    then pure ()
    else printFrame h w >> main

printFrame :: Int -> Int -> IO ()
printFrame h w = putStrLn $ unlines frame
  where
    line_inner = "#" ++ replicate (w-2) '.' ++ "#"
    line_outer = replicate w '#'
    frame = [line_outer] ++ replicate (h-2) line_inner ++ [line_outer]



Measured memory_bytes: 4104
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
const int MOD=1e9+7;
inline int mul(int a,int b)
{return 1LL*a*b%MOD;}
inline void Mul(int &a,int b)
{a=1LL*a*b%MOD;}
inline int add(int a,int b)
{a+=b;return a>=MOD?a-MOD:a;}
int ksm(int a,int b)
{
    int ans=1;
    for(;b;b>>=1,Mul(a,a))
        if(b&1)Mul(ans,a);
    return ans;
}
int Fac(int n)
{
    int tmp=1;
    for(int i=1;i<=n;i++)
        Mul(tmp,i);
    return tmp;
}
const int Q=1<<19;
#define Link(opsha,xx,yy) opsha[xx].push_back(yy)
vector<int> lk[Q],ps[Q];
int n,pi=1;
int go_to[Q];
int lst[Q];
int tp,st[Q];
int ir[Q];
int cn,cm;
void dfs1(int x)
{
    ++cn;
    go_to[x]=1;
    for(int y:lk[x]){
        ++cm;
        if(go_to[y]){
            if(y==lst[x]||tp)continue;
            for(int t=x;;t=lst[t]){
                st[++tp]=t;
                ir[t]=1; 
                if(t==y)break;
            }
            continue;
        }
        lst[y]=x;
        dfs1(y);
    }
}
int fa[Q];
int apr[Q],maxn;
void dfs2(int x)
{
    apr[++maxn]=x;
    for(int y:lk[x]){
        if(y==fa[x]||ir[y])continue;
        fa[y]=x;
        dfs2(y);
    }
}
int Time=0;
int vis[Q],si[Q];
int cnt;
void dfs3(int x)
{
	if(vis[x]==Time)return;
	vis[x]=Time;
	si[x]=1;
	for(int y: ps[x])
		dfs3(y),si[x]+=si[y];
	Mul(cnt,si[x]);
}
int Calc()
{
	cnt=1;
	++Time;
	for(int i=1;i<=maxn;i++){
		int x=apr[i],y=fa[x];
		if(x<fa[y])Link(ps,y,x);
	}
	for(int i=1;i<=maxn;i++)
		if(vis[apr[i]]!=Time)
			dfs3(apr[i]);
	return cnt;
}
void Deal(int stat)
{
	
    cn=cm=0;
    tp=0;
    dfs1(stat);
    if((cn<<1)!=cm)
    {puts("0");exit(0);}
    maxn=0;
    for(int i=1;i<=tp;i++)
        dfs2(st[i]);
    st[tp+1]=st[1];
    for(int i=1;i<=tp;i++)
    	fa[st[i]]=st[i+1];
    int rem=Calc();
    for(int i=1;i<=maxn;i++)
    	ps[apr[i]].clear();
    st[0]=st[tp];
    for(int i=1;i<=tp;i++)
    	fa[st[i]]=st[i-1];
    Mul(pi,add(ksm(rem,MOD-2),ksm(Calc(),MOD-2)));
}
int main()
{
    scanf("%d",&n);
    n<<=1;
    for(int i=1,x,y;i<=n;i++)
        scanf("%d%d",&x,&y),y+=(n>>1),Link(lk,x,y),Link(lk,y,x);
    for(int i=1;i<=n;i++)
        if(!go_to[i])
            Deal(i);
    printf("%d",mul(Fac(n),pi));
    return 0;
}
/*
2
1 1
1 2
2 1
2 2







4
1 1
2 2
3 3
4 4
1 2
2 1
3 4
4 3


3
1 1
1 2
1 3
2 1
2 2
2 3
*/

Measured memory_bytes: 51584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

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

ll lcm(ll a, ll b){
    ll ret = (a * b)/gcd(a,b);
    return ret;
}

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];

    vector<ll> l(n), r(n);
    l[0] = a[0];
    rep(i, 1, n) l[i] = gcd(l[i-1], a[i]);
    r[n-1] = a[n-1];
    for(ll i=n-2; i>=0; i--) r[i] = gcd(r[i+1], a[i]);

    ll ans = r[1];
    rep(i, 1, n-1){
        ans = max(ans, gcd(l[i-1], r[i+1]));
    }
    ans = max(ans, l[n-2]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
n = int(input())
# print(n)
a_list = list(map(int, input().split()))
# print(a_list)

ans = 0
for i in range(len(a_list)):
    no = i + 1
    value = a_list[i]
    
    if no % 2 == 1:
        if value % 2 == 1:
            ans += 1
print(ans)

Measured memory_bytes: 9044
#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <iostream>
 
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int k = 0; k < n; k++)
#define FORN(k, s, n) for (int k = s; k < n; k++)
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);
 
#pragma warning(disable : 6031)
#pragma warning(disable : 4101)
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;
 
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);
 
// Solution

const int MAXN = 100005;

ll n, k, sum, best, uniq, V[MAXN];
pair<ll, ll> A[MAXN];
priority_queue<ll, vector<ll>, greater<ll>> Q;

int main() {
    scanf("%lld%lld", &n, &k);

    for (int i = 0; i < n; i++) {
        scanf("%lld%lld", &A[i].Y, &A[i].X);
    }

    sort(A, A + n, greater<pair<ll, ll>>());

    for (int i = 0; i < n; i++) {
        if (i >= k) {
            if (Q.empty()) {
                break;
            }

            sum -= Q.top();
            Q.pop();
        }

        if (!V[A[i].Y]) {
            V[A[i].Y] = true;
            uniq++;
        } else {
            Q.push(A[i].X);
        }

        sum += A[i].X;
        best = max(best, sum + uniq * uniq);
    }

    printf("%lld\n", best);

    return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;




int n;
vector<int> a;

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

    cin>>n;
    a.resize(n);
    for (int i=0; i<n; i++) {
	cin>>a[i];
    }
    sort(a.begin(), a.end());
    map<int,int> v;
    for (int i=0; i<n; i++) {
	v[a[i]]++;
    }


    int res=0;
    set<int> s;
    for (auto p: v) {
	int  x = p.first;
	if (p.second>1) {
	    s.insert(x);
	}
	bool ok=true;
	for (int j=1; j*j<=x; j++) {
	    if (x%j==0) {
		if (s.count(j)) {
		    ok=false; break;
		}
		if (s.count(x/j)) {
		    ok=false; break;
		}
	    }
	}
	if (ok) {
	    res += p.second;
	}
	s.insert(x);
    }

    cout<<res<<endl;
    
    
    return 0;
}


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

void swap_asc(int *a, int *b){
	int temp;
	if(*a >= *b){
		temp = *a;
		*a = *b;
		*b = temp;
	}
}

int main(void){

	int a[3];
	cin >> a[0] >> a[1] >> a[2];

	for(int i = 0; i < 3; i++){
		swap_asc(&a[0], &a[1]);
		swap_asc(&a[1], &a[2]);
	}

	for(int i = 0; i < 3; i++){
		cout << a[i];
		if( i != 2 ) cout << " ";
	}
	cout << endl;

	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int p = 0;
  int q = 0;

  for (int i = 0; i < s.size(); i++) {
    p *= 10;
    p += s.at(i) - '0';
    q += s.at(i) - '0';
  }
  if (p % q == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3564
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N,M,K=mis()
    A=lmis()
    B=lmis()
    A.reverse()
    B.reverse()
    c = 0
    t = 0
    s = []
    while A:
        a = A.pop()
        if t + a <= K:
            t += a
            c += 1
            s.append(a)
        else:
            break
    #
    ans = c
    while B:
        if t + B[-1] <= K:
            t += B.pop()
            c += 1
            ans = max(ans, c)
        elif s:
            t -= s.pop()
            c -= 1
        else:
            break
    print(ans)









main()



Measured memory_bytes: 41616
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
string s,t;
cin>>s>>t;
ll i,c=0;
for(i=0;i<s.size();i++)
{
    if(s[i]!=t[i])
        c++;
}
cout<<c;
    return 0;
}





Measured memory_bytes: 3916
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))

A = np.array(A, dtype=int)
B = np.array(B, dtype=int)

# B でソート
idx = B.argsort()
A = A[idx]
B = B[idx]
# この位置より右にいられる
positions = np.searchsorted(B, A, side='left')

heap = [(a, -p) for p, a in enumerate(positions)]
heapq.heapify(heap)

# A を前から見てく
# 右にあるやつのうち一番小さいの使う
cnt = 0
for i in range(N):
    a = positions[i]
    if a <= i:
        continue
    cnt += 1
    while heap and -heap[0][1] < i:
        heapq.heappop(heap)
        new_a, p = heap[0]
        p *= -1
        if positions[p] != new_a:
            continue
    new_a, p = heapq.heappop(heap)
    p *= -1
    positions[i] = new_a
    positions[p] = a
    heapq.heappush(heap, (a, -p))
    # print(positions)
# print(cnt)
# print(positions)
# print(positions <= np.arange(N))
if cnt <= N - 2 and np.all(positions <= np.arange(N)):
    print('Yes')
else:
    print('No')


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

int C[35];

int main()
{
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < N; i++)
    {
        int K;
        cin >> K;
        for (int j = 0; j < K; j++)
        {
            int a;
            cin >> a;
            C[a]++;
        }
    }
    int res = 0;
    for (int i = 1; i <= M; i++) if (C[i] == N) res++;
    cout << res << '\n';
    return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
struct LazySegTree {
    int N;
    vector<Int> A, B;
    LazySegTree(int n) {
        N = 1;
        while (N < n) N *= 2;
        A.resize(2 * N);
        B.resize(N);
    }
    void addrange(int L, int R, Int value) {
        L += N, R += N;
        int L0 = L, R0 = R;
        while (L < R) {
            if (R & 1) apply(--R, value);
            if (L & 1) apply(L++, value);
            L /= 2, R /= 2;
        }
        build(L0), build(R0 - 1);
    }
    Int maxrange(int L, int R) {
        Int ans = LLONG_MIN;
        L += N, R += N;
        push(L), push(R - 1);
        while (L < R) {
            if (R & 1) ans = max(ans, A[--R]);
            if (L & 1) ans = max(ans, A[L++]);
            L /= 2, R /= 2;
        }
        return ans;
    }
    void apply(int X, Int value) {
        A[X] += value;
        if (X < N) B[X] += value;
    }
    void build(int X) {
        X /= 2;
        while (X > 0) {
            A[X] = max(A[2 * X + 0], A[2 * X + 1]) + B[X];
            X /= 2;
        }
    }
    void push(int X) {
        for (int s = 32 - __builtin_clz(N); s > 0; s--) {
            int i = X >> s;
            apply(2 * i + 0, B[i]);
            apply(2 * i + 1, B[i]);
            B[i] = 0;
        }
    }
};
int main() {
    int N, M; cin >> N >> M;
    vector<vector<pair<int, int>>> A(N + 2);
    for (int i = 0; i < M; i++) {
        int l, r, a; cin >> l >> r >> a;
        A[l].emplace_back(l, a);
        A[r + 1].emplace_back(l, -a);
    }
    LazySegTree dp(N + 2);
    for (int i = 1; i <= N + 1; i++) {
        for (auto &p : A[i]) {
            dp.addrange(0, p.first, p.second);
        }
        dp.addrange(i, i + 1, dp.maxrange(0, i));
    }
    cout << dp.maxrange(0, N + 1) << '\n';
    return 0;
}


Measured memory_bytes: 18048
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}
int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  int n,k;
  int ans=0;
  cin>>n>>k;
  vector<int> a(n);
  rep(i,0,n) cin>>a[i];
  asort(a);
  urep(i,n-1,n-k-1) ans+=a[i];
  cout<<ans;
}

// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long arr[10][10];

int main(){
	/*#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif*/
	int n;
	cin>> n;
	long long ans = 0;
	for(int i = 1; i <= n; ++i){
		if(i%10== 0){
			continue;
		}
		int last = i%10;
		int first;
		int x = i;
		while(x){
			first = x%10;
			x/=10;
		}
		arr[first][last]++;
	}
	for(int f = 1; f <= 9; ++f){
		for(int l = 1; l <= 9; ++l){
			ans += arr[f][l]*arr[l][f];
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    S = input()
    left = 0
    right = 0
    stack = []
    for s in S:
        if s == "(":
            stack.append(s)
        else:
            if stack:
                stack.pop()
            else:
                left += 1
    right = len(stack)
    print("("*left + S + ")"*right)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060