akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

from collections import defaultdict
from heapq import *

def main():
	t=II()
	while t:
		t-=1
		n,a,b,c,d=MI()
		Q=[-n,0]
		heapify(Q)
		D=defaultdict(lambda:10**18)
		D[n]=0
		k=n+1
		while Q:
			now=-heappop(Q)
			#print(now,"a")
			if now==0:
				print(D[0])
				break

			if now<k:
				q2,r2=divmod(now,2)
				q3,r3=divmod(now,3)
				q5,r5=divmod(now,5)

				#print(now)
				if D[q5]>D[now]+c+r5*d:
					D[q5]=D[now]+c+r5*d
					heappush(Q,-q5)
				if r5!=0 and D[q5+1]>D[now]+c+(5-r5)*d:
					D[q5+1]=D[now]+c+(5-r5)*d
					heappush(Q,-q5-1)

				if D[q3]>D[now]+b+r3*d:
					D[q3]=D[now]+b+r3*d
					heappush(Q,-q3)
				if r3!=0 and D[q3+1]>D[now]+b+(3-r3)*d:
					D[q3+1]=D[now]+b+(3-r3)*d
					heappush(Q,-q3-1)

				if D[q2]>D[now]+a+r2*d:
					D[q2]=D[now]+a+r2*d
					heappush(Q,-q2)
				if r2!=0 and D[q2+1]>D[now]+a+(2-r2)*d:
					D[q2+1]=D[now]+a+(2-r2)*d
					heappush(Q,-q2-1)

				D[0]=min(D[0],D[now]+now*d)







if __name__ == "__main__":
	main()


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define X first
#define Y second

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

const double PI = 3.14159265358979;

int h, w, n;
int ans[101][101];
vector<int> color;
int now_color;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void dfs(int x, int y)
{
  if (ans[y][x] != 0) return;
  if (color[now_color] == 0)
  {
    now_color++;    
    return dfs(x, y);
  }

  color[now_color]--;
  ans[y][x] = now_color + 1;

  for(int i = 0; i < 4; ++i)
  {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (nx < 0 || w <= nx) continue;
    if (ny < 0 || h <= ny) continue;
    dfs(nx, ny);
  }
}

void solve()
{
  cin >> h >> w >> n;
  color = vector<int>(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> color[i];
  }

  dfs(0, 0);
  for(int y = 0; y < h; ++y)
  {
    for(int x = 0; x < w; ++x)
    {
      cout << ans[y][x] << " ";
    }
    cout << endl;
  }
}

int main()
{
  fastio;
  solve();

  return 0;
}


Measured memory_bytes: 4116
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<vector<ll>> graph(n);
    for(int i = 0; i < n-1; i++) {
        ll a,b;cin >> a >> b;
        a--;b--;
        graph[a].emplace_back(b);
        graph[b].emplace_back(a);
    }
    vector depth(n, vector<ll>());
    vector<ll> dep(n);

    auto dfs = [&](auto self, ll now, ll pre = -1, ll d = 0)->void{
        depth[d].emplace_back(now);
        dep[now] = d;
        for(auto to : graph[now]){
            if(to == pre)continue;
            self(self, to, now, d + 1);
        }
    };
    dfs(dfs, 0);
    debug(depth, dep);

    vector<ll> dp(n);
    rrep(i,n,0){
        for(auto j : depth[i]){
            ll d = dep[j];
            for(auto to : graph[j]){
                if(dep[to] < d)continue;
                dp[j] += dp[to];
            }
            dp[j]++;
            if(dp[j] == 2)dp[j] = 0;
        }
    }

    debug(dp);
    cout << (dp[0] ? "First" : "Second") << "\n";
}

Measured memory_bytes: 14496
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int k,s;
    cin>>k>>s;
    int ans;
    for (int x = 0; x < k+1; x++){
        for (int y = 0; y < k+1; y++){
            if ((s-x-y)<=k&&0<=(s-x-y)){
                ans+=1;
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map<int, int>mp;
int a[300010];
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int t;
		cin >> t;
		a[i] = t;
		mp[t]++;
	}
	long long ans = 0;
	for (auto i : mp) {
		ans += 1ll * i.second * (i.second - 1) / 2;
	}
	for (int i = 1; i <= n; i++) {
		cout << ans - (mp[a[i]]) * (mp[a[i]] - 1) / 2 + (mp[a[i]] - 1) * (mp[a[i]]-2>=1?mp[a[i]] - 2:0) / 2 << '\n';
	}

}

Measured memory_bytes: 8320
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> c[N];
  REP(i,M){
    int u,v,w;
    cin>>u>>v>>w;
    u--;v--;
    c[u].push_back(v);
    c[v].push_back(u);
  }
  int ans=0;
  int index=0;
  int v[N];
  REP(i,N)v[i]=0;
  while(index<N){
    queue<int> q;
    q.push(index);
    v[index]=1;
    while(!q.empty()){
      int p=q.front();
      q.pop();
      for(auto e:c[p]){
        if(v[e])continue;
        q.push(e);
        v[e]=1;
      }
    }
    while(v[index]==1){
      index++;
      if(index==N)break;
    }
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 6904
#include <iostream>

#include <vector>
#include <algorithm>

using namespace std;

int main()	{
  int n;
  cin >> n;
  vector<long long int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  long long res = 0;
  for (int i = 0; i < n; i++)	{
    long long a_term = max(0ll, (long long)(lower_bound(a.begin(), a.end(), b[i]) - a.begin()));
    long long b_term = max(0ll, (long long)(n - (long long)(upper_bound(c.begin(), c.end(), b[i]) - c.begin()))); 
    res += max(0ll, a_term * b_term);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 5580
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args){
        int N = in.i();
        int[] A = in.ii(N);
        Arrays.sort(A);
        long ans = A[A.length - 1];
        final int M = (A.length + 1) / 2;
        for (int i = A.length - 2; i >= M; i--) {
            ans += A[i] * 2;
        }
        if ((A.length & 1) == 1) {
            ans += A[M - 1];
        }
        out.println(ans);
    }

    static class MyReader extends BufferedReader {
        char[] cbuf = new char[1 << 17];
        int head = 0;
        int tail = 0;

        MyReader() {
            super(new InputStreamReader(System.in));
        }

        char next() {
            if (head == tail) {
                try {
                    tail = read(cbuf, 0, cbuf.length);
                } catch (IOException e) {}
                head = 0;
            }
            return cbuf[head++];
        }

        void back() {
            head--;
        }

        boolean minus() {
            boolean minus;
            while (true) {
                char c = next();
                if (c != ' ' && c != '\n' && c != '\r') {
                    if (!(minus = c == '-')) back();
                    return minus;
                }
            }
        }

        void skip() {
            while (true) {
                char c = next();
                if (c != ' ' && c != '\n' && c != '\r') {
                    back();
                    break;
                }
            }
        }

        char[] s(final int N) {
            skip();
            char[] s = new char[N];
            for (int i = 0; i < s.length; i++) {
                s[i] = next();
            }
            return s;
        }

        int i() {
            boolean minus = minus();
            int n = 0;
            while (true) {
                int k = next() - '0';
                if (k < 0 || 9 < k) break;
                n = 10 * n + k;
            }
            return minus ? -n : n;
        }

        int[] ii(final int N) {
            int[] a = new int[N];
            for (int j = 0; j < a.length; j++) a[j] = i();
            return a;
        }

        long l() {
            boolean minus = minus();
            long n = 0;
            while (true) {
                int k = next() - '0';
                if (k < 0 || 9 < k) break;
                n = 10 * n + k;
            }
            return minus ? -n : n;
        }
    }
}


Measured memory_bytes: 37828
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int n,a,b; cin >> n >> a >> b;
    int ans1 = min(a,b);
    int ans2 = max(0,a+b-n);

    cout << ans1 << " " << ans2  << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  ll n,a[100010],s=0,kari=0,ans=0;
  bool f;
  cin>>n;
  fr(i,n) cin>>a[i];
  fr(i,n){
    s+=a[i];
    if(i%2){if(s>=0){kari+=s+1;s=-1;}}
    else{if(s<=0){kari+=1-s;s=1;}}
  }
  s=0;
  fr(i,n){
    s+=a[i];
    if(1-i%2){if(s>=0){ans+=s+1;s=-1;}}
    else{if(s<=0){ans+=1-s;s=1;}}
  }
  cout<<min(ans,kari)<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
string s;
cin>>n>>s;
int ans=0;
reps(i,n-1,1){
    int tmp_cnt=0;
    set<char> log;
    string x=s.substr(0,i);
    string y=s.substr(i,n-i);
    if(x.size()>y.size()){
        int len=x.size();
        rep(i,len){
            if(count(y.begin(),y.end(),x[i]) &&log.count(x[i])==0){
                log.insert(x[i]);
                tmp_cnt++;
            }
        }
    }
    else{
        int len=y.size();
        rep(i,len){
            if(count(x.begin(),x.end(),y[i])&&log.count(y[i])==0){
               log.insert(y[i]);
               tmp_cnt++;
            }
        }
    }
    ans=max(ans,tmp_cnt);
}
cout<<ans<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let (n, k): (usize, usize) = read();
    let mut a: Vec<usize> = readnc();

    let left = dodp(&a, k);
    a.reverse();
    let right = dodp(&a, k);
    a.reverse();

    let mut ans = 0;
    for i in 0..n {
        if a[i] >= k {
            continue
        }
        let mut rsum = vec![0; k+2];
        for r in 0..k {
            rsum[r+1] = rsum[r] + if right[n-i-1][r] { 1 } else { 0 };
        }

        let mut isok = false;
        for l in 0..k+1 {
            let from = if k <= a[i] + l { 0 } else { k - a[i] - l };
            let to = k - l;
            if left[i][l] && rsum[to] - rsum[from] >= 1 {
                isok = true;
                break
            }
        }
        if !isok {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn dodp(a: &Vec<usize>, k: usize) -> Vec<Vec<bool>> {
    let n = a.len();
    let mut dp: Vec<Vec<bool>> = vec![vec![false; k+1]; n+1];
    dp[0][0] = true;
    for i in 0..n {
        for j in 0..k+1 {
            if !dp[i][j] {
                continue
            }
            dp[i+1][j] = true;

            let tj = min(k, j + a[i]);
            dp[i+1][tj] = true;
        }
    }
    dp
}

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr <<"at line "<< __LINE__<<": [" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
typedef tree<int, null_type,
		less_equal<int>, 
		rb_tree_tag,tree_order_statistics_node_update> ordered_mset;
		
typedef tree<int, null_type,
		less<int>, 
		rb_tree_tag,tree_order_statistics_node_update> ordered_set;
*/
 
/*
 
PBDS
-------------------------------------------------
			0 based indexing
-------------------------------------------------			 
1) insert(value)
2) erase(value)
3) order_of_key(value) // Number of items strictly smaller than value
4) *find_by_order(k) : K-th element in a set (counting from zero)
 
*/
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());	

void solve()
{
	int n,m,x;
	cin>>n>>m>>x;
	vector<int>c(n);
	
	int ara[n][m];
	
	for(int i=0;i<n;i++)
	{
		cin>>c[i];
		for(int j=0;j<m;j++) cin>>ara[i][j];
	}
	
	int ans=1e9;
	
	for(int i=0;i<(1<<n);i++)
	{
		vector<int>vec(m,0);
		int temp=0;
		for(int j=0;j<n;j++)
		{
			if(i&(1<<j))
			{
				temp+=c[j];
				for(int k=0;k<m;k++) vec[k]+=ara[j][k];
			}
		}
		if(*min_element(vec.begin(),vec.end())>=x) ans=min(ans,temp);
	}
	
	if(ans<1e9) cout<<ans;
	else cout<<-1;
}
		
	
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	
	#ifdef LOCAL
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif
	
	
	return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  int cnt = 0;
  vector<char> v;
  v.push_back(S[0]);
  for (int i = 1; i < N; i++) {
    if (v.back() != S[i]) v.push_back(S[i]);
  }
  
  int ans = N - max(1, (int)v.size() - 2 * K);
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 640
h, w = map(int, input().split())

s = []
for i in range(h):
    s.append(input())

t = [['']*w for i in range(h)]
# print(t.count)

dx = [0, 0, 1, -1, 1, 1, -1, -1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
for y in range(h):
    for x in range(w):
        if s[y][x] == '#':
            t[y][x] = '#'
        else:
            count = 0
            for i in range(8):
                if x + dx[i] < 0 or x + dx[i] >= w or y + dy[i] < 0 or y + dy[i] >= h:
                    continue
                nx = x + dx[i]
                ny = y + dy[i]
                if s[ny][nx] == '#':
                    count += 1
            t[y][x] = str(count)

for i in range(len(t)):
    print(''.join(t[i]))

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip	;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
class DIJ{
	public:
	struct edge{
		int to,cost;
	};
	vector<vector<edge> >G;
	int n;
	vi d;//distance
	DIJ(int size){
		n=size;
		G=vector<vector<edge> >(n);
		d=vi(n,inf);
	}
	void add_edge(int a,int b,int c){
		edge e={b,c},ee={a,c};
		G[a].pb(e);
		G[b].pb(ee);
	}
	void dij(int s){
		d[s]=0;
		priority_queue<pii>q;
		q.push(pii(0,s));
		while(!q.empty()){
			pii p=q.top();
			q.pop();
			int pos=p.second,cost=-p.first;
			if(cost>d[pos])continue;
			rep(i,G[pos].size()){
				edge e=G[pos][i];
				int to=e.to;
				int nowcost=cost+e.cost;
				if(nowcost<d[to]){
					d[to]=nowcost;
					q.push(pii(-d[to],to));
				}
			}
		}
	}
};
int main(){
	int n,m,s;
	cin>>n>>m>>s;
	DIJ dij(n);
	while(m--){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		dij.add_edge(a,b,c);
	}
	while(s--){
		int a;
		cin>>a;
		a--;
		dij.dij(a);
	}
	int out=0;
	rep(i,n)rep(j,dij.G[i].size()){
		int a=dij.d[i],b=dij.d[dij.G[i][j].to],c=dij.G[i][j].cost;
		out=max(out,(int)(0.5+(a+b+c)/2.));
	}
	cout<<out<<endl;
}

Measured memory_bytes: 4196
#include <iostream>

using namespace std;

int main()
{
    int H, W;

    while (1) {
        cin >> H >> W;
        if (H == 0 && W == 0)   break;

        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cout << "#";
            }
            cout << '\n';
        }
        cout << endl;
    }
    return 0;    
}


Measured memory_bytes: 3084
function Main(input){
	//var xs = input.split('\n')[0].split('')
    var xs = input.trim().split('').map(v=>parseInt(v,10));
    ans = '';
    if(xs[1]==xs[2]){
	if(xs[0]==xs[1]||xs[2]==xs[3]){
    ans += 'Yes';
    }else{
    ans += 'No';
    }
    }else{
    ans += 'No';  
	}
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
using std::cout;
using std::endl;
using std::vector;
using std::cin;
using std::map;
using std::multimap;
using std::set;
using std::multiset;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		b /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a - b < b) { return comb(a, a - b); }
	ll c = 1;
	FOR(i, a - b + 1, a + 1) {
		c *= i;
		c %= MOD;
	}
	ll k = 1;
	FOR(i, 2, b + 1) {
		k *= i;
		k %= MOD;
	}
	c *= pow(k, MOD - 2);
	return c % MOD;
}
multiset<ll> prime_decomposition(ll n) {
	ll i = 2;
	multiset<ll> table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace(n);
		return table;
	}
	return table;
}

int main() {
	ll a, b;
	cin >> a >> b;
	cout << ((a < 9 && b < 9) ? "Yay!" : ":(") << endl;
}

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

int main() {
  int l, r, d;
  cin >> l >> r >> d;
  int cnt = 0;
  for (int i = l; i <= r; i++) {
    if (i % d == 0) cnt++;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3592
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;



string s;


int main(int argc, const char * argv[]) {
 //   freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> s;
    int last = 0;
    int ans = 0;
    for (int i = 0; i < (int)s.size(); ++i) {
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') ++last;
        else last = 0;
        if (last > ans) ans = last;
    }
    cout << ans << '\n';
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int mayer[51]={0};

int isNone(int me,int max){
	int i;
	for(i=0;i<max;i++){
		if(i==me);
		else if(mayer[i]>0)return 0;
	}
	return 1;
}

int main(){
	int n,p,i,j;
	int count=0;
	while(1){
		memset(mayer,0,sizeof(mayer));
		scanf("%d %d",&n,&p);
		if(!n &&!p)break;
		count=0;
		for(i=0;1;i++,count++){
			if(i==n)i=0;
			if(p==0){
				if(mayer[i]>0){
					p=mayer[i];
					mayer[i]=0;
				}
			}
			else if(p>0){
				mayer[i]++;
				p--;
			}
			if(p==0){
				if(isNone(i,n)){
					printf("%d\n",i);
					break;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define endl '\n'
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long 
using namespace std;
const int N = 1e5+10;
const int M = 1e9+7;

int main(){
	FIO;
	int n;
	cin >> n;
	int dp1[n+2],dp2[n+2],dp3[n+2],a[n+1],b[n+1],c[n+1];
	dp1[0]=0;
	dp2[0]=0;
	dp3[0]=0;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a[i] >> b[i] >> c[i];
	}
	for (int i = 1; i <= n; ++i)
	{
		dp1[i] = a[i]+max(dp2[i-1],dp3[i-1]);
		dp2[i] = b[i]+max(dp1[i-1],dp3[i-1]);
		dp3[i] = c[i]+max(dp2[i-1],dp1[i-1]);
		// cout << dp1[i] << dp2[i] << dp3[i] <<" "; 
	}
	cout << max(dp1[n],max(dp2[n],dp3[n])); 
}

Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.MathContext;
import java.math.RoundingMode;

public class Main {

  private static final long DIVIDER =  (long)Math.pow(10, 9) + 7;

  private static final MathContext MC = new MathContext(0, RoundingMode.HALF_DOWN);


  public static void main(String[] args) {

    int n = 0;
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      n = Integer.parseInt(br.readLine());
    } catch(IOException e) {
      e.printStackTrace();
      System.exit(1);
    }

    long quotient = 1;
    for (int i = 1; i <= n; i++) {
      quotient = (quotient * i) % DIVIDER;
    }

    System.out.print(quotient);
  }
}


Measured memory_bytes: 22612
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int a = scanner.nextInt();
        final int b = scanner.nextInt();

        final List<Long> list = IntStream.range(0, n)
                .mapToObj(i -> scanner.nextLong())
                .sorted(Comparator.reverseOrder())
                .collect(Collectors.toList());

        final int answer = binarySearch(list, 0, 2_000_000_000, a, b);
        System.out.println(answer);
    }

    private static int binarySearch(final List<Long> list, final int begin, final int end, final long a, final long b) {
        if (end - begin <= 1) {
            return end;
        }

        final int mid = (end + begin) / 2;
        final List<Long> bAttackedList = list.stream()
                .filter(i -> i > (mid * b))
                .map(i -> i - mid * b)
                .collect(Collectors.toList());

        if (bAttackedList.isEmpty()) {
            return binarySearch(list, begin, mid, a, b);
        }

        long count = mid;
        final long attack = a - b;
        for (final long remainedHP : bAttackedList) {
            count -= (remainedHP + attack - 1) / attack;
        }

        if (count >= 0) {
            return binarySearch(list, begin, mid, a, b);
        } else {
            return binarySearch(list, mid, end, a, b);
        }
    }
}


Measured memory_bytes: 97508
import Control.Applicative

divide :: Int -> [Int] -> [[Int]]
divide _ [] = []
divide n xs = [take n xs] ++ divide n (drop n xs)

mapeven f [] =[]
mapeven f [x] =[x]
mapeven f (x:y:xs) = x:(f y):(mapeven f xs)

evenflip = mapeven reverse

collist0 :: Int -> [Int]->[Int]
collist0 _ [] = []
collist0 n (x:xs) = (replicate x n) ++ collist0 (n+1) xs

collist = collist0 1

solver w as = evenflip $ (divide w) (collist as)

myshow = unwords.(map show)

showIO [xs] = do putStrLn $ myshow xs
showIO (xs:xss) = do
    putStrLn $ myshow xs
    showIO xss

main :: IO ()
main = do
    [_,w] <- map read . words <$> getLine 
    getLine 
    as <- map read . words <$> getLine 
    showIO $ solver w as



Measured memory_bytes: 2428
#include <stdio.h>

#define INF (1<<29)

int main(void) {
	int a[100];
	int n, ans, cost;
	int i, j;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	
	ans = INF;
	
	for (i = -100; i <= 100; i++) {
		cost = 0;
		for (j = 0; j < n; j++)
			cost += (a[j] - i) * (a[j] - i);
		
		if (ans > cost) ans = cost;
	}
	
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Input
	n := readInt()
	p := make([]int, n, n)
	for i := 0; i < n; i++ {
		p[i] = readInt()
	}

	// Solve
	fmt.Println(solve(p))
}

func solve(p []int) int {
	sum := 0
	max := 0
	for _, price := range p {
		if price > max {
			sum += max
			max = price
		} else {
			sum += price
		}
	}
	return sum + max/2
}

// - Util functions

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	n, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return n
}

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

int main() {
  int s;
  cin >> s;
  int cnt=0;
  if(s==1||s==2||s==4)
    cout << 4 << endl;
  else{
  while(s!=4){
    
    if(s%2==0){
      s /=2;
    }
    else{
      s=3*s+1;
  }
    cnt++;
  }
  
  cout << cnt+4 << endl;
  }
  
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if (a == b + c) {
		printf("Yes\n");
	}
	else if (a + b == c) {
		printf("Yes\n");
	}
	else if (a + c == b) {
		printf("Yes\n");
	}
	else { printf("No\n"); }
	return 0;
}

Measured memory_bytes: 128
/*
I believe on myself and I will achieve
this->author = Fuad Ashraful Mehmet, CSE ,University of Asia Pacific
Todo:
https://codeforces.com/problemset/problem/1365/E
*/
#include<bits/stdc++.h>
#define forn(i,n) for(int i=0;i<(int)n;++i)
#define all(o) (o).begin(),(o).end()
#define sz(o) (o).size() 
#define dbg(o)  cerr<<"at "<<__LINE__<<" response = "<<o<<endl;
#define pb push_back
using namespace std;

template<class T> void print(T & x){ cout << x; }
template<class T> void print(vector<T> & v) {
	cout << "{";
	if (sz(v)) print(v[0]);
	for (int i = 1; i < sz(v); i++) cout << ", ", print(v[i]);
	cout << "}\n";
}

typedef long long ll;
const int N=1e5+5;
int q,k,m,n,cs=1;
bool color[N];
vector<int>g[N];

void dfs(int from)
{
	color[from]=1;
	for(int to:g[from])
	{
		if(color[to])continue;
		dfs(to);
	}	
}
void HalfDead(){
	cin>>n>>m;
	int x,y;
	for(int i=1;i<=m;++i){
		cin>>x>>y;
		g[x].pb(y);
		g[y].pb(x);
	}

 
	int ans=0;
	for(int i=1;i<=n;++i)
	{
		if(color[i])continue;
		dfs(i);
		ans+=1;
	}

	cout<<--ans<<endl;
}// end func
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(nullptr);  cout.tie(0);
	// cout<<setprecision(10)<<fixed;
	int tc=1;
	//cin>>tc;
	while(tc--){
		HalfDead();
	}
	  return 0;
}

Measured memory_bytes: 9700
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M = map(int, readline().split())

    COM_MAX = M

    fac, finv, inv = [0] * (COM_MAX + 1), [0] * (COM_MAX + 1), [0] * (COM_MAX + 1)
    fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1

    for i in range(2, COM_MAX + 1):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    def com(n, r):
        if n < 0 or r < 0 or n < r:
            return 0
        return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD

    def perm(n, r):
        if n < 0 or r < 0 or n < r:
            return 0
        return fac[n] * finv[n - r] % MOD

    ans = 0
    for k in range(N + 1):
        tmp = perm(M - k, N - k) * com(N, k) % MOD
        if k & 1:
            tmp *= -1
        ans = (ans + tmp) % MOD

    ans = ans * perm(M, N) % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 68068
# coding: utf-8
# Your code here!

N,M = map(int,input().split())
A = []

ans = 0
for _ in range(N):
    A.append(list(map(int,input().split())))

A = sorted(A, key=lambda x: x[0])
# print(A)
for a in A:
    if a[1] >= M:
        ans += a[0]*M
        break
    else:
        ans += a[0]*a[1]
        M -= a[1]
        
print(ans)

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

typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;

#define FOR(i,a,b) for (int i=a;i<b;i++)
int N, M, Q;
bool board[2005][2005];
int prf[2005][2005];
bool edgb[2005][2005];
int prfb[2005][2005];
bool edgs[2005][2005];
int prfs[2005][2005];

int main(){
    scanf("%d %d %d",&N,&M,&Q);
    char line[2005];
    FOR(i,1,N+1){
        scanf("%s",line);
        FOR(j,1,M+1){
            board[i][j] = line[j-1]=='1';
        }
    }
    FOR(i,1,N) FOR(j,1,M+1){
        edgb[i][j] = board[i][j] && board[i+1][j];
    }
    FOR(i,1,N+1) FOR(j,1,M){
        edgs[i][j] = board[i][j] && board[i][j+1];
    }
    FOR(i,1,N+1) FOR(j,1,M+1){
        prf[i][j] = prf[i - 1][j] + prf[i][j - 1] - prf[i - 1][j - 1]+board[i][j];
        prfb[i][j] = edgb[i][j] + prfb[i-1][j]+prfb[i][j-1]-prfb[i-1][j-1];
        prfs[i][j] = edgs[i][j]+prfs[i-1][j]+prfs[i][j-1]-prfs[i-1][j-1];
    }
    int a, b, c, d;
    int p, pb, ps;
    FOR(i,0,Q){
        scanf("%d %d %d %d",&a,&b,&c,&d);
        p = prf[c][d]+prf[a-1][b-1]-prf[a-1][d]-prf[c][b-1];
        if (a!=c) pb = prfb[c-1][d]+prfb[a-1][b-1]-prfb[a-1][d]-prfb[c-1][b-1];
        else pb = 0;
        if (b!=d) ps = prfs[c][d-1]+prfs[a-1][b-1]-prfs[a-1][d-1]-prfs[c][b-1];
        else ps = 0;
        printf("%d\n",p-pb-ps);
    }
    return 0;
}


Measured memory_bytes: 60672
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace AtCoder {
    public class Program {
        static int[] getKeys() {
            var Keys = Console.ReadLine().Split(' ');
            int N = Keys.Length;
            int[] Ns = new int[N];
            for (int i = 0; i < N; i++) {
                Ns[i] = int.Parse(Keys[i]);
            }
            return Ns;
        }
        static int[] getKeys(char delimiter) {
            var Keys = Console.ReadLine().Split(delimiter);
            int N = Keys.Length;
            int[] Ns = new int[N];
            for (int i = 0; i < N; i++) {
                Ns[i] = int.Parse(Keys[i]);
            }
            return Ns;
        }
        public static void Show<T>(T[,] map) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        public static void Show<T>(T[,] map, string delimiter) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + delimiter);
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        public static void Show<T>(IEnumerable<T> ts) {
            foreach (var item in ts) {
                Console.Write(item + " ");
            }
            Console.WriteLine();
        }
        public static void Show<T>(IEnumerable<T> ts, string delimiter) {
            foreach (var item in ts) {
                Console.Write(item + delimiter);
            }
            Console.WriteLine();
        }
        static void Main() {
            string s = Console.ReadLine();
            string answer = "";
            for (int i = 0; i < s.Length; i++) {
                if (i % 2 == 0) {
                    answer += s[i];
                }
            }
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 34772
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define FFOR(i, a, b) for(int (i)=a;(i)>(b);--(i))
#define rrep(i,n) FFOR(i,0,n)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define ll long long
#define mod 1000000007LL
#define INF 123456789012345
typedef pair<int, int> P;
typedef pair<int, P> PP;

const int maxn =1e4 + 10;

string s[maxn];

int main() {
	
	int a,b;cin>>a>>b;
	
	cout <<(a+b)%24<< endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#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 unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
ll read(){ll a;scanf("%lld",&a);return a;}

const int inf = 3 * TEN(18) + 10;
const int mod = 998244353;

int N, L;

bool is_ok(string s)
{
	int n = s.size();
	rep(i, n / 2) {
		if (s[i] != s[i + n / 2]) return false;
	}
	return true;
}

signed main()
{
	string S; cin >> S;

	int ans = S.size();

	while (1) {
		ans-=2;
		S.pop_back();
		S.pop_back();
		if (is_ok(S)) {
			cout << ans << endl;
			return 0;
		}
	}

	cout << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0);
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define gg exit(0);

const int N=510;

int n,tot;
int f[N][N],a[N][N];
int p[N*N];

int D[]={-1,0,1,0};
int C[]={0,1,0,-1};

main(){
    #define task "TASK"
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);

    n=in;
    forinc(i,1,n*n) p[i]=in;

    forinc(i,1,n) forinc(j,1,n){
        f[i][j]=min({i,n-i+1,j,n-j+1})-1;
        a[i][j]=1;
    }

    forinc(w,1,n*n){
        int i=(p[w]-1)/n+1, j=p[w]-(i-1)*n; tot+=f[i][j];
        queue<ii> q; q.push({i,j}); a[i][j]=0;

        while(q.size()){
            tie(i,j)=q.front(); q.pop();
            int val=f[i][j] + a[i][j];
            forinc(t,0,3){
                int x=i+D[t], y=j+C[t];
                if(1>x||x>n||1>y||y>n||f[x][y]<=val) continue;
                f[x][y]=val;
                q.push({x,y});
            }
        }
    }
    cout<<tot;
}


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


public class Main {
    static long divCeil(long a, long b){
        return (a+b-1)/b;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A = new long[N];
        for(int n=0; n<N; n++) A[n] = sc.nextLong();
        
        long step = 0;
        long highest = 0;
        for(int n=0; n<N; n++){
            step += Math.max(0, highest-A[n]);
            highest = Math.max(highest, A[n]);
            
        }
        System.out.println(step);
    }
}


Measured memory_bytes: 62360
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	int n=in(),i,d,t,f[101]={};
	t=n;
	while(n--){
		d=in();
		if(f[d])t--;
		else f[d]++;
	}
	print(t);
	return 0;
}

Measured memory_bytes: 128
def gcd(a,b):
    if a < b:
        a,b = b,a
    if b != 0:
        return gcd(b,a%b)
    return a

def solve(n,ts):
    a = ts[0]
    for i in range(n):
        b = ts[i]
        c = gcd(a,b)
        a = a*b//c
    return a

if __name__ == '__main__':
    n = int(input())
    ts = [int(input()) for i in range(n)]
    print(solve(n,ts))

Measured memory_bytes: 62560
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int h, w;
    cin >> h >> w;
    vector<vector<int>> c(10, vector<int>(10));
    for(int i = 0; i < 10; ++i){
        for(int j = 0; j < 10; ++j){
            cin >> c[i][j];
        }
    }
    vector<int> C(10, 0);
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            int a;
            cin >> a;
            if(a != -1) ++C[a];
        }
    }
    for(int k = 0; k < 10; ++k){
        for(int i = 0; i < 10; ++i){
            for(int j = 0; j < 10; ++j){
                chmin(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < 10; ++i) ans += C[i] * c[i][1];
    cout << ans << endl;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
ll f(ll b,ll n){
    if(n<b)return n;
    else return f(b,n/b)+n%b;
}
int main(){
    ll n,s;cin>>n>>s;
    ll ma=-1;
    REP(i,2,sqrt(n)+1){
        if(s==f(i,n)){
            if(ma==-1){
                ma=i;
                break;
            }
        }
    }
    ll mi=-1;
    REP(i,1,sqrt(n)){
        if((s-n%i)%i==0&&(s-n%i)/i<=n/i-n/(i+1)&&(s-n%i)/i>=1){
            mi=n/i+1-(s-n%i)/i;
        }
    }
    if(ma!=-1)cout<<ma<<endl;
    else if(mi!=-1)cout<<mi;
    else if(s==n)cout<<n+1<<endl;
    else cout<<-1<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>
#include<sstream>
#include<math.h>
  
using namespace std;
  
void Solution()
{
    char n;
    int count[26]={0};
     
    while (cin>>n) 
    {
        if(isalpha(n)) //if n is alphabet, then change all to the lowercase
        {
            n = tolower(n);
        }
        
        count[n -'a']++; //change to integer
    }
    
    for(int i=0; i<26; i++) 
    {
       cout<<(char)(i + 'a')<<" : "<<count[i]<<endl; // (char)(i + 'a') can change to char
    }     
}
  
int main()
{
    Solution();
    return 0;
}

Measured memory_bytes: 1140
#include <stdio.h>

int main(void){
    int K, X;
    scanf("%d %d", &K,&X);
    int a = X-K;
    for(int i=0; i < 2*K-1; i++){
        a++;
        printf("%d ", a);
    }
    putchar('\n');
    return 0;
}


Measured memory_bytes: 128