akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pb emplace_back
#define pf emplace_front
#define mp make_pair
#define ld long double

const int MAXN = 1000009;
int cnt[MAXN];
int mod = 998244353;
int a[MAXN];
int n;

int binpow(int x, int p)
{
    if (p == 0)
        return 1;
    if (p == 1)
        return x % mod;
    int y = binpow(x, p / 2);
    y = (y * y) % mod;
    if (p % 2)
        y = (y * x) % mod;
    return y;
}

int divide(int x, int y)
{
    return (x * binpow(y, mod - 2)) % mod;
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        cnt[a[i]] = (cnt[a[i]] + a[i]) % mod;
    }
    for (int i = 1; i < MAXN; i++)
    {
        for (int e = i * 2; e < MAXN; e += i)
            cnt[i] = (cnt[i] + cnt[e]) % mod;
//        if (cnt[i])
//            cout << i << " " << cnt[i] << "\n";
    }
    for (int i = 1; i < MAXN; i++)
        cnt[i] = (cnt[i] * cnt[i]) % mod;
    for (int i = MAXN - 1; i >= 1; i--)
    {
        for (int e = i * 2; e < MAXN; e += i)
        {
            cnt[i] -= cnt[e];
            if (cnt[i] < 0)
                cnt[i] += mod;
        }
//        if (cnt[i])
//            cout << i << " " << cnt[i] << "\n";
    }
    int ans = 0;
    for (int i = 1; i < MAXN; i++)
        ans = (ans + divide(cnt[i],  i)) % mod;
        //ans = (ans + cnt[i] /  i) % mod;
    for (int i = 0; i < n; i++)
    {
        ans -= a[i];
        if (ans < 0)
            ans += mod;
    }
    if (ans % 2 == 1)
        ans += mod;
    ans /= 2;
    cout << ans;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> struct Segtree {
    inline T merge(T a, T b) { return a + b; }
    inline void act(T &a, T b) { a += b; }
    vector<T> dat;
    int n;
    T e;
    Segtree(int n_, T e) : e(e) {
        n = 1;
        while (n < n_) {
            n <<= 1;
        }
        dat.resize(2 * n, e);
    }
    void set(const int &a, const int &b, const T &x, int k, int l, int r) {
        if (b <= l || r <= a) {
            return;
        }
        if (a <= l && r <= b) {
            act(dat[k], x);
            return;
        }
        set(a, b, x, k << 1, l, (l + r) >> 1);
        set(a, b, x, k << 1 | 1, (l + r) >> 1, r);
    }
    inline void set(const int &a, const int &b, const T &x) {
        if (a >= b) {
            return;
        }
        set(a, b, x, 1, 0, n);
    }
    T get(int k) {
        k += n;
        T res = dat[k];
        k >>= 1;
        while (k > 0) {
            res = merge(res, dat[k]);
            k >>= 1;
        }
        return res;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    Segtree<int> seg(n, 0);
    while (q--) {
        int t;
        cin >> t;
        if (t == 0) {
            int l, r, x;
            cin >> l >> r >> x;
            --l;
            seg.set(l, r, x);
        } else {
            int i;
            cin >> i;
            --i;
            cout << seg.get(i) << "\n";
        }
    }
}


Measured memory_bytes: 3876
#include <stdio.h>
int main(void){
	int H,W,i,j;
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0&W==0)break;
		for(i=0;i<H;i++){
			if(i%2==0){
				for(j=0;j<W;j++){
				if(j%2==0){
					printf("#");
				}else{
					printf(".");
				}}
			}else{
				for(j=0;j<W;j++){
				if(j%2==1){
					printf("#");
				}else{
					printf(".");
				}}
		}
	printf("\n");
	}
	printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include <stdio.h>

int main() {
  // 変数の宣言
  int a, b;
  // 入力値を受け取り, a, b に格納する.
  scanf("%d %d", &a, &b);

  if (b % a == 0) {
    printf("%d\n", a+b);
  } else {
    printf("%d\n", b-a);
  }

  return 0;
}

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

const int kInf = 1'000'000'000;
int main() {
    int n, k, s; scanf("%d%d%d", &n, &k, &s);
    if (s == kInf) {
        for (int i = 0; i < k; ++i) printf("%d ", s);
        for (int i = 0; i < n - k; ++i) printf("%d ", 1);
        puts("");
    } else {
        for (int i = 0; i < k; ++i) printf("%d ", s);
        for (int i = 0; i < n - k; ++i) printf("%d ", kInf);
        puts("");
    }
    return 0;
}


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

using ll = long long;
using namespace std;

const int MAX = 1e7;
const int mod = 4;

ll fac[MAX];

void init() {
    fac[0] = 1;
    for (int i = 1; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % mod;
    }
}

ll com(int n, int k) {
    int fact = 2;
    int c1 = 0;
    while (n / fact) {
        c1 += n/fact;
        fact *= 2;
    }
    fact = 2;
    int c2 = 0;
    while (k / fact) {
        c2 += k/fact;
        fact *= 2;
    }
    fact = 2;
    int c3 = 0;
    while ((n - k) / fact) {
        c3 += (n - k)/fact;
        fact *= 2;
    }
    if (c1 - c2 - c3 > 0) {
        return 0;
    } else {
        return 1;
    }
}

int main() {
    int n;
    cin >> n;
    init();
    string s;
    cin >> s;
    bool no2 = true;
    for (auto c: s) {
        if (c == '2') {
            no2 = false;
            break;
        }
    }

    if (no2) {
        vector<int> diff(n - 1);
        for (int i = 1; i < n; i++) {
            diff[i - 1] = abs(s[i] - s[i - 1]);
        }
        ll sum = 0;
        for (int i = 0; i < n - 1; i++) {
            sum += int(diff[i] - '0') * com(n - 2, i);
            sum %= mod;
        }
        if (sum % 4 == 0) {
            cout << 0 << endl;
        } else {
            cout << 2 << endl;
        }
    } else {
        ll sum = 0;
        for (int i = 0; i < n; i++) {
            sum += int(s[i] - '0') * com(n - 1, i);
            sum %= mod;
        }
        if (sum % 2 == 0) {
            cout << 0 << endl;
        } else {
            cout << 1 << endl;
        }
    }
    return 0;
}


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

int main(void){
    string s;
    string t;

    cin >> s >> t;
    int i;
    if(t.size() == s.size()){
        cout << "No" << endl;
        return 0;
    }
    int size = t.size();
    for(i=0; i<size-1; i++){
        if(s[i] != t[i]){
            cout << "No" << endl;
            return 0;

        }
    }
    cout << "Yes" << endl;
}

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

int main(){
  int p,n[6];
  int c[6] = {1,5,10,50,100,500};
 
  while(cin >> p,p){
    int sum = 0;
    for(int i=0;i<6;i++){
      cin >> n[i];
      sum += n[i]*c[i];
    }

    int m = 1000000;
    for(int i=p;i<=sum;i++){
      int tmp = i,cnt = 0;
      for(int j=5;j>=0;j--){
	cnt += min(n[j],tmp/c[j]);
	tmp -= c[j] * min(n[j],tmp/c[j]);
      }
      if(tmp)continue;
      tmp = i-p;
      for(int j=5;j>=0;j--){
	cnt += tmp/c[j];
	tmp -= c[j] * (tmp/c[j]);
      }
      m = min(m,cnt);
    }
    cout << m << endl;
  }
}

Measured memory_bytes: 864
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main{
	public static void main(String[] args) {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
   	    try{
   	    	String buf;
          while((buf = br.readLine()) != null){
        	double a,b,c,d,e,f;
            String[] co = buf.split("\\s");
            a = Double.parseDouble(co[0]);
            b = Double.parseDouble(co[1]);
            c = -1*Double.parseDouble(co[2]);
            d = Double.parseDouble(co[3]);
            e = Double.parseDouble(co[4]);
            f = -1*Double.parseDouble(co[5]);
            double x = -((c*(a*e-b*d)-b*(a*f-d*c))/(a*(a*e-b*d)));
            double y = -(a*f-c*d)/(a*e-b*d);
            if(x == -0.0) x = 0.0;
            if(y == -0.0) y = 0.0;
            String strx = String.format("%4.3f",x);
            String stry = String.format("%4.3f",y);
            //System.out.printf(strx+" "+stry);
            System.out.printf("%4.3f %4.3f\n", x, y);
   	      }
   	    }catch(Exception e){
   	    	
   	    }
	}
}

Measured memory_bytes: 24788
import math
if __name__=='__main__':
    n=int(input())
    oldn=10**20
    for i in range(int(math.sqrt(n))+1):
        if n%(i+1)==0 and oldn>=(((i+1)+n//(i+1))-2):
            oldn=(((i+1)+n//(i+1))-2)
        elif n%(i+1)==0 and oldn<(((i+1)+n//(i+1))-2):
            break
    print(oldn)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll n,h,w; cin >>n>>h>>w;
ll a[n]={};
ll b[n]={};
for(ll i=0; i<n; i++){
cin>>a[i]>>b[i];}
ll ca=0;
rep(i,n){
if(a[i]>=h&&b[i]>=w){
ca++;}}
cout << ca << endl;}


Measured memory_bytes: 3488
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
map<long long int,long long int>u;
int main()
{
    ll n,m,i,j,k,p,q,o,W,V,U;
    u[1]=300000;
    u[2]=200000;
    u[3]=100000;
    k=0;
scanf("%lld %lld",&n,&m);
k=u[n]+u[m];
if(n==1 && m==1){k+=400000;}
cout<<k<<endl;
    return 0;
}





Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] v = new int[n];
		int[] c = new int[n];
		for(int i=0;i<n;i++) {
			v[i] = sc.nextInt();
		}
		for(int i=0;i<n;i++) {
			c[i] = sc.nextInt();
		}
		sc.close();
		
		int ans=0;
		for(int i=0;i<n;i++) {
			if(v[i]-c[i] > 0) {
				ans += v[i]-c[i];
			}
		}
		System.out.println(ans);

	}

}

Measured memory_bytes: 21844
n = int(input())
s = input()

tmp = 0
a = 0
for i in s:
    if i == "(":
        tmp -= 1
    else:
        tmp += 1
    a = max(a, tmp)
ans = a * "(" + s
print(ans + ")" * (ans.count("(") - ans.count(")")))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, T;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    int x2 = x;
    x2 *= 2;
    x = (K - x) * 2;
    if (x2 > x) {
      T += x;
    } else {
      T += x2;
    }
  }
  cout << T << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, m; cin >> a >> b >> m;
	vector<int> va(a), vb(b);
	for(int i = 0; i < a; i++) cin >> va[i];
	for(int i = 0; i < b; i++) cin >> vb[i];
	int ans = (*min_element(va.begin(), va.end())) + (*min_element(vb.begin(), vb.end()));
	for(int i = 0; i < m; i++){
		int x, y, c; cin >> x >> y >> c;
		x--; y--;
		ans = min(ans, va[x] + vb[y] - c);
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1024
from collections import Counter
from operator import mul
from functools import reduce


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


def cmb(n, r):
    # combination
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


ans = 0
N = int(input())
S = [list(input()) for i in range(N)]

d = {}
for s in S:
    tmp = list(s)
    tmp.sort()
    d[tuple(tmp)] = d.get(tuple(tmp), 0) + 1

# print(d)
for k, v in d.items():
    ans += cmb(v, 2)

print(ans)


Measured memory_bytes: 45300
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

N,M = m()

c = [0 for i in range(N)]
ca = [0 for i in range(N)]
cw = [0 for i in range(N)]


cc = 0
for i in range(M):
    p,s = input().split()
    if s == "WA":
        if ca[int(p)-1] == 0:
            cw[int(p)-1] += 1
    else:
        if ca[int(p)-1] == 0:
            ca[int(p)-1] = 1


for i in range(N):
    if ca[i] == 1:
        cc += cw[i]
print(sum(ca),cc)























Measured memory_bytes: 48560
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

vector<ll> divisor(ll n){
    vector<ll> ret;
    for(ll i=1; i*i<=n; i++){
        if(n%i==0){
            ret.push_back(i);
            if(i*i!=n) ret.push_back(n/i);
        }
    }
    sort(begin(ret),end(ret));
    return(ret);
}

main() {
    ll N; cin >> N;
    vector<ll> v=divisor(N);
    string a,b;
    if(v.size()%2==0){
       a=to_string(v[v.size()/2]);
       b=to_string(v[v.size()/2-1]);
       cout << max((int)a.size(),(int)b.size()) << endl;
    }
    else {
        a=to_string(v[v.size()/2]);
        cout << (int)a.size() << endl; 
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

void tofree();
void print();
void put(int);
int row[N],c[N],dpos[2*N-1],dneg[2*N-1],T[N][N];

int main(){
  int i,j,n,m,v;
  tofree();

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&m,&v);
    T[m][v]=1;
  }
  put(0);
  return 0;
}


void tofree(){
  int i,j;
  for(i=0;i<N;i++) for(j=0;j<N;j++) T[i][j]=0;
  for(i=0;i<N;i++)row[i]=c[i]=FREE;
  for(i=0;i<2*N-1;i++)dpos[i]=dneg[i]=FREE;
}

void print(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(T[i][j]==1){
	if(row[i]!=j)return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}
void put(int i){
  int j;
  if(i==N){
    print();
    return;
  }
  for(j=0;j<N;j++){
    if(c[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+N-1]==NOT_FREE)continue;
    row[i]=j;
    c[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    put(i+1);
    c[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
}



Measured memory_bytes: 2048
from bisect import bisect_left

N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A.sort()
B.sort()
C.sort()

ba = [0]*N
for i in range(N):
	ba[i] = bisect_left(A, B[i])

for i in range(N-1):
	ba[i+1] += ba[i]

ans = 0
for i in range(N):
	t = bisect_left(B,C[i])
	if t<=0:
		continue
	ans += ba[t-1]

print(ans)


Measured memory_bytes: 23232
n = int(input())
a = [input().split() + [_ +1] for _ in range(n)]

for _ in a:
	_[1] = int(_[1])

sorted_a = sorted(a,key= lambda x:x[1], reverse=True)
sorted_a = sorted(sorted_a,key= lambda x:x[0], reverse=False)

for index in range(len(a)):
	print(a.index(sorted_a[index])+1)

#last = [0,0]




Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10 ** 6)

n = int(input())
graph = [[] for _ in range(n+1)]
for _ in range(n-1):
    a,b,c = map(int,input().split())
    graph[a].append([b,c])
    graph[b].append([a,c])

def dfs(v):
    dist = [10 ** 20] * (n+1)
    stack = [v]
    dist[v] = 0
    while stack:
        v = stack.pop()
        for w,cost in graph[v]:
            if dist[w] >= dist[v] + cost:
                dist[w] = dist[v] + cost
                stack.append(w)
    return dist
q,k = map(int,input().split())
distance = dfs(k)
for i in range(q):
    x,y = map(int,input().split())
    print(distance[x]+distance[y])

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

#define    ll     long long int

int main( )
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b) swap(a, b);
    if (b > c) swap(c, b);
    if (a > b) swap(a, b);
    int i, j, k, s = 0;
    i = (c - a) / 2;
    s += i;
    a += 2 * i;
    i = (c - b) / 2;
    s += i;
    b += 2 * i;
    if (a != b) {
        s += 2;
    }
    else if (a != c){
        s++;
    }
    cout << s << '\n';
    return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

constexpr int MAX = 3010000;
constexpr int MOD = 1000000007;

//Please set MAX and MOD!!========================================

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

ll COM(int n, int k) {
	if (n < k || n < 0 || k < 0) return (0);
	return (fac[n] * (finv[k] * finv[n - k] % MOD) % MOD);
}


void Main() {
	int K; string S; cin >> K >> S;
	int N = S.size();

	ll sum = 0;
	vll val25(3000000, 1), val26(3000000, 1);
	for (int i = 1; i < 3000000; i++) {
		val25[i] = (val25[i-1] * 25) % mod;
		val26[i] = (val26[i-1] * 26) % mod;
	}

	COMinit();
		
	for (int i = N; i <= K+N; i++) {
		(sum += COM(i-1, N-1) * val25[i-N] % mod * val26[K+N-i] % mod) %= mod;
	}
	cout << sum << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 121660
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int N;
	string S;
	vector<int> f,b;
	cin >> N;
	cin >> S;
	for (int i = 0; i < N; ++i)
	{
		if(S[i] == 'W') f.push_back(i);
		else b.push_back(i);
	}
	sort(b.begin(), b.end(),greater<int>());
	if(f.empty() || b.empty()){
		cout << "0" << endl;
		return 0;
	}
	for(int i = 0; i < min(f.size(),b.size()); i++){
		if(f[i] > b[i]){
			cout << i << endl;
			return 0;
		}
	}
	cout << min(f.size(),b.size()) << endl;
}

Measured memory_bytes: 4784
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

k,x = get_nums_l()

print("Yes" if k*500 >= x else "No")

Measured memory_bytes: 38512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  int n, k, tmp;
  vector<int> h;
  cin >> n >> k;
  while (cin >> tmp) h.push_back(tmp);
  sort(h.begin(), h.end());
  vector<int> dif;
  for (int i = 0; i < h.size()-k+1; i++) dif.push_back(h[i+k-1]-h[i]);
  sort(dif.begin(), dif.end());
  cout << dif[0] << endl;
  return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
  cin>>a;
  int p=a.size();
 // for(int i=0i<p;i++)
    if(a[p-1]=='s')
    {
   cout<<a;
  cout<<"es";
    }
  else
  {
  cout<<a;
  cout<<"s";
  }
	return 0;
}

Measured memory_bytes: 3628
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC pop_options
//#pragma GCC target("popcnt")
//#pragma GCC target("sse4")
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(),a.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i > -1; i--)
#define rer(i, x, n) for (int i = x; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef long double ld;














const int INF = 1e9;
signed main(){
    int n, m;
    cin >> n >> m;
    char c[n][m];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> c[i][j];
    int dp[n][m];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            dp[i][j] = INF;
    if (c[0][0] == '#') dp[0][0] = 1;
    else dp[0][0] = 0;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            if (i){
                if (c[i][j] == '.'){
                    dp[i][j] = min(dp[i][j], dp[i - 1][j]);
                }else{
                    if (c[i-1][j] == '#'){
                        dp[i][j] = min(dp[i][j], dp[i - 1][j]);
                    }else dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
                }
            }
            if (j){
                if (c[i][j] == '.'){
                    dp[i][j] = min(dp[i][j], dp[i][j - 1]);
                }else{
                    if (c[i][j - 1] == '#'){
                        dp[i][j] = min(dp[i][j], dp[i][j - 1]);
                    }else dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
                }
            }
        }
    }

    cout << dp[n - 1][m - 1];
}


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

int main(){
    int N,A,B;
    cin>>N>>A>>B;

    int res=0;
    for(int i=1;i<=N;i++){
        int mod = 10;
        int sum = 0;
        int tmp = i;
        while(tmp>9){
            sum += tmp%mod;
            tmp /=mod;
        }
        sum += tmp;
        if(sum>=A&&sum<=B){
            res += i;
        }
    }
    cout<<res;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        String str = "";


        for (int i = 1; i < (n + 1); i++) {
            String s = Integer.toString(i);
            if((i%3)==0 || s.contains("3")){
                str = str + " " + s;
            }


        }

        System.out.println(str);

        scn.close();

    }
}



Measured memory_bytes: 185228
import Data.Functor
import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine
  ls <- sort . unfoldr (BS.readInt . BS.dropWhile (<'!')) <$> BS.getLine
  let diffs = sort $ zipWith (-) (tail ls) ls
  print $ sum $ take (max 0 $ m-n) $ diffs

Measured memory_bytes: 16764
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 998244353
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, S; cin >> N >> S;
	VI A(N);
	REP(i, N)cin >> A[i];

	int dp[3010][3010] = { 0 };
	dp[0][0] = 1;
	REP(i, N) {
		eREP(j, S) {
			dp[i + 1][j] += 2 * dp[i][j];
			dp[i + 1][j] %= mod;
			if (j + A[i] <= S) {
				dp[i + 1][j + A[i]] += dp[i][j];
				dp[i + 1][j + A[i]] %= mod;
			}

		}
	}

	cout << dp[N][S] << endl;

	return 0;
}


Measured memory_bytes: 74472
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
bool isprime(int v) {
    if (v == 1) return false;
    if (v == 2) return true;
    for (int i = 2; 1LL * i*i <= v; i++) if (v%i == 0) return false;
    return true;
}
vector<int> cumsum(1e5 + 1, 0);
int query(int l, int r){
    return cumsum[r+1] - cumsum[l];
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    //前処理
    vector<bool> prime(1e5 + 1, false);
    vector<bool> islike(1e5 + 1, false);
    for(int i = 1; i <= 1e5; i++){
        if(isprime(i)){
            prime[i] = true;
            if(i % 2 == 0)continue;
            if(prime[(i + 1) / 2]){
                islike[i] = true;
            }
        }
    }
    rep(i,1e5){
        cumsum[i+1] += cumsum[i] + islike[i];
    }
    int Q;
    cin>>Q;
    while(Q--){
        int l,r;
        cin>>l>>r;
        cout<<query(l, r)<<endl;
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    int A[N+1] = {0};
    for(int i = 0; i < N-1; i++){
        int val;
        cin >> val;
        A[val]++;
    }

    for(int i = 1; i <= N; i++){
        cout << A[i] << "\n";
    }
    return 0;
}
// CLEAN CODE!


Measured memory_bytes: 4440
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc075.contest.atcoder.jp/tasks/arc075_a>
問題文============================================================
 あなたはコンピュータで試験を受けています。試験は N 問の問題からなり、
 i 問目の問題の配点は si です。
 それぞれの問題に対するあなたの解答は「正解」または「不正解」のいずれかとして判定され、
 正解した問題の配点の合計があなたの成績となります。
 あなたが解答を終えると、解答がその場で採点されて成績が表示される…はずでした。
 
 ところが、試験システムに欠陥があり、成績が 10 の倍数の場合は、画面上で成績が 0 と表示されてしまいます。
 それ以外の場合は、画面に正しい成績が表示されます。
 この状況で、成績として画面に表示されうる最大の値はいくつでしょうか？
=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> s(N);
    for(auto &in:s) cin >> in;
    ll Sum = accumulate(s.begin(), s.end(), 0LL);
    ll ans = Sum%10 == 0 ? 0 : Sum;
    for(int i = 0; i < N;i++){
        if(s[i]%10 == 0) continue;
        ans = max(ans,Sum-s[i]);
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map> 
 
using namespace std;
typedef long long int ll;
 
ll N = 0;
ll M = 0;
ll x = 0;
ll y = 0;

const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool areAnagram(string str1, string str2) 
{ 
    // Get lengths of both strings 
    int n1 = str1.length(); 
    int n2 = str2.length(); 
  
    // If length of both strings is not same, then they 
    // cannot be anagram 
    if (n1 != n2) 
        return false; 
  
    // Sort both the strings 
    sort(str1.begin(), str1.end()); 
    sort(str2.begin(), str2.end()); 
  
    // Compare sorted strings 
    for (int i = 0; i < n1; i++) 
        if (str1[i] != str2[i]) 
            return false; 
  
    return true; 
} 
 
int main(){
    //初期化
    COMinit();

    //入力
    cin >> N;
    //初期化


    vector<string > s(N);

    for(ll i = 0; i < N; i++){
        string S;
        cin >> S;
        sort(S.begin(), S.end()); 
        s[i] = S;
    }
    sort(s.begin(), s.end()); 

    //カウント用
    map<string, ll> count;
    //答えを格納する
    ll ans = 0;
    for(ll i = 0; i < N ; i++){

        if(count[s[i]] >= 1){
            ans += count[s[i]];
        }

        count[s[i]]++;

    }

    cout << ans << endl; 
    
}

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

int main() {
  int M, N, D, X, Y, i;
  M = 0;
  vector<int> vec(2);
  cin >> vec.at(0) >> vec.at(1);
  
  N = vec.at(0);
  D = vec.at(1);
  
  vector<int> tenn(2*N);
  
  for (int i = 0; i < N; i++) {
  cin >> tenn.at(2*i) >> tenn.at(2*i+1);
    
  X = tenn.at(2*i);
  Y = tenn.at(2*i+1);
 
   
  if (std::pow(X,2) + std::pow(Y,2) <= std::pow(D,2)){
    ++M;
  }
   
 }
  cout << M << endl;
}

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

#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define pb push_back
#define ar array

typedef long long ll;
typedef long double ld;
//using ll = long long;

typedef vector<int> vi;

const ld EPS = 1e-9, PI = acos(-1.);
const int INF = 0x3f3f3f3f, MOD = 1e9+7;

// global to problem

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int th, ts, ah, as;
	cin >> th >> ts >> ah >> as;
	bool flag = true;
	while(true){
		if(th <= 0){
			cout << "No\n";
			break;
		}
		else if(ah <= 0){
			cout << "Yes\n";
			break;
		}
		if(flag){
			ah = ah - ts;
		}
		else{
			th = th - as;
		}
		flag = !flag;
	}
}


Measured memory_bytes: 3652
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

s = input()
C = collections.Counter(s)
# print(C)
for si in ("a","b","c"):
    if C[si]!=1:
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl;
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

llong gcd(llong a, llong b)
{
        return b != 0 ? gcd(b, a % b) : a;
}


int main()
{
  int n;
  cin>>n;
  vector<llong> a(n,0);
  REP(i,n) cin>>a[i];
  vector<llong> front(n,0);
  front[0]=a[0];
  vector<llong> back(n,0);
  back[n-1]=a[n-1];
  for(int i=0 ; i<n-1; i++)
  {
      front[i+1]=gcd(front[i],a[i+1]);
  }
  for(int i=n-2; i>=0; i--)
  {
      back[i]=gcd(a[i],back[i+1]);
  }
  llong ans=0;
  for(int i=1; i<n-1; i++)
  {
      llong m=gcd(front[i-1],back[i+1]);
      ans=max(ans,m);
  }
  llong fro=back[1];
  llong bac=front[n-2];
  cout<<max({ans,fro,bac})<<endl;
}

Measured memory_bytes: 2560
#!/usr/bin/env python3
n = int(input())
a = [None] * n
x = [[None] * 15 for _ in range(n)]
y = [[None] * 15 for _ in range(n)]
for i in range(n):
    a[i] = int(input())
    for j in range(a[i]):
        x[i][j], y[i][j] = map(int, input().split())
        x[i][j] -= 1

m = 0
for b in range(1 << n):
    f = True
    for i in range(n):
        if b >> i & 1 == 0:
            continue
        for j in range(a[i]):
            if y[i][j] == 1:
                if b >> x[i][j] & 1 == 0:
                    f = False
                    break
            else:
                if b >> x[i][j] & 1 == 1:
                    f = False
                    break

    if f:
        m = max(m, sum(map(int, bin(b)[2:])))

print(m)


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

int N;
const ll MOD = (ll)1e9 + 7;

int main(){
  cin >> N;
  ll ans = 1;
  for(int i = 2; i <= N; i++){
    ans *= i;
    ans %= MOD;
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct number
{
    ll value =0, freq =0;
};
bool compare( struct number a , struct  number b)
{
    return a.freq > b.freq;
}
int main()
{
    ll n;
    cin>>n;
    number* even = new number[100001];
    number* odd  = new number[100001];
    ll eventerms = 0 , oddterms =0;
    for(int i=0;i<n;i++)
    {
        ll temp ;
        cin>>temp;
        if( i%2==0)
        {
            even[ temp ].value = temp;
            even[temp].freq ++;
            eventerms ++;
        } else
        {
            odd[temp].value = temp;
            odd[temp ].freq ++;
            oddterms ++;
        }
    }
    sort( even , even + 100001 , compare);
    sort( odd , odd + 100001 , compare);
    if( even[0].value != odd[0].value )
    {
        cout<<eventerms - even[0].freq + oddterms  - odd[0].freq;
    } else
    {
            cout<< min( oddterms - odd[0].freq + eventerms - even[1].freq ,
                        eventerms - even[0].freq + oddterms - odd[1].freq);
    }
}

Measured memory_bytes: 6744
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

using ll=long long;

int main() {
  ll N; cin >>N;
  deque<char> ans;
  while (N>0) {
    N--;
    char a='a'+(N%26);
    ans.push_front(a);
    N/=26;
  }
  rep(i,0,ans.size()) {cout <<ans[i];}
  return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
map<int,int>M;
int main()
{
    int n,m;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x,M[x]++;
    }
    cin>>m;
    int f=0;
    for(int i=0; i<m; i++)
    {
        int x;
        cin>>x;
        if(!M[x])
        {
            f=1;
            break;
        }
        else M[x]--;
    }
    cout<<(f?"NO\n":"YES\n");
    return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  ll A, B, M;
  cin >> A >> B >> M;
  vector<ll> a(A+1), b(B+1);
  ll mn_a = pow(10,6), mn_b = pow(10,6);
  for(ll i=1; i<=A; ++i){
    cin >> a[i];
    mn_a = min(a[i], mn_a);
  }
  for(ll i=1; i<=B; ++i){
    cin >> b[i];
    mn_b = min(b[i], mn_b);
  }

  vector<ll> x(M+1), y(M+1), c(M+1);
  for(ll i=1; i<=M; ++i) cin >> x[i] >> y[i] >> c[i];
  
  ll ans;
  ll mn_ans = a[1] + b[1];
  for(ll i=1; i<=M; ++i){
    ans = a[x[i]] + b[y[i]] - c[i];
    mn_ans = min(ans, mn_ans);
  }
  
  ll ans1 = min(mn_ans, mn_a + mn_b);
  cout << ans1 << endl;
  return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
const int N=100100;
int a[N],b[N],c[N],d[N],e[N],f[N],g[N],n,K;
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>K;
	for(int i=1;i<=n;++i)cin>>a[i],c[a[i]]=i;
	for(int i=1;i<=n;++i)cin>>b[i],d[b[i]]=i;
	for(int i=1;i<=n;++i)e[i]=b[c[d[a[i]]]];
	int u=(K-1)%6,v=(K-1)/6;
	while(u--){
		for(int i=1;i<=n;++i)a[i]=b[c[i]];
		for(int i=1;i<=n;++i)swap(a[i],b[i]),c[a[i]]=d[b[i]]=i;
	}
	for(int i=1;i<=n;++i)if(!f[i]){
		int cnt=1;g[0]=i;
		for(int j=e[i];j!=i;j=e[j])g[cnt++]=j;
		for(int j=0;j<cnt;++j)f[g[j]]=g[(j+v)%cnt];
	}
	for(int i=1;i<=n;++i)e[f[i]]=i;
	for(int i=1;i<=n;++i)cout<<f[a[e[i]]]<<(i==n?'\n':' ');
	return 0;
}


Measured memory_bytes: 3584
mod=1000000007
n,m=map(int,input().split())
S=tuple(map(int,input().split()))
T=tuple(map(int,input().split()))
DP=[[0]*(m+1) for _ in range(n+1)]
for i,s in enumerate(S):
    for j,t in enumerate(T):
        if s==t:
            DP[i+1][j+1]=DP[i][j+1]+DP[i+1][j]+1
        else:
            DP[i+1][j+1]=DP[i][j+1]+DP[i+1][j]-DP[i][j]
        DP[i+1][j+1]%=mod
print((DP[-1][-1]+1)%mod)

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

int main() {


  string a[8],b[8];

  for(int i=0;i<8;i++){
    cin >> a[i];
    b[i] = a[i];
  }


  for(int k=1;k<=3;k++) {
    cout << k*90 << endl;
  
  for(int i=0;i<8;i++){
    for(int j=0;j<8;j++){
      a[i][j] = b[7-j][i];
    }
  }

  for(int i=0;i<8;i++) b[i] = a[i];

  for(int i=0;i<8;i++)
    cout << a[i] << endl;
  }

  return 0;
}
  
      

Measured memory_bytes: 1192
a=[int(input()) for _ in range(5)]
b=[10-a[i]%10 for i in range(5)]
c=[-(-a[i]//10) for i in range(5)]
d=[0]
for i in range(5):
    if b[i]!=10:
        d.append(b[i])
print(sum(c)*10-max(d))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    vector<string> s;
    rep(i, n){
        string x;
        cin >> x;
        s.push_back(x);
    }
    int res=0;
    vector<int> a, b;
    rep(i, n){
        int slen = s[i].size();
        if(s[i][slen-1]=='A'){
            a.push_back(i);
        }
        if(s[i][0]=='B'){
            b.push_back(i);
        }
        rep(j, slen-1){
            if(s[i][j]=='A'&&s[i][j+1]=='B'){
                res++;
            }
        }
    }

    bool flag=true;
    if(a.size()!=b.size()){
        flag = false;
    }else{
        int len = a.size();
        rep(i, len){
            if(a[i]!=b[i]){
                flag = false;
                break;
            }
        }
    }
    if(flag){
        int alen = a.size();
        cout << res + max(0, alen - 1) << endl;
    }else{
        cout << res + min(a.size(), b.size()) << endl;
    }
    return 0;
}

Measured memory_bytes: 3932
using System;
class Program
{
    static void Main(string[] args)
    {
        long x=Read();
        YN(x==3||x==5||x==7);
    }

    static void Write(string s) { Console.WriteLine(s); return; }
    static void Write(long n) { Console.WriteLine(n.ToString()); return; }
    static string ReadStr() { return Console.ReadLine(); }
    static string[] ReadStrs() { return Console.ReadLine().Split(' '); }
    static long Read() { return long.Parse(Console.ReadLine()); }
    static long[] Read(long n)
    {
        long[] p = new long[n];
        string[] t = Console.ReadLine().Split(' ');
        for(long i = 0; i < n; i++) { p[i] = long.Parse(t[i]); }
        return p;
    }
    static long abs(long n) { return (n > 0) ? n : -n; }
    static long gcd(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = gcd(p, n[i]); } return p; }
    static long gcd(long a, long b) { return (a==0)?b:gcd(b % a, a); }
    static long lcm(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = lcm(p, n[i]); } return p; }
    static long lcm(long a, long b) { return a * b / gcd(a, b); }
    static long max(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p>n[i])?p:n[i]; } return p; }
    static long min(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p<n[i])?p:n[i]; } return p; }
    static void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
    static void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
    static void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
}


Measured memory_bytes: 11092
import math

K = int(input())

def develop_lun(lun):
  lastdigit = lun % 10
  if lastdigit==0:
    return [lun*10+lastdigit, lun*10+lastdigit+1]
  elif lastdigit==9:
    return [lun*10+lastdigit-1, lun*10+lastdigit]
  else:
    return [lun*10+lastdigit-1, lun*10+lastdigit, lun*10+lastdigit+1]

lunlist = [1,2,3,4,5,6,7,8,9]
i = 0
while len(lunlist)<K:
  lunlist.extend(develop_lun(lunlist[i]))
  i+=1

print(lunlist[K-1])


Measured memory_bytes: 7172
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			int n=in.nextInt();
			int a[]=new int[n];
			for(int i=0;i<n;i++)
				a[i]=in.nextInt();
			long dp[][]=new long[n][21];
			dp[0][a[0]]=1;
			for(int i=1;i<=n-2;i++)
			{
				for(int j=0;j<=20;j++)
				{
					int up=j+a[i];
					int down=j-a[i];
					if(up<=20)
					dp[i][up]+=dp[i-1][j];
					if(down>=0)
					dp[i][down]+=dp[i-1][j];
				}
			}
			System.out.println(dp[n-2][a[n-1]]);
		}
	}

	
	static public void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 18296
import math

def is_prime(n):
    if n == 1:
        return False
    if not isinstance(n,int):
        return False
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False
    return True

Q=int(input())
L,R=[],[]
for i in range(Q):
    l,r = list(map(int,input().split()))
    L.append(l)
    R.append(r)

list_2017_similar_num=[0]
for i in range(1,100001):
    if i % 2 == 0:
        list_2017_similar_num.append(list_2017_similar_num[i-1])
    else:
        if is_prime(i) == True and is_prime(int((i+1)/2)) == True:
            list_2017_similar_num.append(list_2017_similar_num[i-1]+1)
        else:
            list_2017_similar_num.append(list_2017_similar_num[i-1])

for i in range(Q):
    print(list_2017_similar_num[R[i]] - list_2017_similar_num[L[i]-1])


Measured memory_bytes: 12592
n = int(input())
a,b = map(int,input().split())
c = map(int,input().split())
lis1 = []
lis2 = []
lis3 = []
for i in c:
    if i <= a:
        lis1.append(i)
    if a+1 <= i <= b:
        lis2.append(i)
    if b+1 <= i:
        lis3.append(i)
print(min(len(lis1),len(lis2),len(lis3)))

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

template<class INT>
std::vector<INT> factorize(INT n){
    std::vector<INT> res;
    for (INT i = 1; i * i <= n; i++){
        if (n % i == 0){
            res.push_back(i);
            if (i * i != n)
                res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> A(n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    auto F = factorize(accumulate(A.begin(), A.end(), 0));
    sort(F.begin(), F.end(), greater<int>());
    const auto g = [&](const auto &f){
        vector<int> B(n);
        int border = 0;
        for (int i = 0; i < n; i++){
            B[i] = A[i] % f;
            border += min(B[i], f - B[i]);
            if (border > k + k)
                return false;
        }
        const auto S = accumulate(B.begin(), B.end(), 0);
        const auto i = S / f;
        nth_element(B.begin(), B.begin() + (n - i), B.end());
        if (max(accumulate(B.begin(), B.begin() + (n - i), 0), S - accumulate(B.begin() + (n - i), B.end(), 0)) <= k){
            return true;
    }};

    for (const auto &f: F){
        if (g(f)){
            printf("%d\n", f);
            return 0;
        }
    }

    puts("0");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
int main()
{
    int h, a;
    cin >> h >> a;
    cout << h / a + !(!(h % a));
    return 0;
}


Measured memory_bytes: 256