akhauriyash/Code-Regression huggingface dataset:
#include <map>
#include <iostream>

using namespace std;


typedef long long LL;


const LL MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
	LL ans = 1;
	int N;
	cin >> N;
	map<int,int> mp;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		mp[tmp]++;
	}

	bool flag = true;
	int i = 0;
	if(N % 2 == 1) {
		mp[0]++;
		for (auto&& var : mp) {
			if(var.first != i || var.second != 2 || var.first > N) {
				flag = false;
				break;
			}
			i += 2;
		}
	}
	else {
		i = 1;
		for (auto&& var : mp) {
			if (var.first != i || var.second != 2 || var.first > N) {
				flag = false;
				break;
			}
			i += 2;
		}
	}

	if (flag) {
		for (int i = 0; i < N/2; i++) {
			ans = ans*2;
			ans = ans % MOD;
		}
		cout << ans << endl;
	}

	else {
		cout << 0 << endl;
	}

	return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int n;
  cin>>n;
  long long int a[n];
  vector<long long int>v(n+1,0);
  for(long long int i=0;i<n-1;i++)
  {
    cin>>a[i];
    v[a[i]]+=1;
  }
  for(long long int i=1;i<n+1;i++)
    cout<<v[i]<<endl;
  return 0;
}

Measured memory_bytes: 6332
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	double n; cin >> n;
	if ((int)n % 2 == 0) {
		cout << (n / 2) / n << endl;
	}
	else {
		cout << ((n + 1) / 2) / n << endl;
	}
	cin >> n;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for (int i = 0; i < values.length; i++) {
			values[i] = i + 1;
		}
		for (int i = 0; i < n; i++) {
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1;
			int swap;
			swap = values[a];
			values[a] = values[b];
			values[b] = swap;
		}
		for (int i = 0; i < values.length; i++) {
			System.out.println(values[i]);
		}
	}

}

Measured memory_bytes: 26276
from sys import stdin
import numpy as np
from numba import njit

@njit("i8(i8[:,:,:],i8[:],i8,i8,i8)",cache=True)
def f(dp,x,con,n,a):
    for i in range(n):
        for k in range(n):
            for j in range(con+1-50):
                #i枚目を選ぶ
                dp[i+1][j+x[i]][k+1]+=dp[i][j][k]

                #i枚目を選ばない
                dp[i+1][j][k]+=dp[i][j][k]
    ans=0
    for k in range(1,n+1):
        ans+=dp[n][k*a][k]

    return ans

def main():
    #入力
    readline=stdin.readline
    con=2500
    n,a=map(int,readline().split())
    x=list(map(int,readline().split()))
    x=np.array(x,dtype=np.int64)

    dp=[[[0]*(n+1) for _ in range(con+1)] for _ in range(n+1)]
    dp[0][0][0]=1
    dp=np.array(dp,dtype=np.int64)

    print(f(dp,x,con,n,a))

if __name__=="__main__":
    main()

Measured memory_bytes: 222996
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
vector<int> d, f;
vector<vector<int>> g;
void dfs(int now, int &time) {
    d[now] = time;
    time++;
    for (int nxt : g[now]) {
        if (d[nxt] != -1) continue;
        dfs(nxt, time);
    }
    f[now] = time;
    time++;
}
int main() {
    int n;
    cin >> n;
    g.resize(n);
    d.assign(n, -1);
    f.resize(n);
    rep(i, n) {
        int u, k;
        cin >> u >> k;
        rep(j, k) {
            int v;
            cin >> v;
            v--;
            g[i].push_back(v);
        }
    }
    int time = 1;
    rep(i,n) {
        if(d[i]==-1) dfs(i,time);
    }
    rep(i,n) {
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
bitset<10> B;
int n, k;
int main(){
    scanf("%d %d", &n, &k);
    for(int i=0;i<k;i++){
        int a; scanf("%d", &a);
        B[a] = 1;
    }
    for(int i=n;;i++){
        bool f = 1;
        int j = i;
        while(j){
            if(B[j%10]) { f = 0; break; }
            j/=10;
        }
        if(f) return !printf("%d", i);
    }
}

Measured memory_bytes: 256
N,M = (int(x) for x in input().split())
a = [0]*N  
k = []
ans = 0
for i in range(M):
  k = [int(x) for x in input().split()]
  for j in range(k[0]): #kよりつながっている電球を一個ずつ見てる
    s = k[j+1]-1
#    print(i,j,s,a[s],a)
    a[s] = a[s] | (1<<i)
#   print(i,j,s,a[s],a)
    #二進数でi桁目が１のとき、スイッチsとi番目の電球がつながっている?
p = [int(x) for x in input().split()]
P = 0
for i in range(M):
  P |= p[i] << i
for s in range(1<<N):
  t = 0
  for i in range(N):
    if ((s>>i) & 1):
      t ^= a[i]
  if (t == P):
    ans += 1
print(ans)

Measured memory_bytes: 3064
from collections import Counter
def main():
    N, P = (int(_) for _ in input().split())
    A = [int(_) for _ in input().split()]
    
    dp = [[0] * 2 for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        dp[i+1][0] += dp[i][0]
        dp[i+1][1] += dp[i][1]
        if A[i]%2 == 0:
            dp[i+1][0] += dp[i][0]
            dp[i+1][1] += dp[i][1]
        else:
            dp[i+1][0] += dp[i][1]
            dp[i+1][1] += dp[i][0]
    print(dp[N][P])
    return

if __name__ == '__main__':
    main()
    

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

using namespace std;
typedef  long long ll;

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

int st[100];
int top=0;

int pop(){
    top--;
    return st[top];
}

void push(int x){
    st[top]=x;
    top++;
    return ;
}

char enzanshi[]={'+','-','*','/'};

int is_enzanshi(string s,int p){
    rep(i,0,4){
        if(s[p]==enzanshi[i]){
            return true;
        }
    }
    return false;
}

int main( ){
    stack<int> sta;
    while(true){
        string s;
        cin>>s;
        if(is_enzanshi(s,0)){
            int second=pop();
            int first=pop();
            switch (s[0])
            {
            case '+':
                push(first+second);
                break;
            case '-':
                push(first-second);
                break;
            case '*':
                push(first*second);
                break;
            default:
                break;
            }
        }
        else {
            int v=0;
            int i=0;
            while(s[i]>='0'&&'9'>=s[i]){
                v*=10;
                v+=(s[i]-'0');
                i++;
            }
            push(v);
        }
        if(getchar()=='\n')break;
    }
    int ans=pop();
    cout<<ans<<endl;
    return 0;
}





Measured memory_bytes: 3156
#include<cstdio>
#include<map>

using namespace std;

typedef pair<int,int> P;

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

P start,goal;
int W,H;

void cpy(char dst[20][20], const char src[20][20]) {
    for(int i=0; i<20; i++)
        for(int j=0; j<20; j++)
            dst[i][j] = src[i][j];
}

int dfs(const char map[20][20], const P pos, int n) {
    if(n>10) return 100;

    char dst[20][20];
    int res = 100;

    for(int d=0; d<4; d++) {
        P now = pos;

        now.first+= dx[d], now.second+= dy[d];
        if(!(now.first>=0 && now.second>=0 && now.first<W && now.second<H) || map[now.first][now.second] == 1 )
            continue;
        while(!map[now.first][now.second] && now.first>=0 && now.second>=0 && now.first<W && now.second<H)
            now.first+= dx[d], now.second+= dy[d];
        if(!(now.first>=0 && now.second>=0 && now.first<W && now.second<H))
            continue;

        switch(map[now.first][now.second]) {
            case 1:
                cpy(dst, map);
                dst[now.first][now.second] = 0;
                now.first-=dx[d]; now.second-=dy[d];
                res = min(dfs(dst, now, n+1), res);
                break;
            case 3:
                return n;
        }

    }

    return res;
}

int main(void) {
    while(true) {
        scanf("%d%d",&W,&H);
        if(!W) break;

        char map[20][20];
        for(int i=0; i<H; i++)
            for(int j=0; j<W; j++) {
                int in;
                scanf("%d", &in);
                map[j][i]=in;
            }
        for(int i=0; i<H; i++)
            for(int j=0; j<W; j++)
                if(map[j][i] == 2)
                    start = P(j,i), map[j][i] = 0;
                else if(map[j][i] == 3)
                    goal = P(j,i);

        int res = dfs(map, start, 1);
        printf("%d\n", res==100 ? -1 : res);

    }
    return 0;
}

Measured memory_bytes: 1032
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    len_s=len(s)
    mod=10**9+7
    dp=[[0]*13 for _ in range(len_s+1)] #i(1-)桁目までについて，13で割った余り
    dp[0][0]=1
    for i in range(len_s):
        if s[i]=="?":
            for j in range(13):
                for k in range(10):
                    dp[i+1][(10*j+k)%13]+=dp[i][j]%mod
        else:
            c=int(s[i])
            for j in range(13):
                dp[i+1][(10*j+c)%13]=dp[i][j]
        for j in range(13):
            dp[i+1][j]%=mod
    print(dp[len_s][5])

if __name__=='__main__':
    main()

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

#define ll long long

using namespace std;

int n, p[22];
int main() {
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> p[i];
    int sol =0;
    for (int i = 1; i < n - 1; ++i)
        if ((p[i] > p[i + 1] && p[i - 1] > p[i]) || (p[i - 1] < p[i] && p[i] < p[i + 1]))
            sol++;

        cout << sol;
    return 0;
}


Measured memory_bytes: 256
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

# define INF 0x3f3f3f3f

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

const ll MOD7 = 1000000007;

struct FactorialTable {
  vector<ll> fact;
  vector<ll> inv;
  ll n;
  ll m;

  explicit FactorialTable(ll n, ll m) {
    this->n = n;
    this->m = m;
    fact = vector<ll>(n + 1, 0);
    fact[0] = 1;
    for (int i = 1; i <= n; i++) {
      fact[i] = fact[i - 1] * i % m;
    }
    inv = vector<ll>(n + 1, 0);

    for (int i = 0; i <= n; i++) {
      inv[i] = mod_pow(fact[i], m - 2);
    }
    /*
    inv[n] = mod_pow(fact[n], m - 2);
    for (int i = n - 1; i >= 0; i--) {
      inv[i] = inv[i + 1] * (i + 1) % m;
    }
    */
  }
  ll mod_pow(ll x, ll n) {
    ll ans = 1;
    while (n > 0) {
      if ((n & 1) == 1) ans = ans * x % m;
      x = x * x % m;
      n >>= 1;
    }
    return ans;
  }
  ll factorial(int n) {
    assert(this->n > n);
    return fact[n];
  }
  // 組み合わせ nCk
  ll comb(int n, int k) {
    assert(this->n > n);
    assert(n >= k);
    return fact[n] * inv[k] % m * inv[n - k] % m;
  }
  // 重複組み合わせ nHr = (n + r + 1)Cr
  // n 種類のものから重複を許して r 個選ぶ場合の数
  ll mcomb(int n, int k) {
    return comb(n + k - 1, k);
  }
};

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

  ll N, M;
  cin >> N >> M;

  FactorialTable f(100010, MOD7);

  if (abs(N - M) > 1) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = f.factorial(N) * f.factorial(M);
  ans %= MOD7;
  if (N == M) {
    ans *= 2;
    ans %= MOD7;
  }

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


Measured memory_bytes: 1792
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>

using namespace std;
const int64_t INF=1e10;

int main(){
	int64_t n,m;
	cin>>n>>m;
	vector<int64_t> vote;
	int64_t sum=0;
	for(int64_t i1=0;i1<n;i1++){
		int64_t temp;
		cin>>temp;
		sum+=temp;
		vote.push_back(temp*4*m);
	}
	sort(vote.begin(),vote.end());
	reverse(vote.begin(),vote.end());
	if(vote[m-1]>=sum){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 256
/*
    CP Submission
*/

#include<bits/stdc++.h>

using namespace std;

/* Shortcuts */
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define val(x) cout << #x << ": " << (x) << endl;
#define log(x) cout << (x) << endl;
#define sz(x) (int)(x.size())

/* typedefs */
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <string,string> mss;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k; cin >> n >> k;

    if(n % k == 0){
        log(0);
    } else {
        log(1);
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    ll n,c,k;cin>>n>>c>>k;
    ll t[n];rep(i,0,n-1)cin>>t[i];
    sort(t,t+n);
    ll now=0;
    ll ans=0;
    while(now<n){
        ans++;
        ll bus=t[now]+k;
        now++;
        ll sum=1;
        while(now<n && sum<c && t[now]<=bus){
            now++;
            sum++;
        }
        //cout<<now<<endl;
    }
    cout<<ans<<endl;
    
    return 0;
}






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

int main() {
    string S;
    cin >> S;
    int K = S.size();
    bool check = true;
    if (K == 1) {
        cout << S << endl;
        return 0;
    }
    for (int i = 1; i < K; i++) {
        if (S[i] != '9') {
            check = false;
        }
    }
    int top = (S[0] - '0');
    if (check) {
        cout << top + 9 * (K - 1) << endl;
    } else {
        cout << top - 1 + 9 * (K - 1) << endl;
    }
}

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

int main() {
    int n, a;
    cin >> n;
    map<int, int> mp;
    for(int i = 0; i < n; ++i) {
        cin >> a;
        mp[a]++;
    }
    long long int ans = 0;
    auto begin = mp.begin(), end = mp.end();
    for(auto iter = end; iter != begin; iter--) {
        if(iter->second >= 2) {
            if(ans == 0) ans = iter->first;
            else {
                ans *= iter->first;
                break;
            }
            iter->second -= 2;
            iter++;
        }
    }
    cout << ans << '\n';
    
    return 0;
}


Measured memory_bytes: 4992
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

#define PI 3.1415926535

int dim;
 
void Koch(double x1, double y1, double x2, double y2, int dim){
    double x3=0, y3=0, x4=0, y4=0, x5=0, y5=0;
    double s, c;
     
    if(dim != 0){
        s = sin(PI/3);
        c = cos(PI/3);
   
        x3 = (2 * x1 + x2) / 3;
        y3 = (2 * y1 + y2) / 3;
        x5 = (x1 + 2 * x2) / 3;
        y5 = (y1 + 2 * y2) / 3;
        x4 = x3 + (x5 - x3) * c + (y5 - y3) * s;
        y4 = y3 - (x5-x3) * s + (y5 - y3) * c;
    
        Koch(x1, y1, x3, y3, dim-1);
        printf("%1.8f %1.8f\n",x3,fabs(y3));
        Koch(x3, y3, x4, y4, dim-1);
        printf("%1.8f %1.8f\n",x4,fabs(y4));
        Koch(x4, y4, x5, y5, dim-1);
        printf("%1.8f %1.8f\n",x5,fabs(y5));
        Koch(x5, y5, x2, y2, dim-1);
    }
    
    return;
}

int main(){
    int i;
    double x1=0, y1=0, x2=100, y2=0;
     
    scanf("%d", &dim);
    printf("%1.8f %1.8f\n",x1,y1);
     
    if(0 <= dim || dim <= 6){
        Koch(x1,y1,x2,y2,dim);
    }  
    printf("%1.8f %1.8f\n",x2,y2);
     
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}
vector<string> split(const string &src, const char *delim = ".") {
    vector<string> vec;
    string::size_type len = src.length();

    for (string::size_type i = 0, n; i < len; i = n + 1) {
        n = src.find_first_of(delim, i);
        if (n == string::npos) {
            n = len;
        }
        vec.push_back(src.substr(i, n - i));
    }

    return vec;
}

ll intpow(const int &a, const int &n) {
    if (n == 0)
        return 1;
    else if (n & 1)
        return intpow(a * a, n / 2) * a;
    else
        return intpow(a * a, n / 2);
}

signed main() {
    cin >> N;
    vector<pair<int, int>> a(N);
    H = 1000;
    vvi imos(H, vi(H));
    int geta = H / 2;
    REP(i, N) {
        cin >> S;
        auto x = split(S);
        if (x.size() == 1)
            x.push_back("0");
        ll tmp = intpow(10, x[1].size()) * stoi(x[0]) + stoi(x[1]);
        while (tmp % 2 == 0) {
            a[i].first++;
            tmp /= 2;
        }
        while (tmp % 5 == 0) {
            a[i].second++;
            tmp /= 5;
        }
        a[i].first -= x[1].size();
        a[i].second -= x[1].size();
        dump(a[i]);
        imos[a[i].first + geta][a[i].second + geta]++;
        if (stoi(x[1]) == 0) {
            ans--;
        }
    }
    dump(ans);
    RREP(i, H)
    RREP(j, H - 1) {
        imos[i][j] += imos[i][j + 1];
    }
    RREP(i, H - 1)
    RREP(j, H) {
        imos[i][j] += imos[i + 1][j];
    }
    REP(i, N) {
        int h = -a[i].first + geta;
        int w = -a[i].second + geta;
        ans += imos[h][w];
        dump(a[i], h, w, imos[h][w]);
    }
    dump(ans);
    cout << ans / 2 << endl;
}

Measured memory_bytes: 8708
#include<bits/stdc++.h>
#define N 500
using namespace std;
template<typename T>inline void read(T &x)
{
	x=0;
	static int p;p=1;
	static char c;c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c-'0');c=getchar();}
	x*=p;
}
const int mod=1e9+7;
int n,c;
int A[N],B[N];
int dp[N][N],sum[N][N],poww[N][N];
int main()
{
	read(n);read(c);
	for(int i=1;i<=n;i++) read(A[i]);
	for(int i=1;i<=n;i++) read(B[i]);
	for(int i=1;i<=400;i++)
	{
		poww[i][0]=1;
		for(int j=1;j<=c;j++)
			poww[i][j]=(long long)poww[i][j-1]*i%mod;
		for(int j=0;j<=c;j++)
			sum[i][j]=(sum[i-1][j]+poww[i][j])%mod;
	}
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=c;j++)
			for(int k=0;k<=j;k++)
				(dp[i][j]+=(long long)dp[i-1][j-k]*(sum[B[i]][k]-sum[A[i]-1][k])%mod)%=mod;
	printf("%d\n",(dp[n][c]%mod+mod)%mod);
	return 0;
}

Measured memory_bytes: 2560
import std.stdio;
import std.string;
import std.conv;
import std.range;
import std.array;
import std.algorithm;

void main() {
    string input;

    while ((input = readln.chomp).length != 0) {
        while (input.length > 1) {
            string output;
            for (int i = 0; i < input.length-1; i++) {
                output ~= (((input[i] - '0')+(input[i+1] - '0'))%10).to!string;
            }
            input = output;
        }

        writeln(input);
    }
}

Measured memory_bytes: 1060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            int N = int.Parse(line);
            var dict = new Dictionary<string, int>();
            dict.Add("AC", 0);
            dict.Add("WA", 0);
            dict.Add("TLE", 0);
            dict.Add("RE", 0);
            for(int i = 0; i < N; i++)
            {
                line = Console.ReadLine();
                dict[line]++;
            }
            Console.WriteLine("AC x "+dict["AC"]);
            Console.WriteLine("WA x " + dict["WA"]);
            Console.WriteLine("TLE x " + dict["TLE"]);
            Console.WriteLine("RE x " + dict["RE"]);
        }
    }
}


Measured memory_bytes: 30976
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    string S;
    cin >> S;
    int a = 0;
    long long ans = 0;

    for ( int i = S.length()-1; i >= 0; i-- ) {
        if ( S[i] == 'B' ) {            
            ans += (S.length()-1-a)-i;
            a++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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); }

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

  int x, y, add = 1;
  cin >> x >> y;

  if ((x > 0 && y > 0) || (x < 0 && y < 0)) {
    if (x < y)
      add = 0;
    else
      add = 2;
  } else if (x == 0 && y > 0)
    add = 0;
  else if (x < 0 && y == 0)
    add = 0;

  cout << abs(abs(x) - abs(y)) + add << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES 
#include <iomanip> 
#include <cmath>  
#include<iostream>
#include <fstream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

ll N, C[10], ans;
string S;

int main() {
	rd(N);
	repi(i, 0, N) {
		rd(S);
		if (S[0] == 'M') C[0]++;
		if (S[0] == 'A') C[1]++;
		if (S[0] == 'R') C[2]++;
		if (S[0] == 'C') C[3]++;
		if (S[0] == 'H') C[4]++;
	}
	repi(i, 0, 5) {
		repi(j, i + 1, 5) {
			repi(k, j + 1, 5) {
				ans += C[i] * C[j] * C[k];
			}
		}
	}

	wrln(ans);

	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();

        for (int i = 0; i < k; i++) {
            if (a + i <= b - k) {
                System.out.println(a + i);
            }
        }
        for (int i = k - 1; i >= 0; i--) {
            if (b - i >= a) {
                System.out.println(b - i);
            }
        }
    }
}


Measured memory_bytes: 21968
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, N) for (int i = 0; i < N; ++i)
int main()
{
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int> l(Q), r(Q);
  REP(i, Q)
  {
    cin >> l[i] >> r[i];
    l[i]--;
    r[i]--;
  }
  vector<int> sum(N);
  sum[0] = 0;
  for (int i = 1; i < N; i++)
  {
    sum[i] = sum[i - 1];
    if (S[i - 1] == 'A' && S[i] == 'C')
      sum[i]++;
  }
  REP(i, Q)
  cout << sum[r[i]] - sum[l[i]] << endl;
  return 0;
}

Measured memory_bytes: 2176
from collections import Counter, defaultdict, deque

R, C, M = [int(x) for x in input().split()]
targets = [tuple(int(x) - 1 for x in input().split()) for i in range(M)]  # 0 indexed

if False:
    # Answer should be 4, not 3
    targets = [
        (0, 0),
        (0, 2),
        (1, 2),
        (2, 0),
        (2, 1),
    ]

mostByRow = Counter(r for r, c in targets)
mostByCol = Counter(c for r, c in targets)

r = max(mostByRow.keys(), key=lambda r: mostByRow[r])
c = max(mostByCol.keys(), key=lambda c: mostByCol[c])
ans = mostByRow[r] + mostByCol[c]
intersectsTarget = False
if (r, c) in targets:
    intersectsTarget = True
    ans -= 1
if intersectsTarget:
    maxR = max(mostByRow.values())
    maxC = max(mostByCol.values())

    rs = set(r for r, v in mostByRow.items() if v == maxR)
    cs = set(r for r, v in mostByCol.items() if v == maxC)

    points = 0
    for r, c in targets:
        if r in rs and c in cs:
            points += 1
    if points < len(rs) * len(cs):
        ans += 1

print(ans)


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

int main() {
  int n,a,b,c,d;
  cin >> n;
  a=n/1000,b=n%1000,b=(n%1000)/100,c=((n%1000)%100)/10,d=((n%1000)%100)%10 ;
    if ((a==b && b==c)||(b==c && c==d) ) {
      cout << "Yes" << endl ;
    }
  else {
    cout << "No" << endl ;
  }
      
}

Measured memory_bytes: 256
H,W = map(int,input().split())
ans = []
board = []
for _ in range(H):
    row = list(input())
    board.append(row)
for i in range(H):
    row = ""
    for q in range(W):
        neighbor = []
        if q > 0: #左側
            neighbor.append(board[i][q-1]) #真左
            if i > 0:
                neighbor.append(board[i-1][q-1]) #左上
            if i < (H - 1):
                neighbor.append(board[i+1][q-1]) #左下
        if i > 0: #真上
            neighbor.append(board[i-1][q])
        if q < (W - 1): #右側
            neighbor.append(board[i][q+1]) #真右
            if i > 0:
                neighbor.append(board[i-1][q+1]) #右上
            if i < (H - 1):
                neighbor.append(board[i+1][q+1]) #右下
        if i < (H - 1): #真下
            neighbor.append(board[i+1][q])
        if board[i][q] == "#":
            row += board[i][q]
        else:
            row += str(neighbor.count("#"))
    print(row)


Measured memory_bytes: 3064
/****************************************************************************************************
                                        SUBMITTED BY-

                                                AISH_07

****************************************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ll long long
#define sl set<ll>
#define vs vector<string>
#define pb push_back
#define vl vector<ll>
#define vi vector<int>
#define PI  3.14159265
#define mod 998244353

int main()
{

 int n;
 cin>>n;

 int a[n+1];
 ll sum=0;
 a[0]=0;
 int b[100001]={0};
 for(int i=1;i<=n;i++)
 {
     cin>>a[i];
     sum+=a[i];
     b[a[i]]++;
 }

 int m;
 cin>>m;

 for(int i=0;i<m;i++)
 { int x,y;
    cin>>x>>y;
    if(b[x]>=0)
    {
        int d=b[x]*x;
        int m=b[x]*y;
        b[y]+=b[x];
        b[x]=0;
        sum+=(m-d);
        cout<<sum<<"\n";
    }
 }
  return 0;

}



Measured memory_bytes: 4376
#include <iostream>

int fun(int n,int m);

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    cout<<fun(n,m)<<endl;
}

int fun(int n,int m)
{
    n=n%m;
    return n?fun(m,n):m;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAXN=2e5+100;
int a[110],b[110];
int main(){
	ios;
	int n;
	cin>>n;
	ll sum=0;
	for(int i=1;(n-1)>=i;i++){
		sum+=(n-1)/i;
	}
	cout<<sum<<'\n';	
	return 0;
}

Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        string[] cin = Console.ReadLine().Split();
        int n = int.Parse(cin[0]);
        int m = int.Parse(cin[1]);

        // 始点からの距離dist（初期値は無限。後でdist[始点]だけ0にする）
        // 配列やListは参照型なので普通に引数にした場合(値渡し)
        // 引数にしたdistは戻り値にしなくても結果を受け取れる
        long[] dist = new long[n];
        for (int i = 0; i < n; i++)
            dist[i] = long.MaxValue;

        // Bellman_ford(頂点数,始点,辺の数,dist)
        // 戻り値はbool[n]で始点→各頂点の途中に負閉路が存在するか(存在すればtrue)
        int s = 0; // 今回の始点は固定で0
        bool[] negative = Bellman_ford(n, s, m, dist);

        // 今回の目的地は固定でn-1
        // n-1までの経路に負閉路が存在すれば答えはinf
        // また、本問題ではコストの正負を反転させてるので元に戻す
        if (negative[n - 1]) Console.WriteLine("inf");
        else Console.WriteLine(-dist[n - 1]);
    }

    static bool[] Bellman_ford(int n, int s, int m, long[] dist)
    {
        // グラフの受け取りはこっちでやる
        // 頂点a→頂点b(コストc)
        string[] cin;
        int[] a = new int[m];
        int[] b = new int[m];
        long[] c = new long[m];
        for (long i = 0; i < m; i++)
        {
            cin = Console.ReadLine().Split();
            // 本問題では
            // ・入力のインデックスが1スタートなので0スタートに変更
            // ・コストの正負を反転させる
            a[i] = int.Parse(cin[0]) - 1;
            b[i] = int.Parse(cin[1]) - 1;
            c[i] = -long.Parse(cin[2]);

            //a[i] = int.Parse(cin[0]);
            //b[i] = int.Parse(cin[1]);
            //c[i] = long.Parse(cin[2]);
        }

        // 始点から始点の距離は0
        dist[s] = 0;

        // 第一ステップ：最短距離の算出
        // 始点を除くn-1個の頂点と全ての辺について貪欲的に最短距離を算出
        for (int i = 1; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                // dist[a[j]]がlong.MaxValueだと桁あふれするのでその場合を除外
                if (dist[a[j]] != long.MaxValue) dist[b[j]] = Math.Min(dist[b[j]], dist[a[j]] + c[j]);
            }
        }

        // 第二ステップでdistの値が変化する場合、それは最短距離では無いので
        // 作業用にdist2作ったりする必要はない

        // 第二ステップ：負閉路の検出
        // 負閉路が無い場合はここまでで最短距離が出てるはず
        // 全ての辺について再計算して最短距離が変わるならそれは負閉路の存在を示す
        bool[] negative = new bool[n];

        for (int j = 0; j < m; j++)
        {
            if (dist[a[j]] != long.MaxValue && dist[b[j]] > dist[a[j]] + c[j])
            {
                dist[b[j]] = dist[a[j]] + c[j];
                negative[b[j]] = true;
            }
            // 負閉路を経由してきたやつはその先も負閉路経由となるので
            if (negative[a[j]]) negative[b[j]] = true;
        }
        return negative;
    }
}

Measured memory_bytes: 13248
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


int main(){
  int N;
  cin >> N;
  int a[110];
  float  mean = 0;
  rep(i,N) cin >> a[i],mean+=a[i];
  int m = round(mean / N);
  int ans = 0;
  rep(i,N) ans += (a[i]-m)*(a[i]-m);
  
  cout << ans << endl;
  
  return 0;
}




Measured memory_bytes: 512
n=int(input())
a = list(map(int, input().split()))
a.sort()
if n % 2 == 0:
  result = 2*sum(a[n//2:]) - a[n-1]
else:
  result = 2*sum(a[n//2:]) - a[n-1] - a[n//2]
print(result)


Measured memory_bytes: 31444
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int arr[3];
	for(int i=0;i<3;i++)cin>>arr[i];
	sort(arr,arr+3);
	cout<<arr[0]*arr[1]/2;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a));reverse(all(a))
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) rep(ghf,SZ(a)){rep(kjh,SZ(a[ghf])){cout<<(a[ghf][kjh]<10?" ":"")<<a[ghf][kjh]<<" ";}ENDL;}
#define out(a) cout<<(a)<<endl
#define fi first
#define se second
#define Vec vector
#define P pair
typedef long long ll;
typedef string str;
typedef vector<ll> V;
typedef pair<ll,ll> Pi;
typedef vector<Pi> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int max(int a,int b){if(a>b)return a; return b;}
int min(int a,int b){if(a>b)return b; return a;}
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin>>n;
  V a(n);
  rep(i,n)cin>>a[i];
  SORT(a);
  map<int,int> m;
  rep(i,n)m[a[i]]++;
  UNIQUE(a);
  reverse(all(a));
  int now=-1;
  for(auto&i:a){
    if(m[i]>=2){
      if(now!=-1){
        cout<<now*i<<endl;
        return 0;
      }
      else now=i;
    }
    if(m[i]>=4){
      cout<<(i*i)<<endl;
      return 0;
    }
  }
  out(0);

  
  return 0;
}



Measured memory_bytes: 7296
#include<stdio.h>
int main(){
  int n,c=1,s,t,d[101]={0};
  int i,j,r[101];
  while(1){
    scanf("%d,%d",&n,&t);
    if(n==0&&t==0)break;
    d[n]=t;
  }
  for(i=30;i>=0;i--){
    s=0;
    for(j=1;j<101;j++){
      if(d[j]==i){
	r[j]=c;
	s=1;
      }
    }
    if(s==1)c++;
  }
  while(scanf("%d",&n)!=EOF){
    printf("%d\n",r[n]);
  }
  return 0;
}

Measured memory_bytes: 600
import heapq

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

q,k = map(int, input().split())

dist = [float('inf') for i in range(n)]
dist[k-1] = 0
visited = [False for i in range(n)]
hq = [(0, k-1)]
while hq:
    d, v = heapq.heappop(hq)
    if visited[v]:
        continue
    visited[v] = True
    for nv, c in g[v]:
        if visited[nv]:
            continue
        if d+c < dist[nv]:
            heapq.heappush(hq, (d+c, nv))
            dist[nv] = d+c


for i in range(q):
    x,y = map(int, input().split())
    print(dist[x-1] + dist[y-1])

    

Measured memory_bytes: 51932
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}



void oneCase () {
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n);
    for (auto& el : h) {
        cin >> el;
    }
    sort(h.begin(), h.end());
    cout << accumulate(h.begin(), h.begin() + n - min(n, k), 0LL) << "\n";

}




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

    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
	Scanner scanner = new Scanner(System.in);
	int a = scanner.nextInt();
	int b = scanner.nextInt();
	System.out.println(day(a, b));
    }
    public static int day (int a, int b) {
	if (a > b) {
	    return a - 1;
	} else {
	    return a;
	}
    }
}



Measured memory_bytes: 21716
def main():
    from bisect import bisect_left,bisect
    import sys
    input = sys.stdin.readline
    A,B,Q = map(int, input().split())
    S = [int(input()) for i in range(A)]
    T = [int(input()) for i in range(B)]
    X = [int(input()) for i in range(Q)]
    
    for i in X:
        ans = float("inf")
        j = min(bisect(S,i),A-1)
        k = min(bisect(T,i),B-1)
        l = [min(bisect(T,S[j]),B-1), min(bisect(T,S[j-1]),B-1)]
        r = [min(bisect(S,T[k]),A-1), min(bisect(S,T[k-1]),A-1)]
        for p in range(2):
            for q in range(2):
                tmp = abs(S[j-p] - i) + abs(T[l[p]-q] - S[j-p])
                if tmp < ans:
                    ans = tmp
                tmp = abs(T[k-p] - i) + abs(S[r[p]-q] - T[k-p])
                if tmp < ans:
                    ans = tmp
        print(ans)
    
    
    
    
main()

Measured memory_bytes: 86364
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = ni();
        }
        boolean alleven = true;
        for (int i = 0; i < N; i++) {
            if(a[i]%2==1) alleven = false;
        }
        if(alleven){
            out.println("second");
        }else{
            out.println("first");

        }
    }

    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);
    int upperBound(ArrayList<Long> list, Long target){
        int i = Collections.binarySearch(list, target, new UpperBoundComparator<Long>());
        return ~i;
    }
    class UpperBoundComparator<T extends Comparable<? super T>> implements Comparator<T>{
        public int compare(T x, T y){
            return (x.compareTo(y) > 0) ? 1 : -1;
        }
    }
    int lowerBound(ArrayList<Long> list, Long target){
        int i = Collections.binarySearch(list, target, new LowerBoundComparator<Long>());
        return ~i;
    }
    class LowerBoundComparator<T extends Comparable<? super T>> implements Comparator<T>{
        public int compare(T x, T y){
            return (x.compareTo(y) >= 0) ? 1 : -1;
        }
    }
    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 47704
#include<iostream>
#include<string>
#include<stdio.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#include<algorithm>
using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	rep(i, s.size()) {
		if (n + static_cast<int>(s.at(i)) >= 91) {
			printf("%c", n + static_cast<int>(s.at(i) - 26));
		}
		else {
			printf("%c", n + static_cast<int>(s.at(i)));
		}
	}
	cout << endl;
	return 0;
}

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

int main(){
    int W,H,x,y,r;
    cin >> W>> H >> x >> y >> r;
    
    if(0 <= x- r && x + r <= W && 0<= y - r && y + r <=H){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int const p=200003,g=5;
double const pi=acos(-1);
int lg[200005],r[800005];
struct comp
{
	double r,i;
	comp(double a=0,double b=0){r=a,i=b;}
	friend comp operator +(comp x,comp y){return comp(x.r+y.r,x.i+y.i);}
	friend comp operator -(comp x,comp y){return comp(x.r-y.r,x.i-y.i);}
	friend comp operator *(comp x,comp y){return comp(x.r*y.r-x.i*y.i,x.i*y.r+x.r*y.i);}
}A[800005];
void fft(comp *f,int n,int op)
{
	for(int i=1;i<n;i++)r[i]=(r[i>>1]>>1)|((i&1)?(n>>1):0);
	for(int i=1;i<n;i++)if(i<r[i])swap(f[i],f[r[i]]);
	for(int len=2;len<=n;len<<=1)
	{
		int q=len>>1;
		comp wn=comp(cos(pi/q),op*sin(pi/q));
		for(int i=0;i<n;i+=len)
		{
			comp w=comp(1,0);
			for(int j=i;j<i+q;j++,w=w*wn)
			{
				comp d=f[j+q]*w;
				f[j+q]=f[j]-d;
				f[j]=f[j]+d;
			}
		}	
	}
	if(op==-1)
		for(int i=0;i<n;i++)
			f[i]=f[i]*comp(1.0/n,0);
}
int pw(int x,int y)
{
	int res=1;
	while(y)
	{
		if(y&1)res=1ll*res*x%p;
		x=1ll*x*x%p;
		y>>=1;
	}
	return res;
}
int main()
{
	long long ans=0;
	int n,now=1,x;
	scanf("%d",&n);
	lg[1]=0;
	for(int i=1;i<p-1;i++)now=now*g%p,lg[now]=i;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(!x)continue;
		cerr<<lg[x]<<endl;
		A[lg[x]].r=A[lg[x]].r+1;
		ans-=1ll*x*x%p;
	}
	int lim=1;
	while(lim<(p<<1))lim<<=1;
	fft(A,lim,1);
	for(int i=0;i<lim;i++)A[i]=A[i]*A[i];
	fft(A,lim,-1);
	for(int i=0;i<lim;i++)
		ans+=1ll*((long long)(A[i].r+0.5))*pw(g,i);
	printf("%lld",ans/2);
    return 0;
}


Measured memory_bytes: 19480
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll n,m,t,i,j,a,b,k;
    string s;
    cin>>s;
    if(s=="SUN") cout<<"7";
    else if(s=="MON") cout<<"6";
    else if(s=="TUE") cout<<"5";
    else if(s=="WED") cout<<"4";
    else if(s=="THU") cout<<"3";
    else if(s=="FRI") cout<<"2";
    else cout<<"1";
}

Measured memory_bytes: 3592
s = str(input())
t = str(input())

L = [set() for _ in range(len(t))]
for i in range(len(t)):
    for j in range(len(s)):
        if s[j] == t[i] or s[j] == '?':
            L[i].add(j)
#print(L)

temp = set(range(len(s)))
for i in reversed(range(len(t))):
    temp = temp & L[i]
    if i != 0:
        temp = list(temp)
        temp = [p-1 for p in temp]
        temp = set(temp)
#print(temp)

if len(temp) == 0:
    print('UNRESTORABLE')
    exit()

temp = list(temp)
temp.sort()
id = temp[-1]
s_ = list(s)
t_ = list(t)
s_[id:id+len(t)] = t_
ans = ''
for c in s_:
    if c == '?':
        ans += 'a'
    else:
        ans += c
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}
typedef long long ll;
int n,m;
const int N=5e5+10;
struct edge{
	int u,v;ll val;
	inline bool operator <(const edge B)const{return val<B.val;}
}a[N];int cnt=0;
int q,fa[N];
int find(int x){return fa[x]==x? x:fa[x]=find(fa[x]);}
ll data[N];
int main()
{
	init(n),init(q);Set(data,-1);
	if(n==1) return puts("0"),0;
	for(int i=1;i<=q;++i){
		int X,Y;ll Z;
		init(X),init(Y),init(Z);
		a[++cnt]=(edge){X,Y,Z};
		if(~data[X]) data[X]=min(data[X],Z+1);
		else data[X]=Z+1;
		if(~data[Y]) data[Y]=min(data[Y],Z+2);
		else data[Y]=Z+2;
	}
	int pos=-1;
	for(int i=0;i<n;++i) {if(~data[i]) {if((~pos)&&data[pos]>data[i])pos=i;else if(pos==-1) pos=i;}}
	int u=pos,v;
	for(int i=1;i<=n;u=v,++i) {
		v=u+1;if(v>=n) v-=n;
		if(data[u]==-1) continue;
		if(~data[v]) data[v]=min(data[v],data[u]+2);
		else data[v]=data[u]+2;
		if(~data[u]) a[++cnt]=(edge){u,v,data[u]};
	}
	sort(a+1,a+1+cnt);
	for(int i=0;i<n;++i) fa[i]=i;
	ll tot=0;
	for(int i=1;i<=cnt;++i) {
		u=a[i].u,v=a[i].v;
		int fx=find(u),fy=find(v);
		if(fx==fy) continue;
		else fa[fx]=fy,tot+=a[i].val;
	}
	cout<<tot<<endl;
	return 0;
}


Measured memory_bytes: 15616
from math import floor

N = [int(_) for _ in input().split()]

H, W = N[0], N[1]


def solve(H, W):
    acnt = floor(W / 2) + 1
    bcnt = W - acnt
    
    if H == 1 or W == 1:
        return 1
    else:
        return floor((H * W + 1) / 2)
    
    # if H % 2 == 0:
    #     cnt = acnt * floor(H/2) + bcnt * floor(H/2)
    # else:
    #     cnt = acnt * (floor(H/2) + 1) + bcnt * floor(H/2)
    # return cnt

print(solve(H, W))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n; cin>>n;
	for(ll a=1;a<=3500;a++){
		for(ll b=1;b<=3500;b++){
			ll x=a+b;
			ll y=a*b;
			ll p=y*n;
			ll q=(4*y)-(x*n);
			if(q<=0) continue;
			if(p%q) continue;
			ll c=p/q;
			if(c>3500) continue;
			cout<<a<<" "<< b<<" "<<c<<endl;
			return 0;
		}
	}	
	return 0;
}

Measured memory_bytes: 256