akhauriyash/Code-Regression huggingface dataset:
import copy

h, w = map(int, input().split())
maze = []
maze.append([-1 for i in range(w+2)])
for i in range(h):
    si = input()
    s_lst = [-1]
    for j in range(w):
        if si[j] == '.':
            s_lst.append(0)
        else:
            s_lst.append(-1)
    s_lst.append(-1)
    maze.append(s_lst)
maze.append([-1 for i in range(w+2)])

def solve_maze(maze, s):
    queue = [s]
    maze[s[0]][s[1]] = -2
    cnt = 0
    while queue != []:
        cnt += 1
        next_queue = []
        for ten in queue:
            i, j = ten[0], ten[1]
            if maze[i-1][j] == 0:
                maze[i-1][j] = cnt
                next_queue.append([i-1, j])
            if maze[i+1][j] == 0:
                maze[i+1][j] = cnt
                next_queue.append([i+1, j])
            if maze[i][j-1] == 0:
                maze[i][j-1] = cnt
                next_queue.append([i, j-1])
            if maze[i][j+1] == 0:
                maze[i][j+1] = cnt
                next_queue.append([i, j+1])
        queue = next_queue.copy()
    return cnt-1

ans = 0
for i in range(h+2):
    for j in range(w+2):
        if maze[i][j] == 0:
            copied_maze = copy.deepcopy(maze)
            ans = max(ans, solve_maze(copied_maze, [i, j]))

print(ans)

Measured memory_bytes: 3436
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    a = [int(i) for i in ipt().split()]
    num = 0
    for i,ai in enumerate(a):
        if i%2 == 0 and ai%2:
            num += 1
    print(num)

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 68720
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
#include <iomanip>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

///////////////////////////////////////////////////////////////
// namespace
///////////////////////////////////////////////////////////////
using namespace std;
namespace mp = boost::multiprecision;

///////////////////////////////////////////////////////////////
// types
///////////////////////////////////////////////////////////////
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mpi = mp::cpp_int;
// using mpf = mp::number<mp::cpp_dec_float<1024>>;

/////////////////////////////////////////////////////////////////
// https://github.com/atcoder-live/library/blob/master/mint.cpp
/////////////////////////////////////////////////////////////////
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main() {
    int N; cin >> N;
    vector<ll> v;
    for (int i = 0; i < N; ++i) {
        ll a; cin >> a;
        if (a == 0) {
            cout << "0" << endl;
            return 0;
        }
        v.push_back(a);
    }
    mpi ans = 1;
    for (int i = 0; i < N; ++i)
    {
        mpi a = mpi(v[i]);
        if (ans * a > mpi(1e18)) {
            cout << "-1" << endl;
            return 0;
        }
        ans *= a;
    }
    cout << ans << endl;
    // cout << setprecision(10);
    return 0;
}


Measured memory_bytes: 4328
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
int main() {
	ll m, n;
	cin >> m >> n;
	if (m * 2 < n) {
		ll ans = 0;
		ans = m;
		n -= m * 2;
		cout << ans +(n / 4) << endl;
	}
	else {
		cout << n / 2 << endl;
	}
}


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

int main()
{
	auto& in = cin;

	int N;
	in >> N;
	long long sum = 0;
	long long cur = 0;
	for (int i = 0; i < N; ++i) {
		long long a;
		in >> a;
		if (a < cur) {
			sum += cur - a;
		}
		else {
			cur = a;
		}
	}
	cout << sum;

	return 0;
}


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


    int N=0;
    int W=0;
    int max=0;
    int a[1000]={0};
    int w[1000]={0};
    int v[1000]={0};
    int dp[10000][1000]={0};
    

    
int main(void){
        
    cin>>N>>W;

    for(int i=0;i<N;i++){
        cin>>v[i]>>w[i];
    }
    for(int i=1;i<W+1;i++){
        for(int j=0;j<N;j++){
            
            if(i>=w[j]&&dp[i][j]==0){
                for(int B=i;B<W+1;B++){
                    dp[B][j]=v[j];
                }
            }
            if(i-w[j]>0&&j>0){
                dp[i][j]+=dp[i-w[j]][j-1];
            }
            if(dp[i][j]<dp[i][j-1]&&j>0){
                dp[i][j]=dp[i][j-1];
            }
       
       
        }
    
    }
    if(dp[W][N-1]<dp[W][N-2]){
        dp[W][N-1]=dp[W][N-2];
    }

    cout<<dp[W][N-1]<<endl;
   
    
    return 0;

}

Measured memory_bytes: 42124
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;//typo用
using itn = int;//typo用
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl//1次元配列の出力
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl//二次元配列の出力
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl kai(intl k){//k!を求める関数,
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl digit10(intl a){//aを10進数で表したときの桁数を求める関数
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}

//--------------入力受け取る場所----------------------------------------------------
intl n;
ld m;

void input_var(){
    cin >> n >> m;
}
//-------------------------------------------------------------------------------


signed main(){
    cout << fixed << setprecision(10);
    input_var();
    cout << (intl)floor(n * m) << endl;
    return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P ,ll> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9)+7;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()


ll n, m, ans = 0;
priority_queue<P> que;

int main() {
    cin >> n >> m;
    REP(i,n){
        ll a;
        cin >> a;
        que.push({a,1});
    }
    REP(i,m){
        ll b, c;
        cin >> b >> c;
        que.push({c,b});
    }
    REP(i,n){
        P p = que.top();
        que.pop();
        ans += p.first;
        p.second--;
        if(p.second > 0){
            que.push(p);
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define N 3
#define TRUE 1
#define FALSE 0

int x[4]={0,-1,0,1};
int y[4]={1,0,-1,0};
int l;
int puzzle[N][N];

void swap(int *,int *);
int abc();
int dfs(int,int,int,int);
void Solved(int,int);

int main()
{
  int i,j,sx,sy;
   
   for(i=0;i<N;i++){
     for(j=0;j<N;j++){
       scanf("%d",&puzzle[i][j]);
        if(puzzle[i][j]==0){
            sy=i;sx=j;
        }
     }
   }
   Solved(sy,sx);
   return 0;
}


void swap(int *x,int *y)
{
  int tmp;
  tmp=*x;
  *x=*y;
  *y=tmp;
}


int abc()
{
  int i,j,s=0,r;
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
        
        if(puzzle[i][j]==0)continue;
        
        r=puzzle[i][j]-1;
        s+=abs(r/N-i)+abs(r%N-j);
    }
  }
  return s;
}


int dfs(int d,int p,int sy,int sx)
{
  int i,m;
  int tx,ty;

  m=abc();
  
  if(m==0)return TRUE;
  if(d+m>l)return FALSE;
  
  for(i=0;i<4;i++){
    if(abs(i-p)==2)continue;
    
    tx=sx+x[i],ty=sy+y[i];
    
    if(tx<0||ty<0||tx>=N||ty>=N)continue;
    
    swap(&puzzle[ty][tx],&puzzle[sy][sx]);
    
    if(dfs(d+1,i,ty,tx))return TRUE;
    
    swap(&puzzle[ty][tx],&puzzle[sy][sx]);
  }
    return FALSE;
}


void Solved(int sy,int sx)
{
  for(l=0;;l++){
    if(dfs(0,99,sy,sx)){
      printf("%d\n",l);
      return ;
    }
  }
}


Measured memory_bytes: 2756
def main():
    s = input()
    st = set(s)
    if len(st) == 1:
        print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


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

string arr;
char s[100],n=1;
int main(){
	cin>>arr;
	s[0]=arr[0];
	for(int i=1;i<arr.length();i++){
		int fase=1; 
		for(int j=0;j<n;j++){
			if(arr[i]==s[j]){
				fase=0;
			} 
		}
		if(fase){
			s[n]=arr[i];
			n++; 
		}
	}
	if(n==2){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	return 0; 
} 

Measured memory_bytes: 504
#include<iostream>

unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        digit++;
        num /= 10;
    }
    return digit;
}

int main(void){
    int n;
    std::cin >> n;

    int cnt = 0;

    for(int i = 1; i <= n; i++){
        if(GetDigit(i) % 2 == 1){
            cnt++;
        }
    }
    std::cout << cnt << std::endl;
    return 0;
}

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

int main() {
    
    int a,b,c;
    cin >> a >> b >> c;
    if(b*c >= a){
        cout << "Yes\n";
    }
    else{
        
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()0
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=100009;
 
// Happy Coding!



void solve(){
    string str;
    cin>>str;
    int l=str.l();
    int ans=0,curr=0;
    bool flag=true;
    string xx="ACTG";
    
    for(int i=0;i<l;i++){
        if(xx.find(str[i])==string::npos){
            curr=0;
        }
        else{
            curr++;
            ans=max(ans,curr);
        }
    }
    cout<<ans;
}

 
int main() {
    faster;
    int t=1;
    // cin>>t;
    
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=998244353;
using namespace std;


int main(){
int N;
cin>>N;
vector<long long >v(N);

rep(i,N){
    cin>>v[i];
    
}
long long ans=1;
if(v[0]!=0)ans=0;
sort(v.begin(),v.end());






int mp[100001]={};
for(int i=1;i<N;i++){
    if(v[i]==0 || v[i]>=N){
        ans=0;
        break;
    }

    if(v[i]>1){
    ans*=mp[v[i]-1];
    if(ans>=mod)ans%=mod;
    }
mp[v[i]]++;

}

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

*/


Measured memory_bytes: 1408
n=int(input())
s=[list(map(int,input().split(" "))) for k in range(n)]
aa=sorted(s,key=lambda x:x[0]+x[1],reverse=True)
c=0
for l in range(n):
  if l%2==0:
    c+=aa[l][0]
  else:
    c-=aa[l][1]
print(c)    

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

int main(){
   int a,b;
   cin>>a>>b;
   int ans=-1;
   for(int i=1;i<10000;i++){
     if(int(floor(double(i)*0.08))==a && int(floor(double(i)*0.1))==b) {
        ans=i;break;
     }
   }
   cout<<ans;
    return 0;
}



Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W, n = map(int, input().split())
    sr, sc = map(int, input().split())
    S = input()[::-1]
    T = input()[::-1]

    left, right = 1, W
    bottom, up = 1, H
    for s, t in zip(S, T):
        if t == "R":
            left -= 1
            left = max(1, left)
        elif t == "L":
            right += 1
            right = min(W, right)
        elif t == "U":
            bottom -= 1
            bottom = max(1, bottom)
        else:
            up += 1
            up = min(H, up)

        if s == "R":
            right -= 1
        elif s == "L":
            left += 1
        elif s == "U":
            up -= 1
        else:
            bottom += 1

        if left > right or bottom > up:
            print("NO")
            break
    else:
        print("YES" if left <= sc <= right and bottom <= H - sr + 1 <= up else "NO")


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9724
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
#include <utility>
//#include <set>
#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b%mod ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

ll modpow(ll a,ll b){
	ll res = 1 ;
	while(b>0){
		if(b&1) res = res*a%mod ;
		b >>= 1 ;
		a = a*a%mod ;
	}
	return res ;
}

int main(){
	ll n ; cin >> n ;
	vll a(n),p(1000000,0) ;
	for(int i=0;i<n;i++){
		cin >> a.at(i) ;
		ll num = a.at(i) ;
		for(int j=2;j*j<=num;j++){
			if(num%j==0){
				ll cnt = 0 ;
				while(num%j==0){
					cnt++ ;
					num /= j ;
				}
				p.at(j) = max(p.at(j),cnt) ;
			}
		}
		if(num!=1&&p.at(num)==0) p.at(num) = 1 ;
	}
	ll l = 1 ;
	for(int i=0;i<p.size();i++) l = l*modpow(i,p.at(i))%mod ;
	ll ans = 0 ;
	for(int i=0;i<n;i++) (ans += l*modpow(a.at(i),mod-2)%mod) %= mod ;
	cout << ans << endl ;
}


Measured memory_bytes: 8192
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<climits>
#include<set>
#include<map>
#define ll long long
using namespace std;

int main() {
	ll h, w;
	cin >> h >> w;
	vector <vector<char>>s(h + 2, vector<char>(w + 2));
	vector <vector<ll>>x(h + 2, vector<ll>(w + 2,0));
	for (ll i = 1; i <= h; i++) {
		for (ll j = 1; j <= w; j++) {
			cin >> s[i][j];
		}
	}
	for (ll i = 1; i <= h; i++) {
		for (ll j = 1; j <= w; j++) {
			if (s[i][j] == '#') {
				x[i][j]++;
			}
		}
	}
	for (ll i = 1; i <= h; i++) {
		for (ll j = 1; j <= w; j++) {
			if (s[i][j] == '#'&&
				x[i-1][j]+x[i+1][j]+x[i][j-1]+x[i][j+1]==0){
				cout << "No" << endl;
				exit(0);
			}
		}
	}
	cout << "Yes" << endl;
	

	
}



Measured memory_bytes: 256
#include <stdio.h>

long long Count(long long H){
  long long c, C;
  c = 1;
  C = 2;
  while(H != 1){
    H *= 0.5;
    c += C;
    C *= 2;
  }
  return c;
}

int main(void){
  long long H;
  scanf("%lld", &H);
  printf("%lld\n", Count(H));
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, a, b;
	pii ab[114514];
	cin>>n>>m;
	REP(i, m){
		cin>>a>>b;
		ab[i]=make_pair(a-1, b-2);
	}
	sort(ab, ab+m);
	int r=m;
	int ans=1;
	REP(i, m){
		if(r>=ab[i].first){
			r=min(r, ab[i].second);
		}
		else{
			r=ab[i].second;
			++ans;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    ll N,K; cin >> N >> K;
    map<ll,ll> A;
    REP(i,N){
        ll a,b; cin >> a >> b;
        A[a] += b;
    }
    
    ll cnt = 0;
    for(auto a: A){
        cnt += a.second;
        if(cnt >= K){
            cout << a.first << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 7540
from itertools import accumulate
n,k = map(int,input().split())
x = int(n**0.5)
mod = 10**9+7
if x*(x+1)<=n:
  flg = 1
else:
  flg = 0
t = 2*x+flg
dp = [[0 for i in range(t)] for j in range(2)]
for i in range(1,t):
  if i<=x:
    dp[0][i] = 1
    dp[1][i] = 1
  else:
    p = t-i
    dp[0][i] = n//p-n//(p+1)
    dp[1][i] = n//p-n//(p+1)
dp[1] = list(accumulate(dp[1]))
for i in range(2,k+1):
  dp[1][1:] = dp[1][t:0:-1]
  for j in range(1,t):
    dp[1][j] = dp[1][j]*dp[0][j]%mod
  for j in range(1,t):
    dp[1][j] = (dp[1][j]+dp[1][j-1])%mod
print(dp[1][t-1])

Measured memory_bytes: 46700
#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()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int INF = 1e9+5;
const ll LINF = 1e18;
ll n;


void func(ll cur, int use, ll &counter){
    if(cur > n) return ;
    if(use == 0b111) ++counter;
    func(cur*10+7, use | 1,counter);
    func(cur*10+5, use | 2,counter);
    func(cur*10+3, use | 4,counter);
}  

int main(){
  cin >> n;
  //cur：現在の値 use : どれを使ったか,counter：個数
  ll res = 0;
  func(0,0,res);
  cout << res << endl;
}

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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
#define guard(x) if( not ( x ) ) continue;
typedef int64_t Int;
typedef std::vector<Int> LI;
const double pi = 3.14159265358979323846264338;
const Int mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(Int& x) { if( scanf("%" PRId64, &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(Int &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

template<typename T>
struct Maybe {
   T x;
   bool valid;
   Maybe() : valid(false) {}
   Maybe(T x_) : x(x_), valid(true) {}
   operator T() const {
      assert( valid );
      return x;
   }
};

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      Int n, k; scan(n, k);
      std::vector<Int> xs(n); scan(xs);
      std::vector<std::pair<Int, Int>> ys;
      std::sort(xs.begin(), xs.end());
      for(Int i = 0; i < n; ++i) {
         if( i == 0 or xs[i-1] != xs[i] ) {
            ys.push_back(std::make_pair(1, xs[i]));
         }
         else {
            ys.back().first += 1;
         }
      }
      std::sort(ys.begin(), ys.end());
      Int res = 0;
      for(Int i = 0; i < (Int)ys.size() - k; ++i) {
         res += ys[i].first;
      }
      printf("%ld\n", res);
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}




Measured memory_bytes: 6384
#include<iostream>
#include<cstdio>
#include<algorithm>
#define M 100000007
using namespace std;
char c1[300000];
char c2[300000];
char c;
int a1[30];
int a2[30];
int n=0;

int main()
{
    for (int i=0; i<26; ++i)
        a1[i]=a2[i]=1;
    while (true)
    {
        scanf("%c",&c);
        if (c=='\n') break;
        n++;
        a1[c-'a']*=(n);
        a1[c-'a']%=M;
    }
    for (int i=1; i<=n; ++i)
    {
        scanf("%c",&c);
        a2[c-'a']*=(i);
        a2[c-'a']%=M;
    }
    sort(a1,a1+26);
    sort(a2,a2+26);
    bool flag=1;
    for (int i=0; i<='z'-'a'; ++i)
        if (a1[i]!=a2[i])
            flag=0;
    if (flag==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int cnt = 0;
        for(int i = 0; i < S.length(); i++){
          char c = S.charAt(i);
          if(c == '1') {
            cnt++;
          }
        }
        System.out.println(Math.min(cnt,S.length() - cnt)*2);
    }
}


Measured memory_bytes: 25356
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func insertionSort(a []int, n int) {
	var i, j int
	var v int

	for k, p := range a {
		fmt.Printf("%d", p)
		if k == len(a) - 1 {
			fmt.Printf("\n")
		} else {
			fmt.Print(" ")
		}
	}

	for i = 1; i < n; i++ {
		v = a[i]
		j = i - 1
		for j >= 0 && a[j] > v {
			a[j+1] = a[j]
			j--
		}
		a[j+1] = v
		for k, p := range a {
			fmt.Printf("%d", p)
			if k == len(a) - 1 {
				fmt.Printf("\n")
			} else {
				fmt.Print(" ")
			}
		}
	}
}

func main() {
	var n int
	var s string

	var sc = bufio.NewScanner(os.Stdin)
	sc.Scan()
	n, _ = strconv.Atoi(sc.Text())
	sc.Scan()
	s = sc.Text()

	var a = make([]int, n)

	for i, t := range strings.Split(s, " ") {
		a[i], _ = strconv.Atoi(t)
	}

	insertionSort(a, n)
}



Measured memory_bytes: 1224
N, M = map(int, input().split())
AB = []
for i in range(N):
   a, b = map(int, input().split())
   AB.append([a, b])
AB.sort(key=lambda x:(x[0], x[1]))
ans = 0
for i in range(N):
   cost = AB[i][0]
   b = AB[i][1]
   if b < M:
      M -= b
      ans += b*cost
   else:
      ans += cost * M
      break
print(ans)

Measured memory_bytes: 27608
#include <iostream>
#include <string>
#include <utility> // pairとか
#include <vector>
#include <array>
#include <list>
#include <deque>
#include <map>
#include <algorithm> // sortとか findとか
#include <functional> // algorithmに渡せる関数
#include <cmath>
#include <cstdio>
#include <numeric> // gcd,lcmとか
#define rep(iter, beg, end, step) for (long(iter) = (beg); (iter) < (end); (iter) += (step))
using namespace std;

int main() {
	int N;
	int t;
	cin >> N;
	vector<int> a;
	rep(i, 0, N, 1) {
		cin >> t;
		a.push_back(t);
	}
	sort(a.rbegin(), a.rend());

	int kake = +1;
	int sum = 0;
	rep(i,0,N,1) {
		sum += kake * a.at(i);
		kake *= -1;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
// 2011/07/31 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int X, Y;
		cin >> X >> Y;
		if(X==0&&Y==0)
			break;

		int C[18][17];
		for(int i=0; i<=Y+2; i++)
			for(int j=0; j<=X+1; j++)
				C[i][j] = 1;

		for(int i=1; i<=Y; i++)
			for(int j=1; j<=X; j++)
				cin >> C[i][j];

		for(int i=Y+1; i<=Y+2; i++)
			for(int j=1; j<=X; j++)
				C[i][j] = 0;

		int DP[18][17];
		for(int i=0; i<=Y+2; i++)
			for(int j=0; j<=X+1; j++)
				DP[i][j] = 0;

			for(int j=1; j<=X; j++)
				if(C[1][j]==0)
					DP[1][j] = 1;

		for(int i=1; i<=Y-1; i++)
			for(int j=1; j<=X; j++)
				if(C[i][j]==0){
					for(int k=j-1; k<=j+1; k++)
						if(C[i+1][k]==0){
							DP[i+1][k] += DP[i][j];
						}
						else if(C[i+1][k]==1){
							DP[i+1][k] = 0;
						}
						else if(C[i+1][k]==2){
							if(k==j)
								DP[i+1][k] += DP[i][j];
						}
				}
				else if(C[i][j]==1){
					DP[i][j] = 0;
				}
				else if(C[i][j]==2){
					if(C[i+2][j]==1)
						DP[i+2][j] = 0;
					else
						DP[i+2][j] += DP[i][j];
				}

			for(int j=1; j<=X; j++)
				if(C[Y][j]==1){
					DP[Y][j] = 0;
				}

		int sum = 0;
		for(int i=Y; i<=Y+1; i++)
			for(int j=1; j<=X; j++)
				sum += DP[i][j];

		cout << sum <<endl;
	}

	return 0;
}

Measured memory_bytes: 0
n, m = map(int, input().split())

city_list = []
for i in range(m):
	p, y = map(int, input().split())
	city_list.append([i, p, y, 0])

city_list = sorted(city_list, key = lambda x: x[2])
city_list = sorted(city_list, key = lambda x: x[1])

nowp = 1
index = 1
for city in city_list:
	if city[1] == nowp:
		city[3] = index
		index += 1
	else:
		nowp = city[1]
		index = 1
		city[3] = index
		index += 1

city_list = sorted(city_list, key = lambda x: x[0])

for city in city_list:
	kami_str = '0' * (6 - len(str(city[1]))) + str(city[1])
	shimo_str = '0' * (6 - len(str(city[3]))) + str(city[3])
	answer = kami_str + shimo_str
	print(answer)


Measured memory_bytes: 30328
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner kb = new Scanner(System.in);
		int n = kb.nextInt();
		int[][] activity = new int[n][3];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < 3; j++) {
				activity[i][j] = kb.nextInt();
			}
		}
		int[][] dp = new int[n][3];
		dp[0][0] = activity[0][0];
		dp[0][1] = activity[0][1];
		dp[0][2] = activity[0][2];
		for(int i = 1; i < n; i++) {
			for(int j = 0; j < 3; j++) {
				for(int k = 0; k < 3; k++) {
					if(k == j) continue;
					dp[i][j] = Math.max(dp[i][j], dp[i-1][k] + activity[i][j]);
				}
			}
		}
		int max = Math.max(dp[n-1][0], Math.max(dp[n-1][1], dp[n-1][2]));
		System.out.println(max);
	}
}


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

struct Node{
	int key;
	Node *parent, *left, *right;
};
Node *root, *NIL;
void insert(int x);
void Inorder(Node *u);
void Preorder(Node *u);
bool Find(Node *u, int t);
int main()
{
	int n, t;
	string s;
	cin >> n;
	while(n--){
		cin >> s;
		if(s == "insert"){
			cin >> t;
			insert(t);
		}
		else if(s == "print"){
			Inorder(root);
			printf("\n");
			Preorder(root);
			printf("\n");
		}
		else if(s == "find"){
			cin >> t;
			if(Find(root, t)) printf("yes\n");
			else printf("no\n");
		}
	}
	return 0;
}
void insert(int t){
	Node *z, *y = NIL, *x = root;
	z = (Node *)malloc(sizeof(Node));//神奇了 ,不加不行？？？？？？ 
	z -> key = t;
	z -> left = NIL;
	z -> right = NIL;
	while(x != NIL){
		y = x;
		if(t < x -> key){
			x = x -> left;
		}
		else x = x -> right;
	}
	z -> parent = y;
	if(y == NIL) root = z;
	else{
		if(t < y -> key) y -> left = z;
		else y -> right = z;
	}
}

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

void Preorder(Node *u){
	if(u == NIL) return;
	printf(" %d", u -> key);
	Preorder(u -> left);
	Preorder(u -> right);
}
bool Find(Node *u, int t){
	if(u == NIL) return false;
	if(t == u -> key) return true;
	else if(t > u -> key) return Find(u -> right, t);
	else return Find(u -> left, t);
}







 


Measured memory_bytes: 21992
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,a,n) for(int i=a;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;

const int INF=1000000;
char fi[101][101];
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
double EPS = 1e-10;
int N,M;
int sx,sy;
int gx,gy;
int w,h;
int ans;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int MAX_V=100;
const int MAX_N=100;
char o[3]={'+','-','*'};
#define md 1000003


int dp[353][353]={0};
int bow[353][353]={0};
double add(double a,double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b)))
	return 0;
	return a+b;
}

struct P{
	double x,y;
	P(){}
		P(double x,double y):x(x),y(y){
		}
		P operator + (P p){
			return P(add(x,p.x),add(y,p.y));
		}
		P operator - (P p){
			return P(add(x,-p.x),add(y,-p.y));
		}
		P operator *(double d){
			return P(x*d,y*d);
		}
		double dot(P p){
			return add(x*p.x,y*p.y);
		}
		double det(P p){
			return add(x*p.y,-y*p.x);
		}
};

bool cmp_x(const P& p,const P& q){
	if(p.x!=q.x) return p.x<q.x;
	return p.y<q.y;
}

vector<P> convex_hull(P* ps, int n){
	sort(ps,ps+n,cmp_x);
	int k=0;
	vector<P> 	qs(n*2);
	
	rep(i,n){
		while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
			k--;
		qs[k++]=ps[i];
	}
	for(int i=n-2,t=k;i>=0;i--){
		while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
		k--;
		qs[k++]=ps[i];
	}
	qs.resize(k-1);
	return qs;
}

int n,m;
vector<double> p;
P ps[101];
char c[520][520];

int main(){
	
	int n,max,min;
	while(cin>>n>>min>>max,n!=0&&min!=0&&max!=0){
		int ans=0;
		int com=min;
		vector<int> p(n+100);
		rep(i,n)
			cin>>p[i];
		
		for(int i=min-1;i<max;i++){
			if(p[i]-p[i+1]>=ans){
				ans=p[i]-p[i+1];
				com=i+1;
			}
		}
		cout<<com<<endl;
	}
}

Measured memory_bytes: 1204
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint mo=1000000007;
#define N 1001001
lint zyo[N],zs[N],dp[N],ds[N];
int main()
{
	int n,h,d;
	cin>>n>>h>>d;
	zyo[0]=1;
	rep(i,N-10) zyo[i+1]=(zyo[i]*(i+1))%mo;
	zs[0]=0;
	rep(i,N-10) zs[i+1]=(zs[i]+zyo[i+1])%mo;
	dp[0]=1;ds[0]=0;ds[1]=1;
	REP(i,1,h){
		dp[i]=ds[i]-ds[max(0,i-d)];
		dp[i]+=mo;dp[i]%=mo;
		dp[i]*=zs[n];dp[i]%=mo;
		ds[i+1]=ds[i]+dp[i];ds[i+1]%=mo;
	}
	lint out=ds[h]-ds[h-d];out+=mo;out%=mo;
	cout<<(out*zyo[n])%mo<<endl;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (int i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (int i = x.size()-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define fst first
#define scd second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int n, m;
vector<pair<ll, ll>> key;
VLL dp;

int main()
{
    cin>>n>>m;
    key.resize(m);
    dp.resize(pow(2, n), INF * 100);
    dp[0] = 0ll;
    REP(i,m) {
        ll a, b;
        cin>>a>>b;
        key[i] = {a, 0ll};
        REP(j,b) {
            int c;
            cin>>c;
            key[i].scd += pow(2, c - 1);
        }
    }

    REP(i,m) {
        REP(j,pow(2, n)) {
            //cout<<i<<": "<<(key[i].scd|j)<<" ";
            dp[key[i].scd|j]
            = min(dp[key[i].scd|j], key[i].fst + dp[j]);
            //cout<<dp[key[i].scd|j]<<endl;
        }
    }

    cout<<(dp[pow(2, n) - 1] == INF * 100 ? -1: dp[pow(2, n) - 1])<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>    // for pair
using namespace std;

#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rep1(i, n) for(ll i = 1; i < (n); ++i)
#define rep4(i, start, end, step) for (ll i = (start); i < (end); i += (step))

#define BIG_PRIME 1000000007
#define BP_remainder(x) ((x) % BIG_PRIME)

#define INF 0x3fffFFFF
#define INF_NEG (INF * -1)
#define INF_LONG (INF << 32)
#define INF_LONG_NEG (INF_LONG * -1L)

typedef long long ll;
typedef pair<ll, ll> lpair;
typedef char str255[256];
// char *用、strlen の ll 版
ll StrLen(char *s) { for(ll ptr = 0L;; ++ptr) if(!s[ptr]) return ptr; } 
// char * の後ろから n 文字削除, 削除後の文字数を返す
ll StrDel(char *s, int n) { ll l = StrLen(s); s[l - n + 1L] = '\0'; return l - n; }
// 正の整数の桁数
ll NumDigits(ll l){ char s[30]; sprintf(s, "%lld", l); return StrLen(s); }

int isFirst = 1;
template <class T> 
void print(T t) { if (isFirst) cout << t, isFirst = 0; else cout << " " << t; }

void chmin(ll& a, ll b) { if (a > b) a = b; }
void chmax(ll& a, ll b) { if (a < b) a = b; }

ll gcd(ll a, ll b){ if (a % b) return (gcd(b, a % b)); else return b; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

signed main()
{
    cout << fixed << setprecision(10);

    int W, H, x, y;
    cin >> W >> H >> x >> y;
    double S = (double)W * (double)H;
    double ans = (double)S / 2.0;

    int ans2 = 0;
    if ((2 * x == W) && (2 * y == H))
        ans2 = 1;

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


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

// 入力
int N;

double dp[310][310][310];

double rec(int i, int j, int k) {
    if (dp[i][j][k] >= 0) return dp[i][j][k];
    if (i == 0 && j == 0 && k == 0) return 0.0;

    double res = 0.0;
    if (i > 0) res += rec(i - 1, j, k) * i;
    if (j > 0) res += rec(i + 1, j - 1, k) * j;
    if (k > 0) res += rec(i, j + 1, k - 1) * k;
    res += N;
    res *= 1.0 / (i + j + k);

    return dp[i][j][k] = res;
}

int main() {
    cin >> N;
    int one = 0, two = 0, three = 0;
    rep(i, N) {
        int a;
        cin >> a;
        if (a == 1) ++one;
        else if (a == 2) ++two;
        else ++three;
    }

    memset(dp, -1, sizeof(dp));
    cout << fixed << setprecision(10) << rec(one, two, three) << endl;
}

Measured memory_bytes: 233088
#!/usr/bin/env python3
import sys
import itertools
import collections
import functools
import math
from queue import Queue
# import numpy as np
INF = float("inf")


def solve(N: int, A: int, B: int, C: int, D: int, E: int):
    t = [A, B, C, D, E]
    mt = min(t)
    print((N-1)//mt + 5)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    E = int(next(tokens))  # type: int
    solve(N, A, B, C, D, E)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4200
D = int(input())
c_list = list(map(int, input().split()))
s_list, t_list = [], []
for i in range(D):
    s_list.append(list(map(int, input().split())))

for i in range(D):
    t_list.append(int(input()))

base = 1000000
S = 0

contests_held_day = []
for i in range(26):
    contests_held_day.append(0)

for i in range(D):
    S += s_list[i][t_list[i]-1]
    contests_held_day[t_list[i]-1] = i + 1
    for j in range(26):
        S -= c_list[j] * ((i+1) - contests_held_day[j])
    print(S)


Measured memory_bytes: 9500
#include<bits/stdc++.h>
using namespace std;
int main()
{
  map<string,int>m;
  string s;
  int n;
  cin>>n;
  while(n--)
  {
    int q,x;
    cin>>q;
    if(q==0)
    {
      cin>>s>>x;
      m[s]=x;
    }
    else if(q==1)
    {
      cin>>s;
      cout<<m[s]<<endl;
    }
  }
}



Measured memory_bytes: 27804
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false); cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const int nmax = 2e5 + 10;
int n;
int a[nmax], b[nmax];
int main() {
    IO;
 
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b + 1, b + 1 + n);
    for (int i = 1; i <= n; i++) {
        if (a[i] <= b[n / 2]) cout << b[n / 2 + 1] << "\n";
        else cout << b[n / 2] << "\n";
    }
    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

int main(){

  int N;
  int sum=0;
  for(int i=0;i<10;i++){
    cin>>N;
    sum+=N;
  }
  cout<<sum<<endl;
  
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

#define BV_SIZE 64ULL // 64bit
#define MAX_BV_NUM 100 // m <= 100*64 = 6400

unsigned long long Peq[MAX_BV_NUM][0x100];
int levenshteinDistance(string a,string b) {
  int m=a.size(),n=b.size();
  int num_of_bv = (m + BV_SIZE -1) / BV_SIZE;

  for (int i = 0; i < m; i++) {
    Peq[i / BV_SIZE][a[i]] |= 1ULL << ((unsigned long long)i % BV_SIZE);
  }

  int score = m;
  unsigned long long Pv[MAX_BV_NUM], Mv[MAX_BV_NUM], Ph[MAX_BV_NUM], Mh[MAX_BV_NUM], Xv[MAX_BV_NUM], Xh[MAX_BV_NUM], Eq[MAX_BV_NUM], Xt[MAX_BV_NUM], Xa[MAX_BV_NUM];
  unsigned long long top = 1ULL << (((unsigned long long)m - 1ULL) % BV_SIZE);

  for(int i = 0; i < num_of_bv; i++) {
    Pv[i] = ~0ULL; Mv[i] = 0ULL;
  }

  for (int j = 0; j < n; j++) {
    for(int i = 0; i < num_of_bv; i++){
      Eq[i] = Peq[i][b[j]];
      Xv[i] = Eq[i] | Mv[i];
      Xt[i] = Eq[i] & Pv[i];
    }

    unsigned long long carry = 0ULL;

    for(int i = 0; i < num_of_bv; i++){
      Xa[i] = Xt[i] + Pv[i] + carry;
      if(Xt[i] == ~0ULL && carry == 1ULL){
        carry = 1ULL;
      }else{
        unsigned long long cXt = Xt[i] + carry;
        carry = (((cXt & Pv[i]) | ((cXt | Pv[i]) & ( ~ (cXt + Pv[i]) ))) >> 63ULL) & 1ULL;
      }
    }

    for(int i = 0; i < num_of_bv; i++){
      Xh[i] = (Xa[i] ^ Pv[i]) | Eq[i];

      Ph[i] = Mv[i] | ( ~ (Xh[i] | Pv[i]) );
      Mh[i] = Pv[i] & Xh[i];
    }

    if((Ph[num_of_bv - 1] & top) != 0ULL)score++;
    else if((Mh[num_of_bv - 1] & top) != 0ULL)score--;    

    unsigned long long Ph_carry = 1ULL;
    unsigned long long Mh_carry = 0ULL;

    for(int i = 0; i < num_of_bv; i++){
      unsigned long long nxt_Ph_carry = (Ph[i] >> 63ULL) & 1ULL;
      Ph[i] = (Ph[i] << 1ULL) | Ph_carry;
      Ph_carry = nxt_Ph_carry;

      unsigned long long nxt_Mh_carry = (Mh[i] >> 63ULL) & 1ULL;
      Pv[i] = ((Mh[i] << 1ULL) | Mh_carry ) | ( ~ (Xv[i] | Ph[i]) );
      Mh_carry = nxt_Mh_carry;

      Mv[i] = Ph[i] & Xv[i];
    }

  }
  return score;
}

int main(){
	string a,b;
  cin>>a>>b;
  cout<<levenshteinDistance(a,b)<<endl;
	return 0;
}

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

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n"
#define ll long long
#define uint unsigned int
#define ushort unsigned short
#define ulong unsigned long

ll MOD = 10e9 + 7;

int main() {
    string s,t,u;
    int a,b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if (s==u) {
        cout << a-1 << " " << b << endl;
        return 0;
    } else {
        cout << a << " " << b-1 << endl;
        return 0;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); 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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n, m;
  cin >> n >> m;

  if (n > m) swap(n, m);
  if (n == 1) {
    if (m == 1) cout << 1 << endl;
    else cout << m - 2 << endl;
  }
  else cout << (ll)(m - 2) * (ll)(n - 2) << endl;
  


  
  return 0;
}

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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

// chmax, chmin
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; }

using pll = pair<ll,ll>; // money, time
using Edge = pair<int,pll>;
using Graph = vector<vector<Edge>>;
const ll INF = 1LL<<60;
const int MAX = 2500;

int N,M;
ll S;
Graph G;
vector<ll> C,D; // money, time

vector<vector<ll>> dijsktra () {
    if ( S >= MAX ) S = MAX;
    vector<vector<ll>> dp(N,vector<ll>(MAX+1,INF)); // dp[v][s] 頂点vで所持金sになるのにかかる所要時間
    priority_queue<pair<ll,pll>,vector<pair<ll,pll>>,greater<pair<ll,pll>>> que;
    dp[0][S] = 0;
    que.push(make_pair(0,pll(0,S))); // 時間,場所,金
    while ( !que.empty() ){
        auto p = que.top(); que.pop();
        ll time = p.first; // time
        int v = p.second.first; // position
        ll s = p.second.second; // money
        if ( time > dp[v][s] ) continue;
        
        if ( s + C[v] <= MAX ) {
            ll ns = s + C[v];
            ll ntime = time + D[v];
            if ( chmin(dp[v][ns],ntime) ){
                que.push(make_pair(ntime,pll(v,ns)));
            }
        }
        
        for ( auto e: G[v] ){
            if ( s < e.second.first ) continue;
            int nv = e.first;
            ll ns = s - e.second.first;
            ll ntime = time + e.second.second;
            if ( chmin(dp[nv][ns],ntime) ){
                que.push(make_pair(ntime,pll(nv,ns)));
            }
        }
    }
    return dp;
}

int main() {
    cin >> N >> M >> S;
    G.assign(N,vector<Edge>());
    REP(i,M){
        ll u,v,a,b;
        cin >> u >> v >> a >> b;
        G[u-1].push_back(Edge(v-1,pll(a,b)));
        G[v-1].push_back(Edge(u-1,pll(a,b)));
    }
    C.resize(N); D.resize(N);
    REP(i,N) cin >> C[i] >> D[i];
    
    vector<vector<ll>> dp = dijsktra();
    
    for ( int v = 1; v < N; ++v){
        ll ans = INF;
        REP(s,MAX) chmin(ans,dp[v][s]);
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 7392