akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>
#include <cstring>
using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int mp[4][14];

void solve(){
	int n;
	cin >> n;
	char c;
	int m;
	for(int i=0;i<n;i++){
		cin >> c >> m;
		if(c=='S')mp[0][m]=1;
		if(c=='H')mp[1][m]=1;
		if(c=='C')mp[2][m]=1;
		if(c=='D')mp[3][m]=1;
	}
	for(int i=0;i<4;i++){
		for(int j=1;j<=13;j++){
			if(mp[i][j]==0){
				if(i==0)cout << "S " << j << endl;
				if(i==1)cout << "H " << j << endl;
				if(i==2)cout << "C " << j << endl;
				if(i==3)cout << "D " << j << endl;
			}
		}
	}
}

int main() {
  solve();
  return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

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

    sort(str.begin(), str.end());
    if (str[0] == str[1] && str[2] == str[3])
    {
        if (str[0] != str[2] && str[1] != str[3])
            cout << "Yes";
        else cout << "No";
    }
    else cout << "No";
}

Measured memory_bytes: 3600
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <cstdio>
#include <time.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <math.h>
//#include <bits/stdc++.h>
#define ll long long
#define int64 long long
#define mem(x,y) memset(x,y,sizeof(x))
#define ull unsigned long long
#define pb push_back
#define INF 0x3f3f3f3f
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
#define pi 3.141592653589793238462

using namespace std;

const int maxn = 2e5 + 5;
const int maxm = 3e5 + 5;
const int mod = 1e9 + 7;
const int seed = 10007;
const double eps = 1e-5;
int n,m;
vector<int> g[maxn];

int main() {
    scanf("%d%d",&n,&m);
    int u,v;
    for(int i=0;i<m;i++){
        scanf("%d%d",&u,&v);
        g[u].pb(v);
        g[v].pb(u);
    }
    for(int i=0;i<g[1].size();i++){
        int v=g[1][i];
        for(int j=0;j<g[v].size();j++){
            if(g[v][j]==n){
                printf("POSSIBLE\n");
                return 0;
            }
        }
    }
    printf("IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 12016
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define vi vector<int>
#define nl endl
#define tc    \
    ll t;     \
    cin >> t; \
    while (t--)
#define fastio                       \
    ios_base::sync_with_stdio(NULL); \
    cin.tie(NULL);                   \
    cout.tie(NULL);
using namespace std;
int main()
{
    fastio;
    int n;
    cin >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++)
    {
        b[a[a[i]-1]-1]=a[i];
    }
     for (int i = 0; i < n; i++)
    {
        cout<< b[i]<<" ";
    }
}

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

const int MAXN = 10;

int N;
int A[MAXN];

int ANS;

void dfs(int x, vector<int> &vec) {
  if (x == N) { 
    int r = 1;
    for (int i = 0; i < N; ++i) {
      (r *= vec[i]) %= 2;
    }
    ANS += r % 2 == 0;
    return;
  }
  for (int i = -1; i <= 1; ++i) {
    vec[x] += i;
    dfs(x + 1, vec);
    vec[x] -= i;
  }
}

signed main() {
  ios::sync_with_stdio(false);
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  vector<int> vec(N);
  for (int i = 0; i < N; ++i) {
    vec[i] = A[i];
  }
  dfs(0, vec);
  cout << ANS << endl;
  return 0;
}


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

int main(void)
{

    int N;//人数
    int D;//日数
    int X;//残っていたチョコレート
    
    int *A;
    int i,j;
    scanf("%d",&N);
    scanf("%d%d",&D,&X);
    
    A = (int*)malloc(sizeof(int)*N);
    if(A == NULL)exit(0);
    
    
    for(i = 0;i<N;i++){
        scanf("%d",&A[i]);
    }
    //
    
    int Max;//チョコレートの合計値
    Max = X;
    
    int x;//kosuu
    x = 0;
    for(j=0;j<N;j++){
        for(i=0;i<D;i++){
            
            
            if((i+1) == x*A[j]+1){
                Max += 1;
                x += 1;
            }
            
        }
        x = 0;
    }
    
    
    
    printf("%d",Max);
    
    
    
    free(A);
    return EXIT_SUCCESS;
}

Measured memory_bytes: 128
N, M ,Q = map(int, input().split())
train = [list(map(int, input().split())) for i in range(M)]
qs = [list(map(int, input().split())) for i in range(Q)]
ns = []
for i in range(N+1):
    ns.append([0]*(N+1))
for l, r in train:
    for i in range(r, N+1):
        ns[l][i] += 1
for p, q in qs:
    ans = 0
    for i in range(p, q+1):
        ans += ns[i][q]
    print(ans)



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

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

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

int ct(VI& s){
	int c=0;
	rep(i,sz(s)) if(s[i]==i+1) c++;
	return c;
}
struct UF{
	vector<int> p;
	UF() {}
	UF(int n) : p(n, -1) {}
	int find(int a){ return p[a] < 0 ? a : p[a] = find(p[a]); }
	bool unite(int a, int b) {
		a = find(a); b = find(b);
		if(a == b) return false; //閉路検出
		if(-p[a] < -p[b]) swap(a, b);
		p[a] += p[b]; p[b] = a;
		return true;
	}
	bool root(int a){ return p[a] < 0; }
	bool same(int a, int b){ return find(a) == find(b); }
	int size(int a){ return -p[find(a)]; }
};

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,m;
	cin >>n >>m;
	VI p(n), x(m), y(m);
	rep(i,n){ cin >> p[i]; p[i]--;}
	UF ufa(n);
	rep(i,m){
		int a,b; cin >> a >>b;
		x[i]=a-1; y[i]=b-1;
		ufa.unite(a-1, b-1);
	}
	
	VI rv(n);
	rep(i,n) rv[p[i]] = i;
	int ans =0;
	rep(i,n){
		if(ufa.same(rv[i], i )) ans++;
	}
	cout << ans <<endl;
	return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector<int> ai(N);
  for(int i = 0; i < N; i++)
    cin >> ai.at(i);
  sort(ai.begin(), ai.end(), greater<int>());
  int Alice = 0, Bob = 0;
  for(int i = 0; i < N; i++)
  {
    if(i%2 == 0)
      Alice += ai.at(i);
    else
      Bob += ai.at(i);
  }
  cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
//https://blog.csdn.net/qq_41021816/article/details/80383253
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
    return x>y;
}
const int N=2e5+20;
const ll mod=1e9+7;
ll f[N],n,m,A,B;
ll powmod(ll x,ll n)
{
    ll s=1;
    while(n){
        if(n&1)
            s=(s*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return s;
}
ll C(ll n,ll m)
{
    ll a=f[n];
    ll b=(f[m]*f[n-m])%mod;
    return (a*powmod(b,mod-2))%mod;
}
int main()
{
    f[0]=1;
    for(ll i=1;i<N;i++)
        f[i]=(f[i-1]*i)%mod;
    while(cin>>n>>m>>A>>B){
        ll res=0;
        for(ll i=B+1;i<=m;i++){
            ll tmp=(C(i-1+n-A-1,n-A-1)*C(m-i+A-1,m-i))%mod;
            res=(res+tmp)%mod;
        }
        cout<<res<<endl;
    }
    return 0;
}

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

using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef long int li;

int main()
{
    IOS;
    //freopen("fr.txt","r",stdin);
    int A,P;
    cin>>A>>P;
    int x=A*3+P;
    cout<<x/2<<endl;


    return 0;
}


Measured memory_bytes: 3564
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using Vi = vector<int>;

Graph G;
Vi color;
void dfs(int now,int prec){
    for(auto next:G[now]){
        if(color[next.fs]!=-1) continue;
        color[next.fs]=(next.sc+prec)%2;
        dfs(next.fs,color[next.fs]);
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n;
    cin>>n;
    G.resize(n);
    color.resize(n,-1);
    rep(i,n-1){
        int a,b,w;
        cin>>a>>b>>w;
        a--;b--;
        w%=2;
        G[a].pb(mp(b,w));
        G[b].pb(mp(a,w));
    }
    color[0]=0;
    dfs(0,0);
    rep(i,n) cout<<color[i]<<endl;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

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

const int INF = 1001001001;
const int MAX_N = 50;
int g[MAX_N][MAX_N];
int u[MAX_N];
int v[MAX_N];
vector<pair<int,int>> edges;

int main2() {
  edges.clear();

  int N = nextInt();

  REP(i, N) REP(j, N) g[i][j] = INF;
  REP(i, N) g[i][i] = 0;
  REP(i, N-1) {
    int a = nextInt() - 1;
    int b = nextInt() - 1;
    g[a][b] = 1;
    g[b][a] = 1;
    edges.push_back({a, b});
  }

  int M = nextInt();
  REP(i, M) {
    u[i] = nextInt() - 1;
    v[i] = nextInt() - 1;
  }

  REP(k, N) REP(i, N) REP(j, N) chmin(g[i][j], g[i][k] + g[k][j]);

  vector<int> D(N-1);
  for (int e = 0; e < N-1; e++) {
    const int a = edges[e].first;
    const int b = edges[e].second;
    for (int i = 0; i < M; i++) {
      if ( g[ u[i] ][ v[i] ] == g[ u[i] ][a] + g[a][b] + g[b][ v[i] ] ||
           g[ u[i] ][ v[i] ] == g[ u[i] ][b] + g[b][a] + g[a][ v[i] ] ) {
        D[e] |= (1 << i);
      }
    }
  }

  // REP(i, N-1) cout << bitset<20>(D[i]) << endl;

  ll ans = 0;
  REP(bs, 1 << M) {
    int sign = __builtin_popcount(bs) % 2 ? +1 : -1;
    ll ways = 1;
    REP(e, N-1) {
      if ((D[e] & bs) == 0) ways *= 2;
    }
    // cout << bs <<" -> " << ways << endl;
    ans += sign * ways;
  }
  cout << abs(ans) << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;

int main(){
    double a,b,c,d=0,e=0;
    cin>>a>>b;
    a*=500;
    if(a>=b){cout<<"Yes"; return 0;}
    if(a<b){cout<<"No"; return 0;}
    return 0;
}


Measured memory_bytes: 3672
import numpy as np
import math
N=int(input())
M=N*(N-1)//2
X=np.array([list(map(int,input().split())) for _ in range(N)])
L=0
for i in range(N-1):
    for j in range(i+1,N):
        l=((X[i][0]-X[j][0])**2+(X[i][1]-X[j][1])**2)
        L+=np.sqrt(l)
print(L*2/N)

Measured memory_bytes: 12428
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;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/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[2000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<200007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
using namespace std;
int solve()
{
	facto();
	int n,k;
	cin>>n>>k;
	int sum=0;
	for(int i=0;i<=min(n-1,k);i++)
	{
		int x=ncr(n,i);
		int y=ncr(n-1,i);
		int ans=(x*y)%mod;
		sum=(sum+ans)%mod;
	}
	cout<<sum<<endl;
}
signed main()
{
	fastio;
	clock_t start, end;
//	test
	{
		start=clock();
		solve();
		end=clock();
		double time_taken=double(end-start)/double(CLOCKS_PER_SEC);
//		cout<<time_taken<<endl;
	}
}


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

void answer1() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  long long n;
  cin >> n;
  // 素朴な実装
  long long x = 1, y = 1;
  for (long long i = floor(sqrt(n)); i >= 1; i--) {
    if (n % i == 0) {
      x = i;
      y = n / x;
      break;
    }
  }
  cout << x + y - 2 << endl;
}

int main() {
  answer1();
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
   
int main(void){
    int n;
    scanf("%d", &n);
    int a[n];
    int min = pow(10, 9);
    int max_prof = -pow(10, 9);
    for (int i=0; i<n; i++){
      scanf("%d", &a[i]);
      if((i!=0) && (a[i]-min)>max_prof){
        max_prof = a[i] - min;
      }
      if(a[i]<min){
         min = a[i];
      }
    }
    printf("%d\n", max_prof);
    return 0;
}


Measured memory_bytes: 3548
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
    int tc = (C+B-1)/B;
    int ac = (A+D-1)/D;
    string res = (ac < tc)?"No":"Yes";
    cout << res << endl;
    
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define in read()
#define re register
#define fur(i,a,b) for(re int i=a;i<=b;++i)
#define fdr(i,a,b) for(re int i=a;i>=b;--i)
#define cl(a,b) memset(a,b,sizeof(a))
#define jinitaimei signed
#define int long long
inline int read()
{
	int x=0;
	char ch=getchar();
	for(;!isalnum(ch);ch=getchar());
	for(;isalnum(ch);ch=getchar()) x=x*10+ch-'0';
	return x;
}
int num[11],tmpp[11],bit=0;
int ans=0;
inline void search(int now,int sum)
{
	if(now==bit)
	{
		ans+=sum;
		return;
	}
	int tmp=0;
	fur(i,now+1,bit)
	{
		tmp=tmp*10+num[i];
		search(i,sum+tmp);
	}
}
jinitaimei main()
{
	int n=in;
	while(n)
	{
		tmpp[++bit]=n%10;
		n/=10;
	}
	fur(i,1,bit) num[i]=tmpp[bit-i+1];
	search(0,0);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
module Memoizable
	def memoize(name)
		original = "__original_#{name}__"
		([Class, Module].include?(self.class) ? self : self.class).class_eval {
			alias_method(original, name)
			private(original)
			cache = {}
			define_method(name){|*args|
				cache[args] ||= send(original, *args)
			}
		}
	end 
end

def f(schedule, n)  
	x = (schedule & 0b11)
	y = ((schedule & 0b1100) >> 2)
	z = ((schedule & 0b110000) >> 4)
	return (f(schedule | 1, n) + f(schedule | 2, n) + f(schedule | 3, n)) % 10000 if x == 0
	return (f(schedule | 4, n) + f(schedule | 8, n) + f(schedule | 12, n)) % 10000 if y == 0
	return (f(schedule | 16, n) + f(schedule | 32, n) + f(schedule | 48, n)) % 10000 if z == 0
	return 0 if x == y && y == z
	return 1 if n == 3
	f(schedule >> 2, n - 1) % 10000
end

include Memoizable
memoize :f

n, k = gets.split.map(&:to_i)
schedule = 0
k.times {
	a, b = gets.split.map(&:to_i)
	schedule |= (b << 2 * (a-1))
}
p f(schedule, n)

Measured memory_bytes: 6376
#include <stdio.h>

typedef struct{
  int p;
  int l;
  int r;
}Tree;

Tree T[100005];
int n, D[100005];

int rec(int u, int p){
  D[u] = p;
  if(T[u].r!=-1)rec(T[u].r, p);
  if(T[u].l!=-1)rec(T[u].l, p+1);
}

int main(){
  int i,j,k,d,v,c,l,r,n,a;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=-1;
    T[i].l=-1;
    T[i].r=-1;
  }
  for(i=0; i<n; i++){
    scanf("%d", &v);
    scanf("%d", &d);
    for(j=0; j<d; j++){
      scanf("%d",&c);
      if(j==0)T[v].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=v;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p==-1)r=i;
  }
  rec(r,0);

  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,T[i].p, D[i]);
    if(T[i].p==-1)printf("root, [");
    else if(T[i].l==-1)printf("leaf, [");
    else printf("internal node, [");
    for(k=0,a=T[i].l; a!=-1;k++, a=T[a].r){
      if(k)printf(", ");
      printf("%d", a);
    }
    printf("]\n");
  }
  return 0;
}

Measured memory_bytes: 5296
import java.util.*;

// ABC 76-C
// https://beta.atcoder.jp/contests/abc076/tasks/abc076_c

public class Main {
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		char[] S = in.next().toCharArray();
		char[] T = in.next().toCharArray();
		
		ArrayList<String> answers = new ArrayList<String>();
		
		for (int i = 0; i < S.length; i++) {
			if (i + T.length > S.length) {
				continue;
			}
			
			char[] answer = S.clone();
			
			for (int j = 0; j < i; j++) {
				if (answer[j] == '?') {
					answer[j] = 'a';
				}
			}
			
			boolean isAnswer = true;
			
			for (int j = 0; j < T.length; j++) {
				int index = i + j;
				
				if (answer[index] == '?' || answer[index] == T[j]) {
					answer[index] = T[j];
				} else {
					isAnswer = false;
				}
			}
			
			for (int j = i + T.length; j < S.length; j++) {
				if (answer[j] == '?') {
					answer[j] = 'a';
				}
			}
			
			if (isAnswer) {
				answers.add(new String(answer));
			}
		}
		
		answers.sort(null);
		
		if (answers.size() > 0) {
			System.out.println(answers.get(0));
		} else {
			System.out.println("UNRESTORABLE");
		}
	}
}

Measured memory_bytes: 21716
import java.util.Scanner;
import java.math.BigDecimal;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int numA, numB;
        double buf;

        numA = Integer.parseInt(scan.next());
        numB = Integer.parseInt(scan.next());

        buf = (double)numA / (double)numB;

        System.out.print(numA / numB + " ");
        System.out.print(numA % numB + " ");
        System.out.println(BigDecimal.valueOf(buf).toPlainString());
    }
}



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

static const int N = 1000;

int lcs(string X, string Y) {
  int c[N + 1][ N + 1], i, j;
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for(i = 0; i <= m; i++) c[i][0] = 0;
  for(j = 1; j <= n; j++) c[0][j] = 0;

  for(i = 1; i <= m; i++) {
    for(j = 1; j <= n; j++) {
      if(X[i] == Y[j]) {
        c[i][j] = c[i-1][j-1] + 1;
      } else {
        c[i][j] = max(c[i][j - 1], c[i - 1][j]);
      }
      maxl = max(maxl, c[i][j]);
    }
  }

  return c[m][n];
}

int main() {
  string s1, s2;
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    cout<< lcs(s1, s2)<<endl;
  }

  return 0;
}



Measured memory_bytes: 7072
N,M = map(int,input().split())
import time
start_t = time.time()
path = [[] for _ in range(N+3)]
for _ in range(M):
    u,v = map(int,input().split())
    path[u].append(v)

S,T = map(int,input().split())
import collections

q = collections.deque()
vis = [[-1 for _ in range(3)] for _ in range(N+3)]
vis[S][0] = 1
q.append([S,0])
while len(q):
    now,cnt = q.popleft()
    step = cnt % 3
    for x in path[now]:
        if vis[x][(step+1)%3] < 0:
            vis[x][(step+1)%3] = cnt
            q.append((x,cnt+1))

if vis[T][0] == -1:
    print(-1)
else:
    print(vis[T][0]//3+1)



Measured memory_bytes: 98584
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
//typedef pair<ll,ll> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};


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

    int a,b;
    cin>>a>>b;
    if(a>b) swap(a,b);
    for(int i=0;i<b;i++) cout<<a;
    cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double PI=3.14159265358979323846;
ll dp;

int main(){
   ll x,y,k;
   cin>>k>>x>>y;
   REP(i,x,y+1){
      if(i%k==0){
         cout<<"OK"<<endl;
         return 0;
      }
   }
   cout<<"NG"<<endl;
   
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main() {
  int n,k;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  rep(i,n-1) {
    cin >> a.at(i);
    }
  rep(i,n-1) {
      b.at(a.at(i)-1)++;
  }
  rep(i,n) {
    cout << b.at(i) <<endl;
  }
}


Measured memory_bytes: 4780
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# 初期値設定
ans = 0
Ai = A[0]
Bi = B[0]

for i in range(N):
    # i番目の街のモンスターを倒す
    ans += min(Ai, Bi)

    # i + 1番目の街の残りモンスターを設定
    if Ai < Bi:
        ans += min(A[i + 1], Bi - Ai)
        Ai = A[i + 1] - min(A[i + 1], Bi - Ai)
    else:
        Ai = A[i + 1]

    # N番目の勇者を設定していなければ、i + 1番目の勇者を設定
    if i == (N - 1):
        break
    else:
        Bi = B[i + 1]

print(ans)


Measured memory_bytes: 19156
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main(){
    int N, K;
    cin >> N>>K;
    if(K==1){
        cout<<0<<endl;
        return 0;
    }
    if(N>K){
        cout << N-K<<endl;
        return 0;
    }else{
        cout << 0<< endl;
        return 0;
    }
}

Measured memory_bytes: 256
import sys, math, bisect



def solve(W_N, V_N, bombs, H, W):

    max_x = 1
    xs = []
    for i in range(W):
        if(W_N[i] > max_x):
            max_x = W_N[i]
            xs = [i]
        elif(W_N[i] == max_x):
            xs.append(i)
    max_y = 1
    ys = []
    for j in range(H):
        if(V_N[j] > max_y):
            max_y = V_N[j]
            ys = [j]
        elif(V_N[j] == max_y):
            ys.append(j)

    value = max_x + max_y

    for j in ys:

        bombs[j].sort()
        for i in xs:
            index = bisect.bisect_left(bombs[j], i)
            if(index == V_N[j] or i != bombs[j][index]):
                return value
            
    return value-1



if(__name__ == "__main__"):
    """
    N = int( input().strip() )
    Length = list( map(int, input().strip().split() ) )
    """
    H, W, N_bombs= map(int, input().strip().split() )


    V_N = [0] * H
    W_N = [0] * W
    bombs = [ [] for _ in range(H) ]


    for i in range(N_bombs):
        y, x = map(int, input().strip().split() )
        """
        W_N_bomb[x-1][0] += 1
        V_N_bomb[y-1][0] += 1
        """
        V_N[y-1] += 1
        W_N[x-1] += 1
        bombs[y-1].append(x-1)




    print( solve(W_N, V_N, bombs, H, W) )


Measured memory_bytes: 160660
@mod = 10**9 + 7
@n = gets.to_i
@ans = 0

def ok_last_4(str)
  str !~ /A(\w?G|G\w?)C$/  
end

def ok_last_3(str)
  str !~ /AGC$/ and str !~ /ACG$/ and str !~ /GAC$/
end

def dfs(len, last_3_pat)
  if len == @n
    last_3_pat.each do |k, v|
      @ans = (@ans + v) % @mod
    end
  else
    n_last_3_pat = {}

    last_3_pat.each do |last_3, pat|
      ["A", "T", "C", "G"].each do |c|
        last_4 = last_3 + c
        n_last_3 = last_4[1..-1]
        if ok_last_3(last_4) and ok_last_4(last_4)
          n_last_3_pat[n_last_3] = 0 if not n_last_3_pat.key?(n_last_3)
          n_last_3_pat[n_last_3] += pat
          n_last_3_pat[n_last_3] %= @mod
        end
      end
    end

    dfs(len + 1, n_last_3_pat)
  end
end

dfs(0, {"TTT" => 1})
puts @ans

Measured memory_bytes: 2428
import Control.Applicative
main = do
    [a, op, b] <- words <$> getLine
    putAnswer $ calc a op b

putAnswer :: Maybe Int -> IO ()
putAnswer Nothing = putStr ""
putAnswer (Just x) = do
    putStrLn $ show x
    [a, op, b] <- words <$> getLine
    putAnswer $ calc a op b

calc :: String -> String -> String -> Maybe Int
calc _ "?" _ = Nothing
calc sa op sb
    | op == "+" = Just $ a + b
    | op == "-" = Just $ a - b
    | op == "*" = Just $ a * b
    | op == "/" = Just $ a `div` b
    where
        a = read sa :: Int
        b = read sb :: Int

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

using namespace std;

int main(){
  long long H,W;
  cin>>H>>W;
  long long ans=0;
  if(H==1||W==1) ans=1;//コーナーケース
  else{
  if(H%2==0||W%2==0) ans=W*H/2;
  else ans=H*(W/2)+((H+1)/2);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define vi vector<int>
#define vl vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define two ios_base::sync_with_stdio(0)
#define powerofn cin.tie(0)
using namespace std;

ll const MOD = 998244353;

int const max_n = 3 * 1e5 + 10;

void yes(){
    cout<<"YES"<<'\n';
}

void no(){
    cout<<"NO"<<'\n';
}

ll fact(int n){
    ll ans = 1;
    for(int i=2;i<=n;i++){
        ans = (ans*i)%MOD;
    }

    return ans;
}

ll powM(int n, int x){
    if(x==0){
        return 1;
    }
    if(x==1){
        return n%MOD;
    }

    if(x%2==0){
        ll a = powM(n,x/2);
        return (a*a)%MOD;
    }else{
        return (n*powM(n,x-1))%MOD;
    }
}

ll C(int n, int k){
    return (fact(n) * powM((fact(k)*fact(n-k))%MOD,MOD-2))%MOD;
}

ll A(int n, int k){
    return (fact(n) * powM(fact(n-k)%MOD,MOD-2))%MOD;
}

void add_self(int &a, int b){
    a += b;
    if(a>=MOD){
        a-=MOD;
    }
}

void sub_self(int &a, int b){
    a -= b;
    if(a<0){
        a+=MOD;
    }
}


struct segtree {

    vl tree;
    int size;

    void init(int n){
        size = 1;
        while(size < n) size*=2;
        tree.assign(2*size-1,0);
    }
    void build(vi &a,int x, int lx, int rx){
        if(rx-lx == 1){
            if(lx<a.size())
                tree[x] = a[lx];
        }else{
            int m = (lx+rx)/2;
            build(a,2*x+1,lx,m);
            build(a,2*x+2,m,rx);
            tree[x] = tree[2*x+1]+tree[2*x+2];
        }
    }

    void build(vi &a){
        init(a.size());
        build(a,0,0,size);
    }

    void set(int i, int v, int x, int lx, int rx){
        if(rx-lx==1){
            tree[x] = v;
            return;
        }
        int m = (lx+rx)/2;
        if(i<m){
            set(i,v,2*x+1,lx,m);
        }else{
            set(i,v,2*x+2,m,rx);
        }
        tree[x] = tree[2*x+1] + tree[2*x+2];
    }

    void set(int i, int v){
        set(i,v,0,0,size);
    }

    ll sum(int l, int r, int x, int lx, int rx){
        if(l>=rx || lx>=r){
            return 0;
        }
        if(lx>=l && rx<=r){
            return tree[x];
        }
        int m = (rx+lx)/2;
        ll s1 = sum(l,r,2*x+1,lx,m);
        ll s2 = sum(l,r,2*x+2,m,rx);
        return s1+s2;
    }

    ll sum (int l,int r){
        return sum(l,r,0,0,size);
    }

};

int a[max_n];

void solve(){

    int n;
    cin >> n;

    n = n % 1000;
    cout << (1000 - n) % 1000;

}

int main(){
    two;
    powerofn;

    int t = 1;
    // cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


Measured memory_bytes: 3652
def solve():
  n = int(input())
  s = input()
  ans = s.count("R")*s.count("G")*s.count("B")
  for i in range(n-2):
    for j in range(i+1,n):
      k = 2*j-i
      if k < n and s[k] != s[i] and s[k] != s[j] and s[i] != s[j]:
        ans -= 1
  print(ans)
  return 0
 
if __name__ == "__main__":
  solve()


Measured memory_bytes: 9232
import scala.math._

// longでrangeの作り方

object Main extends App {

  val YES = "YES"
  val Yes = "Yes"
  val NO = "NO"
  val No = "No"
  ///////////////////////////////////////////

  val sc = new java.util.Scanner(System.in)
  val a, b, c = sc.nextLong
//  val list = List.fill(n, d)(sc.nextInt)

  val ans = if (a <= c && c <= b) Yes else No

  println(ans)


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

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

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

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

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

Measured memory_bytes: 27324
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

const int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int x, a; cin >> x >> a;
    if (x < a) cout << 0 << endl;
    else cout << 10 << endl;
    return 0;
}


Measured memory_bytes: 256
import kotlin.math.*

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map(String::toInt) // list of ints
private fun readLongs() = readStrings().map(String::toLong) // list of longs

fun main() {
    val n = readInt()
    println(generateSequence { readLn() }.take(n).toSet().count())
}


Measured memory_bytes: 78268
# WARN: Require mod number m is prime number
class ModComb:
    # For nCr mod m
    def __init__(self, n_max, m):
        self._n_max = n_max
        self._m = m
        self._mod_facts = [1] * (n_max+1)       # list of n! mod m
        self._mod_inv_facts = [1] * (n_max+1)   # list of inverse r! mod m

        if not m >= 3:
            raise ValueError('Require mod number m >= 3')

        # Calc n_max! mod m
        for i in range(2, n_max+1):
            self._mod_facts[i] = self._mod_facts[i-1] * i % m

        # Calc inverse r! mod m
        self._mod_inv_facts[n_max] = pow(self._mod_facts[n_max], m-2, m)
        for i in range(n_max-1, 1, -1):
            self._mod_inv_facts[i] = self._mod_inv_facts[i+1] * (i+1) % m

    def calc(self, n, r):
        # Return nCr mod m
        if n > self._n_max:
            raise Exception('n is larger than n_max')

        if r == 0:
            return 1

        m = self._m
        return self._mod_facts[n] * self._mod_inv_facts[r] * self._mod_inv_facts[n-r] % m

N, K = map(int, input().split())

MOD = 10**9 + 7

mcomb = ModComb(N, MOD)
for i in range(1, K+1):
    if N-K < (i-1) :
        print(0)
        continue
    b = mcomb.calc(K-1, i-1)
    # N-K-(i-1) を i+1に組分け
    p = mcomb.calc(N-K-(i-1) + i, i)
    #print(N-K-(i-1) + i, i)
    #print(b, p)
    print(b*p % MOD)


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    string S;
    cin >> N >> S;
    string ans={};
    rep(i,S.size()){
        int x;
        x=S[i]-'A';
        x+=N;
        if(x>=26) x-=26;
        ans+='A'+x;
    }
    cout << ans << endl;



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {

	int n,m;
	cin >> n >> m;
	if (n == m) cout << "Yes" << endl;
	else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,m;
  cin>>n>>m;
  int a[n-1];
  for(int i=0;i<n-1;i++) cin>>a[i];
  int s[n];
  s[0]=0;
  for(int i=0;i<n-1;i++) s[i+1]=s[i]+a[i];
  int b[m];
  for(int i=0;i<m;i++) cin>>b[i];
  int ans=0,pos=0;
  int mod=100000;
  for(int i=0;i<m;i++){
    int x=pos;
    pos+=b[i];
    int y=pos;
    if(x<y) swap(x,y);
    //cout<<x<<" "<<y<<":"<<s[x]-s[y]<<endl;
    ans+=s[x]-s[y];
    ans%=mod;
    //cout<<pos<<endl;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5436
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int a, b;
    cin >> a >> b;
    
    for (int i = b-a+1; i < b+a; i++) {
        cout << i << endl;
    }
    
    return 0;

}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
Ac = Counter(A)
flag = False
a = 0
b = 0
ac2 = sorted(Ac.items(),reverse=True)
for k,v in ac2:
    if v < 2:
        continue
    elif v >= 4:
        if flag:
            b = k
            break
        else:
            a = k
            b = k
            break
    else:
        if flag:
            b = k
            break
        else:
            a = k
            flag = True
print(a*b)

Measured memory_bytes: 21412
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int a, b;

  cin >> a >> b;

  cout << (a * b % 2 ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define oo 0x3f3f3f3f
#define ooLL 0x3f3f3f3f3f3f3f3f
#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL)
const int mod = 1e9+7;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
 
int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll sum = 0LL;
    while(d && (a || b || c)){
        if(a){
            if(a >= d) sum = d, d = 0;
            else sum = a, d -= a;
            a = 0;
        }
        if(!d) break;
        if(b){
            if(b >= d) break;
            else d -= b;
            b = 0;
        }
        if(!d) break;
        if(c){
            if(c >= d) sum -= d;
            else sum -= c;
            c = 0;
            break;
        }
    }

    printf("%lld\n", sum);
    return 0;
}

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

// update: overwrite
// query : minimun
// unit  : 2^31 - 1
template <class T>
struct SegmentTree {
    int length;
    std::vector<T> dat;
    T unit = (1U << 31) - 1;  // unit

    explicit SegmentTree(int n) : length(1) {
        while (length < n) {
            length <<= 1;
        }
        dat.assign(length * 2 - 1, unit);
    }

    T query(int ql, int qr, int nidx, int nl, int nr) {
        if (nr <= ql || qr <= nl) return unit;
        if (ql <= nl && nr <= qr) return dat[nidx];

        int nm = (nl + nr) / 2;
        T vl = query(ql, qr, nidx * 2 + 1, nl, nm);
        T vr = query(ql, qr, nidx * 2 + 2, nm, nr);
        return std::min(vl, vr);  // query
    }

    T query(int ql, int qr) { return query(ql, qr, 0, 0, length); }

    void update(int nidx, T elem) {
        nidx += length - 1;
        dat[nidx] = elem;  // update

        while (nidx > 0) {
            nidx = (nidx - 1) >> 1;
            T vl = dat[nidx * 2 + 1];
            T vr = dat[nidx * 2 + 2];
            dat[nidx] = std::min(vl, vr);  // query
        }
    }
};

int main() {
    int n;
    std::cin >> n;
    SegmentTree<uint> seg(n);

    int q;
    std::cin >> q;
    while (q--) {
        int t;
        std::cin >> t;

        if (t == 0) {
            int i;
            uint x;
            std::cin >> i >> x;
            seg.update(i, x);
        } else {
            int l, r;
            std::cin >> l >> r;
            std::cout << seg.query(l, r + 1) << std::endl;
        }
    }
    return 0;
}



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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;

int n;
int a[MAXN];

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	scanf ( "%d", &n );
	lpi ( i, 1, n ) scanf ( "%d", &a[i] );
}

void work ()
{
	// main work

	sort ( a+1, a+1+n );

	int la = 1;
	LL ns = a[1];
	lpi ( i, 2, n ){
		if ( ns * 2 < a[i] ){
			la = i;
		}
		ns += a[i];
	}

	printf ( "%d\n", n - la + 1 );
}

Measured memory_bytes: 640
#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++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;

int  main()
{
	int r,g; cin >> r >> g;
	cout << g*2 - r << endl;
	return (0);
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
using namespace std;
int main(){
	int n,r,s=0;
	cin>>n>>r;
	while(n)s++,n/=r;
	cout<<s;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int sort(const void *a,const void *b){
  return  *(int*)b-*(int*)a;
}
int main(void){
  int n,i,sum=0;
  int a[100];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  qsort((void*)a,n,sizeof(int),sort);
  for(i=0;i<n;i++){
    if(i%2==0){
      sum+=a[i];
    }else{
      sum-=a[i];
    }
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vector<int> dp(N + 1);
    rep(i, N) {
        if (A[i] == dp[i] + 1) dp[i + 1] = dp[i] + 1;
        else dp[i + 1] = dp[i];
    }
    write(dp[N] ? N - dp[N] : -1);
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll s,c,ans=0;
	cin>>s>>c;
	ans+=min(s,c/2);
	if(s>c/2){
		cout<<ans<<endl;
	}else{
		c-=s*2;
		ans+=c/4;
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdint>
#include <cstdlib>
#include <cstring>

namespace FastIO{static constexpr size_t E=(1<<17);static constexpr size_t T=23
,A=334;static constexpr char O[]="%.16f";FILE*e=stdin,*t=stdout;char a[E|1],*o,
*i;char n[E|1],*s,*h;inline size_t r(){size_t f=fread(a,1,E,e);*(i=a+f)=0;o=a;
return f;}inline size_t d(){std::ptrdiff_t f=i-o;if(a+f>=o){return 0;}memcpy(a,
o,f);size_t b=fread(a+f,1,E-f,e);*(i=a+(f+=b))=0;o=a;return b;}inline void l(d\
ouble&f){if(*o==0&&r()){f=0;return;}char*p;f=strtod(o,&p);while(p==o){if(!r()){
f=0;return;}f=strtod(o,&p);}if(p==i&&d()){f=strtod(a,&p);}o=p;}inline void l(c\
har&f){if(*o==0){r();}if((f=*o)!=0){++o;}}inline void l(char*f){while(1){if(*o
==0){if(!r()){*f=0;return;}}if(*o<=' '){++o;}else{break;}}for(char*p=o;;++o){if
(*o==0){memcpy(f,p,o-p);f+=o-p;if(!r()){*f=0;return;}p=o;}else if(*o<=' '){mem\
cpy(f,p,o-p);f+=o-p;*f=0;return;}}}template<class N>inline void l(N&f,typename
std::enable_if<std::is_signed<N>::value>::type*g=0){f=0;int y=0;if(o+T>=i){d();
}while(*o<'-'){++o;}if(*o=='-'){y=1;++o;}do{f=f*10+*o-'0';}while(*++o>='0');++o
;if(y){f=-f;}}template<class N>inline void l(N&f,typename std::enable_if<!std::
is_signed<N>::value>::type*g=0){f=0;if(o+T>=i){d();}while(*o<'+'){++o;}do{f=f*
10+*o-'0';}while(*++o>='0');++o;}inline void c(){fwrite(n,1,s-n,t);s=n;}inline
void u(char f){if(s+1>=h)c();*s++=f;}inline void u(const char*f){size_t g=strl\
en(f);if(s+g>=h){c();}if(s+g>=h){fwrite(f,1,g,t);}else{memcpy(s,f,g);s+=g;}}te\
mplate<size_t N>inline void u(const char(&f)[N]){if(s+N>=h){c();}if(s+N>=h){fw\
rite(f,1,N,t);}else{memcpy(s,f,N);s+=N;}}inline void u(double f){char g[A];siz\
e_t y=snprintf(g,A,O,f);char*p=s+y;if(p>=h){c();p=n+y;}memcpy(s,g,y);s=p;}temp\
late<class N>inline void u(N f,typename std::enable_if<std::is_signed<N>::value
>::type*g=0){if(s+T>=h){c();}if(f==0){*s++='0';return;}char v[T],*k=v+T,*j=k;if
(f<0){*s++='-';f=-f;}do{*--k=f%10+'0';f/=10;}while(f);memcpy(s,k,j-k);s+=j-k;}
template<class N>inline void u(N w,typename std::enable_if<!std::is_signed<N>::
value>::type*f=0){if(s+T>=h){c();}if(w==0){*s++='0';return;}char b[T],*v=b+T,*k
=v;do{*--v=w%10+'0';w/=10;}while(w);memcpy(s,v,k-v);s+=k-v;}struct Scanner{Sca\
nner(){o=a;i=a+E;r();}template<class Z>inline void scan(Z&&z){l(z);}template<c\
lass Z,class...Q>inline void scan(Z&&z,Q&&...q){l(z);scan(q...);}};struct Prin\
ter{Printer(){s=n;h=n+E;}~Printer(){c();}template<class Z>inline void print(Z z
){u(z);}template<class Z,class...Q>inline void print(Z z,Q...q){u(z);print(q...
);}template<class Z>inline void println(Z z){u(z);u('\n');}};}

FastIO::Scanner cin;

int main() {
  int N, x;
  cin.scan(N, x);

  intmax_t res=0, prev=0;
  for (int i=0; i<N; ++i) {
    unsigned a;
    cin.scan(a);

    if (a+prev > x) {
      res += a+prev-x;
      a = x-prev;
    }
    prev = a;
  }

  printf("%jd\n", res);
  return 0;
}


Measured memory_bytes: 256
"""
Match Matching
提出 #4299735 を参考に作成
"""


def solve():
	# 初期値の設定
	num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
	N, M = map(int, input().split())
	A = [int(i) for i in input().split()]
	A.sort(reverse=True)
	# 丁度n本で作成できる最大桁数を格納する.
	# 初期値は -inf (丁度使い切ることは不可能) としておく
	dp = [-1 * float("inf")] * (N + 1)

	# 動的計画法で丁度n本のマッチを使うときに作れる最大桁数を計算する
	dp[0] = 0
	for n in range(1, N + 1):
		for a in A:
			if n - num[a] >= 0:
				# マッチがnum[a]本あるときにaが作れるなら,
				# n - num[a]本の時よりも1桁多く作れるはず.
				# これをすべてのAに対して行い、その中で最大となった桁数を求める.
				dp[n] = max(dp[n], dp[n - num[a]] + 1)

	# 回答となる数値を算出
	ans = ''
	for i in range(dp[N]):  # dp[N]桁の数を上位の桁から決定していく
		for a in A:
			# num[a]本使って数を作ったとき,
			# N - num[a] 本で作れる桁数よりも N 本で作れる桁数のほうが1多い場合,
			# numを作っても最終的に作れる数の桁数は変わらない.
			# そのため dp[N] - 1 == dp[N - num[a]] を満たすような最大のAを作り,
			# 作成する数の上位桁に使用すればよい.
			# 同じ本数のマッチを使用する場合はより大きい数を採用する.
			# そのためAはあらかじめ降順にソートしておく.
			# 最初の条件で配列外アクセスを防ぐ
			if N - num[a] > -1 and dp[N] - 1 == dp[N - num[a]]:
				ans += str(a)
				N -= num[a]
				break
		# print('現在の残本数', N, '採用された数', a)

	print(ans)


if __name__ == '__main__':
	solve()


Measured memory_bytes: 3312