akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

ll dp[50][500][500];
const ll INF = 1e18;

void init(){
    rep(i, 0, 50) rep(j, 0, 500) rep(k, 0, 500) dp[i][j][k] = INF;
}

int main(){

    // input
    ll n, ma, mb;
    cin >> n >> ma >> mb;
    vector<ll> a(n), b(n), c(n);
    rep(i, 0, n) cin >> a[i] >> b[i] >> c[i];

    // dp
    init();
    dp[0][0][0] = 0;
    rep(i, 0, n){
        rep(j, 0, 450){
            if(j + a[i] >= 450) continue;
            rep(k, 0, 450){
                if(k + b[i] >= 450) continue;
                dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
                dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i]);
            }
        }
    }

    // search ans
    ll ans = INF;
    rep(j, 1, 450){
        if(j % ma != 0) continue;
        rep(k, 1, 450){
            if(k % mb != 0) continue;
            if(j / ma == k / mb) ans = min(ans, dp[n][j][k]);
        }
    }

    // output
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 101240
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
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;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
using namespace atcoder;

void solve(){
	string s;
	cin>>s;
	ll n=s.size();
	auto sa=suffix_array(s);
	ll ans=n*(n+1)/2;
	for(auto x:lcp_array(s,sa)){
		ans-=x;
	}
	cout<<ans<<"\n";
}


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


Measured memory_bytes: 15612
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int n;
vector<int> edge[100010];
queue<int> q;
int col[100010];
int main()
{
	cin >>n;
	for (int i=1;i<n;i++)
	{
		int x,y;
		cin >>x>>y;
		x--,y--;
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	fill(col,col+n,-1);
	col[0]=1;
	col[n-1]=0;
	q.push(0);
	q.push(n-1);
	while (!q.empty())
	{
		int x=q.front(); q.pop();
		int t=col[x];
		for (int i=0;i<edge[x].size();i++)
		{
			int xi=edge[x][i];
			if (col[xi]==-1) col[xi]=t,q.push(xi);
		}
	}
	int r1=0,r2=0;
	for (int i=0;i<n;i++)
	{
		if (col[i]) r1++;
		else r2++;
	}
	cout <<(r1>r2 ? "Fennec" : "Snuke");
	return 0;
}

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

using namespace std;

int main()
{
   int n,k,x;
   int s;
   cin>>n>>k;
   for(int i=0;i<n;i++)
   {
       cin>>s;
       if(s>=k) x++;
   }
   cout<<x;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath> 
using namespace std; 
int main() {
double q,x; 
while(scanf("%lf",&q), q!=-1) {
x=q/2.0; 
while(abs(x*x*x-q) >= 0.00001*q) { 
x = x-(x*x*x-q)/(3*x*x); 
} 
printf("%.6lf\n",x); 
} 
}



Measured memory_bytes: 2568
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,*A = map(int, read().split())

    t = Counter(A)

    for i in range(1,N+1):
        print(t[i] if i in t else 0)


if __name__ == "__main__":
    main()


Measured memory_bytes: 33992
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=1e6+4;

int main()
{
	int n;

	scn(n);

	vector<pair<int,int>> pos,neg;

	int support=0,sum=0;

	rep(i,0,n)
	{
		string s; cin>>s;

		int balance=0,prefix_min=inf;

		for(char x:s)
		{
			if(x=='(')
			balance++;
			else
			balance--;

			prefix_min=min(prefix_min,balance);
		}

		if(prefix_min>=0)
		support+=balance;
		else
		{
			if(balance>0)
			pos.emplace_back(prefix_min,balance);
			else
			neg.emplace_back(prefix_min-balance,balance);
		}

		sum+=balance;
	}

	if(sum!=0)
	{
		printf("No"); return 0;
	}

	sort(pos.rbegin(),pos.rend());

	sort(neg.begin(),neg.end());

	for(auto it:pos)
	{
		if(it.F+support<0)
		{
			printf("No"); return 0;
		}

		support+=it.S;
	}

	for(auto it:neg)
	{
		int min_here=it.F+it.S;

		if(support+min_here<0)
		{
			printf("No"); return 0;
		}

		support+=it.S;
	}

	printf("Yes"); 

    return 0;
}


Measured memory_bytes: 7528
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 200001;

template<int SZ> struct DSU {
    int par[SZ], sz[SZ];
    DSU() {
        F0R(i,SZ) par[i] = i, sz[i] = 1;
    }
    
    int get(int x) { // path compression
    	if (par[x] != x) par[x] = get(par[x]);
    	return par[x];
    }
    
    bool unite(int x, int y) { // union-by-rank
    	x = get(x), y = get(y);
    	if (x == y) return 0;
    	if (sz[x] < sz[y]) swap(x,y);
    	sz[x] += sz[y], par[y] = x;
    	return 1;
    }
};

ll ans = 0;

DSU<MX> D;
vector<array<int,3>> ed;

void kruskal() {
	sort(all(ed));
	for (auto a: ed) if (D.unite(a[1],a[2])) ans += a[0]; // edge is in MST	
}

int N,Q, mn[MX];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> Q;
    F0R(i,N) mn[i] = 2*MOD;
    F0R(i,Q) {
        int A,B,C; cin >> A >> B >> C;
        ed.pb({C,A,B});
        mn[A] = min(mn[A],C+1);
        mn[B] = min(mn[B],C+2);
    }
    F0R(i,2*N) mn[(i+1)%N] = min(mn[(i+1)%N],mn[i%N]+2);
    // F0R(i,N) cout << mn[i] << "\n";
    F0R(i,N) ed.pb({mn[i],i,(i+1)%N});
    kruskal();
    cout << ans;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

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

const int N = 3001;
int dp[N][N];
string s, t;

int solve(int i, int j) {
    if (i == -1 || j == -1) {
        return 0;
    }
    int& ans = dp[i][j];
    if (ans != -1) {
        return ans;
    }
    if (s[i] == t[j]) {
        ans = solve(i - 1, j - 1) + 1;
    } else {
        ans = max(solve(i - 1, j), solve(i, j - 1));
    }
    return ans;
}

string solution(int i, int j) {
    if (i == -1 || j == -1) {
        return "";
    }
    string res;
    if (s[i] == t[j]) {
        res += solution(i - 1, j - 1);
        res += s[i];
    } else if (solve(i, j) == solve(i - 1, j)) {
        res += solution(i - 1, j);
    } else if (solve(i, j) == solve(i, j -1)) {
        res += solution(i, j - 1);
    }
    return res;
}

int main() {
    cin >> s >> t;
    memset(dp, -1, sizeof dp);
    solve(s.length() - 1, t.length() - 1);
    cout << solution(s.length() - 1, t.length() - 1);
    return 0;
}


Measured memory_bytes: 36096
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

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

    vector<ll> h(N);
    REP(i, N) cin >> h[i];
    sort(h.begin(), h.end());

    ll l = 0, r = 1e9+2;
    while(r - l > 1){
        ll k = (r + l + 1) / 2;
        ll count = 0;
        REP(i, N){
            ll hoge = h[i] - B * k;
            if (hoge > 0) {
                count += hoge / (A - B);
                if ((hoge % (A - B)) != 0) count++;
            }
        }
        if (count > k) l = k;
        else r = k;
    }
    cout << r << endl;


    return 0;
}

Measured memory_bytes: 1024
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n = int(input())
	h = list(map(int,input().split()))
	for i in reversed(range(1,n)):
		if(h[i] < h[i-1] - 1):
			print('No')
			exit()
		if(h[i] < h[i-1]):
			h[i-1] -= 1
	print('Yes')

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()


Measured memory_bytes: 88940
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {


        // Scannerクラスのインスタンスの生成
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        int p = a + b;
        int m = a - b;
        int t = a * b;
        int values[] = {p, m, t};//[1]
        int max      = values[0];//[2]

        for (int index = 1; index < values.length; index ++) {//[3]
            max = Math.max(max, values[index]);//[4]
        }
        System.out.println(max);

	}
}

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

#define ll long long
#define ld long double
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n, m;
    cin >> n >> m;
    if (n > m)
    {
        cout << "No" << endl;
    }
    else if (n == m)
    {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int A, B;
string S;

void check_number(int A, int B, string S)
{
    for (int i = 0; i < A; i++)
    {
        if (S[i] == '-')
        {
            cout << "No" << endl;
            return;
        }
    }
    if (S[A] != '-')
    {
        cout << "No" << endl;
        return;
    }
    for (int i = 0; i < B; i++)
    {
        if(S[A+1+i]=='-'){
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
    return;
}

int main(int argc, char const *argv[])
{
    cin >> A >> B >> S;
    check_number(A,B,S);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <math.h>  

using std::cin;
using std::cout;

struct point {
	double x, y;
	point() = default;
	point(double x, double y) : x(x), y(y) {}
	friend double distance(const point & p1, const point & p2) {
		return sqrt(pow((p1.x - p2.x), 2) + pow((p1.y - p2.y), 2));
	}
};

int main() {
	size_t N;
	cin >> N;
	std::vector<point> points(N);
	for (size_t i = 0; i < N; ++i) {
		cin >> points[i].x >> points[i].y;
	}
	double ** b = new double *[N];
	for (size_t i = 0; i < N; ++i) {
		b[i] = new double[N];
	}
	b[0][1] = distance(points[0], points[1]);
	for (size_t j = 2; j < N; ++j)
		b[0][j] = b[0][j - 1] + distance(points[j - 1], points[j]);
	for (size_t i = 1; i < N; ++i) {
		for (size_t j = i + 1; j < N; ++j) {
			if (i < j - 1) {
				b[i][j] = b[i][j - 1] + distance(points[j - 1], points[j]);
			}
			else if (i == j - 1) {
			double min = b[0][j - 1] + distance(points[0], points[j]);
			for (size_t k = 1; k < i; ++k) {
			double temp = b[k][j - 1] + distance(points[k], points[j]);
			        if (temp < min) {
					min = temp;
				}
			}
			b[i][j] = min;
			}
		}
	}
	size_t i = N - 2;
	cout.precision(10);
	cout << b[i][i + 1] + distance(points[i], points[i + 1]) << std::endl;
	return 0;
}


Measured memory_bytes: 10180
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double theta1 =  ((h + m/60.) * 30.0)  * M_PI / 180.0;
    double theta2 =  (m * 6.0)  *  M_PI / 180.0;

    double x1 = a * sin(theta1);
    double y1 = a * cos(theta1);

    double x2 = b * sin(theta2);
    double y2 = b * cos(theta2);

    double dx = x2 - x1;
    double dy = y2 - y1;


    cout << fixed;
    cout << setprecision(16);

    cout << sqrt(dx * dx + dy * dy) << endl;

    return 0;
}


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

using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v); // 再帰的に探索
    }
}

int main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    // 全頂点が訪問済みになるまで探索
    int count = 0;
    seen.assign(N, false);
    for (int v = 0; v < N; ++v) {
        if (seen[v]) continue; // v が探索済みだったらスルー
        dfs(G, v); // v が未探索なら v を始点とした DFS を行う
        ++count;
    }
    cout << count - 1  << endl;
}


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

using namespace std;

const int maxn=1e4;
string s;
int x = 0 , y = 0, z =0 , t= 0;

int main()
{
	cin >> s;
	for(int i =0 ;i< s.size(); i++){
		if(s[i] == 'N'){
			x += 1;
		}
		if(s[i] == 'S'){
			y += 1;
		}
		if(s[i] == 'W'){
			z += 1;
		}
		if(s[i] == 'E'){
			t += 1;
		}
	}
	
	if(((x>0 && y>0) || (x ==0 && y == 0)) && ((t>0 && z>0) || (z ==0 && t == 0))){
		cout <<"Yes";
	}
	else{
		cout <<"No";
	}
	
	return 0;
	
}


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

int main(){
    string S;
    LL K;
    cin>>S>>K;

    LL cnt = 0;
    char T;
    REP(i,S.size()){
        if(S[i] == '1'){
            cnt++;
        }else{
            T = S[i];
            break;
        }
    }
    if(K<=cnt){
        cout<<1<<endl;
    }else{
        cout<<(char)T<<endl;
    }
    return 0;
}

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

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

    int count = 0;
    bool is_even = true;

    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        while (a > 1 && a % 2 == 0) {
            a /= 2;
            count++;
            is_even = true;
        }
    }

    if (!is_even) {
        cout << 0 << endl;
        return 0;
    }

    cout << count << endl;

    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;

vvi f;
int h,w,c;

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

map<pair<pi,vvi>,int> dp;

int dfs(int col, int num, const vvi &field)
{
    pair<pi,vvi> d(pi(col,num),field);
    if(dp.find(d) != dp.end()) return dp[d];

    //BFS
    vvi vis(h,vi(w,0));
    //?????????????????????
    int lu=field[0][0];
    queue<pi> que;
    vis[0][0]=1;
    que.push(pi(0,0));
    while(!que.empty())
    {
        pi now=que.front();
        que.pop();
        rep(i,4)
        {
            int nx=now.se+dx[i], ny=now.fi+dy[i];
            if(0<=nx&&nx<w && 0<=ny&&ny<h)
            {
                if(!vis[ny][nx] && field[ny][nx]==lu)
                {
                    vis[ny][nx]=1;
                    que.push(pi(ny,nx));
                }
            }
        }
    }

    //????????????
    vvi nf(field);
    rep(i,h)rep(j,w)
    {
        if(vis[i][j]) nf[i][j]=col;
    }

    int ret=0;
    if(num==6)
    {
        //???????????????
        int ct=0;
        rep(i,h)rep(j,w) ct+=vis[i][j];
        return ct;
    }
    else if(num==5)
    {
        //???????????????
        //???????????§dfs
        ret=max(ret,dfs(col,num+1,nf));
    }
    else if(num==4)
    {
        //????????????c??????????????¨????????????
        ret=max(ret,dfs(c,num+1,nf));
    }
    else
    {
        //?¬???????????????¶
        for(int i=1; i<=6; ++i)
        {
            //????????????????§?
            if(i==col) continue;

            ret=max(ret,dfs(i,num+1,nf));
        }
    }

    return dp[d]=ret;
}

int main()
{
    while(scanf(" %d %d %d",&h,&w,&c),h|w|c)
    {
        f=vvi(h,vi(w));
        rep(i,h)rep(j,w) scanf(" %d", &f[i][j]);

        dp.clear();

        int ans=0;
        for(int i=1; i<=6; ++i) ans=max(ans,dfs(i,1,f));

        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3820
/*  ***  In The Name of God ... ***  */ 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
 
#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

string t ;
bool w , s , n , e ; 

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> t ;
	for ( auto x : t ) {
		w |= ( x == 'W' ) ;
		s |= ( x == 'S' ) ;
		n |= ( x == 'N' ) ;
		e |= ( x == 'E' ) ; 
	}
	if ( ( w ^ e ) || ( s ^ n ) )
		return cout << "No\n" , 0 ;
	cout << "Yes\n" ;
}


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

int main() {
	int n, m, l, r;
	cin >> n >> m;
	int inf = 1, sup = n;
	for (int i = 0; i < m; i++) {
		cin >> l >> r;
		if (l > inf)
			inf = l;
		if (r < sup)
			sup = r;
	}
	cout << max(sup - inf + 1, 0) << endl;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //b
  int n;
  cin >> n;
  int k;
  cin >> k;
  long long ans = 0;
  while (n > 0) {
    n /= k;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int N,MOD=pow(10,9)+7;
map<ll,map<string,ll> > memo;

bool ok(string last4){
    REP(i,4){
        string str=last4;
        if(i>=1){
            swap(str[i],str[i-1]);
        }
        if(str.find("AGC") != -1){
            return false;
        }
    }
    return true;
}

ll dfs(int cur, string last3){
    if(memo[cur][last3] != 0)return memo[cur][last3];
    if(cur == N)return 1;
    ll res=0;
    char agct[4]={'A','G','C','T'};
    REP(i,4){
        if(ok(last3+agct[i])){
            string next=last3.substr(1,2)+agct[i];
            res=res+dfs(cur+1,next)%MOD;
        }
    }
    memo[cur][last3]=res;
    return res;
}

int main(){
    cin >> N;
    dfs(0,"TTT");
    cout << memo[0]["TTT"]%MOD;
    return 0;   
}

Measured memory_bytes: 896
#include<iostream>
#include<cmath>
#include<map>
#include<deque>
#include<string>
#include<algorithm>
#include<bitset>
typedef long long ll;

#define all(x) (x).begin(),(x).end()
#define puts(x) cout<< x << endl;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define fore(i,a) for(auto i:a)
const ll MOD= 1000000007;
using namespace std;

string s;
int main(){
    cin>>s;
    if(s=="SUN")puts(7);
    if(s=="MON")puts(6);
    if(s=="TUE")puts(5);
    if(s=="WED")puts(4);
    if(s=="THU")puts(3);
    if(s=="FRI")puts(2);
    if(s=="SAT")puts(1);
}


Measured memory_bytes: 256
import pdb
import sys

def solve(a,N):
    dp = [10**9 for x in xrange(N)]
    dp[0] = 0
    for i in xrange(N-1):
        if i+1 < N:
            dp[i+1] = min(dp[i+1],abs(a[i]-a[i+1])+dp[i])
        if i+2<N:
            dp[i+2] = min(dp[i+2],abs(a[i]-a[i+2])+dp[i])
        
    return dp[N-1]
    
if __name__=='__main__':
    N = int(raw_input())
    a = map(int,raw_input().split())
    print solve(a,N)


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

int main(void){
    int a[3][3],n,b[100],i,j,q,t[3][3],result=0;
  
  scanf("%d%d%d",&a[0][0],&a[0][1],&a[0][2]);
  scanf("%d%d%d",&a[1][0],&a[1][1],&a[1][2]);
  scanf("%d%d%d",&a[2][0],&a[2][1],&a[2][2]);
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&b[i]);
  }
  for(j=0;j<3;j++){
    for(q=0;q<3;q++){
      for(i=0;i<n;i++){
        if(b[i]==a[j][q]){
          t[j][q]=1;
        }
      }
    }
  }
  if(t[0][0]==1&&t[0][1]==1&&t[0][2]==1) result=1;
  if(t[1][0]==1&&t[1][1]==1&&t[1][2]==1) result=1;
  if(t[2][0]==1&&t[2][1]==1&&t[2][2]==1) result=1;
  if(t[0][0]==1&&t[1][0]==1&&t[2][0]==1) result=1;
  if(t[0][1]==1&&t[1][1]==1&&t[2][1]==1) result=1;
  if(t[0][2]==1&&t[1][2]==1&&t[2][2]==1) result=1;
  if(t[0][0]==1&&t[1][1]==1&&t[2][2]==1) result=1;
  if(t[0][2]==1&&t[1][1]==1&&t[2][0]==1) result=1;
  if(result==1){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}
 

Measured memory_bytes: 1728
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;

vector<LL> vec;

int sod(int num)
{
	int ret = 0;
	while(num > 0) {
		ret += num % 10;
		num /= 10;
	}
	return ret;
}

int main()
{
	LL t = 1;
	rep(i, 16) {
		int cur = 9 * i;
		if(i > 0) cur --;
		rep1(i, 300) if(i % 10 != 0 && i - sod(i) <= cur)
		vec.push_back(i * t - 1);
		t *= 10;
	}
	sort(vec.begin(), vec.end());
	int k;
	scanf("%d", &k);
	rep1(i, k) printf("%lld\n", vec[i]);
	return 0;
}

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

int main(){

    int n;
    int k;

    string s;

    cin >> n >> k >> s;

    if(s.at(k-1) == 'A')s.at(k-1) = 'a';
    if(s.at(k-1) == 'B')s.at(k-1) = 'b';
    if(s.at(k-1) == 'C')s.at(k-1) = 'c';

    cout << s << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,M;
  cin >>a>>b>>c;
  M=c;
  if (M<b){
    M=b;
  }
  if (M<a){
    M=a;
  }
  cout <<a+b+c-M<<endl;
}

Measured memory_bytes: 256
N = int(input())

H = list(map(int, input().split()))

def f(s=0, e=len(H), depth=0):
    if e == s:
        return 0
    if e - s == 1:
        return H[s] - depth
    for i in range(s, e):
        if H[i] <= depth:
            return f(s, i, depth) + f(i + 1, e, depth)
    return 1 + f(s, e, depth + 1)

print(f())


Measured memory_bytes: 40428
N = int(input())
A = list(map(int, input().split()))

x = 0
for i,a in enumerate(A):
    if i%2==0:
        x += a
    else:
        x -= a
ans = [str(x)]
for i in range(1,N):
    x = 2*A[i-1] - x
    ans.append(str(x))

print(' '.join(ans)) 

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

int main(){
	char s[100], p[100], s2[200];
	cin >> s;
	cin >> p;
	strcpy(s2, s);
	strcat(s2, s);
	if(strstr(s2, p) == NULL) cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

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

	bool flag = true;

	int i = 0;
	do {
		if (s[i] == 'B'){
			if (i == 0){
				s.erase(s.begin());
			}
			else {
				s.erase(s.begin() + i-1, s.begin() + i+1);
			}
			i = 0;
			continue;
		}
		if (i == (int)s.size()) flag = false;

		i++;

	} while (flag);

	cout << s << endl;

}


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

long long MOD = 1000000007;

int main() {
   
   vector<long long> key;
    map<long long, int> M1,M2;
    long long N,M;
    cin >> N;
    for ( int i = 0; i < N; i++ ) {
        
        long long a;
        cin >> a;
        
        if ( M1.count(a) ) {
            M1[a]++;
        }
        else {
            M1.insert( make_pair( a, 1 ) );
        }
    }
    cin >> M;
    for ( int i = 0; i < M; i++ ) {
        
        long long a;
        cin >> a;
        
        key.push_back(a);
        
        if ( M2.count(a) ) {
            M2[a]++;
        }
        else {
            M2.insert( make_pair( a, 1 ) );
        }
    }
   
   for ( int i = 0; i < key.size(); i++ ) {
       if ( !M1.count(key[i]) ) { cout << "NO" << endl; return 0; }
       if ( M1[key[i]] < M2[key[i]] ) { cout << "NO" << endl; return 0; }
   }
   
   cout << "YES" << endl;
   
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  int temp_i = 0;
  int res = 0;
  for(int i = 9; i >= 1; i--){
    if(n%i==0){
      temp_i = i;
      res = n/i;
      break;
    }
  }
  if(res < 10 && res > 0) cout << "Yes";
  else cout << "No";
}

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

using namespace std;

typedef long long ll;

const ll maxx = 2e3 + 20, inf = 1e17 + 20;

ll dp[maxx][maxx], n, x, a[maxx], mn[maxx][maxx];

int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	memset(dp, inf, sizeof dp);
	cin >> n >> x;
	for(ll i = 0; i < n; i++) cin >> a[i], dp[0][i] = 0;
	for(ll i = 0; i <= n; i++)
	{
		for(ll j = 0; j < n; j++)
		{
			if (!i) mn[j][0] = a[j];
			else mn[j][i] = min(mn[j][i - 1], mn[(j + n - 1) % n][i - 1]);
		}
	}
//	cout << dp[0][2] << endl;
	for(ll i = 0; i < n; i++)
	{
		for(ll j = 1; j <= n; j++)
		{
			dp[j][i] = dp[j-1][i] + mn[j-1][i];
//			cout << j << " " << i << "     " << dp[j][i] << endl;
		}
	}
	ll ans = inf;
	for(ll i = 0; i < n; i++) ans = min(ans, dp[n][i] + (i * x));
	cout << ans;
	return 0;
}

Measured memory_bytes: 64128
s = input()
n = len(s)

ans = 0
bit_n = n-1
for i in range(2**bit_n):
    tmp = 0
    res = int(s)
    mod = 10
    for j in range(bit_n):
        if ((i>>j)&1):
            tmp+=res%mod
            res//=mod
            mod=10
        else:
            mod*=10
    ans+=res
    ans+=tmp
print(ans)

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    vector<int> a({1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51});
    int k; cin >> k;
    cout << a[k - 1] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
	int n, i;
	cin >> n >> i;
	cout << n - i + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    double a, b, x;
    cin >> a >> b >> x;
    double h = x / pow(a, 2);
    cout << setprecision(15);
    if (h > b / 2) {
        cout << atan((b - h) * 2 / a) / M_PI * 180;
    } else if (h < b / 2) {
        cout << atan(b / (x / a / b * 2)) / M_PI * 180;
    } else {
        cout << atan(b / a) / M_PI * 180;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 384
#ABC166d
N, M = map(int,input().split())
H = list(map(int, input().split()))
count=[0]*M
A = [0]*M
B = [0]*M

for i in range(M):
    A[i], B[i] = map(int, input().split())

ans = [1]*N

for i in range(M):
    if H[A[i]-1] == H[B[i]-1]:
        ans[A[i]-1] = 0
        ans[B[i]-1] = 0
    elif H[A[i]-1] > H[B[i]-1]:
        ans[B[i]-1] = 0
    elif H[A[i]-1] < H[B[i]-1]:
        ans[A[i]-1] = 0
print(sum(ans))


Measured memory_bytes: 22576
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();

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

    int k, s; cin >> k >> s;

    int ans = 0;
    for (int x=0;x<=k;x++) {
        for (int y=0;y<=k;y++) {
            int z = s - x -y;
            if (0<=z&&z<=k) {
                ans++;
            }
        }
    }

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


Measured memory_bytes: 3652
#include<stdio.h>
  
void swap(int* a,int* b){
  int tmp=*a;
  *a=*b;
  *b=tmp;
}
  
int Partition(int A[],int p,int r){
  int x = A[r];
  int i=p-1,j;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      swap(&A[i],&A[j]);
    }
  }
  swap(&A[i+1],&A[r]);
  return i+1;
}
  
int main(){
  int n,i,x;
  int A[100000];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  x=Partition(A,0,n-1);
  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==x)printf("[");
    printf("%d",A[i]);
    if(i==x)printf("]");
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define F first
#define S second
#define endl "\n"
#define nl cout<<endl
#define pb push_back
#define f(i,a,b) for(ll i=a;i<b;i++)
#define Knucklehead ios_base::sync_with_stdio(false);cin.tie(NULL);
#define txti freopen("input.txt", "r", stdin);
#define txto freopen("output.txt", "w", stdout);
//#define mod 100000007

#define mat vector<vector<ll>>
mat cn(ll n, ll m){return vector< vector<ll> >(n, vector<ll>(m));}
bool compare(char &s1,char &s2){return s1 > s2;} 

bool sortmahstyle(const pair<ll,ll> &a,  const pair<ll,ll> &b) 
{ 
    if(a.second > b.second )
        return true;
    if( a.second==b.second && a.first > b.second )
       return true;
 
    return false;
 }
//me
ll const mod = 1e9+7;//998244353;
ll const inf = 3e6+1;

void solve()
{

    ll n,x,t;
    cin >> n >> x >> t;

    cout << t * ((n+x-1)/x) << endl;

}
int main() {
Knucklehead 
//*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
/**/ 
        
        ll t;
        /**/t=1;
        /*/cin>>t;/**/
        f(testcases,0,t){
            solve();
        }
 
 
    return 0;
}

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

int main()
{
    int d, g;
    cin >> d >> g;
    vector<vector<int>> score(d, vector<int>(2));
    for (int i = 0; i < d; i++)
    {
        cin >> score[i][0] >> score[i][1];
    }

    int mask, num, ans = 1e9;
    for (mask = 0; mask < (1 << d); mask++)
    {
        int point = 0, tyuto = -1;
        num = 0;
        for (int i = 0; i < d; i++)
        {
            if ((mask >> i) & 1)
            {
                point += score[i][0] * (i + 1) * 100 + score[i][1];
                num += score[i][0];
            }
            else
                tyuto = i;
        }

        if (point < g)
        {
            int tyuto_point = 100 * (tyuto + 1);
            int need = (g - point) / tyuto_point;
            if ((g - point) % tyuto_point != 0)
                need++;
            if (need >= score[tyuto][0])
                continue;
            num += need;
        }
        ans = min(num, ans);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
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 c = sc.nextInt();
        int d = sc.nextInt();
        
        if (a >= d || b <= c) {
        	System.out.println(0);
        } else {
        	int s = Math.max(a, c);
        	int e = Math.min(b, d);
        	System.out.println(e - s);
        }
    }
}

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector< ii >
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }

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

int32_t main(){
  DESYNC;
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  set<int, greater<int> > zero;
  int p[n+1];
  int d[n+1];
  for(int i=0; i<=n; i++){
    if(s[i] == '0') zero.insert(i);
    p[i] = -1;
    d[i] = INF;
  }
  set<ii> q;
  q.insert(ii(0, 0));
  d[0] = 0;
  while(!q.empty()){
    int u = q.begin()->ff;
    int dst = q.begin()->ss;
    q.erase(q.begin());
    if(d[u] != dst) continue;
    int cur = u+k+1;
    while(true){
      auto it = zero.upper_bound(cur);
      if(it == zero.end()) break;
      int ad = *it;
      if(ad <= u) break;
      if(ad - u > k) break;
      if(d[ad] <= dst + 1) break;
      if(d[ad] > dst+1){
        //cout << "from " << u << " go to " << ad << endl;
        p[ad] = u;
        d[ad] = dst+1;
        q.insert(ii(ad, d[ad]));
      }
      cur = ad;
    }
  }
  if(d[n] >= INF){
    cout << -1 << endl;
    return 0;
  }
  vector<int> v;
  int cur = n;
  while(cur != -1){
    v.pb(cur);
    cur = p[cur];
  }
  reverse(v.begin(), v.end());
  for(int i=1; i<v.size(); i++){
    if(i > 1) cout << " ";
    cout << v[i] - v[i-1];
  }
  cout << endl;
}




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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.length()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>())
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////
	int n;
	cin >> n;
	cout << (n<1200 ? "ABC" : "ARC") << endl;

	
//////////////////////////////////////////////
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

void print_sol(vector<vector<char>>& A, string s, int i, int j) {
    if (i == 0 || j == 0) return;
    if (A[i][j] == 'D') {
        print_sol(A, s, i-1, j-1);
        cout << s[i-1];
    } else if (A[i][j] == 'L') {
        print_sol(A, s, i, j-1);
    } else {
        print_sol(A, s, i-1, j);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t; cin >> s >> t;
    int n = (int)s.size(), m = (int) t.size();
    vector<vector<int>> dp(n+1, vector<int>(m+1));
    vector<vector<char>> build(n+1, vector<char> (m+1));

    for (int i = 0; i < n; ++i) dp[i][0] = 0;
    for (int i = 0; i < m; ++i) dp[0][i] = 0;

    for (int i = 1; i < n + 1; ++i) {
        for (int j = 1; j < m + 1; ++j) {
            if (s[i-1] == t[j-1]) {
                dp[i][j] = 1 + dp[i-1][j-1];
                build[i][j] = 'D';
            } else if (dp[i][j - 1] > dp[i-1][j]) {
                dp[i][j] = dp[i][j-1];
                build[i][j] = 'L';
            } else {
                dp[i][j] = dp[i-1][j];
                build[i][j] = 'U';
            }
        }
    }
    print_sol(build, s, n, m);
    cout << '\n';
    return 0;
}



Measured memory_bytes: 62244
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
pnt = 0
for i in range(len(A)):
  pnt += B[A[i]-1]
  if i>0 and A[i]-A[i-1]==1:
    pnt += C[A[i]-2]
print(pnt)
  

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
typedef long long ll;
int main (void) {
    int N;
    int K;

    cin >> N >> K;

    ll ans = 1;
    for (int i = 0; i < N; i++) {
        if (i == 0) ans *= K;
        else ans *= (K - 1);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		List<Integer> rows = new ArrayList<>();
		List<Integer> columns = new ArrayList<>();
		boolean flag=true;
		
		while (true) {
			int h = s.nextInt();
			int w = s.nextInt();
			if(h==0 && w==0) {
				break;
			}
			if(h>=1 && w>=1 && h<=300 && w<=300) {
				rows.add(h);
				columns.add(w);
			}else {
				flag = false;
				break;
			}
		}
		
		if(flag == true) {
		for(int i=0;i<rows.size();i++) {
			for(int r=0;r<rows.get(i);r++) {
				for(int c=0;c<columns.get(i);c++) {
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
		}
	}

}

Measured memory_bytes: 37260
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
int main(void){
    int n,ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        ans+=(b-a+1);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

const long long int INF=1e9+7;

int main(){
    long long n, k, h[100009], dp[100009];
    cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> h[i];
        dp[i] = INF;
    }
    dp[0] = 0;
    for(int i=1;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i - j>=0){
                dp[i] = min(dp[i], dp[i-j] + abs(h[i-j] - h[i]));
            }
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
from collections import Counter

def main():
    N = int(input())
    a = Counter(map(int, input().split()))
    a1, a2, a3 = a.get(1, 0), a.get(2, 0), a.get(3, 0)
    a123 = a1 + a2 + a3 + 1
    u = [[0.0] * (a123 - c2) for c2 in range(a123)]
    v = [[0.0] * (a123 - c2) for c2 in range(a123)]
    t1 = 0.0
    v2 = v[0]
    for c1 in range(1, a123):
        v2[c1] = t1 = N / c1 + t1
    for c2 in range(1, a123):
        v2 = v[c2]
        for c1, t2 in zip(range(301 - c2), v[c2 - 1][1:]):
            v2[c1] = t1 = (N + c1 * t1 + c2 * t2) / (c1 + c2)

    for c3 in range(1, a3 + 1):
        u, v = v, u
        v2 = v[0]
        for c1, t3 in zip(range(a123 - c3), u[1]):
            v2[c1] = t1 = (N + c1 * t1 + c3 * t3) / (c1 + c3)
        for c2 in range(1, a123 - c3):
            v2 = v[c2]
            c23 = c2 + c3
            for c1, t2, t3 in zip(range(a123 - c3 - c2), v[c2 - 1][1:], u[c2 + 1]):
                v2[c1] = t1 = (N + c1 * t1 + c2 * t2 + c3 * t3) / (c1 + c23)

    print(v[a2][a1])
main()


Measured memory_bytes: 43212
#include <bits/stdc++.h>
using namespace std;
double dp[301][301][301];
int n;
// double dfs(int a, int b, int c){
//     if(a+b+c == 0)
//     return 0.0;
//     if(dp[a][b][c] > -0.5)
//     return dp[a][b][c];
//     double ks = (double)n/ (a+b+c);
//     double ret=0;
//     if(a){
//         ret += (dfs(a-1,b,c) + ks)*(a/(a+b+c));
//     }
//     if(b){
//         ret += (dfs(a+1,b-1,c) + ks)*(b/(a+b+c));
//     }
//     if(c){
//         ret += (dfs(a,b+1,c-1) + ks)*(c/(a+b+c));
//     }
//     return dp[a][b][c]=ret;
// }
double rec(int i, int j, int k){
  if(!i && !j && !k)return 0.0;
  if(dp[i][j][k]>0.0)return dp[i][j][k];
 
  double sum = i+j+k;
  double ret = n/sum;
  if(i>0)ret += (double)(i/sum) * rec(i-1, j, k);
  if(j>0)ret += (double)(j/sum) * rec(i+1, j-1, k);
  if(k>0)ret += (double)(k/sum) * rec(i, j+1, k-1);
 
  return dp[i][j][k]=ret;
}


int main() {
    //memset(dp, -1, sizeof(dp));
    for(int i=0;i<301;i++){
        for(int j=0;j<301;j++){
            for(int k=0;k<301;k++){
                dp[i][j][k]=-1;
            }
        }
    }
    int st[4];
     memset(st, 0, sizeof(st));
    
     cin>>n;
     for(int i=0;i<n;i++){
         int t;
         cin>>t;
         st[t]++;
     }
    // cout<<dfs(st[1],st[2],st[3]);
    // cout<<setprecesion(12)<<dfs(st[1],st[2],st[3]);
    cout<<fixed<<setprecision(12)<<rec(st[1], st[2], st[3])<<endl;
     
	return 0;
}

Measured memory_bytes: 216888
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int MAXN=1e5+5;
const int INF=0x3f3f3f3f;

int n,L,m;
int a[MAXN],pre[MAXN][20];

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    scanf("%d",&L);
    memset(pre,0x3f,sizeof pre);
    for(int i=1;i<=n;i++){
        int t=a[i]+L;
        pre[i][0]=lower_bound(a+1,a+n+1,t)-a;
        if(a[pre[i][0]]>a[i]+L) pre[i][0]--;
    }
    for(int j=1;(1<<j)<=n;j++)
        for(int i=1;i<=n;i++)
            if(pre[i][j-1]!=INF&&pre[pre[i][j-1]][j-1]!=INF)
                pre[i][j]=pre[pre[i][j-1]][j-1];
    scanf("%d",&m);
    for(int i=1;i<=m;i++){
        int x,y,ans=0;
        scanf("%d%d",&x,&y);
        if(x>y) swap(x,y);
        for(int j=18;j>=0;j--)
            if(pre[x][j]<=y){
                ans+=(1<<j);
                x=pre[x][j];
            }
        if(x<y) ans++;
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 8960
n = int(input())
l = list(map(int, input().split()))
s = sum(l)
evens = 0
for i in range(1, n, 2):
    evens += 2*l[i]
x1 = s - evens
ans = [x1]
for i in range(n-1):
    temp = l[i] - ans[-1]//2
    ans.append(2*temp)
print(*ans)



Measured memory_bytes: 95264
h,w,d=map(int,input().split())
n=h*w
a=[None for i in range(n)]
for i in range(h):
  inp=list(map(int,input().split()))
  for j in range(w):
    a[inp[j]-1]=(i,j)

dst=[0 for i in range(d)]
for i in range(d,n):
  dst.append(abs(a[i-d][0]-a[i][0])+abs(a[i-d][1]-a[i][1]))

s=[0 for i in range(d)]
for i in range(d,n):
  s.append(s[i-d]+dst[i])

  
  
q=int(input())
for i in range(q):
  l,r=map(int,input().split())
  print(s[r-1]-s[l-1])

Measured memory_bytes: 83268
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N,K; cin>>N>>K;
    string S; cin>>S;
    
    char c=S.front();
    bool mismatch=false;
    int _k=0;
    rep(i,0,N){
        if(c!=S.at(i)){
            if(_k<K){
                S.at(i)=c;
                if(mismatch){

                }else{
                    mismatch=true;
                }
            }
        }else{
            if(mismatch){
                _k++;
                mismatch=false;
            }else{

            }
        }
    }

    int ans=0;
    rep(i,1,N){
        if(S.at(i)==S.at(i-1)){
            ans++;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 512