akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;

#define EPS 0.0000000001
#define equals(a, b) (fabs((a) - (b)) < EPS)

class Point{
	public:
		double x, y;

		Point(double x = 0, double y = 0): x(x), y(y) {}

		Point operator + (Point p){ return Point(x + p.x, y + p.y);}
		Point operator - (Point p){ return Point(x - p.x, y - p.y);}
		Point operator * (double a){ return Point(a * x, a * y);}
		Point operator / (double a){ return Point(x / a, y / a);}

		double abs(){ return sqrt(norm());}
		double norm(){ return x * x + y * y;}

		bool operator < (const Point &p) const{
			return x != p.x ? x < p.x : y < p.y;
		}

		bool operator == (const Point &p) const{
			return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
		}
};

struct Segment {
	Point p1, p2;
};
typedef Segment Line;

class Circle{
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0): c(c), r(r) {}
};

typedef Point Vector;
typedef vector<Point> Polygon;

double dot(Vector a, Vector b){
	return a.x * b.x + a.y * b.y;
}
double cross(Vector a, Vector b){
	return a.x * b.y - a.y * b.x;
}

Point project(Segment s, Point p){
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + base * r;
}

int main(void){
	Segment s;
	Point p;
	int q;

	cin >> s.p1.x >> s.p1.y >> s.p2.x >> s.p2.y;
	cin >> q;
	for(int i=1;i<=q;i++){
		cin >> p.x >> p.y;
		Point projection = project(s, p);
		printf("%.10f %.10f\n",projection.x, projection.y);
	}

	return 0;
}

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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    int N,X; cin >> N>>X;
    vector<int> m(N); cin >> m;

    int m_sum = accumulate(ALL(m), 0);
    int m_min = *min_element(ALL(m));

    int ans = N + (X - m_sum) / m_min;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1e9+7
#define LINF (long long)4e18

int dp[100010];

int main(){
    int N;
    cin >> N;
    dp[0] = 0;
    repr(i,1,N+1){
        dp[i] = INF;
        int power = 1;
        while(power <= i){
            dp[i] = min(dp[i],dp[i-power]+1);
            power *= 6;
        }
        power = 1;
        while(power <= i){
            dp[i] = min(dp[i],dp[i-power] +1);
            power *= 9;
        }
    }
    int ans = dp[N];
    cout << ans << endl;
}
   

Measured memory_bytes: 640
N, M = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(M)]
p = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    cnt = 0
    for j in range(M):
        count = 0
        for k in ks[j][1::]:
            if (i >> k-1)&1 == 1:
                count += 1
        if count%2 == p[j]:
            cnt += 1
    if cnt == M:
        ans += 1
print(ans)

Measured memory_bytes: 3064
from collections import defaultdict
import sys
n = int(input())
v = list(map(int, input().split()))

dd_even = defaultdict(int)
dd_odd  = defaultdict(int)

# 偶数番目のヒストグラムを作る
for i in range(0, n, 2):
    dd_even[v[i]] += 1

l_even = list(dd_even.items())
l_even.sort(key= lambda x:x[1])
top_even = l_even[-1][0]
#print(l_even)

# 奇数番目のヒストグラムを作る
for i in range(1, n, 2):
    dd_odd[v[i]] += 1

l_odd = list(dd_odd.items())
l_odd.sort(key= lambda x:x[1])
#print(l_odd)
top_odd = l_odd[-1][0]

if top_even == top_odd:
    if len(l_odd) == 1: # つまり全部同じ数字のとき
        res = int(n / 2)
        print(res)
        sys.exit()
    else:
        # 2パターン試す
        l_odd_1 = [l for l in l_odd if l[0] != l_odd[-2][0]]
        sum_odd_1 = sum(l[1] for l in l_odd_1)
        l_even_1 = [l for l in l_even if l[0] != top_even]
        sum_even_1 = sum(l[1] for l in l_even_1)
        sum_1 = sum_odd_1 + sum_even_1

        l_odd_2 = [l for l in l_odd if l[0] != top_odd]
        sum_odd_2 = sum(l[1] for l in l_odd_2)
        l_even_2 = [l for l in l_even if l[0] != l_even[-2][0]]
        sum_even_2 = sum(l[1] for l in l_even_2)
        sum_2 = sum_odd_2 + sum_even_2

        if sum_1 < sum_2:
            print(sum_1)
        else:
            print(sum_2)
        sys.exit()
else:
    l_odd = [l for l in l_odd if l[0] != top_odd]

sum_odd = sum(l[1] for l in l_odd)
#print(l_odd, sum_odd)

l_even = [l for l in l_even if l[0] != top_even]
sum_even = sum(l[1] for l in l_even)
#print(l_even, sum_even)

res = sum_odd + sum_even
print(res)

Measured memory_bytes: 22024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
    if((a*b)%2==0){
        cout << "Even" << endl;
    }else{
        cout << "Odd" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[101];
int tmp=-1;
int main()
{
	gets(s);
	for(int i=0;i<strlen(s);i++)if(s[i]=='C'){tmp=i;break;}
	if(tmp>=0)for(int i=tmp+1;i<=strlen(s);i++)if(s[i]=='F'){printf("Yes");return 0;}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;

typedef int flow_t;

const int MAX_N = 500;
const int MAX_E = 20000;
const int MAX_Q = 1000;

struct edge{
	int tar;
	flow_t cap;
	bool on;
};

struct query{
	int cmd;
	int x, y;
};

int V, E, Q;
vector<edge> graph[MAX_N];
int id_table[MAX_N][MAX_N];
query qs[MAX_Q];

void add_edge(int x, int y, flow_t cap, bool on){
	id_table[x][y] = graph[x].size();
	id_table[y][x] = graph[y].size();
	graph[x].push_back((edge){y, cap, on});
	graph[y].push_back((edge){x, cap, on});
}

void init(){
	scanf("%d%d%d", &V, &E, &Q);
	memset(id_table, -1, sizeof(id_table));
	for(int i=0; i<E; i++){
		int x, y;
		scanf("%d%d", &x, &y);
		x--; y--;
		add_edge(x, y, 1, true);
	}

	for(int i=0; i<Q; i++){
		int c, x, y;
		scanf("%d%d%d", &c, &x, &y);
		x--; y--;
		qs[i] = (query){c, x, y};
		if(id_table[x][y] == -1){
			add_edge(x, y, 0, false);
		}
	}

}

bool visited[MAX_N];
int vis_time[MAX_N];

bool dfs(int v, int sink){
	if(v == sink){
		return true;
	}
	visited[v] = true;
	for(int i=0; i<(int)graph[v].size(); i++){
		edge& e = graph[v][i];
		if(e.on && e.cap > 0 && !visited[e.tar] && dfs(e.tar, sink)){
			e.cap--;
			graph[e.tar][id_table[e.tar][v]].cap++;
			return true;
		}
	}

	return false;
}

bool rem_dfs(int v){
	vis_time[v] = 2;
	for(int i=0; i<(int)graph[v].size(); i++){
		edge& e = graph[v][i];
		if(e.on && e.cap > 0){
			if(vis_time[e.tar] == 1 || (vis_time[e.tar] == 0 && rem_dfs(e.tar))){
				e.cap--;
				graph[e.tar][id_table[e.tar][v]].cap++;
				return true;
			}
		}
	}
	return false;
}

bool remove_cycle(int x, int y){
	memset(vis_time, 0, sizeof(vis_time));
	vis_time[y] = 1;
	return rem_dfs(x);
}

void solve(){
	const int source = 0, sink = V - 1;
	flow_t current = 0;

	for(;memset(visited, false, sizeof(visited)), dfs(source, sink); current++);

	for(int i=0; i<Q; i++){
		if(qs[i].cmd == 1){
			int x = qs[i].x, y = qs[i].y;
			graph[x][id_table[x][y]].on = true;
			graph[y][id_table[y][x]].on = true;
			graph[x][id_table[x][y]].cap = 1;
			graph[y][id_table[y][x]].cap = 1;
			memset(visited, false, sizeof(visited));
			if(dfs(source, sink)){
				current++;
			}
		}
		else{
			int x = qs[i].x, y = qs[i].y;
			if(graph[x][id_table[x][y]].cap != 1){
				// ツ個サツ催敖づ郊 -> yツづ猟ャツづェツづつ「ツづゥツづヲツつ、ツづ可暗ェツ氾環可サ
				if(graph[x][id_table[x][y]].cap == 2){
					swap(x, y);
				}
				if(!remove_cycle(x, y)){
					memset(visited, false, sizeof(visited));
					if(dfs(sink, source)){
						current--;
					}
					int cur = graph[x][id_table[x][y]].cap;
					if(cur != 1){
						if(cur == 2){
							swap(x, y);
						}
						remove_cycle(x, y);
					}
				}
			}
			graph[x][id_table[x][y]].on = false;
			graph[y][id_table[y][x]].on = false;
			graph[x][id_table[x][y]].cap = 0;
			graph[y][id_table[y][x]].cap = 0;
		}
		printf("%d\n", current);
	}
}

int main(){
	init();
	solve();

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll A,B,C, K; cin >> A >> B >> C >> K;
    while (K && A>=B) {
        B*=2;
        --K;
    }
    while (K && B>=C) {
        C*=2;
        --K;
    }
    if (A<B && B<C) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int h,w;
   cin >> h >> w;
   if(h == 1 or w == 1){
      cout << 1;
      return 0;
   }
   cout << (h*w+1)/2 << '\n';
   return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int maxn = 1010;
const int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
int H,W,N,sx,sy;
char maze[maxn][maxn];
bool visit[maxn][maxn];
char target = '1';
struct node{
	int x,y;
	int step;
};
void bfs(int x,int y){
	node p,q;
	queue<node> que;
	p.x = x;p.y = y;
	p.step = 0;
	que.push(p);
	memset(visit,false,sizeof(visit));
	visit[x][y] = true;
	while(!que.empty()){
		p = que.front();que.pop();
		if(maze[p.x][p.y]==target){
			if(target==N) {
				printf("%d\n",p.step);
				return;
			}
			else{
				target += 1;
				while(!que.empty()) que.pop();
				memset(visit,false,sizeof(visit));
			}
		}
		for(int i=0;i<4;i++){
			q.x = p.x + dx[i];
			q.y = p.y + dy[i];
			if(q.x>=0&&q.x<H&&q.y>=0&&q.y<W&&maze[q.x][q.y]!='X'&&!visit[q.x][q.y]){
				visit[q.x][q.y] = true;
				q.step = p.step + 1;
				que.push(q);
			}
		}
	}
}
int main(){
	scanf("%d %d %c",&H,&W,&N);
	getchar();
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			scanf("%c",&maze[i][j]);
			if(maze[i][j]=='S'){
				sx = i;sy = j;
			}
		}
		getchar();
	}
	bfs(sx,sy);
} 


Measured memory_bytes: 5272
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector <int> A(N);
  for(int i=0;i<N;i++){
  cin>>A.at(i);
  }
  int sum=0;
  for(int i=0;i<N;i++){
   sum+=A.at(i);
  }
  int ave=sum/N;
  int sum1=0;
  if(sum%N<=N/2){
  for(int i=0;i<N;i++){
  sum1+=(A.at(i)-ave)*(A.at(i)-ave);
  
  }
  }else{
    for(int i=0;i<N;i++){
  sum1+=(A.at(i)-ave-1)*(A.at(i)-ave-1);
    }
  }
    cout<<sum1<<endl;
  
  return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    string s;cin >> s;
    map<char, char> m;
    m['b'] = 'd';
    m['d'] = 'b';
    m['p'] = 'q';
    m['q'] = 'p';
    int n = s.size();
    string ans = "Yes";
    for(int i=0;i<n;i++){
        if(m[s[i]] != s[n-i-1]) ans = "No";
    }
    cout << ans << endl;
    return 0;
}


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

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

    if(s.length() < 4){
        cout << "No" << endl;
    }else{
        if(s.substr(0,4) == "YAKI") cout << "Yes" << endl;
        else                        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
def f():
	from math import ceil
	T1,T2 = map(int,input().split())
	A1,A2 = map(int,input().split())
	B1,B2 = map(int,input().split())
	if B1 > A1:
		A1,A2,B1,B2 = B1,B2,A1,A2
	diff1 = (A1 - B1) * T1
	fac = (B2 - A2) * T2 - diff1
	if fac == 0:
		print("infinity")
	elif diff1 / fac < 0:
		print(0)
	elif diff1 / fac <= 1:
		print(1)
	else:
		print(2 * ceil(diff1 / fac) - int(diff1 % fac != 0))
f()

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)















int main() {
	ll a[3];
	REP(i, 3) cin >> a[i];
	sort(a, a + 3);
	if ((a[0] == a[1] && a[1] != a[2])|| (a[0] != a[1] && a[1] == a[2])) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

int N, W; cin >> N >> W;
VI v(N),w(N); rep(i, 0, N) cin >> v[i] >> w[i];

// val[i+1][j] = i 番目までの品物から重さの総和が j 以下となるように選んだ時の，価値の総和の最大値
VVI val(N+1, VI(W+1, 0));
// val[0][j] = 0 . 0 番目での価値の最大値

rep(i, 0, N){
    rep(j, 0, W+1){
        if (j < w[i]) 
            val[i + 1][j] = val[i][j];
        else 
            val[i + 1][j] = max(val[i][j], val[i + 1][j -  w[i]] + v[i]);
    }
}

cout << val[N][W] << endl;
}

// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり




Measured memory_bytes: 10788
#include <cstdio>

int main(){
	char s[5];
	scanf("%s", s);
	for(int i=0;i<3;i++){
		if(s[i] == s[i+1]){
			printf("Bad");
			return 0;
		}
	}
	printf("Good");
	return 0;
}
	


Measured memory_bytes: 128
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 1000 + 5;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
char mp[maxn][maxn];
int n, m;
int sx, sy, tx, ty;
pii s, t;
map <pii, bool> vis;
int dis[maxn][maxn];
struct node {
    int dis;
    pii id;
    bool operator < (const node &x) const {
        return dis > x.dis;
    }
};
priority_queue<node> q;
void bfs() {
    q.push({0, s});
    memset(dis, 0x3f3f3f3f, sizeof(dis));
    dis[s.first][s.second] = 0;
    while(!q.empty()) {
        node cur = q.top();
        q.pop();
        int x = cur.id.first;
        int y = cur.id.second;
        if(vis[cur.id]) continue;
        vis[cur.id] = 1;
        for(int i = 0; i < 4; ++i) {
            int xx = x + dx[i];
            int yy = y + dy[i];
            if(x < 1 || y < 1 || x > n || y > m) continue;
            if(mp[xx][yy] == '.' && dis[xx][yy] > dis[x][y]) {
                dis[xx][yy] = dis[x][y];
                if(!vis[make_pair(xx, yy)])
                q.push({dis[xx][yy], make_pair(xx, yy)});
            }
        }
        for(int i = max(0, x - 2); i <= min(n, x + 2); ++i)
            for(int j = max(0, y - 2); j <= min(m, y + 2); ++j) {
                if(mp[i][j] == '.' && dis[i][j] > dis[x][y] + 1) {
                    dis[i][j] = dis[x][y] + 1;
                    if(!vis[make_pair(i, j)])
                    q.push({dis[i][j], make_pair(i, j)});
                }
            }
    }
    int ans = dis[tx][ty] == 0x3f3f3f3f ? -1 : dis[tx][ty];
    cout << ans;
}
int main() {	
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cin >> n >> m;
    cin >> sx >> sy;
    cin >> tx >> ty;
    s = make_pair(sx, sy);
    t = make_pair(tx, ty);
    for(int i = 1; i <= n; ++i)
        cin >> mp[i] + 1;
    bfs();
    return 0;
}

Measured memory_bytes: 39716
<?php
fscanf(STDIN, "%d", $n);
$v = explode(' ', trim(fgets(STDIN)));
$c = explode(' ', trim(fgets(STDIN)));
$x = 0;
for ($i = 0; $i < $n; $i++) {
	$d = $v[$i] - $c[$i];
	if ($d > 0) $x += $d;
}
echo $x;

Measured memory_bytes: 4728
H,W=map(int,input().split())
c=[]
for i in range(10):
    tmp=list(map(int,input().split()))
    c.append(tmp)
A=[]
for i in range(H):
    A.append(list(map(int,input().split())))
    
for k in range(10):#経由する点
    for i in range(10):#始点
        for j in range(10):#終点
            c[i][j]=min(c[i][j],c[i][k]+c[k][j])

res=0    
for i in range(H):
    for j in range(W):
        if(A[i][j]!=-1):
            res+=c[A[i][j]][1]
print(res)

Measured memory_bytes: 3444
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	string a,b;
	int k=0,c;
	cin>>a>>b;
	a+=b;
	for(int i=0;i<a.size();i++)k=k*10+a[i]-48;
	c=sqrt(k);
	if(c*c==k)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

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

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

    deque<int> deq;
    int back_front = 0; // 0: back 1: front
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (back_front == 0) {
            deq.push_back(a);
        } else {
            deq.push_front(a);
        }
        back_front ^= 1;
    }
    if (back_front == 1) {
        reverse(deq.begin(), deq.end());
    }
    int i = 0;
    for (auto a : deq) {
        if (i > 0) {
            cout << " ";
        }
        cout << a;
        i++;
    }
    cout << endl;
    return 0;
}

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

const int MOD(1000000007);
int n, k;
int fac[4000000], inv_fac[4000000], dp[2001][2001];


int Power(long long a, int b)
{
	long long ret(1ll);
	
	while (b) {
		b & 1 && (ret *= a);
		ret >= MOD && (ret %= MOD);
		a *= a;
		a >= MOD && (a %= MOD);
		b >>= 1;
	}
	return ret;
}


int main()
{
	register long long lt;
	int t;
	
	scanf("%d%d", &n, &k);
	if (k == 1) {
		printf("1\n");
		return 0;
	}
	fac[0] = 1;
	t = n * k;
	for (int i = 1; i < t; ++i) {
		lt = (long long)i * fac[i - 1];
		fac[i] = lt < MOD ? lt : lt % MOD; 
	}
	inv_fac[t - 1] = Power((long long)fac[t - 1], MOD - 2);
	for (int i = t - 2; i; --i) {
		lt = (long long)(i + 1) * inv_fac[i + 1];
		inv_fac[i] = lt < MOD ? lt : lt % MOD;
	}
	inv_fac[0] = 1;
	dp[0][0] = 1;
	t = -2;
	for (int i = 1; i <= n; ++i) {
		t += k - 1;
		for (int j = 0; j <= i; ++j) {
			++t;
			lt = (long long)fac[t] * inv_fac[t - k + 2];
			lt >= MOD && (lt %= MOD);
			lt *= (long long)inv_fac[k - 2];
			lt >= MOD && (lt %= MOD);
			lt *= (long long)dp[i - 1][j];
			j && (lt += dp[i][j - 1]);
			dp[i][j] = lt < MOD ? lt : lt % MOD;
		}
		t -= i + 1;
	}
	lt = (long long)dp[n][n] * fac[n] % MOD;
	printf("%lld\n", lt);
	return 0;
}



Measured memory_bytes: 46208
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
ans = x[1]-x[0]
for i in range(N):
    ans = gcd(ans,x[i+1]-x[i])
print(ans)


Measured memory_bytes: 62576
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long res = 0;
        int n = sc.nextInt();
        int[] ar = new int[n*3];
        for (int i = 0; i < n * 3; i++) {
            ar[i] = sc.nextInt();
        }
        Arrays.sort(ar);
        for (int i = 0; i < n; i++) {
            res += ar[ar.length - 2 - i * 2];
        }
        System.out.println(res);


        sc.close();
    }
}

class io {
    public static void br() {
        System.out.println("");
    }

    public static void yesno(boolean f) {
        System.out.println(f ? "yes" : "no");
    }

    public static void YesNo(boolean f) {
        System.out.println(f ? "Yes" : "No");
    }

    public static void YESNO(boolean f) {
        System.out.println(f ? "YES" : "NO");
    }

}

class Algo {
    public static int nibutan(int target, int[] ar) {
        // ar[i] >= target なる最小のiを探す
        int res;
        int high = ar.length;
        int low = 0;
        while (high > low) {
            res = (high + low) / 2;
            if (ar[res] < target) {
                // ↑↓ここを変える
                low = res + 1;
            } else {
                // ↓ここを変える
                high = res;
            }
        }
        return low;
    }

    public static boolean isOdd(int n) {
        return n % 2 == 1;
    }

    public static boolean isEven(int n) {
        return n % 2 == 0;
    }


}



Measured memory_bytes: 92484
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cerr<<' ';cerr<<elem;}cerr<<endl;}

/*エラトステネスの篩*/
struct Sieve{
	int n;		//要素数.
	vi fac;		//fac[i]:=(iの最大の素因数). fac[i]=iのとき,iは素数. 
	vi prime;	//1~nの素数の集合.
	
	Sieve(int n_):n(n_),fac(n+1,0){//constructor.
		fac[0]=fac[1]=-1;
		for(int i=2;i<=n;++i){//O(n log n).
			if(!fac[i]){
				fac[i]=i;
				prime.push_back(i);
				for(int j=i+i;j<=n;j+=i) fac[j]=i;
			}
		}
	}
	
	bool is_prime(int x){return fac[x]==x;}	//素数判定.
	map<int,int> prime_factor(int x){		//素因数分解.
		map<int,int> res;
		while(x>1){
			res[fac[x]]++;
			x/=fac[x];
		}
		return res;
	}
};

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

template<class Type_k,class Type_p>
Type_p mod_pow(long long n,Type_k k,Type_p p){//n^k(mod p).
	if(k==0) return 1;
	long long res=mod_pow(n*n%p,k/2,p);
	if(k&1) res=res*n%p;
	return res;
}

//解説参考.
int main(){
	int n;
	cin>>n;
	
	vi a(n);
	REP(i,n) cin>>a[i];//cin>>a[i];
	
	Sieve ob(1e6);
	map<int,int> mp;
	REP(i,n){
		map<int,int> res=ob.prime_factor(a[i]);
		for(auto elem:res) chmax(mp[elem.first],elem.second);
	}
	
	llong ln=1LL;
	for(auto elem:mp) ln=ln*mod_pow(elem.first,elem.second,MOD)%MOD;
	
	llong ans=0LL;
	REP(i,n){
		llong b=ln*mod_pow(a[i],MOD-2,MOD)%MOD;
		ans=(ans+b)%MOD;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 7944
import math
N = int(input())
t = 1
a = 1
for i in range(N):
  ti, ai = map(int, input().split())
  
  # trick to calc m accurately, instead of ceil(t/ti). '/' isn't accurate. 
  m = max( (t-1)//ti+1, (a-1)//ai+1 ) 
  t = m*ti
  a = m*ai
print(t+a)

Measured memory_bytes: 3060
#include"bits/stdc++.h"
using namespace std;

vector<int> par;

int root(int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = root(par[x]);
    }
}

bool same(int x, int y) {
    return root(x) == root(y);
}

void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
        return;
    }

    par[x] = y;
}

int main() {
    int N, M;
    cin >> N >> M;
    par.resize(N);
    for (int i = 0; i < N; i++) {
        par[i] = i;
    }

    vector<int> p(N);
    for (int i = 0; i < N; i++) {
        cin >> p[i];
        p[i]--;
    }
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        unite(x, y);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (same(i, p[i])) {
            ans++;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define MN 500
#define ll long long
#define INF 1000000000000000000LL
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n;
ll a[MN+5][MN+5],f[MN+5][MN+5],g[MN+5][MN+5],tot,b[MN+5][MN+5],c[MN+5][MN+5],ans=-INF;
int main()
{
    n=read();
    for(int i=1;i<=n;++i) for(int j=1;j<=n;++j)
    {
        if(i!=j) a[i][j]=read();
        if(i>j) tot+=a[i][j];
        f[i][j]=g[i][j]=-INF;
    }
    for(int i=n;i;--i) for(int j=i;j<=n;++j) 
        b[i][j]=b[i][j-1]+b[i+1][j]-b[i+1][j-1]+a[i][j],
        c[i][j]=c[i][j-1]+c[i+1][j]-c[i+1][j-1]+a[j][i];
    for(int i=1;i<=n;++i) for(int j=i;j<=n;++j)
    {
        if(i==1) f[1][j]=max(f[1][j],c[1][j]-b[1][j]);
        for(int k=j+1;k<=n;++k)
            f[j+1][k]=max(f[j+1][k],f[i][j]-b[j+1][k]+c[i][k]-c[i][j]);
    }
    for(int i=1;i<=n;++i) ans=max(ans,f[i][n]);
    cout<<tot-ans;
    return 0;
}

Measured memory_bytes: 10240
n=int(input())
A=[int(i) for i in input().split()]

pa=0
s=A[0]
if A[0]<=0:
    pa=1-A[0]
    s=1

for i in range(1,n):
    if i%2==1:
        if s+A[i]>=0:
            pa+=s+A[i]-(-1)
            s=-1
        else:
            s+=A[i]
    else:
        if s+A[i]<=0:
            pa+=1-(s+A[i])
            s=1
        else:
            s+=A[i]
ma=0
s=A[0]
if A[0]>=0:
    ma=A[0]-(-1)
    s=-1

for i in range(1,n):
    if i%2==1:
        if s+A[i]<=0:
            ma+=1-(s+A[i])
            s=1
        else:
            s+=A[i]
    else:
        if s+A[i]>=0:
            ma+=s+A[i]-(-1)
            s=-1
        else:
            s+=A[i]
       
print(min(pa,ma))

Measured memory_bytes: 85692
"use strict";
const input = require("fs").readFileSync("/dev/stdin","utf8").trim();

const n = input.length - 1;

if (n===0) {
  console.log(Number(input))
} else {
  let sum = 0;
  for(let i=0; i < 1<<n; i++){
    let str="";
    for(let shift=0; shift<n; shift++) {
      str = input[n - shift] + str;
      if ((i >> shift) & 1) {
        sum += Number(str);
        str = "";
      }

      if (shift === n - 1) {
        str = input[0] + str;
        sum += Number(str);
        str = "";
      }
    }
  }
  console.log(sum);
}

Measured memory_bytes: 9548
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> K >> N;
  if(500*K<N)Out("No");
  else Out("Yes");
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }

const ll mod = 1e9+7;

int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  ll ans = 1;
  vi col(3);
  rep(i,n) {
    int idx;
    ll cnt = 0;
    rep(j,3) {
      if(a[i] == col[j]) idx = j, cnt++;
    }
    ans *= cnt;
    ans %= mod;
    col[idx]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define vel vector<long long>
#define vech vector<char>
#define ves vector<string>
#define veb vector<bool>
#define vvel vector<vel>
#define vvech vector<vech>
#define int long long
#define pin pair<int,int>
#define ppin pair<int,pin>
#define mkp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define maxel(vec, j) *max_element(vec.begin(), vec.begin()+j)

using namespace std;
void mmin(int &a, int b) { a = min(a, b); }
void mmax(int &a, int b) { a = max(a, b); }
int vsum(vel v){ return accumulate(v.begin(), v.end(), 0); }
int msum(vvel v){
    int ans = 0;
    rep(i, v.size()){
        ans += vsum(v[i]);
    }
    return ans;
}
signed main() {
    int pr = 1000;
    pr *= pr * pr; pr += 7;
    int N;
    cin >> N;
    cout<<180*(N-2);

    return 0;
}
/*
2 2
2 1 2
1 2
0 1
 */


Measured memory_bytes: 256
#include <iostream>

using namespace std;

void solve()
{
	double time[2];
	string str[8] = {"AAA", "AA", "A", "B", "C", "D", "E", "NA"};
	int a = 0;
	int b = 0;
	while(cin >> time[0] >> time[1])
	{
		if(time[0] < 35.50)
		{
			a = 0;
		}
		else if(time[0] < 37.50)
		{
			a = 1;
		}
		else if(time[0] < 40.00)
		{
			a = 2;
		}
		else if(time[0] < 43.00)
		{
			a = 3;
		}
		else if(time[0] < 50.00)
		{
			a = 4;
		}
		else if(time[0] < 55.00)
		{
			a = 5;
		}
		else if(time[0] < 70.00)
		{
			a = 6;
		}
		else
		{
			a = 7;
		}

		if(time[1] < 71.00)
		{
			b = 0;
		}
		else if(time[1] < 77.00)
		{
			b = 1;
		}
		else if(time[1] < 83.00)
		{
			b = 2;
		}
		else if(time[1] < 89.00)
		{
			b = 3;
		}
		else if(time[1] < 105.00)
		{
			b = 4;
		}
		else if(time[1] < 116.00)
		{
			b = 5;
		}
		else if(time[1] < 148.00)
		{
			b = 6;
		}
		else
		{
			b = 7;
		}

		if(a >= b)
		{
			cout << str[a].data() << endl;
		}
		else
		{
			cout << str[b].data() << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
S = str(input())

chrs = ('A', 'C', 'G', 'T')
max_len = 0
this_len = 0
for s in S:
  if s in chrs:
    this_len += 1
  else:
    this_len = 0

  max_len = max(this_len, max_len)

print(max_len)

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

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

  vector<int> t(n + 1);
  vector<int> x(n + 1);
  vector<int> y(n + 1);

  for (int i = 1; i <= n; i++) cin >> t[i] >> x[i] >> y[i];

  for (int i = 0; i <= n; i++) {
    ll dist = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
    ll td = t[i] - t[i - 1];
    ll rest = td - dist;
    if (rest < 0 || rest % 2 != 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 4252
import static java.lang.System.out;
 public class Main {
     public static void main(String[] args){
         String str = new java.util.Scanner(System.in).nextLine();
         String[] tmp = str.split(" ");
         int a = Integer.parseInt(tmp[0]);
         int b = Integer.parseInt(tmp[1]);
         int c = Integer.parseInt(tmp[2]);
 
         if(a < b && a < c && b < c){                                                                                                       
             out.println("Yes");
         }
         else{
             out.println("No");
         }
 
     }
 }

Measured memory_bytes: 26172
import java.util.Scanner;

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

		String W = sc.next();

		int same = 0;

		while (true)
		{
			String temp = sc.next();
			if (temp.equals("END_OF_TEXT"))
			{
				break;
			}
			if (temp.equalsIgnoreCase(W))
			{
				same++;
			}
		}

		System.out.println(same);
	}
}



Measured memory_bytes: 26268
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>

#define isNum(a) (a >= '0' && a <= '9')
#define SP putchar(' ')
#define EL putchar('\n')
#define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)

template<class T>
inline void read(T&);
template<class T>
inline void write(const T&);

typedef long long ll;
typedef const long long & cll;
typedef const int & ci;
typedef std::pair<int, int> pii;
const int iinf = 2147483647;
const ll llinf = 9223372036854775807ll;
using std::min;
using std::max;
using std::abs;
using std::sort;
const int N = 25;

int a[N], b[N];

int main () {
    int n;
    read(n);
    for (int i = 1; i <= n; ++i) {
        read(a[i]);
    }
    for (int i = 1; i <= n; ++i) {
        read(b[i]);
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += max(0, a[i] - b[i]);
    }
    write(ans), EL;
    return 0;
}

template<class T>
void read(T &Re) {
    T k = 0;
    char ch = getchar();
    int flag = 1;
    while (!isNum(ch)) {
        if (ch == '-') {
            flag = -1;
        }
        ch = getchar();
    }
    while (isNum(ch)) {
        k = (k << 1) + (k << 3) + ch - '0';
        ch = getchar();
    }
    Re = flag * k;
}
template<class T>
void write(const T &Wr) {
    if (Wr < 0) {
        putchar('-');
        write(-Wr);
    } else {
        if (Wr < 10) {
            putchar(Wr + '0');
        } else {
            write(Wr / 10);
            putchar((Wr % 10) + '0');
        }
    }
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

int N, M, K, H, W, L, R;
//long long int N, M, K, H, W, L, R;



int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s,t;
	cin>>s>>t;
	cin>>N>>M;
	string u;
	cin>>u;
	if(s==u)N--;
	else M--;
	cout<<N<<" "<<M<<endl;
}


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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) (i64)(a / (f64)__gcd(a, b) * b) /* 最小公倍数 */

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

void Main() {
    i32 K;
    cin >> K;
    for (i32 i = 0; i < K; i++) {
        cout << "ACL";
    }
    cout << endl;
}


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

using namespace std;

#define MAXN 500

int par[MAXN+5];
vector<pair<int, pair<int,int> > > edge;

int find(int v)
{
    if (par[v] != v) par[v] = find(par[v]);
    return par[v];
}

int join(int u, int v)
{
    int pu = find(u), pv = find(v);
    par[pu] = pv;
}

void setds(int n)
{
    for (int i = 1; i <= n; ++i) par[i] = i;
}
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    setds(n);
    for (int i = 0; i < m; ++i) {
        int u, v, c;
        scanf("%d%d%d", &u, &v, &c);
        edge.push_back(make_pair(c,make_pair(u, v)));
    }
    sort(edge.begin(), edge.end());
    vector<int> mst;
    for (int i = 0; i < m; ++i) {
        int u = edge[i].second.first;
        int v = edge[i].second.second;
        if (find(u) != find(v)) {
            join(u,v);
            mst.push_back(i);
        }
    }

    int a = 0, b = 0;
    for (int i = 0; i < mst.size(); ++i) {
        setds(n);
        int w = edge[mst[i]].first;
        for (int j = 0; j < mst.size(); ++j) {
            if (i == j) continue;
            int jj = mst[j];
            int u = edge[jj].second.first;
            int v = edge[jj].second.second;
            if (find(u) != find(v)) join(u, v);
        }
        bool ok = true;
        for (int j = 0; j < m; ++j) {
            int u = edge[j].second.first;
            int v = edge[j].second.second;
            if (j != mst[i] && edge[j].first == w && find(u) != find(v)) {
                ok = false;
            }
        }
        if (ok) {
            a++;
            b+=w;
        }
    }
    printf("%d %d\n", a, b);
    return 0;
}

Measured memory_bytes: 1984
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = [int(a)-1 for a in input().split()]
    B = [int(b) for b in input().split()]
    C = [int(c) for c in input().split()]

    ans = sum(B)
    for i in range(N-1):
        if A[i]+1 == A[i+1]:
            ans += C[A[i]]
    print(ans)

if __name__ == "__main__":
    main()

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n, m;
		cin >> n >> m;
		vector<vector<int>> dp(m+1, vector<int>(1 << n, 0x3f3f3f3f));
		dp[0][0] = 0;
		vector<int> a(m, 0), b(m, 0);
		vector<int>  c(m);
		for(int i=0; i < m; i++){
			cin >> a[i] >> b[i];
			for(int j=0; j<b[i]; j++){
				int t;
				cin >> t;
				t--;
				c[i] |= 1 << t;
			}
		}
		for(int i=0; i < m; i++){
			for(int j=0; j < (1<<n); j++){
				updmin(dp[i+1][j|c[i]], dp[i][j] + a[i]);
				updmin(dp[i+1][j], dp[i][j]);
			}
		}
		if(dp[m][(1 << n)-1] == 0x3f3f3f3f)cout << -1 << endl;
		else cout << dp[m][(1 << n) -1] << endl;
		return;
	};
};

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

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

using namespace std;

int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	if(n&1){
		cout<<"No";
	}
	else{
		string tmp=s.substr(0,n/2);
		string t=s.substr(n/2);
		if(tmp==t){
			cout<<"Yes";
		}
		else cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    rep(i, n) cin >> a[i], a[i]--;

    vector<int> ql(q), qr(q), qi(q);
    rep(i, q) cin >> ql[i] >> qr[i], ql[i]--;
    iota(qi.begin(), qi.end(), 0);

    int width = sqrt(n);
    sort(qi.begin(), qi.end(), [&](int i, int j) {
        if (ql[i] / width != ql[j] / width) return ql[i] < ql[j];
        return qr[i] < qr[j];
    });

    vector<int> cnt(n), ans(q);
    int sum = 0;
    int l = 0, r = 0;

    auto add = [&](int i) { if (cnt[a[i]]++ == 0) sum++;};
    auto del = [&](int i) { if (--cnt[a[i]] == 0) --sum;};
    
    for (int i : qi) {
        while (ql[i] < l) add(--l);
        while (r < qr[i]) add(r++);
        while (l < ql[i]) del(l++);
        while (qr[i] < r) del(--r);
        ans[i] = sum;
    }
    
    rep(i, q) cout << ans[i] << endl;
}


Measured memory_bytes: 15440
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)


LL n, m;

int main() {
	cin >> n >> m;
	if (n == 1 && m == 1)cout << 1 << endl;
	else if (n == 1 || m == 1)cout << max(n, m) - 2 << endl;
	else cout << (n - 2)*(m - 2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

void secondsort(vector<p> &v){
  REP(i,v.size()){
    swap(v[i].first,v[i].second);
  }
  sort(v.begin(),v.end(),greater<p>());
  REP(i,v.size()){
    swap(v[i].first,v[i].second);
  }
}

void print(const std::vector<p>& v)
{
  std::for_each(v.begin(), v.end(), [](p x) {
    std::cout << x.first<<x.second << " ";
  });
  std::cout << std::endl;
}



int main(){
  int n;cin>>n;
  vector<p> r(n),b(n);
  REP(i,n){
    cin>>r[i].first>>r[i].second;
  }
  REP(i,n){
    cin>>b[i].first>>b[i].second;
  }
  sort(b.begin(),b.end());
  secondsort(r);//rのyが大きいもの順番
  //print(b);
  //print(r);
  vector<int> r_used(n,0);
  vector<int> b_used(n,0);
  int cnt = 0;
  for(int i = 0; i < b.size(); i++)//blueのx座標が小さいものから
  {
    for(int j = 0; j<r.size();j++){//redの
      if(r[j].first <b[i].first and r[j].second<b[i].second and r_used[j] == 0 and b_used[i] == 0){
        cnt++;
        //cout<<r[j].first<<r[j].second<<b[i].first<<b[i].second<<endl;
        r_used[j] = 1;
        b_used[i] = 1;
        break;
      }
    }
  }
  
  cout<<cnt<<endl;
}

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

int main(){
  int n; cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];
  sort(d.begin(), d.end());
  int ans = d[n/2] - d[n/2-1];    
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e7+9, M = (1<<31), OO = 0x3f3f3f3f;
int h[N],n;
LL memo[N];
LL solve(int idx=0)
{
  if(idx>=n) return 0;
  LL &ret = memo[idx];
  if(~ret) return ret;
  ret = 0;
  if(idx+1<n) ret = abs(h[idx]-h[idx+1])+solve(idx+1);
  if(idx+2<n) ret = min(ret,solve(idx+2)+abs(h[idx]-h[idx+2]));
  return ret;

}
int main()
{
  memset(memo,-1,sizeof memo);
  scanf("%d",&n);
  for(int i=0;i<n;++i) scanf("%d",h+i);
  printf("%lld",solve());
  #ifdef _LOCAL_DEFINE
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

Measured memory_bytes: 83200
l,r = map(int, input().split())
min = 0

for i in range(l,r):
    for j in range(l+1,r+1):

        ans = i*j%2019
        
        if i == l and j == l+1:
            min = ans
    
        if ans < min:
            min = ans
        
        if min == 0:
            break

    if min == 0:
        break

print(min)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define Maxn 200007
using namespace std;
int n;
long long x[Maxn],p[Maxn];
long long s;
long long ans=0;
int main()
{
	scanf("%d%lld",&n,&s);
	for (int i=1;i<=n;i++)
		scanf("%lld%lld",&x[i],&p[i]);
	int lx=1,rx=n,pos=0;
	while (true)
	{
		if (x[lx]>=s)
		{
			ans+=x[rx]-s;
			break;
		}
		if (x[rx]<=s)
		{
			ans+=s-x[lx];
			break;
		}
		if (p[lx]>=p[rx])
		{
			if (pos!=1)
			{
				pos=1;
				ans+=x[rx]-x[lx];
			}
			p[lx]+=p[rx];
			--rx;
		} else
		{
			if (pos!=2)
			{
				pos=2;
				ans+=x[rx]-x[lx];
			}
			p[rx]+=p[lx];
			++lx;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1792
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = [ir() for _ in range(N)]
answer = A[0] - 1
cur_limit = 2
for a in A[1:]:
    if a == cur_limit:
        cur_limit += 1
        continue
    answer += -((-(a-cur_limit)) // cur_limit)

print(answer)
# 44

Measured memory_bytes: 7884
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll NN, HH, WW;


  std::cin >> NN >> HH >> WW;

  ll A[NN], B[NN];
  for (size_t i = 0; i < NN; i++) {
    std::cin >> A[i]>>B[i];
  }

  int count = 0;
  for (size_t i = 0; i < NN; i++) {
    if (A[i] >= HH) {
      if (B[i] >= WW)  {
        count++;
      }
    }
  }

  std::cout << count << '\n';


  return 0;
}


Measured memory_bytes: 256