akhauriyash/Code-Regression huggingface dataset:
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

N, M = MI()
K, switch = [], []

for _ in range(M):
    k, *s = MI()
    K.append(k)
    switch.append(s)
    
p = LI()
ans = 0

for i in range(1 << N):
    on = [False] * N
    
    for j in range(N):
        if (i >> j) & 1:
            on[j] = True
    
    can = True
    
    for k in range(M):
        tmp = 0
        for s in switch[k]:
            tmp += on[s - 1]
            
        if tmp % 2 != p[k]:
            can = False
            break
    
    ans += can
    
print(ans)

Measured memory_bytes: 73680
n = int(input())
h = list(map(int,input().split()))

dp =[0 for k in range(n)]
dp[1] =abs(h[1]-h[0])
for i in range(2,n):
    dp[i] =min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]))
print(dp[n-1])

Measured memory_bytes: 52720
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;

int main() {
    double n;
    cin >> n;
    int a=0,b=0,c=0,sum=0;
    rep(i,n){
        int f;
        cin >> f;
        if (f==1) {a++;sum++;}
        else if (f==2) {b++;sum+=2;}
        else {c++;sum+=3;}
    }
    int nn=n;
    double dp[nn+1][nn+1][nn+1];
    rep(i,nn+1){
        rep(j,nn+1){
            rep(k,nn+1) dp[i][j][k]=0;
        }
    }
    dp[a][b][c]=1;
    double ans=0;
    rep(i,sum){
        rep(j,nn+1){
            rep(k,nn+1){
                int t=sum-i-j-k*2;
                if (t>c*3 || t%3!=0 || t<0) continue;
                t/=3;
                if (dp[j][k][t]==0) continue;
                double jj=j,kk=k,tt=t;
                double s=j+k+t;
                if (j!=0) dp[j-1][k][t]+=dp[j][k][t]/s*jj;
                if (k!=0) dp[j+1][k-1][t]+=dp[j][k][t]/s*kk;
                if (t!=0) dp[j][k+1][t-1]+=dp[j][k][t]/s*tt;
                ans+=dp[j][k][t]*n/s;
            }
        }
    }
   cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 213248
#include <iostream>

using namespace std;


int main() {
  int a, b, x;
  
  cin >> a >> b >> x;
  
  if (a+b == x){
    cout << "YES" << endl;
  }
  else{
    if (a > x || a+b < x){
      cout << "NO" << endl;
    }
    else{
      if (a + b > x){
        cout << "YES" << endl;
      }
    }
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,q;
    string s;
    cin>>n>>q>>s;
    vector<int> a(n);
    repi(i,1,n){
        a[i]=a[i-1];
        if(s[i-1]=='A'&&s[i]=='C') a[i]++;
    }
    vector<int> l(q),r(q);
    rep(i,q){
        cin>>l[i]>>r[i];
        cout<<a[r[i]-1]-a[l[i]-1]<<endl;
    }
}

Measured memory_bytes: 4524
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
const int MaxN = 1e5;
char a[MaxN + 5];
int k;

int main()
{
	scanf("%s", a);
	scanf("%d", &k);
	for(int i = 0; i < strlen(a); i++)
	{
		if(k == 0) break;
		if(a[i] == 'a') continue;
		else if((k - 1) >= 'z' - a[i])
		{
			k = k - 'z' + a[i] - 1;
			a[i] = 'a';
		}
		else
		{
			continue;
		}
	}
	int len = strlen(a);
	if(a[len - 1] == 'a')
	{
		a[len - 1] += k % 26;
		k = 0;
	}
	else
	{
		a[len - 1] += k;
		k = 0;
	}
    puts(a);
	return 0;
}

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

using namespace std;

static const int maxn = 1e5 + 5;

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



      int n;
      cin >> n;
      vector <long long> vec(n);
      for (long long &x : vec) cin >> x;
      long long ans = 0;
      for (int i = 0; i < n; i++)
      {
            for (int j = i + 1; j < n; j++)
            {
                  ans += vec[i] * vec[j];
            }
      }
      cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b;i++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const ll mod = 1e9 + 7;



int main(){
    int a,b,h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
total = 1
count = 0
for i in range(n):
    total *= A[i]
    if total > 10**18:
        count += 1
        break

if 0 in A:
    print('0')
elif count == 1:
    print('-1')
else:
    print(total)

Measured memory_bytes: 21644
#include <bits/stdc++.h>
using namespace std;
//char型から数値型に変換する関数（z.at(i)などに使用）
int ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
int main() {
  int64_t n,k;
  cin>>n>>k;
  vector<int64_t> h(n);
  for(int i=0;i<n;i++){
    cin>>h.at(i);
  }
  sort(h.begin(),h.end());
  vector<int64_t> sa(n-k+1);
  for(int i=0;i<(n-k+1);i++){
    sa.at(i)=h.at(k-1+i)-h.at(0+i);
  }
  sort(sa.begin(),sa.end());
  cout<<sa.at(0);
}


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

#define M 500000
#define P 10
#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root;

void insert(int);
void inorder(Node);
void preorder(Node);



int main() {

  int m,k,i;
  char s[10];

  scanf("%d",&m);

  for (i=0 ; i<m ; i++){
    scanf("%s",s);

    if(s[0]=='i'){
      scanf("%d",&k);
      insert(k);
    }

    else {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}

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

  z = malloc(sizeof(struct 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;
  }

  z->parent=y;

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

}

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


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

Measured memory_bytes: 24040
//A.cpp
#include <iostream>
#include <string>
#include <map>
using namespace std;

long long gcd(long long a, long long b);

int main(){
  int N;
  cin >> N;
  long long T,G,Ans;
  cin >> Ans;
  for(int i = 1; i < N; i++){
    cin >> T;
    G = gcd(Ans,T);
    if(G==1) Ans = T*Ans;
    else Ans = T*(Ans/G);
  }

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

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


Measured memory_bytes: 256
#include <iostream>

int insertionSort(int A[], int n, int g) {
    int j;
    int cnt = 0;
    for (int i=g; i<n; i++) {
        int v = A[i];
        j = i - g;
        while (j >= 0 && A[j] > v) {
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j+g] = v;
    }
    return cnt;
}

int shellSort(int A[], int n) {
    int m = n;
    int G[25];
    int i=0;
    int cnt=0;
    
    while (true) {
        G[i] = m;
        if (m == 1)
            break;
        else
            m /= 2;
        i++;
    }
    
    std::cout << i+1 << std::endl;

    for (int j=0; j<=i; j++) {
        std::cout << G[j] << " ";
        cnt += insertionSort(A, n, G[j]);
    }
    std::cout << std::endl;
    return cnt;
}

int main() {
    int A[1000000];
    int n;

    // input
    std::cin >> n;
    for (int i=0; i<n; i++) std::cin >> A[i];

    // sort
    int cnt = shellSort(A, n);
    
    // output
    std::cout << cnt << std::endl;
    for (int i=0; i<n; i++) std::cout << A[i] << std::endl;

    return 0;
}



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

long func(int n, char s[]){
    int ii1, ii2, p;
    long sum_max;
    long RGB[3] = {0, 0, 0};
    for(ii1=0; ii1<n; ii1++){
        if(s[ii1] == 'R') RGB[0]++;
        if(s[ii1] == 'G') RGB[1]++;
        if(s[ii1] == 'B') RGB[2]++;
    }
    sum_max = RGB[0]*RGB[1]*RGB[2];
    for(ii1=0; ii1<n-2; ii1++){
        for(ii2=ii1+1; ii2<n-1; ii2++){
            p = 2*ii2 - ii1;
            if(n > p && (s[ii1] != s[ii2] && s[ii2] != s[p]
               && s[ii1] != s[p])){
                  sum_max--;
               }
        }
    }

    return sum_max;
}

int main(void){
    int n;
    long sum;
    scanf("%d", &n);
    char s[4001];
    scanf("%s", s);
    sum = func(n, s);
    printf("%ld\n", sum);

    return 0;
}


Measured memory_bytes: 1740
import java.util.*;
public class Main {
	static int k, n = 0;
	static int [] w;
	public static int binSearch(int [] arr, int l, int r,  int trucks) {
		int smallestP = -1;
		
			
			
			int m = (l + r) / 2;
			
			
			
			
			while(l <= r) {
				
				if(loadTrucks(m)) {
					smallestP = m;
					r = m - 1;
					m = (l + r) / 2;
				}
				
				
				else {
					l = m + 1;
					m = (l + r) / 2;
				}
			}
		
		return smallestP;
	}
	
	public static boolean loadTrucks(int p) {
		int i = 0;
		int trucks = 0;
		int sum = 0;
		
		while(i < n && trucks < k) {
			sum = 0;
			while(i < n && sum + w[i] <=p) {
				sum += w[i];
				i++;
			}
			
			trucks++;
		}
		
		return i == n;
		
		
		
		
		
	
				
				
			
			
			
	}
	
	public static void main(String [] args) {
		Scanner in = new Scanner(System.in);
		
		n = in.nextInt();
		k = in.nextInt();
		w = new int [n];
		int sum = 0;
		
		
		for(int i = 0; i < n; i++) {
			int j = in.nextInt();
			sum += j;
			w[i] = j;
		}
		
		System.out.println(binSearch(w, 0, sum, k));
		
	
		
	}
		
		
		

}



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

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, d, x;
    cin >> n >> d >> x;
    int r = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        int p = 0;
        while (p * a + 1 <= d) {
            r++;
            p++;
        }
    }
    cout << r + x << endl;

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int64_t> A(N);
    rep(i, 0, N) cin >> A.at(i);
    int64_t ans = 0;
    int64_t sum = 0;
    int count = 1;
    for (int l = 0; l < N; l++){
        int64_t x = A.at(l);
        if (l == 0) sum += x;
        while(true){
            if (l + count >= N){
                while(count >= 1){
                    ans += count;
                    count--;
                }
                goto SKIP;
            }
            int64_t y = A.at(l + count);
            
            if ((sum + y) == (sum xor y)){
                count++;
                sum += y;
            }
            else{
                ans += count;
                sum -= x;
                count --;
                break;
            }
        }
    }
    SKIP:
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define int long long
using namespace std;
signed main() {
	int A, B, X;
	cin >> A >> B >> X;

	if (A <= X && (A + B) >= X) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

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

const int MAXN = 1005;
const int MAXV = MAXN * (MAXN-1) / 2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
int toId(int i, int j){
  if (i > j) swap(i, j);
  return id[i][j];
}

bool visited[MAXV];
bool calculated[MAXV];
int dp[MAXV];

int dfs(int v){
  if (visited[v]){
    if (!calculated[v]) return -1;
    return dp[v];
  }
  visited[v] = true;
  dp[v] = 1;
  for(int u: to[v]){
    int res = dfs(u);
    if (res == -1) return -1;
    dp[v] = max(dp[v], res+1);
  }
  calculated[v] = true;
  return dp[v];
}

int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n-1));
  rep(i, n){
    rep(j, n-1){
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  int V = 0;
  rep(i, n)rep(j, n){
    if (i<j){
      id[i][j] = V++;
    }
  }
  rep(i, n){
    rep(j, n-1){
      a[i][j] = toId(i, a[i][j]);
    }
    rep(j, n-2){
      to[a[i][j+1]].push_back(a[i][j]);
    }
  }
  int ans = 0;
  rep(i, V){
    int res = dfs(i);
    if (res == -1){
      puts("-1");
      return 0;
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 41760
function main() {
  var
  stack = [];
  input[0].split(' ').forEach(function (op) {
    var
    x, y;
    switch(op) {
    case '+':
      y = stack.pop();
      x = stack.pop();
      return stack.push(x + y);
    case '-':
      y = stack.pop();
      x = stack.pop();
      return stack.push(x - y);
    case '*':
      y = stack.pop();
      x = stack.pop();
      return stack.push(x * y);
    default:
      stack.push(Number(op));
    }
  });
  console.log(stack[0]);
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split(/\n\r|\n|\r/);
  main();
});

Measured memory_bytes: 7644
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1LL<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return ((a%md)*(b%md))%md;}
int addmod(int a, int b, int md) {return (a+b)%md;}
int submod(int a, int b, int md) {return (((a-b)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
 
 
signed main(void)
{
	IOS;
	int n; cin>>n;
	map<string,int> m;
	for(int i = 0; i <n; i++) {
		string s; cin>>s;
		if(m.find(s)!=m.end())
			m[s]++;
		else
			m[s]=1;
	}
	int mx=0;
	for(auto it=m.begin(); it!=m.end();it++) {
		mx=max(it->ss,mx);
	}
	set<string> ans;
	for(auto it=m.begin(); it!=m.end(); it++) {
		if(it->ss==mx) {
			ans.insert(it->ff);
		}
	}
	for(auto it=ans.begin(); it!=ans.end(); it++) {
		cout<<*it<<endl;
	}
	return 0;
}

Measured memory_bytes: 33280
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>

using namespace std;

int main() {

	int N;
	cin >> N;
	map<int64_t, int> A;

	for (int i = 0; i < N; i++) {
		int64_t a;
		cin >> a;
		A[a]++;
		if (A[a] == 2) {
			cout << "NO";
			return 0;
		}
	}

	cout << "YES";


}

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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
  
  	ll X;
  	cin >> X;
  
  	if(X==3 || X==5 || X==7)
    {
      cout << "YES" << endl;
    }
  
  	else
    {
      cout << "NO" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

enum OXD { O = 0, X = 1, D = 2};

char hyou[7][7];

OXD hantei(void) {
	for (int i = 2; i < 5; i++) {
		for (int j = 2; j < 5; j++) {
			if (hyou[i][j] == 'o') {
				if (hyou[i][j+1] == 'o' && hyou[i][j+2] == 'o') {
					return O;
				}

				if (hyou[i+1][j] == 'o' && hyou[i+2][j] == 'o') {
					return O;
				}

				if (hyou[i+1][j+1] == 'o' && hyou[i+2][j+2] == 'o') {
					return O;
				}

				if (hyou[i+1][j-1] == 'o' && hyou[i+2][j-2] == 'o') {
					return O;
				}
			}
		}
	}

	for (int i = 2; i < 5; i++) {
		for (int j = 2; j < 5; j++) {
			if (hyou[i][j] == 'x') {
				if (hyou[i][j+1] == 'x' && hyou[i][j+2] == 'x') {
					return X;
				}

				if (hyou[i+1][j] == 'x' && hyou[i+2][j] == 'x') {
					return X;
				}

				if (hyou[i+1][j+1] == 'x' && hyou[i+2][j+2] == 'x') {
					return X;
				}

				if (hyou[i+1][j-1] == 'x' && hyou[i+2][j-2] == 'x') {
					return X;
				}
			}
		}
	}

	return D;
}

int main() {
	char a;
	OXD h;
	while (cin >> a) {
		for (int i = 0; i < 7; i++) {
			for (int j = 0; j < 7; j++) {
				hyou[i][j] = 's';
			}
		}
		hyou[2][2] = a;
		cin >> hyou[2][3] >> hyou[2][4];
		for (int i = 3; i < 5; i++) {
			for (int j = 2; j < 5; j++) {
				cin >> hyou[i][j];
			}
		}
		h = hantei();
		if (h == O) {
			cout << 'o' << endl;
		} else if (h == X) {
			cout << 'x' << endl; 
		} else {
			cout << 'd' << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1132
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#define	MOD  1000000007;
#define PI = 3.14159265358979323846;
using namespace std;

int pow(int a, int b)
{
	if (b == 0) {
		return 1;
	}
	if (b % 2 == 0)
	{
		return pow(a*a, b / 2);
	}
	else {
		return pow(a*a, b / 2) * a;
	}

	return 0;
}

int main()
{
	long long N;
	cin >> N;
	long long a[100000];
	set<long long>s;

	for (long long i = 1; i * i <= N; i++)
	{
		if (N % i == 0)
		{
			s.insert(i);
			s.insert(N / i);
		}
	}
	vector<int> v(s.begin(), s.end());
	int d = v.size() / 2;

	int C = 0;
	if (v.size() == 1)
	{
		C = 1;
	}
	else if (v.size() % 2 == 0)
	{
		C = v[d];
	}
	else {
		C = v[d];
	}
	int digits = 0;
	while (true)
	{
		C /= 10;
		digits++;
		if (C == 0)
		{
			break;
		}
	}
	cout << digits << endl;
}

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

using namespace std;
typedef long long ll;

const ll mod=1000000007;

ll fpow(ll b,ll e)
{
    ll res=1;
    while(e)
    {
        if(e&1) res=(res*b)%mod;
        b=(b*b)%mod;
        e/=2;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int k;
    cin >> k;
    string s;
    cin >> s;
    int n=s.size();
    vector<ll> f(n+k+1,1);
    for(ll i=1;i<=n+k;i++) f[i]=(f[i-1]*i)%mod;
    vector<ll> finv(n+k+1,1);
    finv[n+k]=fpow(f[n+k],mod-2);
    for(ll i=n+k-1;i>=0;i--) finv[i]=(finv[i+1]*(i+1))%mod;
    auto ch=[&](ll a,ll b)->ll
    {
        ll res=f[a];
        res=(res*finv[b])%mod;
        res=(res*finv[a-b])%mod;
        return res;
    };
    ll res=0;
    for(int j=n-1;j<=n+k-1;j++)
    {
        ll now=fpow(26,n+k-j-1);
        now=(now*fpow(25,j-(n-1)))%mod;
        now=(now*ch(j,n-1))%mod;
        res=(res+now)%mod;
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 35664
#include<iostream>
int R,C,s[10000][10],f[10],N,i,j,n,m;void rec(int k){if(k<R){f[k]=0;rec(k+1);f[k]=1;rec(k+1);}else for(n=i=0;i<C;i++,n+=m>R-m?m:R-m){for(m=j=0;j<R;j++)m+=s[i][j]^f[j];}N=N>n?N:n;}main(){for(;std::cin>>R>>C,R|C;rec(0),printf("%d\n",N))for(j=R;j-->0;)for(i=C;i-->0;)std::cin>>s[i][j];}

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

using Weight = int;
using Flow = int;
struct Edge {
    int s, d; Weight w; Flow c;
    Edge() {};
    Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

struct Dinic {
    int n, s, t;
    vector<int> level, prog, que;
    vector< vector< Flow > > cap, flow;
    vector< vector < int > > g;
    Flow inf;
    Dinic(const Graph &graph)
        : n(graph.size()),
        cap(n, vector<Flow>(n)),
        flow(n, vector<Flow>(n)),
        g(n, vector<int>()),
        inf(numeric_limits<Flow>::max() / 8) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < graph[i].size(); j++) {
                    Edge e = graph[i][j];
                    int u = e.s, v = e.d;
                    Flow c = e.c;
                    cap[u][v] += c;
                    cap[v][u] += c;
                    flow[v][u] += c;
                    g[u].push_back(v);
                    g[v].push_back(u);
                }
            }
        }
    inline Flow residue(int u, int v) { return cap[u][v] - flow[u][v]; }
    Flow solve(int s_, int t_) {
        this->t = t_, this->s = s_;
        que.resize(n + 1);
        Flow res = 0;
        while (levelize()) {
            prog.assign(n, 0);
            res += augment(s, inf);
        }
        return res;
    }
    bool levelize() {
        int l = 0, r = 0;
        level.assign(n, -1);
        level[s] = 0;
        que[r++] = s;
        while (l != r) {
            int v = que[l++];
            if (v == t) break;
            for (int i = 0; i < g[v].size(); i++) {
                int d = g[v][i];
                if (level[d] == -1 && residue(v, d) != 0) {
                    level[d] = level[v] + 1;
                    que[r++] = d;
                }
            }
        }
        return level[t] != -1;
    }
    Flow augment(int v, Flow lim) {
        Flow res = 0;
        if (v == t) return lim;
        for (int &i = prog[v]; i < (int)g[v].size(); i++) {
            const int &d = g[v][i];
            if (residue(v, d) == 0 || level[v] >= level[d]) continue;
            const Flow aug = augment(d, min(lim, residue(v, d)));
            flow[v][d] += aug;
            flow[d][v] -= aug;
            res += aug;
            lim -= aug;
            if (lim == 0) break;
        }
        return res;
    }
};

int N;
int a[100],b[100],c[100],d[100];
int main(){
    cin >> N;
    // 2部グラフ + Start + Goal
    Graph G(N*2+2);
    REP(i,N) cin >> a[i] >> b[i];
    REP(i,N) cin >> c[i] >> d[i];
    REP(i,N) REP(j,N) if(a[i] < c[j] && b[i] < d[j]) G[i].emplace_back(i,j+N,1);
    int s = N*2, g = N*2+1;
    REP(i,N) G[s].emplace_back(s,i,1);
    REP(i,N) G[i+N].emplace_back(i+N,g,1);
    // できるペアの最大数＝コスト１での最大流
    Dinic dn(G);
    cout << dn.solve(s,g) << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	ll n; cin>>n;
  ll ans=0;
  rep(i,0,n){
	ll a; cin>>a;
    if(a%2==1)ans++;
  }
if(ans%2==0)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

    


	
	return 0;
}

Measured memory_bytes: 3580
# D
n = int(input())
a = list(map(int, input().split()))

l_minus = [i for i in a if i <= 0]
l_plus = [i for i in a if i > 0]

ans = 0
if len(l_minus) % 2 == 0:
    l_minus_edit = [-i for i in l_minus]
else:
    l_minus_edit = [-i for i in l_minus]
    temp = l_plus[:]
    temp.extend(l_minus_edit)
    l_minus_edit.append(-min(temp) * 2)

ans = sum(l_plus) + sum(l_minus_edit)
print(ans)


Measured memory_bytes: 14332
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
constexpr int MOD = 1e9 + 7;

int n, a[200020];
long dp[200020];
vector<int> b;
vector<int> cnt[200020];


int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  cin >> n;
  for(int i = 0; i < n; ++i) cin >> a[i];
  for(int i = 0; i < n; ++i) {
    b.push_back(a[i]);
    int tmp = i;
    while(a[i+1] == a[tmp]) ++i;
  }

  n = b.size();
  for(int i = 0; i < n; ++i) cnt[b[i]].push_back(i);

  dp[0] = 1; // 1 | 2 1 2 2
  for(int i = 0; i < n; ++i) {
    (dp[i+1] += dp[i]) %= MOD;
    // ikko mae no onaji suuji
    int idx = lower_bound(cnt[b[i]].begin(), cnt[b[i]].end(), i) - cnt[b[i]].begin();
    if(idx > 0) (dp[i+1] += dp[cnt[b[i]][idx-1]+1]) %= MOD;
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 14324
#include<iostream>
#include<cmath>
#include <iomanip>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;
using LL = long long;

LL a, b, n;

int main() {

	cin >> a >> b >> n;

	cout<<floor(a * min(b - 1, n) / b) - a * floor(min(b - 1, n) / b)<<endl;

	return 0;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
int n,ans=0;
int a[111111];
int used[111111];

int dfs(int i){
  if(used[i]==1){
    ans++;
    return i;
  }
  if(used[i]==2)return -1;
  used[i]=1;
  int t=dfs((i+a[i])%n);
  if(t!=i&&t!=-1){
    ans++;
    used[i]=2;
    return t;
  }else{
    used[i]=2;
    return -1;
  }
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    if(i==dfs(i));
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 7004
import sys
from itertools import combinations, permutations
input = sys.stdin.readline
N, K = [int(x) for x in input().strip().split()]
d = {}

pascals_triangle = [1] * 2001
pascals_triangle[0] = [1]
for i in range(1, 2001):
    pascals_triangle[i] = [pascals_triangle[i-1][0]] * (i+1)
    for j in range(1, i):
        pascals_triangle[i][j] = pascals_triangle[i-1][j-1] + pascals_triangle[i-1][j]

for i in range(1, K + 1):
    if i > N - K + 1:
        print(0)
        continue
    ans = 0
    blue_ball = pascals_triangle[K-1][i-1]
    red_ball = pascals_triangle[N-K+1][i]
    ans += (blue_ball * red_ball) % (10 ** 9 + 7)
    print(ans)

Measured memory_bytes: 340980
N = int(input())
S = []
cnt = 0


for i in range(N):
    S.append(input()) #Nこの文字列を読み込み　行列

S.sort()
for i in range(0,N-1):
    if (S[i] == S[i+1]):
        cnt += 1

ans = N - cnt



print(ans)



Measured memory_bytes: 23860
import sys
import heapq
input = sys.stdin.readline


def dijkstra(s, E):
    inf = float('inf')
    d = [inf for i in range(len(E))]
    d[s] = 0
    q = [(0, s)]
    heapq.heapify(q)
    while q:
        c, p = heapq.heappop(q)
        if d[p] < c:
            continue
        for cost, to in E[p]:
            if d[to] > d[p] + cost:
                d[to] = d[p] + cost
                heapq.heappush(q, (d[to], to))
    return d


def main():
    N, M = map(int, input().split())
    E = [[] for _ in range(N)]
    for _ in range(M):
        s, t, c = map(int, input().split())
        E[s-1].append([c, t-1])
    for i in range(N-1):
        E[i+1].append([0, i])

    A = dijkstra(0, E)

    ans = A[N-1]
    if ans == float("inf"):
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int n,k;
    cin>>n>>k;
    vector<P> p(n);
    rep(i,n) {
        cin>>p[i].first>>p[i].second;
    }
    sort(p.begin(), p.end());
    ll ans=LLONG_MAX;
    rep(a,n) {
        ll x1=p[a].first, y1=p[a].second;
        rep(b,n) {
            ll x2=p[b].first, y2=p[b].second;
            rep(c,n) {
                ll x3=p[c].first, y3=p[c].second;
                rep(d,n) {
                    ll x4=p[d].first, y4=p[d].second;
                    ll xma=max({x1, x2, x3, x4}), xmi=min({x1, x2, x3, x4});
                    ll yma=max({y1, y2, y3, y4}), ymi=min({y1, y2, y3, y4});
                    int kk=0;
                    rep(t,n) {
                        int x=p[t].first, y=p[t].second;
                        if (xmi<=x and x<=xma and ymi<=y and y<=yma) {
                            kk++;
                            if (kk>=k) {
                                ans=min(ans, (xma-xmi)*(yma-ymi));
                            }
                        }
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#if 1

#include <bits/stdc++.h>
using namespace std;
char s[3010],t[3010],a[3010];
int d[3010][3010];
int main()
{
    int i,j;
    scanf("%s %s", &s, &t);
    for(i = 0;s[i];i++)
    {
        for(j = 0;t[j];j++)
        {
            d[i+1][j+1] = max(d[i+1][j],d[i][j+1]);
            if (s[i] == t[j]) d[i+1][j+1] = max(d[i+1][j+1],d[i][j] + 1);
        }
    }
    while(i && j)
    {
        if(d[i][j] == d[i-1][j-1] + 1 && s[i-1] == t[j-1])
        {
            i--;
            j--;
            a[d[i][j]] = s[i];
        }
        else if (d[i][j] == d[i-1][j])
        {
            i--;
        }
        else
        {
            j--;
        }
    }
    printf("%s",a);
    return 0;
}

#endif // 1++


Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e7+5;
ll n,p;
ll cnt[N],pri[N],m=0;
ll qpow(ll a, ll n){
    ll ans=1LL;
    while (n){
        if (n&1) ans=ans*a;
        n>>=1;
        a=a*a;
    }
    return ans;
}
int main(){
    cin>>p>>n;
    m=0;
    for (int i=2; i<=sqrt(n)+1; i++){
        if (n%i==0){
            pri[++m]=i,cnt[m]=0;
            while (n%i==0) n/=i,cnt[m]++;
        }
    }
    if (n>1) pri[++m]=n,cnt[m]=1;
    ll ans=1LL;
    //for (int i=1; i<=m; i++) cout<<pri[i]<<" "<<cnt[i]<<endl;
    for (int i=1; i<=m; i++)
        if (cnt[i]>=p) ans*=1LL*qpow(pri[i],(cnt[i]/p));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
//---------------------------------------------------------------------------------------------------

int main(void){
    // Your code here!
    ll a,b,c,d; cin >> a >> b >> c >> d;
    ll ans = - 1000000000000000000;
    ans = max(ans,a*d);
    ans = max(ans,a*c);
    ans = max(ans,b*d);
    ans = max(ans,b*c);
    cout << ans << endl;
}


Measured memory_bytes: 3668
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;



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

    int num = s.size();
    vi vec(2);
    rep(i, num) {
        if(s[i] == 'g') {
            vec[0]++;
        } else {
            vec[1]++;
        }
    }

    cout << num/2 - vec[1] << endl;
}

Measured memory_bytes: 512
package main

import "fmt"

func main(){
	var N, K, Q int64
	var A[100000] int64
	var B[100000] int64
	var i int64

	fmt.Scan(&N, &K, &Q)

	for i = 0 ; i < Q ; i++ {
		fmt.Scan(&A[i])
	}

	for i = 0 ; i < N ; i++{
		B[i] = K 
	}

	for i = 0 ; i < Q ; i++{
		B[A[i]-1]++
	}
	for i = 0 ; i < N ; i++{
		//fmt.Print(B[i])
		if B[i] - Q > 0{
			fmt.Println("Yes")
		}else{
			fmt.Println("No")
		}
	}
	// fmt.Println()
}

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

ll S;

int main() {
    cin >> S;

    int X[3], Y[3];
    X[0] = 0;
    Y[0] = 0;

    if (S <= 1.0e9) {
        X[1] = S;
        Y[1] = 0;
        X[2] = 0;
        Y[2] = 1;
    }
    else {
        X[1] = 1.0e9;
        ll y_2;
        ll y_1;
        if (S % (ll)1.0e9 == 0) {
            y_2 = S/1.0e9;
            y_1 = 0;
        }
        else {
            y_2 = S/1.0e9 + 1;
            y_1 = 1.0e9 - (S % (ll)1.0e9);
        }
        Y[2] = (int)y_2;

        X[2] = 1;
        Y[1] = (int)y_1;
        
    }

    for (int i = 0; i < 3; i++) {
        cout << X[i] << " " << Y[i] << " ";
    }
    cout << endl;


    return 0;
}


Measured memory_bytes: 256
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (a[n - 1] > 2) {
    cout << "-1\n";
    return 0;
  }
  int l = 2, r = 2;
  for (int i = n - 1; i >= 0; i--) {
    r += a[i] - 1;
    if (i != 0) {
      int k1, k2;
      if (l % a[i - 1] == 0) {
        k1 = l;
      } else {
        k1 = a[i - 1] * (l / a[i - 1] + 1);
      }
      k2 = a[i - 1] * (r / a[i - 1]);
      if (k1 < l || k1 > r || k2 < l || k2 > r) {
        cout << "-1\n";
        return 0;
      }
      l = k1, r = k2;
    }
  }
  cout << l << " " << r << "\n";
}



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

int main() {
  string s;
  cin >> s;
  int ans = 753;
  for (int i = 0; i < s.size() - 2; i++) {
    string t = s.substr(i, 3);
    int x = 0;
    for (int j = 0; j < 3; j++) {
      x *= 10;
      x += t.at(j) - '0';
    }
    ans = min(ans, abs(753 - x));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3608
class UFTree
  def initialize(n)
    @parent = (0...n).to_a
    @rank = Array.new(n, 0)
  end
     
  def find(x)
    return x if @parent[x] == x
    return @parent[x] = find(@parent[x])
  end
     
  def unite(a, b)
    a = find(a)
    b = find(b)
    return if a == b
    if @rank[a] < @rank[b]
      @parent[a] = b
    else
      @parent[b] = a
      @rank[a] += 1 if @rank[a] == @rank[b]
    end
  end
end
    
def smaller(a, b)
  a < b ? a : b
end
    
N = gets.to_i
G = (0...N).to_a
xv = []
yv = []
N.times do
  x, y = gets.split.map(&:to_i)
  xv << x
  yv << y
end
     
IND = (0...(N * 2 - 2)).to_a
A = []
B = []
C = []
H = G.sort{|a, b| xv[a] <=> xv[b]}
H.zip(H.drop(1)).take(N - 1).each do |a, b|
  A << a
  B << b
  C << smaller((xv[a] - xv[b]).abs, (yv[a] - yv[b]).abs)
end
     
J = G.sort{|a, b| yv[a] <=> yv[b]}
J.zip(J.drop(1)).take(N - 1).each do |a, b|
  A << a
  B << b
  C << smaller((xv[a] - xv[b]).abs, (yv[a] - yv[b]).abs)
end

tree = UFTree.new(N)
cost = 0
n = 0
IND.sort!{|i, j| C[i] <=> C[j]}.each do |i|
  break if n == N
  next if tree.find(A[i]) == tree.find(B[i])
  cost += C[i]
  tree.unite(A[i], B[i])
  n += 1
end
     
puts cost

Measured memory_bytes: 26144
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  lint H[N];
  REP(i,N)cin>>H[i];
  vector<int> C[N];
  REP(i,M){
    int A,B;
    cin>>A>>B;
    A--;B--;
    C[A].push_back(B);
    C[B].push_back(A);
  }
  int ans=0;
  REP(i,N){
    bool f=true;
    for(auto e:C[i]){
      if(H[e]>=H[i])f=false;
    }
    if(f)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(void){
    ll n;
    ll a[200001];
    ll b[200001]; //砕いた後のレンガの並び
    cin >> n;
    
    
    for(int i=0; i<n; i++){
        cin >> a[i];
        //if (a[i] == i+1) b[i] = i+1;
    }
    
    int ans = 0;
     
    /* 
    for(int i=0; i<n; i++){
        if (b[i] != i+1) break;
    }
    */
    ll bricks = 0;//砕くレンガの数
    ll tmp = 1;
    for(int i=0; i<n; i++){
        if(a[i] == tmp) {
            tmp++;
        }else if(a[i] != tmp){
            bricks++;
        }
    }   
    
    if (bricks == n) bricks = -1;
   
    std::cout << bricks << std::endl;

    return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()

# dp[i] := i円引き出すのに必要な最小回数
dp = [INF] * (N+1)
dp[0] = 0
for i in range(N):
    # 3種類の引き出し方に対応する遷移をする
    dp[i+1] = min(dp[i+1], dp[i] + 1)
    j = 6
    while i+j <= N:
        dp[i+j] = min(dp[i+j], dp[i] + 1)
        j *= 6
    j = 9
    while i+j <= N:
        dp[i+j] = min(dp[i+j], dp[i] + 1)
        j *= 9
print(dp[N])


Measured memory_bytes: 3828
N,K=[int(x) for x in input().rstrip().split()]
A=[int(x) for x in input().rstrip().split()]

stack=[]
done=[0 for i in range(2*(10**5))]
done[0]=0
now=0
dou=[]

while(done[now]<2):
  
  if done[now]==0:
    stack.append(now)
  else:
    dou.append(now)
  done[now]+=1
  now=A[now]-1

if K<len(stack):
  print(stack[K]+1)
else:
  print(dou[(K-len(stack)-len(dou))%len(dou)]+1)

Measured memory_bytes: 33884
#include <iostream>
#include <iomanip>

using namespace std;

double dp[20001][101];

int main(){
    int N;
    int v[20001];
    int v_sect[20001];
    int v_max[20001];
    int t[100];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> t[i];
    }
    for(int i = 0; i < 20001; i++){
        v[i] = 1000;
        v_max[i] = 1000;
        v_sect[i] = 1000;
    }
    int t_sum = 0;  
    for(int i = 0; i < N; i++){
        int v_;
        cin >> v_;
        for(int j = 0; j <= t[i]; j++){
            v[t_sum+j] = min(v[t_sum+j], v_);
        }
        for(int j = 0; j < t[i]; j++){
            v_sect[t_sum+j] = v_;
        }
        t_sum += t[i];
    }
    //v[0] = 0;
    //v[t_sum] = 0;
    v_max[0] = 0;
    v_max[t_sum] = 0;
    for(int i = 1; i < t_sum; i++){
        v_max[i] = min(v[i], v_max[i-1]+1);
        //cout << v_max[i] << ' ';
    }
    //cout << endl;
    for(int i = t_sum-1; i >= 1; i--){
        v_max[i] = min(v_max[i], v_max[i+1]+1);
        //cout << v_max[i] << ' ';
    }
    //cout << endl;
    double ans = 0.0;
    for(int i = 1; i <= t_sum; i++){
        if(v_max[i-1] != v_max[i]){
            ans += ((double)(v_max[i-1] + v_max[i]))/2.0;
        }
        if(v_max[i-1] == v_max[i]){
            if(v_sect[i-1] == v_max[i]){
                ans += v_max[i];
                //cout << 'H' << endl;
                //cout << v[0] << ' ' << v[1] << v_max[0] << ' ' << v_max[1] << endl;
            }else{
                ans += v_max[i]+0.25;
            }
        }
    }
    
    std::cout << std::fixed;
    std::cout << std::setprecision(4) << ans << endl;
    //cout << dp[t_sum][1] << endl;
    //cout << dp[t_sum][2] << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
long long n;
long long a,ans=1;
bool fl;
int main(){
	cin>>n;
	while(n--){
		cin>>a;
		if(1000000000000000000ll/ans>=a){
			ans*=a;
		}
		else fl=1;
		if(!a){
			cout<<0;
			return 0;
		} 
	}
	if(fl){
		cout<<-1;
	}
	else cout<<ans;
	return 0;
}

Measured memory_bytes: 3636
import sys

l = raw_input().split()
a = int(l[0])
l = raw_input().split()
b = int(l[0])
l = raw_input().split()
c = int(l[0])
l = raw_input().split()
d = int(l[0])
l = raw_input().split()
e = int(l[0])
l = raw_input().split()
k = int(l[0])
if b - a > k:
    print(':(')
    exit()
if c - a > k:
    print(':(')
    exit()
if d - a > k:
    print(':(')
    exit()
if e - a > k:
    print(':(')
    exit()
if c - b > k:
    print(':(')
    exit()
if d - b > k:
    print(':(')
    exit()
if e - b > k:
    print(':(')
    exit()
if d - c > k:
    print(':(')
    exit()
if e - c > k:
    print(':(')
    exit()
if d - e > k:
    print(':(')
    exit()
print('Yay!')


Measured memory_bytes: 2696
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define inrep int t;cin>>t; while(t--)
#define pb emplace_back
using namespace std;
using namespace __gnu_pbds; 


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;
const ll MOD = 1e9+7;
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {

    for ( unsigned   i=0; i<v.size(); i++ )
        in>>v[i];
    return in;
}

ll extended_GCD(ll a , ll b , ll &x , ll &y){
    if(a == 0){
        x = 0;
        y = 1;
        return b;
    }
    ll x1 , y1;
    ll gcd = extended_GCD(b%a , a , x1 , y1);
    x = y1 - (b/a)*x1; 
    y = x1;
    return gcd;
}
ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinv(ll a , ll mod ){
    ll x , y;
    extended_GCD(a , mod , x , y);
    if(x < 0) x += mod;
    return x;
}

ll mul(ll a,ll b,ll m)
{
    return (a%m*b%m)%m;
}
  
vector<ll> fact(2000005,1);

ll ncr(ll n,ll r)
{
    ll x = fact[n];
    ll y = fact[r];
    ll z = fact[n-r];
    y = z%MOD*y%MOD;
    y = modinv(y,MOD);
    x*=y;
    x%=MOD;
    return x;
}
 


int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll k;
    string s;
    for(int i=2;i<=2000000;i++)
    {
        fact[i] = fact[i-1]*i;
        fact[i]%=MOD;
    }
    //cout<<ncr(3,1);
    cin>>k>>s;
    ll n = s.length();
    ll p = n+k;
    ll z = power(26,p);
    ll y = 0;
    //cout<<ncr(4,0)<<"\n";
    for(ll i=0;i<=n-1;i++)
    {
        ll mul = ncr(p,i)%MOD;
        //cout<<mul<<" ";
        ll h = power(25,p-i)%MOD;
        mul = (mul*h)%MOD;
        //cout<<mul<<" ";
        z = (z - mul + MOD)%MOD;

    }
    cout<<z;
    
    
    return 0;
}

Measured memory_bytes: 19884
// AtCoder Grand Contest 012
// D - Colorful Balls

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;


const int MAX_N = 200000;
const int MAX_C = MAX_N;
const ll INF = (ll)1e18;
const ll MOD = (ll)1e9 + 7;

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

ll extgcd(ll a, ll b, ll &x, ll &y) {
    ll d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1; y = 0;
    }
    return d;
}

ll mod_inv(ll a, ll m) {
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x) % m;
}

int N;
ll X, Y;
int C;
vector<ll> cw[MAX_C];
pli gl[MAX_C];
ll fact[MAX_N + 1];

int main() {

    int c;
    ll w;
    ll x_sub, y_sub, thr;
    int cnt, sum;
    ll ans;

    cin >> N >> X >> Y;
    C = 0;
    fact[0] = 1;
    for (int i = 0; i < N; i++) {
        cin >> c >> w;
        c--;
        C = max(C, c);
        cw[c].push_back(w);
        fact[i + 1] = ((i + 1) * fact[i]) % MOD;
    }
    C++;

    for (int j = 0; j < MAX_C; j++) {
        sort(cw[j].begin(), cw[j].end());
        gl[j] = pli(cw[j].empty() ? INF : cw[j][0], j);
    }
    sort(gl, gl + C);

    sum = 0;
    ans = 1;
    for (int j = 0; j < C; j++) {
        if (cw[j].empty()) {
            continue;
        }
        x_sub = X - cw[j][0];
        y_sub = (gl[0].second == j) ? Y - gl[1].first : Y - gl[0].first;
        thr = (y_sub < cw[j][0]) ? y_sub : max(x_sub, y_sub);
        cnt = upper_bound(cw[j].begin(), cw[j].end(), thr) - cw[j].begin();
        sum += cnt;
        ans = (ans * mod_inv(fact[cnt], MOD)) % MOD;
    }
    ans = (ans * fact[sum]) % MOD;

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 14208
#include <stdio.h>
#include <string.h>
 
int main()
{
    int i,j,m,h,num;
    char s[301],s1[301],s2[301];
     
    while(1){
        scanf("%s",&s);
        num = strlen(s);
        if(s[0] == '-'){
            break;
        }
        scanf("%d",&m);
        for(i=0;i<m;i++){
            scanf("%d",&h);
            strcpy(s1,s);
            strcpy(s2,s);
            strcat(s1,s2);
            for(j=0;j<num*2;j++){
                s1[j] = s1[j+h];
            }
            for(j=0;j<num;j++){
                s[j] = s1[j];
            }
        }
    for(i=0;i<num;i++){
        printf("%c",s[i]);
    }
    printf("\n");
    }
    return 0;
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  string s, t, u;
  in3(s, t, u);
  char d = 'A' - 'a';
  out((char)(s[0] + d));
  out((char)(t[0] + d));
  out((char)(u[0] + d));
  memi;
}

Measured memory_bytes: 256