akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let s = read_vec::<usize>();
    let t = read_vec::<usize>();
    let big_int = 1000_000_000 + 7;

    let mut dp = vec![0; t.len() + 1];
    dp[0] = 1;
    let mut ans = 1i64;
    for i in 0..s.len() {
        let mut dp_sum = vec![0; t.len() + 1];
        dp_sum[0] = 1;
        for j in 1..t.len() + 1 {
            dp_sum[j] = dp_sum[j - 1] + dp[j];
            dp_sum[j] %= big_int;
        }
        // debug!(i, dp, dp_sum, ans);
        for j in 0..t.len() {
            if s[i] == t[j] {
                dp[j + 1] += dp_sum[j];
                dp[j + 1] %= big_int;
                ans += dp_sum[j];
                ans %= big_int;
            }
        }
    }
    println!("{:?}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = 0; i < (a); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template<typename T>
struct edge {
  int from, to;
  T cost;

  edge(int from, int to) : from(from), to(to), cost((T)1) {}

  edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template<typename T>
using Edges = std::vector<edge<T> >;

template<typename T>
std::vector<T> bellman_ford(const Edges<T> &edges, const vector<bool> &us, const vector<bool> &ut, int n, int s) {
  const auto DINF = INF;
  std::vector<T> distance(n, DINF);
  distance[s] = 0;
  for(int i = 0; i < n - 1; ++i){
    if(!us[i] || !ut[i]) continue;
    for(auto &e : edges){
      if(distance[e.from] == DINF) continue;
      else if(!us[e.from] || !ut[e.from] || !us[e.to] || !ut[e.to]) continue;
      else distance[e.to] = std::min(distance[e.to], distance[e.from] + e.cost);
    }
  }
  bool isCycle = false;
  for(auto &e : edges){
    if(distance[e.from] == DINF) continue;
    else if(!us[e.from] || !ut[e.from] || !us[e.to] || !ut[e.to]) continue;
    else if(distance[e.to] > distance[e.from] + e.cost) {
      isCycle = true;
      break;
    }
  }

  return isCycle ? std::vector<T>() : distance;
}

void bfs(const std::vector<std::vector<int> > &links, std::vector<bool> &used, int s) {
  std::stack<int> st;
  st.push(s);
  used[s] = true;
  while(!st.empty()){
    int v = st.top();
    st.pop();
    for(auto u : links[v]) {
      if(used[u]) continue;
      else {
        st.push(u);
        used[u] = true;
      }
    }
  }
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, p;
  cin >> n >> m >> p;
  Edges<int> edges;
  VVI links(n, VI());
  VVI rlinks(n, VI());
  vector<bool> us(n, false), ut(n, false);

  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    edges.emplace_back(a, b, - c + p);
    links[a].push_back(b);
    rlinks[b].push_back(a);
  }
  bfs(links, us, 0);
  bfs(rlinks, ut, n-1);
  VI dis = bellman_ford<int>(edges, us, ut, n, 0);
  !dis.empty() ? out(max(-dis[n-1], 0)) : cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){
    int i, j, k, l, m;
    double x[4], y[4], c[3];
    
    while(scanf("%lf", &x[0]) != EOF){
        scanf(",%lf", &y[0]);
        
        for(i = 1; i < 4; i++)
            scanf(",%lf,%lf", &x[i], &y[i]);
            
        m = 1;
        
        for(i = 0; i < 4 && m; i++){
            j = (i > 2 ? i - 3 : i + 1);
            k = (i > 1 ? i - 2 : i + 2);
            l = (i > 0 ? i - 1 : i + 3);
            
            c[0] = (x[j] - x[i]) * (y[l] - y[j]) - (y[j] - y[i]) * (x[l] - x[j]);
            c[1] = (x[k] - x[j]) * (y[l] - y[k]) - (y[k] - y[j]) * (x[l] - x[k]);
            c[2] = (x[i] - x[k]) * (y[l] - y[i]) - (y[i] - y[k]) * (x[l] - x[i]);
            
            if((c[0] > 0 && c[1] > 0 && c[2] > 0) ||
               (c[0] < 0 && c[1] < 0 && c[2] < 0))
                m = 0;
        }
        
        printf("%s\n", (m ? "YES" : "NO"));
    }
    
    return 0;
}

Measured memory_bytes: 608
#include <stdio.h>
 
int main(void)
{
  int n;
  double r=0;
  
  scanf("%d", &n);
  
  if (n%2==0) 
    r = 0.5;
  else {
    r = (double)(n-n/2)/n;
  }
  
  printf("%f", r);
  
  return 0;
}

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



int main(void){
    int N;
    cin>>N;
    int ans=0;
    for(int i=1;i<=N;i++){
        int count=0;
        if(i%2!=0){
            for(int j=1;j<=N;j++){
                if(i%j==0) count++;
            }
        }
        if(count==8) ans++;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,a,b)  for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n)    FOR(i,0,n)
#define RER(i,n)    FOR(i,0,(n+1))
#define pb          push_back
#define mp(a,b)     make_pair((a),(b))
#define mset(m,v)   memset(m,v,sizeof(m))
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<string> vs;
typedef long double ld;
const double EPS    = 1e-10;
const int INF       = 1e+9;
const double PI     = acos(-1);


auto main() -> int
{
    int a, b, c;
    cin >> a >> b >> c;

    if ( b - a == c - b ) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	map<char, int> mp;
	rep(i, s.size()) mp[s[i]]++;
	if (mp.size() == 4) cout << "Yes" << endl;
	else if (mp['N'] && mp['S'] && !mp['W'] && !mp['E']) cout << "Yes" << endl;
	else if (!mp['N'] && !mp['S'] && mp['W'] && mp['E']) cout << "Yes" << endl;
	else if (!mp['N'] && !mp['S'] && !mp['W'] && !mp['E']) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#include <list>
#include <unordered_set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll getDigit(ll n) {
	ll cnt = 0;
	while (n != 0) {
		n /= 10;
		cnt++;
	}
	return cnt;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
typedef pair<double, long long> pair_t;
bool comp(const pair_t& a, const pair_t& b) {
	if (a.first == b.first)return  a.second > b.second;
	else {
		return a.first > b.first;
	}
}

int main() {
	ll n,cnt=0;
	cin >> n;
	vector<ll>a(n);
	rep(i, n)cin >> a[i];
	unordered_map<ll, ll>mp;
	unordered_set<ll>st;
	for (ll i = 0; i < n; i++) {
		mp[a[i]]++;
		st.insert(a[i]);
	}
	for (auto itr = st.begin(); itr != st.end();itr++) {
		cnt += (mp[*itr]>= *itr ? abs(mp[*itr] - *itr) : mp[*itr]);
	}
	cout << cnt << endl;
}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    ll N;
    cin >> N;

    vector<pair<ll, ll> >ab(N);
    rep(i,N) cin >> ab[i].second >> ab[i].first;
    sort(all(ab));

    ll key = 0;
    rep(i,N)
    {
        if( ab[i].second + key > ab[i].first )
        {
            cout << "No" << endl;
            return 0;
        }
        else key += ab[i].second;
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	int x[n] = {};
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	int ans = INT_MAX;
	for (int p = 1; p <= 100; p++) {
		int sum = 0;
		for (int i = 0; i < n; i++)
			sum += (x[i] - p) * (x[i] - p);
		ans = min(ans, sum);
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
using System;
namespace ABC058_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var mojiCnt = new int[n,26];
            for(var i = 0;i < n;i++){
                var s = Console.ReadLine();
                for(var j = 0;j < s.Length;j++){
                    mojiCnt[i,s[j] - 'a']++;
                }
            }
            for(var i = 0;i < 26;i++){
                var temp = int.MaxValue;
                for(var j = 0 ;j < n;j++){
                    temp = Math.Min(temp,mojiCnt[j,i]);
                }
                for(var j = 0;j < temp;j++){
                    Console.Write((char)('a' + i));
                }
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 11092
n, m=map(int, raw_input().split())
l=[map(int, raw_input().split()) for i in range(n)]
last, first=0, n
while last+1!=first:
	mid=last+(first-last)/2
	erased=[False]*(m+1)
	bucket=[[] for i in range(m+1)]
	for i in range(n):
		bucket[l[i][0]].append((i, 0))
	ok=True
	while True:
		any_change=False
		for i in range(m+1):
			if len(bucket[i])>mid:
				erased[i]=True
				for which, index in bucket[i]:
					while index<m and erased[l[which][index]]:
						index+=1
					if index==m:
						ok=False
						break
					bucket[l[which][index]].append((which, index))
				bucket[i]=[]
				any_change=True
		if not any_change or not ok:
			break
	if ok:
		first=mid
	else:
		last=mid
print first

Measured memory_bytes: 3832
/*
  Warn - Don't change next line else you will get WA verdict. Online Judge is configured to give WA if next line is not present.
  Author - Aryan Choudhary (@aryanc403)
 
  const short DEBUG { 0 };
  #define debug(x) if (DEBUG) cout << #x << " = " << x << '\n'
*/

#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"
#define PI 3.1415926535897932384626433832795
typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

//const lli [3] ={ 999119999L,1000000007L,1000992299L};
//const lli [3] ={ 97L,101L,103L};
//const lli  = chrono::high_resolution_clock::now().time_since_epoch().count();
clock_t time_p=clock();
void aryanc403()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

class CMP
{
public:
    bool operator()(lli a , lli b) //For min priority_queue .
    {
        return ! ( a <= b );
    }
};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    map<lli,lli> ::iterator jt;
    jt=m.find(x);
    if(jt==m.end())         m.insert(mp(x,cnt));
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    map<lli,lli> ::iterator jt;
    jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}
const lli INF = 0xFFFFFFFFFFFFFFFL;
const lli mod = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,ans;
    lli m;
    string s;
    vi a,b;
    vi :: iterator it;
    //priority_queue < lli , vector < lli > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>m>>n;
    a.clear();a.reserve(n);
    
    fo(i,n)
    {
        cin>>in;
        a.pb(in);
    }
    
    sort(a.begin(),a.end());
    repA(i,1,n-1)
    {
        b.pb(a[i]-a[i-1]);
        ans+=a[i]-a[i-1];
        //cerr<<a[i]-a[i-1]<<endl;
    }
    //cerr<<ans<<endl;
    if(!b.empty())
        sort(b.rbegin(),b.rend());
    m--;
    for(auto x:b)
    {
        if(m<=0)
            break;
        ans-=x;
        //cerr<<x<<" ";
        m--;
    }
    cout<<ans<<endl;
}   aryanc403();
    return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <algorithm>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

struct Card {
	int r, c, v;
	bool operator < (Card o) const { return v > o.v; }
};

int par[200200], size[200200];
int getPar(int x) { return x == par[x] ? x : par[x] = getPar(par[x]); }
bool makeUnion(int a, int b) {
	a = getPar(a);
	b = getPar(b);
	if(a == b) {
		if(size[a] == 0) {
			size[a] = 1;
			return true;
		}
	} else {
		if(size[a] + size[b] <= 1) {
			size[a] += size[b];
			par[b] = a;
			return true;
		}
	}
	return false;
}

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n, r, c;
	std::cin >> n >> r >> c;
	std::vector<Card> cards(n);
	for(auto &card : cards) {
		std::cin >> card.r >> card.c >> card.v;
		card.r--;
		card.c--;
	}
	std::sort(cards.begin(), cards.end());
	for(int i = 0; i < r+c; i++) {
		par[i] = i;
		size[i] = 0;
	}
	long long ans = 0;
	for(auto card : cards) {
		bool valid = makeUnion(card.r, r + card.c);
		if(valid) {
			//std::cout << "got card (" << card.r << ", " << card.c << "), " << card.v << std::endl;
			ans += card.v;
		}
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 3840
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
using ll = long long;

int main() {
  ll w, h, x, y;
  cin >> w >> h >> x >> y;
  cout << setprecision(10) << (double)w*(double)h / 2 << " " << ((x + x == w) && (y + y == h)) << endl;
}

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

typedef long long ll;
const ll MAX_E = 2100;		
const ll MAX_V = 1100;

#define INF (1LL << 62)

// 頂点と頂点を結ぶ辺についての構造体
struct edge { ll from, to, cost; };

edge es[MAX_E]; // 辺

ll d[MAX_V];
ll V, E;

//	ベルマンフォード（単一始点最短経路（Negative Edges))
// 負の閉路が存在したら true を返す
void bellman_ford(ll s) {
	ll cnt = 0;
	// 最短距離の初期化
	for (ll i = 0; i < V; i++) d[i] = INF;
	// 頂点 s への最短距離は0
	d[s] = 0;
	for(int j=0; j<V-1; j++) {
		//cout << i << endl;
		cnt++;
		bool update = false;
		// すべての辺に対して
		for (ll i = 0; i < E; i++) {
			edge e = es[i];
			// この時点での e.to へ行くコストより e.from を経由して行く方がコストが小さいとき d[e.to] を更新する
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				//cout << e.from <<"->"<< e.to <<":"<< e.cost << endl;
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		// 更新がなければ終了
		if (!update) break;
	}
}

bool find_negative_loop() {
	bool negative[MAX_V];
	for(int i=0; i<MAX_V; i++) negative[i]=false;

	for (int i = 0; i < V; i++) {
		for (int j = 0; j < E; j++) {
			edge e = es[j];
			if(d[e.from]==INF) continue;
			if (d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				negative[e.to]=true;
			}
			if(negative[e.from]) negative[e.to]=true;
		}
	}

	if(negative[V-1]) return true;
	else return false;
}

int main() {
	ll r=0;
	cin >> V >> E;
	ll from, to, cost;

	for (ll i = 0; i < E; i++) {
		cin >> from >> to >> cost;
		from--; to--;
		es[i] = edge{ from, to, cost*(-1) };
	}

	bellman_ford(r);

	ll ans = d[V-1]*(-1);

	if (find_negative_loop()) {
		cout << "inf" << endl;
	}
	else {
		cout << ans << endl;
	}

}


Measured memory_bytes: 256
from collections import deque
N = int(input())
A = deque(map(int, input().split()))
A.appendleft(0)
A.append(0)

S = 0
for i in range(1, N+2):
    S += abs(A[i-1] - A[i])
for i in range(1, N+1):
    print(S+abs(A[i-1]-A[i+1])-(abs(A[i-1]-A[i])+abs(A[i]-A[i+1])))

Measured memory_bytes: 13536
#include "bits/stdc++.h"

#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++)

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.first != b.first) {
		return a.first > b.first;
	}
	else {
		return a.second > b.second;
	}
}

int main() {
	int N, M; cin >> N >> M;
	vector<pair<int, int>> A;
	rep(i, N) {
		int a; cin >> a;
		A.push_back(make_pair(a, 1));
	}
	rep(j, M) {
		int b, c; cin >> b >> c;
		A.push_back(make_pair(c, b));
	}
	sort(A.begin(), A.end(), compare_by_b);
	long long ans = 0;
	int count = 0;
	rep(i, A.size()) {
		if (count + A[i].second >= N) {
			ans += (long long)A[i].first * (N - count);
			break;
		}
		else ans += (long long)A[i].first * A[i].second;
		count += A[i].second;
		//cout << ans << endl;
	}
	cout << ans;
}

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

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	if(s.size() <= n)
		return cout << s, 0;
	s = s.substr(0, n);
	s += "...";
	cout << s;
}


Measured memory_bytes: 3080
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - すぬけ君の塗り絵 2 イージー / Snuke's Coloring 2 (ABC Edit)
            var line = ReadLine();
            int w = line[0];
            int h = line[1];
            int n = line[2];

            var x = new int[2];
            x[1] = w;

            var y = new int[2];
            y[1] = h;

            for(int i = 0; i < n; i++)
            {
                line = ReadLine();
                int xi = line[0];
                int yi = line[1];
                int a = line[2];

                switch (a)
                {
                    case 1:
                        if (xi > x[0])
                        {
                            x[0] = xi;
                        }

                        break;
                    case 2:
                        if (xi < x[1])
                        {
                            x[1] = xi;
                        }

                        break;
                    case 3:
                        if (yi > y[0])
                        {
                            y[0] = yi;
                        }

                        break;
                    case 4:
                        if (yi < y[1])
                        {
                            y[1] = yi;
                        }

                        break;
                }
            }

            int height = GetLength(y);
            int width = GetLength(x);

            Console.WriteLine(height * width);
        }

        static int GetLength(int[] coods)
        {
            if (coods[1] - coods[0] > 0)
            {
                return coods[1] - coods[0];
            }
            else
            {
                return 0;
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int freq[200006];
int main()
{
	
	int n;
	cin>>n;int x;
	for(int i=0;i<n-1;i++)
	{
		cin>>x;
		freq[x]++;
	}
	for(int i=1;i<=n;i++)
	cout<<freq[i]<<"\n";
	
	
	
}

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

int main(){
  
  int x1,x2,x3,x4,y1,y2,y3,y4;
  
  cin >> x1 >> y1 >> x2 >> y2;
  
  x3=x2+y1-y2;
  y3=y2-x1+x2;
  x4=x1+y1-y2;
  y4=y1-x1+x2;
  
  cout << x3 << endl;
  cout << y3 << endl;
  cout << x4 << endl;
  cout << y4<< endl;
  
  return 0;
}


Measured memory_bytes: 256
/*input
6
8 6 9 1 2 1

*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 
//change null_type to get ordered_map
#define N  100005
#define DEC(N)	cout << std::fixed; cout << setprecision(N);
vpi v;
lld dp[2005][2005];
lld func(lld pos,lld l,lld r){
	if(l>r){
		return 0;
	}
	if(dp[pos][l]!=-1){
		return dp[pos][l];
	}
	lld ans=0;
	ans=max(func(pos+1,l+1,r)+v[pos].F*abs(v[pos].S-l),func(pos+1,l,r-1)+v[pos].F*abs(v[pos].S-r));
	return dp[pos][l]=ans;
}
void solve()
{
	lld n;
	cin >> n;
	rep(i,1,n+1){
		lld x;
		cin >> x;
		v.pb({x,i-1});
	} 
	sort(all(v));
	reverse(all(v));
	memset(dp,-1,sizeof dp);
	cout << func(0,0,n-1) << endl;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

Measured memory_bytes: 35228
#include<bits/stdc++.h>
#define int long long int
#define inf 1000000000000
#define hell (int)(1e9+7)

using namespace std;

void solve(){
    int n;
    cin>>n;
    vector < vector <int> > dp(10,vector <int> (10,0));
    for(int i=1;i<=n;i++){
        int c=1,x=i;
        while(x>0){
            x/=10;
            c*=10;
        }
        c/=10;
        dp[i/c][i%10]++;
    }
    int ans=0;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            ans+=dp[i][j]*dp[j][i];
        }
    }
    cout<<ans;
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int dfs(vector<vector<int> > &G, int v, vector<int> &deg, vector<bool> &del){
  int num = 1;
  if(deg[v] == 1) del[v] = true;
  else return 0;
  for(const int& u : G[v]){
    if(del[u])continue;
    --deg[u];
    num += dfs(G, u, deg, del);
  }
  return num;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,M;cin >> N >> M;
  vector<vector<int> >G(N);
  vector<int> deg(N,0);
  vector<bool> del(N,false);
  rep(j,M){
    int x,y;cin >> x >> y;
    --x;--y;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }
  queue<int> que;
  rep(i,N){
    deg[i] = G[i].size();
    if(deg[i] == 1)que.push(i);
  }
  int num = 0;
  while(!que.empty()){
    int v = que.front();que.pop();
    num += dfs(G,v,deg,del);
  }
  cout << num << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define PI 3.14159265359
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vll vector<ll>
#define vpint vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define fr(it, a, b) \
    for (int it = (a); it < (b); it++)
#define tr(con, it) \
    for (auto it = con.begin(); it != con.end(); it++)
#define present(con, ele) (con.find(ele) != con.end())
#define cpresent(con, ele) (find(all(con), ele) != con.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
typedef long long ll;
typedef long double lf;
typedef pair<int, int> pi;
typedef unsigned long long lu;
const ll mod = 1e9 + 7, N = 1e6 + 5;
int32_t main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, ans = 0;
    cin >> n;
    vector<int> a(n), cnt(N, 0);
    fr(i, 0, n)
    {
        int u;
        cin >> u;
        a[i] = u;
        cnt[u]++;
    }
    ans = n;
    fr(i, 0, n)
    {
        int u = a[i];
        for (int i = 1; i * i <= u; i++)
        {
            if (u % i == 0)
            {
                if (cnt[i])
                {
                    if (i != u || (i == u && cnt[i] > 1))
                    {
                        ans--;
                        break;
                    }
                }
                else if (cnt[u / i])
                {
                    if (u / i != u || (u / i == u && cnt[u / i] > 1))
                    {
                        ans--;
                        break;
                    }
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<vector<int>> f(n, vector<int>(10));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 10; j++){
      cin >> f.at(i).at(j);
    }
  }
  
  vector<vector<int>> p(n, vector<int>(11));
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 11; j++){
      cin >> p.at(i).at(j);
    }
  }
  
  int ans = -1e9;
  for(int i = 1; i < (1 << 10); i++){
    int keep = 0, count = 0;
    for(int j = 0; j < n; j++){
      count = 0;
      for(int k = 0; k < 10; k++){
        if(f.at(j).at(k) && (i & 1 << k)) count++;
      }
      keep += p.at(j).at(count);
    }
    ans = max(ans, keep);
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef vector<vector<P>> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<ll> vec;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}

template<typename T> 
map<T, int> factorize(T x){
  map<T, int> res;
  for(int i=2;i*i<=x;i++){
    while(x%i==0){
      x/=i;
      res[i]++;
    }
  }
  if(x!=1) res[x]++;
  return res;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n,p;
    cin>>n>>p;
    auto m=factorize(p);
    int ans=1;
    for(auto x:m){
        ll k=x.second/n;
        for(int i=0;i<k;i++) ans*=x.first;
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
using namespace std;
int main(){
    queue<pair<string,int> >v;
    int n,q;
    cin>>n>>q;
    for(int i=0;i<n;i++){
        string a;
        int b;
        cin>>a>>b;
        v.push(make_pair(a,b));
    }
    int time=0;
    while(v.size()>0){
        pair<string,int>P=v.front();v.pop();
        string s=P.first;
        int t=P.second;
        if(t<=q){
            cout<<s<<" "<<time+t<<endl;
            time+=t;
        }else{
            v.push(make_pair(s,t-q));
            time+=q;
        }
    }
}

Measured memory_bytes: 6288
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		DigitNum();
	}
	
	public static void DigitNum(){
			Scanner scan = new Scanner(System.in);
			while(scan.hasNext()){
			int sum = scan.nextInt()+scan.nextInt();
			System.out.println(String.valueOf(sum).length());
		}
	}
}

Measured memory_bytes: 26300
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[]$) {
        Scanner sc = new Scanner(in);
        boolean[] d=new boolean[26];
        for (int i = 0; i < 26; i++) {
            d[i]=false;
        }
        char[] c=new char[26];
        for (int i = 0; i < 26; i++) {
            c[i]=(char)('a'+i);
        }
        String s=sc.next();
        if(s.length()<26) {
            for (int i = 0; i < s.length(); i++) {
                char p = s.charAt(i);
                d[p-97]=true;
            }
            for (int i = 0; i < 26; i++) {
                if(!d[i]){
                    out.println(s+c[i]);
                    break;
                }
            }
        }else{
            int countR=25;
            while(countR>0&&s.charAt(countR)<s.charAt(countR-1)){
                d[s.charAt(countR)-97]=true;
                countR--;
            }
            if(countR==0){
                out.println(-1);
            }else{
                TreeSet<Character> ts=new TreeSet<>();
                for (int i = countR; i < 26; i++) {
                    if(s.charAt(countR-1)<s.charAt(i))ts.add(s.charAt(i));
                }
                for (int i = 0; i <countR-1; i++) {
                    out.print(s.charAt(i));
                }
                out.println(ts.pollFirst());
            }
        }
    }
}

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

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

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

#define INF 1e16
#define mod 1000000007

struct edge{
  ll u,v,c;
};

ll N,M,p;
vector<edge> es;
ll dp[3000];

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

  cin>>N>>M>>p;
  rep(i,M){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    es.push_back((edge){a,b,c-p});
  }

  rep(i,N)dp[i]=-INF;
  dp[0]=0;

  rep(_,N+1){
    rep(i,M){
      edge e=es[i];
      if(dp[e.u]!=-INF&&dp[e.u]+e.c>dp[e.v]){
        dp[e.v]=dp[e.u]+e.c;
      }
    }
  }

  ll preres=dp[N-1];

  rep(_,N+1){
    rep(i,M){
      edge e=es[i];
      if(dp[e.u]!=-INF&&dp[e.u]+e.c>dp[e.v]){
        dp[e.v]=dp[e.u]+e.c;
      }
    }
  }

  if(preres<dp[N-1])cout<<-1<<endl;
  else cout<<max(0LL,dp[N-1])<<endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

int main() {
	i64 a, b, c; scanf("%lld%lld%lld", &a, &b, &c);

	i64 A = a + b - c;
	if(A < 0) {
		if(A * A > 4 * a * b) printf("Yes\n");
		else printf("No\n");
	} else {
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int addNumber[20];
	int ansNumber[200];
	int needAddN, needAnsN;
	int YorN;
	int i, j;

	scanf("%d", &needAddN);
	for (i = 0; i < needAddN; i++) {
		scanf("%d", &addNumber[i]);
	}
	scanf("%d", &needAnsN);
	for (i = 0; i < needAnsN; i++) {
		scanf("%d", &ansNumber[i]);
	}

	for (i = 0; i < needAnsN; i++) {
		int addBox;
		int down; //??°????????°????????????????????????
		down = -1;
		for (j = needAddN - 1; j >= 0; j--) {
			down++;
			addBox = 0;// addNumber[j];
/*			if (addBox == ansNumber[i]) {
				YorN = 1;
				break;
				}
*/
			YorN = calc(ansNumber[i], addNumber, needAddN - down, addBox);
			if (YorN == 1) {
				break;
			}
		}
		if (YorN == 1) {
			printf("yes\n");
		}
		else {
			printf("no\n");
		}
	}

	return 0;
}

int calc (int answer, int* addNumber, int count, int addBox) {
	int trueA;
	if (addBox > answer || count < 0) {
		return -1;
	}

	do {
		count--;
		if (count < 0) {
			return -1;
		}
		addBox += addNumber[count];
		if (addBox == answer) {
			trueA = 1;
		}
		else {
			trueA = calc(answer, addNumber, count, addBox);
			addBox -= addNumber[count];
		}
	} while (trueA == -1);

	return 1;
}

Measured memory_bytes: 580
#include <iostream>

int main()
{
    long n, m;
    std::cin >> n >> m;
    long _gcf = m / n;
    while (1) {
        if (m % _gcf == 0) {
            std::cout << _gcf << std::endl;
            return 0;
        }
        _gcf--;
    }
}


Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True

class UnionFind(object):
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()),


def main():
    N, M = MI()
    uf = UnionFind(N)

    for i in range(M):
        a, b = MI()
        uf.union(a-1, b-1)

    ret = [uf.size(i) for i in uf.roots()]

    print(max(ret))

if __name__ == '__main__':
    main()


Measured memory_bytes: 102984
#include <iostream>
#include <algorithm>
using namespace std;
double arr[1000000];
int main(){
    int a,b,c,i,n;
    cin>>n>>a;
    cout<<a-n+1;
    for(i = 1;i < 2*n-1;i++){
        cout<<' '<<a-n+i+1;
    }
}


Measured memory_bytes: 764
import sys

# sys.stdin = open('c1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    n, x = read_int_list()
    a = read_int_list()
    res = 0
    if a[0] > x:
        res += a[0] - x
        a[0] = x
    for i in range(1, n):
        if a[i - 1] + a[i] > x:
            diff = a[i - 1] + a[i] - x
            res += diff
            a[i] -= diff
    print(res)


main()


Measured memory_bytes: 14348
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  string S;
  long long smax,slength;
  smax=0;
  slength=0;
  cin >> S;
  
  for (int i=0;i<S.size();i++) {
  
    if (S[i]=='A' || S[i]=='C' || S[i]=='G' || S[i]=='T') {
	  slength++;
	  if (smax<slength) {smax++;}
	}
	else  {
	  slength=0;
	}
  }
  
  cout << smax << endl;

}

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

int main() {
    int64_t h,w,ans;

    cin >> h >> w;
    if(h == 1 || w==1) ans = 1;
    else if((h*w) % 2 == 0) ans = (h*w)/2;
    else ans = (h*w + 1)/2;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c;
    cin>>a>>b>>c;
    int action=b/a;
    cout<<min(action,c)<<endl;

    return 0;
}



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

#output
def K_is_one(n):
    p = len(str(n))
    q = int(str(n)[0])
    return q + 9*(p-1)

def K_is_two(n):
    p = len(str(n))
    q = int(str(n)[0])
    if p == 1:
        return 0
    elif p == 2:
        return n - K_is_one(n)
    else:
        r = int(str(n)[1:])
        temp = 0
        for i in range(1, p-1):
            temp += 9*K_is_one(int("9"*i))
        temp += (q-1) * K_is_one(int("9"*(p-1))) + K_is_one(r)
        return temp

def K_is_three(n):
    p = len(str(n))
    q = int(str(n)[0])
    if p == 1:
        return 0
    elif p == 2:
        return 0
    else:
        r = int(str(n)[1:])
        temp = 0
        for i in range(1, p-1):
            temp += 9*K_is_two(int("9"*i))
        temp += (q-1) * K_is_two(int("9"*(p-1))) + K_is_two(r)
        return temp

if K == 1:
    print(K_is_one(N))
elif K == 2:
    print(K_is_two(N))
else:
    print(K_is_three(N))

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>

#include <unordered_map>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <sstream>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll pow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = pow(N, P/2);
        return t*t;
    }
    return N * pow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    n=abs(n);
    m=abs(m);
    if(n*m==0)return max(n,m);
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
int main(){
    int s,w;cin>>s>>w;
    if(s>w)cout<<"safe"<<endl;
    else cout<<"unsafe"<<endl;
}

Measured memory_bytes: 3636
def main():
    N, Ma, Mb = map(int, input().split())
    A = []
    B = []
    C = []
    for _ in range(N):
        a, b, c = map( int, input().split())
        A.append(a)
        B.append(b)
        C.append(c)
    dp = [[10**5]*401 for _ in range(401)]
    dp[0][0] = 0
    for t in range(N):
        a, b, c = A[t], B[t], C[t]
        for i in range(400,-1,-1):
            for j in range(400,-1,-1):
                if i-a >= 0 and j-b >= 0:
                    if dp[i-a][j-b] + c < dp[i][j]:
                        dp[i][j] = dp[i-a][j-b] + c
    ans = 10**5
    for i in range(1, 401):
        if i*Ma > 400 or i*Mb > 400:
            break
        if dp[i*Ma][i*Mb] < ans:
            ans = dp[i*Ma][i*Mb]
    if ans == 10**5:
        print(-1)
    else:
        print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 4860
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1'000'000'007;
template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

int main() {
    int n, k;
    cin >> n >> k;
    vl v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    // vl vsum = v;
    // for (int i = 1; i < n; ++i) {
    //     v[i] += v[i - 1];
    // }
    ll maxi = 0;
    // for (int i = 0; i <= k; ++i) { // i times operations
    int i = k;
    ll total = 0;
    for (int j = 1; j <= min(i, n); ++j) { // get j jems and return i-j jems if negative
        for (int k = 0; k <= j; ++k) {     // get k jems from left
            vl neg;
            ll tot = 0;
            for (int l = 0; l < k; ++l) {
                tot += v[l];
                if (v[l] < 0)
                    neg.push_back(v[l]);
            }
            for (int l = 0; l < j - k; ++l) {
                tot += v[n - 1 - l];
                if (v[n - 1 - l] < 0)
                    neg.push_back(v[n - 1 - l]);
            }
            sort(neg.begin(), neg.end(), less<ll>());
            int revert = i - j;
            for (auto nn : neg) {
                if (revert <= 0)
                    break;
                else {
                    tot -= nn;
                    revert--;
                }
            }
            chmax(maxi, tot);
        }
    }
    //}
    cout << maxi << endl;
    return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "5 3", "10 30 40 50 20" ].parse.expand.solve == 30 );
	assert( [ "3 1", "10 20 10" ].parse.expand.solve == 20 );
	assert( [ "2 100", "10 10" ].parse.expand.solve == 0 );
	assert( [ "10 4", "40 10 20 70 80 10 20 70 80 60" ].parse.expand.solve == 40 );
}



import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	input.popFront;
	auto hs = input.front.split.to!( long[] );
	return tuple( nk[ 1 ], hs );
}

auto solve( long k, long[] hs )
{
	auto dp = new long[ hs.length ];
	
	dp[ 0 ] = 0L;
	for( auto i = 1L; i < dp.length; i++ )
	{
		auto m = long.max;
		for( auto ki = 1L; 0 <= i - ki && ki <= k; ki++ )
		{
			auto mi = i - ki;
			auto d = dp[ mi ] + ( hs[ mi ] - hs[ i ] ).abs;
			m = ( d < m ) ? d : m;
		}
		dp[ i ] = m;
	}
	
	return dp[ $ - 1 ];
}


Measured memory_bytes: 6948
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string S;
    cin >> S;


    REP(i, 1 << (S.size() - 1)) {
        int s = S[0] - '0';

        string out;
        out += S[0];
        REP(j, S.size() - 1) {
            if (i >> j & 1) {
                out += string("+") + S[j + 1];
                s += S[j + 1] - '0';
            } else{
                out += string("-") + S[j + 1];
                s -= S[j + 1] - '0';
            }
        }

        if (s == 7) {
            cout << out << "=7" << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 256