akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
/* data type, special numbers, defines */
//#define int ll //use if ded
#define ll long long
#define ld long double
const ll inf=LLONG_MAX;
//const ll mod=1e9+7;
const ll mod=998244353;
const ld pi=acos(-1.0);
#define all(v) v.begin(), v.end()
/* end data type and special numbers */
 
/* fast input.output */
#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define endl pc('\n')
int get_i(){
	char c=gc(); bool neg=false;
	for(; c<'0'||'9'<c; c=gc())
		if(c=='-') neg=true;
	int rs=c-'0'; c=gc();
	for(; '0'<=c && c<='9'; c=gc())
		rs=(rs<<1)+(rs<<3)+(c-'0');
	if(neg) rs=-rs;
	return rs;
}
ll get_l(){
	char c=gc(); bool neg=false;
	for(; c<'0'||'9'<c; c=gc())
		if(c=='-') neg=true;
	ll rs=c-'0'; c=gc();
	for(; '0'<=c && c<='9'; c=gc())
		rs=rs*10ll+(c-'0');
	if(neg) rs=-rs;
	return rs;
}
string get_s(){
	char c=gc();
	for(; c<33 || 126<c; c=gc());
	string s=""; s+=c; c=gc();
	for(; 33<=c && c<=126; c=gc())
		s+=c;
	return s;
}
char get_c(){
	char c=gc();
	for(; c<33 || 126<c; c=gc());
	return c;
}
void print_i(int _n){
	bool neg=false; if(_n<0) {neg=true; _n=-_n;}
	if(neg) pc('-');
	int N=_n, rev, count=0;
	rev=N;
	if(N==0) {pc('0'); return;}
	while((rev%10)==0) {count++; rev/=10;}
	rev=0;
	while(N!=0) {rev=(rev<<3)+(rev<<1)+N%10; N/=10;}
	while(rev!=0) {pc(rev%10+'0'); rev/=10;}
	while(count--) pc('0');
}
void print_l(ll _n){
	ll N=_n, rev, count=0;
	rev=N;
	if(N==0) {pc('0'); return;}
	while((rev%10)==0) {count++; rev/=10;}
	rev=0;
	while(N!=0) {rev=rev*10ll+N%10; N/=10;}
	while(rev!=0) {pc(rev%10+'0'); rev/=10;}
	while(count--) pc('0');
}
void print_s(string a){
	for(int i=0; i<a.size(); i++)
		pc(a[i]);
}
#define endline pc('\n');
#define space pc(' ');
/* end fast input/output */

/*   E N D   O F   T E M P L A T E   */

bool ok(string a){
	int l=0, r=a.size()-1;
	bool yes=true;
	while(l!=a.size()-1){
		if(a[l]!=a[r]){
			yes=false; break;
		}
		l++; r--;
	}
	return yes;
}
int main(){
	ld a; scanf("%Lf", &a);
	ld ans=pow(a, 3)/27.0;
	printf("%.10Lf\n", ans);
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top, S[1000];

int pop(){
  top--;
  return S[top+1];
}

void push(int x){
  S[top + 1] = x;
  top++;
}

int main(){
  int a, b, x;
  top = 0;
  char s[100];
  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      a = pop();
      b = pop();
      push(a + b);
    } else if ( s[0] == '-' ){
      a = pop();
      b = pop();
      push(b - a);
    } else if ( s[0] == '*' ){
      a = pop();
      b = pop();
      push(a * b);
    } else {
      x = atoi(s);
      push(x);
    }
  }
  printf("%d\n", pop());

  return 0;
}


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

constexpr int64_t mod = 1000000007;
vector<int64_t> fact, inv;

int64_t power(int64_t n, int64_t k) {
  if (k == 0) return 1;
  int64_t ans = power(n * n % mod, k / 2);
  if (k % 2) ans = ans * n % mod;
  return ans;
}

void init(int n) {
  fact.push_back(1);
  inv.push_back(1);
  for (int i = 0; i < n; i++) {
    fact.push_back((i + 1) * fact.at(i) % mod);
    inv.push_back(power(fact.at(i + 1), mod - 2));
  }
}

int64_t ncr(int n, int r) {
  if (n < r) return 0;
  return fact.at(n) * inv.at(r) % mod * inv.at(n - r) % mod;
}

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  init(n * m + k);
  int x = n * n * ncr(m + 1, 3) % mod + m * m * ncr(n + 1, 3) % mod;
  cout << x * ncr(n * m - 2, k - 2) % mod << endl;
}


Measured memory_bytes: 10464
# Problem C - Together

# input
N = int(input())
a_nums = list(map(int, input().split()))

# initialization
nums = [0]*(10**5 + 1)
max_count = 0

# count
for a in a_nums:
    nums[a] += 1

# max count
for i in range(10**5 + 1):
    if i==0 or i==10**5:
        continue

    tmp_count = nums[i-1] + nums[i] + nums[i+1]
    max_count = max(max_count, tmp_count)

# output
print(max_count)


Measured memory_bytes: 14008
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

class Edge{
public:
  int from, to;
  char cost;

  Edge(){}
  Edge(int from, int to, char cost) :
    from(from), to(to), cost(cost) {}
};

int n, s, g, A;
vector<Edge> t[10000], rt[10000];
int closed[10000];

void solve(){
  string ans;
  bool now[10000], next[10000];
  memset(now, 0, sizeof(now));
  memset(next, 0, sizeof(next));

  now[s] = true;

  for(int i = 0; i <= 6 * A; i++){
    if(now[g]){
      cout << ans << endl;
      return;
    }

    memset(next, 0, sizeof(next));

    char minCost = 127;

    for(int j = 0; j < n; j++){
      if(!now[j]) continue;
      for(int k = 0; k < t[j].size(); k++){
        if(closed[t[j][k].to] < 1) continue;
        char cost = t[j][k].cost;
        minCost = min(minCost, cost);
      }
    }

    if(minCost == 127){
      break;
    }

    for(int j = 0; j < n; j++){
      if(!now[j]) continue;
      for(int k = 0; k < t[j].size(); k++){
        if(closed[t[j][k].to] < 1) continue;
        int to = t[j][k].to;
        char cost = t[j][k].cost;
        if(cost == minCost){
          next[to] = true;
        }
      }
    }

    memcpy(now, next, sizeof(next));

    ans += minCost;
  }

  cout << "NO" << endl;
}

void deleteEdge(void){
  int next[10000];
  memset(closed, 0, sizeof(closed));
  closed[g] = 1;

  for(int i = 0; i <= 6 * A; i++){
    memset(next, 0, sizeof(next));

    for(int j = 0; j < n; j++){
      if(!closed[j]) continue;
      next[j] = true;
      for(int k = 0; k < rt[j].size(); k++){
        int to = rt[j][k].to;
        next[to] = 1;
      }
    }

    for(int j = 0; j < n; j++){
      closed[j] = next[j];
    }
  }
}

int main(){
  int N;

  while(cin >> N >> A >> s >> g, N || A || s || g){
    for(int i = 0; i < 10000; i++){
      t[i].clear();
      rt[i].clear();
    }

    n = N;

    for(int i = 0; i < A; i++){
      int X, Y;
      string LAB;
      cin >> X >> Y >> LAB;

      int before = X;

      for(int j = 0; j < LAB.length(); j++){
        int to;

        if(j == LAB.length() - 1) to = Y;
        else                      to = n++;

        t[before].push_back(Edge(before, to, LAB[j]));
        rt[to].push_back(Edge(to, before, LAB[j]));
        before = to;
      }
    }

    deleteEdge();

    solve();
  }
}

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

int solve(int n, int v[], int c[]);

int main(){
    int n; cin >> n;
    int v[n], c[n];
    for(int i=0; i<n; ++i) 
        cin >> v[i];
    for(int i=0; i<n; ++i) 
        cin >> c[i];
    
    cout << solve(n, v, c) << endl;
    
    return 0;
}

int solve(int n, int v[], int c[]){
    int ans = 0;
    for(int i=0; i<n; ++i){
        if(v[i] > c[i]){
            ans += v[i] - c[i];
        }
    }
    return ans;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

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

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

  ll h; cin >> h;
  ll ans = 0;
  ll now = 1;
  while(h > 0) {
    ans += now;
    now *= 2;
    h /= 2;
  }
  cout << ans << endl;

}


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

#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define ll   long long 
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;
 
#define md          1000000007
#define fmd         998244353 
#define M           1000011
#define N            18
ll exp(ll a,ll b){if(b<0)return 0;ll r=1;while(b){if(b&1)r=r*a%md,r%=md;a=a*a%md;b/=2;}return r;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
class BIT{
public:
    int n;
    vector<int> B;
    BIT(int sz){
        n=sz;
        B=vector<int> (n+1);
    }
    void add(int x,int y){
    	y%=md;
        for(;x<=n;x+=x&-x)B[x]+=y,B[x]%=md;
    }
    int sum(int x){int s=0;
        for(;x>=1;x-=x&-x)s+=B[x],s%=md;
        return s;
    }

};
ll a[M][2];
int solve(){
    ll n,i,j,k,m,x,y,z;
    cin>>n;
    a[n][0]=1;
    a[n][1]=n-1;

    BIT b(n);
    b.add(n,1);

    for(i=n-1;i>=1;--i){
    	a[i][0]+=(a[i+1][1]+a[i+1][0])%md;
    	a[i][1]=(n-1)*(n-1);a[i][1]%=md;
    	a[i][1]+=(b.sum(n)-b.sum(i+1)+md)%md;
    	a[i][1]+=(i);a[i][1]%=md;a[i][0]%=md;
    	b.add(i,a[i][0]);
    }
    cout<<(a[1][0]+a[1][1])%md<<"\n";
    die();
}
 
 
int main(){
 
 
#ifndef ONLINE_JUDGE
    double _tBeg=clock();
#endif

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

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

        solve();
    }
 
 
 
 


#ifndef ONLINE_JUDGE
    double _tEnd=clock();
    // printf("\ntotal time %.6f\n",(_tEnd-_tBeg)/CLOCKS_PER_SEC);
#endif
 
    die();
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
  long double ans=0;
  int n,k;
  cin>>n>>k;
  ans=k*pow(k-1,n-1);
  cout<<(long long int)ans<<endl;
}

Measured memory_bytes: 512
/* Simplicity and Goodness */
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 1e6+2;

vi co_op(N), used(N);

void solve()
{
    int n;
    scn(n);

    vi primes(n); map<int, int> fa;

    rep(i, 0, n) {
        scn(primes[i]);
        fa[primes[i]] ++;
    }

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

    rep(i, 0, n) {
        if(!co_op[primes[i]] and !used[primes[i]]) {
            for(int j=2*primes[i]; j<N; j+=primes[i])
                co_op[j] = 1;
            used[primes[i]] = 1;
        } 
    }

    int cnt = 0;

    rep(i, 0, n) {
        if(!co_op[primes[i]] and fa[primes[i]] == 1) 
            cnt ++;
    }

    prin(cnt);
}

int main()
{
    int t = 1;
    // scn(t);

    while(t --) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 21136
#include<iostream>
#include<algorithm>
using namespace std;
int MIN,MAX,n,sum,a,i;
int main(){
while(true){
cin>>n;if(!n){break;}
MIN=10000000;
MAX=0;sum=0;
for(i=0;i<n;i++){cin>>a;MIN=min(MIN,a);MAX=max(MAX,a);sum+=a;}
cout<<(sum-MIN-MAX)/(n-2)<<endl;
}
}

Measured memory_bytes: 1160
from collections import defaultdict
 
mod = 10 ** 9 + 7
n = int(input())
C = [int(input()) for i in range(n)]
 
for i in range(n - 1, 0, -1):
    if C[i] == C[i - 1]:
        del C[i]
        #重複部分を圧縮したCを作成
        
D = defaultdict(int)
ans = 1
for c in C:
    ans += D[c]
    D[c] = ans
    #print(D, ans)

print(ans % mod)

Measured memory_bytes: 31216
var
	N,W,wi,w0,vi,i,j,k,l:Longint;
	v:array[0..3,0..100]of Longint;
	c:array[0..3]of Longint;
	ans,now,noww:int64;
begin
	read(N,W);
	for i:=1 to N do begin
		read(wi,vi);
		if i=1 then w0:=wi;
		inc(c[wi-w0]);
		v[wi-w0,c[wi-w0]]:=vi;
	end;
	for i:=0 to 3 do begin
		for j:=1 to c[i] do begin
			for k:=j+1 to c[i] do begin
				if v[i,j]<v[i,k]then begin
					l:=v[i,j];
					v[i,j]:=v[i,k];
					v[i,k]:=l;
				end;
			end;
		end;
		v[i,0]:=0;
		for j:=1 to c[i] do inc(v[i,j],v[i,j-1]);
	end;
	ans:=0;
	now:=0;
	noww:=0;
	for i:=0 to c[0] do begin
		for j:=0 to c[1] do begin
			for k:=0 to c[2] do begin
				for l:=0 to c[3] do begin
					if(w0*(i+j+k+l)+j+k*2+l*3<=W)and(v[0,i]+v[1,j]+v[2,k]+v[3,l]>ans)then begin
						ans:=v[0,i]+v[1,j]+v[2,k]+v[3,l];
					end;
				end;
			end;
		end;
	end;
	writeln(ans);
end.

Measured memory_bytes: 128
import java.util.Scanner;

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

		int k;
		int ans = 0;

		k = sc.nextInt();
		if (k % 2 == 0) {
			ans = (k / 2) * (k / 2);
		} else {
			ans = ((k + 1) / 2) * (k / 2);
		}

		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 22740
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

const int64 mod = 998244353;

int64 mpow(int64 mm, int64 xx)
{
	if(xx == 0)
	{
		return 1;
	}
	int64 tmp = mpow(mm, xx / 2);
	tmp *= tmp;
	tmp %= mod;
	if(xx % 2 == 1)
	{
		tmp *= mm;
		tmp %= mod;
	}
	return tmp;
}

int main()
{
	int64 nn, ans = 0;
	cin >> nn;
	for(int64 ii = 1;ii <= nn;ii++)
	{
		if((int64)(log10(ii) + 1) % 2 == 1)
		{
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3928
#include<bits/stdc++.h>
using namespace std;
int read(){
	int x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int ans=0,sz[1000005];
int main(){
	int n=read(),m=read();
	for (int i=1;i<=m;i++){
		int u=read(),v=read();
		sz[u]++; sz[v]++;
	}
	for (int i=1;i<=n;i++){
		if (sz[i]%2==1){ans=1; break;}
	}
	if (ans==1) printf("NO\n");
	else printf("YES\n");
	return 0;
}

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

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

int main() {
    char a;
    cin >> a;
    if (a - 'A' < 26) {
        cout<<"A"<<endl;
    }else{
        cout << "a" << endl;
    }

    return 0;
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderTemplate {
    class Program {
        static void Main (string[] args) {
            var S = Console.ReadLine ();
            var N = S.Count ();
            foreach (var max in Enumerable.Range (1, N).Reverse ()) {
                var firsts = Enumerable.Range (0, N - max + 1);
                // Console.WriteLine (max);
                // PrintEnum (firsts);
                // foreach (var item in firsts.Select (i => String.Concat (S.Skip (i).Take (max)))) {
                //     Console.WriteLine (item);
                // }
                if (firsts.Any (i => S.Skip (i).Take (max).All (c => c == 'A' || c == 'C' || c == 'G' || c == 'T'))) {
                    Console.WriteLine (max);
                    return;
                }
            }
            Console.WriteLine (0);
            return;
        }
        /* Input & Output*/
        static int ReadInt () {
            return int.Parse (Console.ReadLine ());
        }
        static List<int> ReadInts () {
            return Console.ReadLine ().Split (' ').Select (c => int.Parse (c)).ToList ();
        }
        static List<List<int>> ReadColumns (int n) {
            /*
            入力例
            A1 B1
            A2 B2
            ...
            An Bn

            出力例
            [[A1,A2,...,An], [B1,B2,...,Bn]]
            */
            var seq = Enumerable.Range (0, n).Select (i => ReadInts ()).ToList ();
            return Enumerable.Range (0, seq.First ().Count ()).Select (i => seq.Select (items => items[i]).ToList ()).ToList ();
        }
        static void PrintEnum<T> (IEnumerable<T> list) {
            Console.Write (list.First ());
            foreach (var item in list.Skip (1)) {
                Console.Write ($" {item}");
            }
            Console.Write ("\n");
        }
        static void PrintLnEnum<T> (IEnumerable<T> list) {
            foreach (var item in list) {
                Console.WriteLine (item);
            }
        }

        /* Numeric Function */
        static int Fact (int n) {
            return Enumerable.Range (1, n).Aggregate (1, ((i, k) => i * k));
        }
        static int PermNum (int n, int m) {
            if (m > n) {
                return 0;
            }
            return Enumerable.Range (n - m, m + 1).Aggregate (1, ((i, k) => i * k));
        }
        static int CombNum (int n, int m) {
            return PermNum (n, m) / Fact (m);
        }
        // 最大公約数 (m ≧ n)
        static int GCD (int m, int n) {
            if (n == 0) {
                return m;
            } else {
                return GCD (n, m % n);
            }
        }
        // 最小公倍数 (m ≧ n)
        static int LCM (int m, int n) {
            return GCD (m, n) / (m * n);
        }

    }
}

Measured memory_bytes: 13268
#include <iostream>
using namespace std;
int main(){
	int b,a[6]={1,5,10,50,100,500},sum=0;
	for (int A=0;A<6;A++){
		cin>>b;
		sum+=b*a[A];
	}
	if (sum>=1000) cout<<1<<endl;
	else cout<<0<<endl;
	return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    string s;
    cin >> s;
    int y = 0;
    rep(i, 4) {
        y += s[i] - '0';
        y *= 10;
    }y/=10;
    int m = (s[5]-'0')*10 + s[6] - '0';
    int d = (s[8]-'0')*10 + s[9] - '0';
    if(y>= 2020) print("TBD");
    else if(y<=2018) print("Heisei");
    else {
        if(m >= 5) print("TBD");
        else  print("Heisei");
    }
}



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

int main() {
	long long n;
	cin >> n;
	int BASE = 26;
	string ans = "";
	while (0 < n) {
		n--;
		char c = 'a' + n % BASE;
		n /= BASE;
		ans.insert(ans.begin(), c);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
k,a,b=map(int,input().split())


bisket=1

cnt=a-bisket

if cnt>k:
    print(1+k)
    exit(0)

k-=cnt
bisket+=cnt

if a+2<=b:
    trade=k//2
    k-=trade*2
    
    bisket+=trade*(b-a)

    if k==1:
        bisket+=1
    
    print(bisket)


else:
    print(bisket+k)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)
#define int long long

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
    T f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

const int INF = 0x3f3f3f3f, N = 200003, M = N << 1, mod = 998244353;

int n, k;
int l[N], r[N];
int tr[N << 2];
int dp[N];

inline int ls(int p) {return p << 1;}
inline int rs(int p) {return p << 1 | 1;}

inline void pushup(int p) {tr[p] = (tr[ls(p)] + tr[rs(p)]) % mod;}

void modify(int x, int val, int l, int r, int p)
{
	if (l == r) {tr[p] += val; return;}
	int mid = (l + r) >> 1;
	if (x <= mid) modify(x, val, l, mid, ls(p));
	else modify(x, val, mid + 1, r, rs(p));
	pushup(p);
}

int getans(int ql, int qr, int l, int r, int p)
{
	if (ql <= l && r <= qr) return tr[p];
	int mid = (l + r) >> 1, ans = 0;
	if (ql <= mid) ans = getans(ql, qr, l, mid, ls(p));
	if (qr > mid) ans = (ans + getans(ql, qr, mid + 1, r, rs(p))) % mod;
	return ans;
}

signed main()
{
    n = gi <int> (), k = gi <int> ();
    for (int i = 1; i <= k; i+=1) l[i] = gi <int> (), r[i] = gi <int> ();
    dp[1] = 1;
    modify(1, 1, 1, n, 1);
    for (int i = 2; i <= n; i+=1)
    {
    	for (int j = 1; j <= k; j+=1)
    	{
    		if (i > l[j])
    		{
    			dp[i] = (dp[i] + getans(max(1ll, i - r[j]), max(1ll, i - l[j]), 1, n, 1)) % mod;
    		}
    	}
    	modify(i, dp[i], 1, n, 1);
    }
    printf("%lld\n", dp[n]);
    return 0;
}

Measured memory_bytes: 9412
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll n;
map<pair<ll,string>, ll> dp ;
string s = "ACGT" ;
const long long MOD = 1e9 + 7 ; 
bool ok(string x){
    if ( x.substr(0,3) == "AGC" || x.substr(1,3) == "AGC" ) return false;
    swap(x[0],x[1]) ; 
    if ( x.substr(0,3) == "AGC" || x.substr(1,3) == "AGC" ) return false;
    swap(x[0],x[1]) ; 
    swap(x[1],x[2]) ; 
    if ( x.substr(0,3) == "AGC" || x.substr(1,3) == "AGC" ) return false;
    swap(x[1],x[2]) ; 
    swap(x[2],x[3]);
    if ( x.substr(0,3) == "AGC" || x.substr(1,3) == "AGC" ) return false;
    return true ;
}
ll dfs(ll x, string last3){
    if ( x == n ){
        return 1 ;
    }
    if ( dp[make_pair(x,last3)] ) return dp[make_pair(x,last3)];
    ll ans = 0 ; 
    for(ll i = 0; i < 4; i++){
        if ( ok(last3 + s.substr(i,1) ) ){
            ans = ans % MOD + dfs(x + 1, last3.substr(1) + s.substr(i,1) )  % MOD ;
        }
    }
    return dp[make_pair(x,last3)] = ans % MOD ;
}
int main(){
    fastio
    cin >> n ;
    ll ans = dfs(0, "TTT") ;
    cout << ans << endl;
    return 0 ;
}


Measured memory_bytes: 896
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  int N=S.size();
  ll K;
  cin>>K;
  for(int i=0;i<N;++i) {
    if(S[i]=='a') continue;
    if(K>='z'-S[i]+1) {
      K -= 'z'-S[i]+1;
      S[i] = 'a';
    }
  }
  K %= 26;
  if(S[N-1]+K>'z') {
    S[N-1] = S[N-1]-'z'+'a'-1;
  }
  else S[N-1] += K;
  cout<<S<<endl;
}



Measured memory_bytes: 3752
/*
シェルソート
*/
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

type ints []int

func (s ints) String() string {
	var buf bytes.Buffer
	sep := ""
	for _, v := range s {
		buf.WriteString(fmt.Sprintf("%s%d", sep, v))
		sep = " "
	}
	return buf.String()
}

func insertionSort(a ints, g int) {

	// ソート済みエリアが右に進んでいくイメージ
	// 最初はa[0]だけがソート済みと考える．
	// a[i]で対象要素を選び，ソート済みエリアのどこに
	// 挿入できるか探す

	for i := g; i < len(a); i++ {
		for j := i; j-g >= 0; j -= g {
			if a[j-g] <= a[j] {
				// ソート済み
				break
			}
			v := a[j]
			a[j] = a[j-g]
			a[j-g] = v
		}
	}
}

func shellSort(a ints) {
	m := 1
	for m < len(a)/9 {
		m = 3*m + 1
	}
	for m > 0 {
		insertionSort(a, m)
		m /= 3
	}
}
func insertionSortForJudge(a ints, g int, cnt *int) {
	for i := g; i < len(a); i++ {
		for j := i; j-g >= 0; j -= g {
			if a[j-g] <= a[j] {
				// ソート済み
				break
			}
			v := a[j]
			a[j] = a[j-g]
			a[j-g] = v
			*cnt++
		}
	}
}
func createG(maxLen int) ints {
	m := 1
	ms := ints([]int{m})
	for {
		m = 3*m + 1
		if m < maxLen {
			ms = append(ms, m)
		} else {
			break
		}
	}
	return ms
}
func printAnswer(a, ms ints, cnt int) {
	fmt.Println(len(ms))
	fmt.Println(ms)
	fmt.Println(cnt)

	var buf bytes.Buffer
	for _, v := range a {
		buf.WriteString(fmt.Sprintf("%d\n", v))
	}
	fmt.Print(buf.String())
}
func shellSortForJudge(a ints) ([]int, int) {
	ms := reverse(createG(len(a)))
	cnt := 0
	for _, m := range ms {
		insertionSortForJudge(a, m, &cnt)
	}
	return ms, cnt
}
func reverse(a ints) ints {
	r := make(ints, len(a))
	for i := 0; i < len(a); i++ {
		r[i] = a[len(a)-1-i]
	}
	return r
}
func main() {
	reader := bufio.NewReader(os.Stdin)
	n := eGetInt(reader)
	a := make([]int, 0, n)
	for i := 0; i < n; i++ {
		a = append(a, eGetInt(reader))
	}
	ms, cnt := shellSortForJudge(a)
	printAnswer(a, ms, cnt)
}
func eGetLine(r *bufio.Reader) string {
	s, err := r.ReadString(byte('\n'))
	if err != nil {
		if err != io.EOF {
			log.Fatal(err.Error())
		}
		return s
	}
	return strings.TrimRight(s, "\r\n")
}
func eGetInt(r *bufio.Reader) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInts(r *bufio.Reader) []int {
	line := eGetLine(r)
	fields := strings.Split(line, " ")
	var ints []int
	for _, f := range fields {
		ints = append(ints, eAtoi(f))
	}
	return ints
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}



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

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	for (int i = 0;; i++)
	{
		if (i % 2 == 0)
		{
			if (c - b <= 0)
			{
				cout << "Yes" << endl;
				return 0;
			}
			c -= b;
		}
		else
		{
			if (a - d <= 0)
			{
				cout << "No" << endl;
				return 0;
			}
			a -= d;
		}
	}

	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int a,b; string s;
    cin>>a>>b>>s;
    int n=s.length();
    int flg=0, pp=1;
    for(ri int i=0;i<n;i++)
    {
        if(i==a&&s[i]=='-') { flg=1; continue; }
        if(i!=a&&s[i]>='0'&&s[i]<='9'&&pp) pp=1;
        else if(i!=a) pp=0;
    }
    if(pp&&flg) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
  int key;
  Node *right, *left;
};

Node *root, *NIL;

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while ( x != NIL ) {
    y = x;
    if ( z->key < x->key )
      x = x->left;
    else
      x = x->right;
  }

  if ( y == NIL ) {
    root = z;
  } else {
    if ( z->key < y->key )
      y->left = z;
    else
      y->right = z;
  }
}

void inorder(Node *u) {
  if ( u == NIL ) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node *u) {
  if ( u == NIL ) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n, i, x;
  string com;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    cin >> com;
    if ( com == "insert" ) {
      scanf("%d", &x);
      insert(x);
    } else if ( com == "print" ) {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}


Measured memory_bytes: 18908
import heapq

def main():
    n,m = map(int,input().split())
    e = [[] for _ in range(n)]
    for _ in range(m):
        a,b,c = map(int,input().split())
        e[a].append([b,c])
        e[b].append([a,c])

    inf = 1000000007
    d = [inf]*n
    d[0] = 0
    visited = [False]*n
    pq = [[0,0]]
    heapq.heapify(pq)
    while pq:
        c,v = heapq.heappop(pq)
        visited[v] = True
        for u,nc in e[v]:
            if not visited[u] and nc < d[u]:
                d[u] = nc
                heapq.heappush(pq,[nc,u])

    res = 0
    for i in range(n):
        res+=d[i]
    print(res)


if __name__ == '__main__':
    main()




Measured memory_bytes: 36404
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  cout<<max(A*B,C*D);
return 0;}

Measured memory_bytes: 3588
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007
//#define DEBUG 1

//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}
//qsort(data, 10, sizeof(int), compare_int)

int count, chh[8], chw[8], h, w, k, c[8][8], lim, now;

void dfs(int i, int j)
{
	if(now==lim) return;
	if(i+j==h+w){
		int black=0;
		for(int i=0; i<h; i++){
			for(int j=0; j<w; j++){
				if((chh[i]!= 1) && (chw[j]!=1) && (c[i][j]==1))
					black++;
			}
		}
		if(black == k) count++;
		now++;
		//printf("now:%d\n", now);
	}
	else if(i<h){
		chh[i] = 0;
		dfs(i+1, j);
		chh[i] = 1;
		dfs(i+1, j);
	}
	else if(j<w){
		chw[j] = 0;
		dfs(i, j+1);
		chw[j] = 1;
		dfs(i, j+1);
	}
}

int main(){
	scanf("%d%d%d", &h, &w, &k);
	char tmp;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			scanf(" %c", &tmp);
			if(tmp == '.') c[i][j] = 0;
			else c[i][j] = 1;
		}
	}

	#ifdef DEBUG
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			printf("%d", c[i][j]);
		}
		printf("\n");
	}
	#endif

	lim = pow(2, h+w);
	now = 0;
	dfs(0, 0);
	
	printf("%d\n", count);
	
	
	return 0;
}



Measured memory_bytes: 2536
S = input()

two_f = int(S[:2])
two_b = int(S[2:])

MMYY_flag = 0
YYMM_flag = 0

if 1 <= two_f <= 12:
    MMYY_flag = 1
if 1 <= two_b <= 12:
    YYMM_flag = 1

if MMYY_flag == 1 and YYMM_flag == 1:
    print('AMBIGUOUS')
elif MMYY_flag == 1:
    print('MMYY')
elif YYMM_flag == 1:
    print('YYMM')
else:
    print('NA')

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

int n;
const int sz = 2e5+5;
vector<int> adj[sz];
ll dp[sz];

void solve(){
    cin >> n;
    for(int i = 0; i < n-1; ++i){
        int u, v;
        cin >> u >> v;
        --u, --v;
        if(u > v) swap(u, v);
        adj[u].push_back(v);
    }
    
    dp[n] = 0;
    for(int i = n-1; i >= 0; --i){
        dp[i] = dp[i+1] + n-i;
        for(int node : adj[i]){
            dp[i] -= n-node;
        }
    }

    ll ans = 0;
    for(int i = 0; i < n; ++i) ans += dp[i];
    cout << ans << '\n';
}

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

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

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main() {
  int n;cin>>n;
  ll an[n];rep(i,n)cin>>an[i];
  sort(an,an+n);
  vector<bool> bn(1001001, false);
  
  int cnt=0;
  rep(i,n){
    vector<ll> div = divisor(an[i]);
    bool flg=false;
    for (auto x: div) {
      flg |= bn[x];
    }
    if (!flg) {
      cnt++;
      bn[an[i]]=true;
      if (i<n-1 && an[i]==an[i+1]) cnt--;
    }
  }
  cout<<cnt;
}


Measured memory_bytes: 5288
import java.util.*;

public class Main{
    static Scanner sc = new Scanner(System.in);
    static int n = sc.nextInt();
    static List<Node>[] edge = new ArrayList[n];
    static int[] arr = new int[n-1];
    static boolean[] visit = new boolean[n];
    static int[] used = new int[n];
    static int[] parent = new int[n];


    public static void main(String[] args){

        for (int i=0; i<n; i++){
            edge[i] = new ArrayList<>();
        }

        for (int i=0; i<n-1; i++){
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;
            edge[a].add(new Node(b, i));
            edge[b].add(new Node(a, i));
        }

        int k = 1;

        for (int i=0; i<n; i++){
            k = Math.max(k, edge[i].size());
        }

        System.out.println(k);
        arr[0] = 1;
        used[0] = 1;
        bfs();


        for (int i=0; i<n-1; i++){
            System.out.println(arr[i]);
        }
    }

    public static void bfs(){
        Queue<Integer> q = new ArrayDeque<>();
        ((ArrayDeque<Integer>) q).push(0);
//        visit[0] = true;
        while (!q.isEmpty()){
            int tmp = 0;
            int u = q.poll();
            int tmp_idx = 0;
            for (Node next : edge[u]){
                if (used[next.node]!=1){
                    tmp++;
                    used[next.node] = 1;
                    if (tmp==parent[u]){
                        tmp++;
                    }
                    arr[edge[u].get(tmp_idx).idx] = tmp;
                    parent[next.node] = tmp;
                    ((ArrayDeque<Integer>) q).push(next.node);
                }
                tmp_idx++;
            }
        }
    }

    public static class Node{
        int node;
        int idx;
        public Node(int n, int i){
            this.node = n;
            this.idx = i;
        }
    }

}


Measured memory_bytes: 104512
const lines = [];
const reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', function (line) {
  lines.push(line);
});
reader.on('close', function () {
  let N = +lines[0];

  while (N >= 1000) {
    N -= 1000
  }

  if (N > 0) {
    N = 1000 - N
  }

  console.log(N);

});

Measured memory_bytes: 30120
var reader = require ('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

var lines = []; 
reader.on('line', (line) => {
    lines.push(line) ;
});

reader.on ('close', () => {
    var line = lines[0];
    var elems = line.split(' ');
    var A = elems[1]
    var B = elems[2]
   var dif = B-A-1;
   if (dif%2 == 0) {
     console.log('Borys');
   } else if (dif%2 == 1){
     console.log ('Alice');
   }
   
  });

Measured memory_bytes: 9548
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n+1);
    map<ll,ll> left,right;
    rep(i,n){ 
        cin >> a[i];
        left[i+a[i]]++;
        right[i-a[i]]++;
    }
    ll ans = 0;

    for(auto e : left){
        ans += e.second * right[e.first];
    }

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

Measured memory_bytes: 38996
fn read() -> i32 {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().unwrap()
}

fn main() {
    let n = read();
    let k = read();
    let x = read();
    let y = read();

    let a = match n >= k {
        true => k * x,
        false => n * x,
    };
    let b = match n - k > 0 {
        true => (n - k) * y,
        false => 0,
    };
    println!("{}", a + b);
}


Measured memory_bytes: 4352
N,C=map(int,input().split())
Z=[list(map(int,input().split())) for i in range(N)]
Z.sort()
def judge(x):
  R=[[-1,-1] for i in range(x)]
  for i in range(N):
    for j in range(x):
      if R[j][1]==Z[i][2]:
        R[j][0]=Z[i][1]
        break
      if j==x-1:
        for k in range(x):
          if R[k][0]<Z[i][0]:
            R[k][0]=Z[i][1]
            R[k][1]=Z[i][2]
            break
          if k==x-1:
            return False
  return True

L,R,M=1,C,0
while L!=R:
  M=(L+R)//2
  if judge(M):
    R=M
  else:
    L=max(L+1,M)
print(L)

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

typedef long long ll;
typedef unsigned long long ull;

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

    static ll dp[3001][3001];
    for(int i=0;i<=s.size();i++) dp[i][0] = 0;
    for(int j=0;j<=t.size();j++) dp[0][j] = 0;

    for(int i=1;i<=s.size();i++){
        for(int j=1;j<=t.size();j++){
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if(s[i-1] == t[j-1]) dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
        }
    }

    int i=s.size(), j=t.size();
    stack<char> ans;
    while(dp[i][j]>0){
        if(s[i-1] == t[j-1]){
            ans.push(s[i-1]);
            i--;
            j--;
        }else{
            if(dp[i-1][j] > dp[i][j-1]) i--;
            else j--;
        }
    }

    while(!ans.empty()){
        cout << ans.top();
        ans.pop();
    }
    cout << endl;
    
    return 0;
}

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


void solve(long long H, long long A){
    cout<<ceil(1.0*H/A)<<endl;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long A;
    scanf("%lld",&A);
    solve(H, A);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
int cost[10]={-1,2,5,5,4,5,6,3,7,6};
vector<pair<int,string>> ers(vector<pair<int,string>> &vec){
    vector<pair<int,string>> ret;
    sort(ALL(vec));
    For(i,0,vec.size()){
        if(i==vec.size()-1 || vec[i].first<vec[i+1].first) ret.push_back(vec[i]);
    }
    sort(ALL(ret),[](auto l,auto r){return l.second>r.second;});
    return ret;
}
string comp(string a,string b){
    string s;
    if(a.size()>b.size()) s=a;
    else if(a.size()<b.size()) s=b;
    else if(a>b) s=a;
    else s=b;
    return s;
}
void Main(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,string>> vec;
    For(i,0,m){
        int a;
        cin >> a;
        string s="";
        s.push_back(char(a+'0'));
        vec.push_back({cost[a],s});
    }
    vec=ers(vec);
    m=vec.size();
    vector<vector<string>> dp(m+1,vector<string> (n+1,""));
    For(i,0,m){
        For(j,1,n+1){
            dp[i+1][j]=dp[i][j];
            if(j==vec[i].first) dp[i+1][j]=comp(dp[i+1][j],vec[i].second);
            if(j>vec[i].first && dp[i+1][j-vec[i].first]!=""){
                char c=vec[i].second[0];
                string s=dp[i+1][j-vec[i].first];
                s.push_back(c);
                dp[i+1][j]=comp(dp[i+1][j],s);
            }
        }
    }
    cout<<dp[m][n]<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 91320
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
// #include <unordered_map>
// #include <unordered_set>
#include <utility>
#include <vector>

#define pb push_back
#define mp make_pair
#define sqr(x) ((x) * (x))

#ifdef ONLINE_JUDGE
#define link renamelink
#define next renamenext
#define prev renameprev
#endif

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef long double ld;

inline void EnableFileIO(const string& fileName, bool local = 0) {
  if (fileName.empty()) return;
  if (local) {
    freopen((fileName + ".in").c_str(), "r", stdin);
    freopen((fileName + ".out").c_str(), "w", stdout);
    return;
  }
#ifdef ONLINE_JUDGE
  freopen((fileName + ".in").c_str(), "r", stdin);
  freopen((fileName + ".out").c_str(), "w", stdout);
#endif
}

const int INF = (1 << 30) - 1;
const LL LINF = (1LL << 61) - 1;
const double EPS = 1e-10, PI = acos(-1);
const int N = 200;

int n;
int cnt[N];
multiset<int> s;

void del(int k) {
  if (!cnt[k]) {
    cout << "Impossible" << endl;
    exit(0);
  }
  --cnt[k];
}

int main() {
  // srand((int)time(0));
  // printf("Hello, world!\n");
  // EnableFileIO("");

  cin >> n;
  int dia = 0;
  for (int i = 0, k; i < n; i++) {
    cin >> k;
    cnt[k]++;
    dia = max(dia, k);
  }
  for (int i = dia; i > dia / 2; i--) {
    del(i);
    del(i);
  }
  if (dia % 2 == 0) del(dia / 2);
  for (int i = 0; i <= (dia + 1) / 2; i++) {
    if (cnt[i]) del(0);
  }
  cout << "Possible" << endl;

  return 0;
}


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

int main() {
  int D;
  cin >> D;
  vector<int> c(26);
  for(int i = 0; i < 26; i++){
    cin >> c.at(i);
  }
  vector<vector <int>> s(D, vector<int>(26));
  for(int i = 0; i < D; i++){
    for(int j = 0; j < 26; j++){
      cin >> s.at(i).at(j);
    }
  }
  vector<int> t(D);
  for(int i = 0; i < D; i++){
    cin >> t.at(i);
  }
  vector<int> l(26);
  int v = 0;
  
  for(int i = 0; i < D; i++){
    v += s.at(i).at(t.at(i) - 1);
    l.at(t.at(i) - 1) = i + 1;
    for(int j = 0; j < 26; j++){
      v -= c.at(j) * (i + 1 - l.at(j));
    }
    cout << v << endl;
  }
}

Measured memory_bytes: 3600
from collections import deque

def getInts():
    return [ int(x) for x in input().split() ]

def f(A,B):
    return A**5 - B**5

[X] = getInts()
Q = deque([(0,0)])
V = set()
A, B = 0,0
r = []
while not r:
    (A,B) = Q.pop()
    l = [(A+1,B),(A,B+1),(A+1,B+1)]
    l = filter(lambda x: x not in V, l)
    for each in l:
        V.add(each)
        Q.appendleft(each)
    
    r = list(filter(lambda x: f(*x)==X, [(A,B), (A,-B), (-A,B), (-A, -B)]))

print(r[0][0], r[0][1])

Measured memory_bytes: 10696
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cii(n);
    cii(m);
    auto ans = m + max(0, (10 - n) * 100);
    co(ans);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
  int **G,n,u,k,v,i,j;
  scanf("%d",&n);
  G = (int**)malloc(sizeof(int) * (n + 1));
  for(i=0; i<=n; i++){
    G[i] = (int*)malloc(sizeof(int) * (n + 1));
    for(j=1; j<=n; j++) G[i][j] = 0;
  }
  for(i=1; i<=n; i++){
    scanf("%d%d",&u,&k);
    for(j=1; j<=k; j++) for(; k>0; k--){
      scanf("%d",&v);
      G[u][v] = 1;
    }
  }
  for(i=1; i<=n; i++) for(j=1; j<=n; j++) printf((j != n ? "%d " : "%d\n"),G[i][j]);
  return 0;
}

Measured memory_bytes: 636