akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

class Main
{
    static  int[]F = new int[45];

    public static void makeFibona()
    {
	F[0] = 1;
	F[1] = 1;

	for(int i = 2; i < F.length; i++)
	    F[i] = F[i - 2] + F[i - 1];
    }

    public static int Fibona(int n)
    {
	if(n == 0 || n == 1)
	    return F[n];

	return F[n];

    }
 
    public static void main(String[] args)
    {
	Scanner In = new Scanner(System.in);
 
	int N = In.nextInt();

	makeFibona();

	System.out.println(Fibona(N));
    }
}

Measured memory_bytes: 26380
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
//#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int T = 81*81 ;
int dp[82][82][2*T+10];
int a[82][82];
int b[82][82];
int n,m;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout)
  
  cin >> n >> m;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      cin >> a[i][j];
    }
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      cin >> b[i][j];
    }
  }
  dp[1][1][ abs(a[1][1]-b[1][1]) ]=1;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      for(int k=0;k<=T;k++){
        if(!dp[i][j][k])continue;
        int x1 = abs(k+a[i+1][j]-b[i+1][j]);
        int x2 = abs(k-a[i+1][j]+b[i+1][j]);
        dp[i+1][j][x1]=1;
        dp[i+1][j][x2]=1;
        x1 = abs(k+a[i][j+1]-b[i][j+1]);
        x2 = abs(k-a[i][j+1]+b[i][j+1]);
        dp[i][j+1][x1]=1;
        dp[i][j+1][x2]=1;
      }
    }
  }
  int ans = T;
  for(int i=0;i<=2*T;i++){
    if(dp[n][m][i]){
      ans = i;
      break;
    }
  }
  cout << ans << endl;

      

return 0;
}
///....


Measured memory_bytes: 340736
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {
	char s[100010];
	scanf("%s",s);
	long long int i=0;
	while(s[i]!='\0'){
		if(i%2==0){
			printf("%c",s[i]);
		}
		i++;
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;

int cmp(const void*a,const void*b)
{

    return *(long long *)a > *(long long *)b ? -1 : 1; 
}

long long A[1000];
long long B[1000];
long long C[1000];

long long AB[1000000];

long long ABC[3000000];

int x,y,z;
int k;

int main()
{
    cin>>x>>y>>z>>k;

    for(int i = 0;i<x;i++)
        cin>>A[i];
    for(int i = 0;i<y;i++)
        cin>>B[i];
    for(int i = 0;i<z;i++)
        cin>>C[i];
    int idx = 0;
    for(int i = 0;i<x;i++)
        for(int j = 0;j<y;j++)
            AB[idx++]=A[i]+B[j];
    qsort(AB,x*y,sizeof(AB[0]),cmp);
    idx = 0;
    for(int i = 0;i<k;i++)
        for(int j = 0;j<z;j++)
            ABC[idx++]=AB[i]+C[j];
    qsort(ABC,idx,sizeof(ABC[0]),cmp);
    for(int i = 0;i<k;i++)
        cout<<ABC[i]<<endl;
    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

ll a, b, c, d;
map<ll, ll> dp;

ll dfs(ll n){
    // cout << now << " " << cost << " " << ans << endl;
    if(n == 0) return 0 ;
    if(dp.find(n) != dp.end()) return dp[n];
    ll ans = LLONG_MAX;
    if(n <= LLONG_MAX/d) ans = n * d;
    
    for(int dx = -4; dx < 5; dx++){
        ll x = n + dx;
        if(abs(dx)<2 && x%2 == 0 && x >= 0 && x/2 < n) ans = min(ans, dfs(x/2) + a + d*abs(dx));
        if(abs(dx)<3 && x%3 == 0 && x >= 0 && x/3 < n) ans = min(ans, dfs(x/3) + b + d*abs(dx));
        if(abs(dx)<5 && x%5 == 0 && x >= 0 && x/5 < n) ans = min(ans, dfs(x/5) + c + d*abs(dx));
    }
    return dp[n] = ans;
}

void Main() {
    int t;
	cin >> t;
    while(t--){
        ll n; 
        cin >> n >> a >> b >> c >> d;
        dp.clear();
        cout << dfs(n) << endl;
    }
    
    return;
}

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


Measured memory_bytes: 4428
N, K = map(int,input().split())
hs = [int(i) for i in input().split()]

dp = [1000000]*N
dp[0] = 0
for i in range(1,N):
    # for k in range(K+1):
    x = max(0, i-K)
    # dp[i] = min(dp[i], dp[min_ind]+abs(hs[min_ind]-hs[i]))
    dp[i] = min([dpj + abs(hs[i] - hj) for hj, dpj in zip(hs[x:i], dp[x:i])])
# print(dp)
print(dp[-1])

Measured memory_bytes: 13976
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,k,l,r,nxt[20][200005],pre[20][200005],q,x[200005],gl,gr;
ll sump[20][200005],sumn[20][200005],ans0,ans1;
int main()
{
	scanf("%d%d",&n,&k);
	nxt[0][n+1]=n+1;
	pre[0][n+1]=n;
	pre[0][0]=0;
	nxt[0][0]=1;
	for(int i=1;i<=n;i++)scanf("%d",&x[i]);
	x[0]=-1e9;x[n+1]=2e9;
	for(int i=1;i<=n;i++)
	{
		pre[0][i]=upper_bound(x+1,x+n+1,x[i]-k)-x-1;
		nxt[0][i]=lower_bound(x+1,x+n+1,x[i]+k)-x;
		sump[0][i]=pre[0][i];
		sumn[0][i]=nxt[0][i];
	}
	for(int i=1;i<20;i++)
	{
		for(int j=0;j<=n+1;j++)
		{
			pre[i][j]=pre[i-1][pre[i-1][j]];
			sump[i][j]=sump[i-1][j]+sump[i-1][pre[i-1][j]];
			nxt[i][j]=nxt[i-1][nxt[i-1][j]];
			sumn[i][j]=sumn[i-1][j]+sumn[i-1][nxt[i-1][j]];
			//printf("%d %d %d\n",i,j,nxt[i][j]);
		}
	}
	scanf("%d",&q);
	for(int i=1;i<=q;i++)
	{
		scanf("%d%d",&l,&r);
		gl=l;gr=r;
		ans0=0;ans1=r-l;
		for(int i=19;i>=0;i--)
		{
			//printf("%d %d %d\n",i,nxt[i][gl],r);
			if(nxt[i][gl]<=r)
			{
				ans0+=(1<<i);
				ans1-=sumn[i][gl];
				ans1+=sump[i][gr];
				//printf("%d %d %d %d %d\n",i,gl,gr,sumn[i][gl],sumn[i][gr]);
				gl=nxt[i][gl];
				gr=pre[i][gr];
			}
		}
		ans1+=ans0+1;
		printf("%lld\n",ans1);
	}
	return 0;
}

Measured memory_bytes: 96264
s = list(input())
n = len(s)

if "".join(s) == "keyence":
	print("YES")
	exit()

for i in range(n):
	ss = s[::]
	for j in range(i, n):
		ss.pop(i)
		if "".join(ss) == "keyence":
			print("YES")
			break
	else:
		continue
	break
else:
	print("NO")

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <ctype.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;

using namespace std;
int main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	int X = c - a;
	int Y = d - b;

	cout << c - Y << ' ' << d + X << ' ' << a - Y << ' ' << b + X << endl;

}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      ps: [usize; n],
    }

    let mut table = vec![0; n+1];
    for p in ps {
        table[p] = table[p-1] + 1;
    }
    let mut ans = *table.iter().max().unwrap();
    ans = n - ans;
    puts!("{}\n", ans);
}


Measured memory_bytes: 8444
def main():
    f = input().split()
    stack = list()
    for i in f:
        if i.isdigit():
            stack.append(i)
        else:
            se = stack.pop()
            fi = stack.pop()
            tmp = eval(fi+i+se)
            stack.append(str(tmp))
    print(stack.pop())
    
if __name__ == '__main__':
    main()


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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; exit(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ull ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ull calc(vl c, vvl a, vector<bool> pos) {
    ll tmp_sum = 0;
    vl as(m + 10, 0);
    NREP() {
        if (pos[i]) {
            tmp_sum += c[i];
            MREP() {
                as[j] += a[i][j];
            }
        }
    }

    MREP() {
        if (as[j] < x) {
            return INF;
        }
    }
    return tmp_sum;
}

void search(vl c, vvl a, ll idx, vector<bool> pos) {
    if (idx >= n) {
        ull ret = calc(c, a, pos);
        if (ret != INF) {
            ans = min(ans, ret);
        }
        return;
    }
    pos[idx] = false;
    search(c, a, idx + 1, pos);
    pos[idx] = true;
    search(c, a, idx + 1, pos);
}

int main() {
    cin >> n >> m >> x;
    vl c(n + 10);
    vvl a(n + 10, vector<ll>(n + 10, 0));

    ans = ULLONG_MAX;
    NREP() {
        cin >> c[i];
        MREP() {
            cin >> a[i][j];
        }
    }

    vl as(m, 0);
    REP(i, 0, n) {
        MREP() {
            as[j] += a[i][j];
        }
    }
    MREP() {
        if (as[j] < x) {
            END(-1)
        }
    }

    vector<bool> pos(n + 10, false);
    search(c, a, 0, pos);
    MSG(ans)
}


Measured memory_bytes: 3708
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
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;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int64_t a,b,n;
    cin>>a>>b>>n;
    if(b-1<=n){
    int64_t ans=a*(b-1)/b;
    cout<<ans<<endl;
    }
    else{
        int64_t ansb=a*n/b;
        cout<<ansb<<endl;
    }
}

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

int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<int> a(m);
  vector<int> b(m);
  vector<int> count(n);
  
  for (int i = 0; i < m; i = i + 1) {
    cin >> a.at(i);
    cin >> b.at(i);
  }
  
  for (int i = 0; i < m; i = i + 1) {
    for (int j = 0; j < n; j = j + 1) {
      if (a.at(i) == j + 1) {
        count.at(j) = count.at(j) + 1;
      }
      
      if (b.at(i) == j + 1) {
        count.at(j) = count.at(j) + 1;
      }
    }
  }
  
  for (int i = 0; i < n; i = i + 1) {
    cout << count.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e18
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;


struct edge { int to, cost;};

class Dijkstra{
private:
    vector< vector<edge> > g;
    
public:
    Dijkstra(){};
    Dijkstra(int size){
        g.resize(size);
    }
    
    vi dist;
    
    void add(int a, int b, int c){//無向辺
        edge e1 = {b, c}, e2 = {a, c};
        g[a].push_back(e1);
        g[b].push_back(e2);//有向辺の場合はここをコメントアウトする
    }
    
    void calc(int s){
        priority_queue< pii, vector<pii>, greater<pii> > q;
        int n = g.size();
        dist = vi (n, INF);
        dist[s] = 0;
        q.push(pii(0, s));
        
        while(!q.empty()){
            pii p = q.top();
            q.pop();
            int v = p.second;
            if(dist[v] < p.first)continue; //更新されていたら何もしない
            for(int i = 0; i < g[v].size(); i++){
                edge e = g[v][i];
                if(dist[e.to] > dist[v] + e.cost){
                    dist[e.to] = dist[v] + e.cost;
                    q.push(pii(dist[e.to], e.to));
                }
            }
        }
    }
    
};



signed main(void) {
    int i,j;
    int n,m,s,t;
    cin>>n>>m>>s>>t;
    s--,t--;
    Dijkstra g1 = Dijkstra(n);
    Dijkstra g2 = Dijkstra(n);
    rep(i,m){
        int u,v,a,b;
        cin>>u>>v>>a>>b;
        u--,v--;
        g1.add(u,v,a);
        g2.add(u,v,b);
    }
    
    g1.calc(s);
    g2.calc(t);
    vi ans(n+1);
    ans[n]=(ll)100000000000000000;
    
    for(int i = n-1; i >= 0; i--){
        ans[i]=min(ans[i+1], g1.dist[i]+g2.dist[i]);
    }
    rep(i,n)
    cout << (ll)1000000000000000-ans[i] << endl;
    
    
}



Measured memory_bytes: 20860
N = int(input())
A = list(map(int, input().split()))
B=[]
C=[]
for i in range(N):
    B.append(A[i]-1)
for i in range(N):
    C.append(A[i]+1)
D=[]
D=A+B+C
mx=0
E=[0]*10**6
for i in D:
    E[i]+=1
    
print(max(E))

Measured memory_bytes: 110104
#include<bits/stdc++.h>
using namespace std;
#define min(a,b) ((a>b)?b:a)
int main()
{
  vector<int> vec;
  int i=1;
  while(pow(6,i)<100000){
    vec.push_back(pow(6,i));
    vec.push_back(pow(9,i));
    i++;
  }
  
  int n;
  cin>>n;
  vector<int> dp;
  dp.push_back(0);
  for(int i=1;i<=n;i++){
    int a=dp[i-1]+1;
    for(int x:vec){
      if(i>=x){
        int b=dp[i-x]+1;
        a=min(a,b);
      }
    }
    dp.push_back(a);
  }
  
  cout<<dp[n];
}

Measured memory_bytes: 896
s = str(input())
N = len(s)
array = [0]*2019
array[0] += 1
count = 0
d = 1
r = 0
for i in reversed(range(0, N)):
    #x = s[i:N]
    #y = int(x)
    r = ( r + int( s[i] ) * d ) % 2019
    d = d * 10 % 2019
    array[r] += 1
for i in array:
    count += i*(i-1)/2
print(int(count))

Measured memory_bytes: 9240
#include <stdio.h>
#include <string.h>

char s[5001], t[6], c[5];
int k, n, l[6], i, j;
inline void findstr(const int x) {
  for (i = l[x]; i < n - x;) {
    for (j = 0; j <= x; ++j) {
      if (s[i + j] != t[j]) goto cont;
    }
    l[x + 1] = i;
    return;
  cont:
    ++i;
  }
  l[x + 1] = -1;
}
int main() {
  scanf("%s", s);
  scanf("%d", &k);
  n = strlen(s);
  for (c[0] = 'a'; c[0] <= 'z'; ++c[0]) {
    t[0] = c[0];
    findstr(0);
    if (l[1] < 0) continue;
    if (k == 1) {
      printf("%s\n", t);
      return 0;
    }
    --k;
    for (c[1] = 'a'; c[1] <= 'z'; ++c[1]) {
      t[1] = c[1];
      findstr(1);
      if (l[2] < 0) continue;
      if (k == 1) {
        printf("%s\n", t);
        return 0;
      }
      --k;
      for (c[2] = 'a'; c[2] <= 'z'; ++c[2]) {
        t[2] = c[2];
        findstr(2);
        if (l[3] < 0) continue;
        if (k == 1) {
          printf("%s\n", t);
          return 0;
        }
        --k;
        for (c[3] = 'a'; c[3] <= 'z'; ++c[3]) {
          t[3] = c[3];
          findstr(3);
          if (l[4] < 0) continue;
          if (k == 1) {
            printf("%s\n", t);
            return 0;
          }
          --k;
          for (c[4] = 'a'; c[4] <= 'z'; ++c[4]) {
            t[4] = c[4];
            findstr(4);
            if (l[5] < 0) continue;
            if (k == 1) {
              printf("%s\n", t);
              return 0;
            }
            --k;
          }
          t[4] = 0;
        }
        t[3] = 0;
      }
      t[2] = 0;
    }
    t[1] = 0;
  }
}


Measured memory_bytes: 1668
#include <bits/stdc++.h>
#define ll  long long
#define ull unsigned long long  
using namespace std;
#define  inf 1e15+18
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mod 1000000007
#define  f1(i,n) for(i=1;i<=n;i++)
#define f0(i,n)  for(i=0;i<n;i++)
#define w(x)   while(x--)
const int maxn=100002;
#define  pq priority_queue
#define  ff first
#define  ss second 
#define pb  push_back
#define lb lower_bound
int  dp[maxn][3];
vector<int>v[maxn];
int solve(int id,int par,int col)
{

	ll int ans=0,j=0;
	if(dp[id][col]!=-1)
		return dp[id][col];
	ll ans1=1;
	ll ans2=0;
	if(col==1)
	 ans2=1;
	for(int child:v[id])
	{

		if(child!=par)
		{
			j=1;
			//if(col==1)
			ans1=(ans1*solve(child,id,1))%mod;
			if(col==1)
				ans2=(ans2*solve(child,id,2))%mod;
		}
	}
	
	dp[id][col]=(ans1+ans2)%mod;
return dp[id][col];
}

int main()
{
	memset(dp,-1,sizeof(dp));
	ll i,j,n;
	cin>>n;
	for(i=0;i<n-1;i++){
		int k,l;
		cin>>k>>l;
		v[k].pb(l);
		v[l].pb(k);
	}

	j=solve(1,-1,1);
	j=j%mod;
	cout<<j;
	//cout<<l;
}

Measured memory_bytes: 17040
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
  int i,j;
  int a,b;
  scanf("%d %d",&a,&b);
  if(a>b)
    printf("%d\n",a-1);
  else
    printf("%d\n",a);
  return 0;
}


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

int main(){
  string S;
  int K;
  cin >> S;
  cin >> K;
  map<string, int> m;
  for(int i = 0; i < S.size(); i++){
    string s = "";
    for(int j = 0; j < K && i + j < S.size(); j++){
      s += S[i+j];
      m[s]++;
    }
  }
  int c = 1;
  for(auto x: m){
    if(c == K){
      cout << x.first << endl;
      break;
    }
    c++;
  }
  return 0;
}


Measured memory_bytes: 1920
o = input()
e = input()
l = []
if len(o)-len(e) == 1:
  for i in range(len(e)):
    l.append(o[i])
    l.append(e[i])
  l.append(o[-1])
else:
  for i in range(len(o)):
    l.append(o[i])
    l.append(e[i])
print("".join(l))

Measured memory_bytes: 9100
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

H, W, K = map(int, input().split())
c = []
for i in range(H):
    c.append(list(input()))

def bit(S, j):
    # Sの右からj bit目(0-indexed)
    return (S>>j)&1

ans = 0
for i in range(1<<H):
    for j in range(1<<W):
        cc = copy.deepcopy(c)
        black = 0
        for ki in range(H):
            for kj in range(W):
                if bit(i,ki) == 1:
                    cc[ki] = ["r" for _ in range(W)]
                if bit(j,kj) == 1:
                    for ii in range(H):
                        cc[ii][kj] = "r"

        for ii in range(H):
            for jj in range(W):
                if cc[ii][jj] == "#":
                    black += 1

        if black == K:
            ans += 1

print(ans)














Measured memory_bytes: 82348
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

int main(){
  int n,k;cin>>n>>k;
  int b = 0;
  repd(i,1,n+1){
    if(i%k == 0)b++;
  }
  ll ans = pow(b,3);
  if(!(k%2)){
    int a = 0;
    repd(i,1,n+1){
      if(i%k == k/2){
        a++;
      }
    }
    ans += pow(a,3);
  }
  cout << ans << endl;
}



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

int N, K;
vector<int> A;

bool solve(int n) {
    vector<int> B;
    rep(i, 0, N) {
        int a = A[i] % n;
        if(a) B.push_back(a);
    }
    sort(B.begin(), B.end());
    int M = B.size();
    ll sumB = 0, sumC = 0;
    rep(i, 0, M) sumC += n - B[i];
    if(max(sumB, sumC) <= K && (sumB - sumC) % n == 0) return true;
    rep(i, 0, M) {
        sumB += B[i];
        sumC -= n - B[i];
        if(max(sumB, sumC) <= K && (sumB - sumC) % n == 0) return true;
    }
    return false;
}

int main() {
    cin >> N >> K;
    A.resize(N);
    rep(i, 0, N) cin >> A[i];
    int sum = accumulate(A.begin(), A.end(), 0);
    int ans = 1;
    for(int i = 1; i * i < sum + 2; ++i) {
        if(sum % i == 0) {
            if(solve(i)) ans = max(ans, i);
            if(solve(sum / i)) ans = max(ans, sum / i);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  string str{}; cin >> str;
  vector<int> A(4);
  for (int i = 0; i < 4; ++i) {
    A[i] = str[i] - '0';
  }
  int it = 1 << 3;
  while (it) {
    vector<int> B = A;
    for (int i = 0; i < 3; ++i) {
      B[i+1] *= (it & (1 << i)) ? -1 : 1;
    }
    auto sum = std::accumulate(B.begin(), B.end(), 0LL);
    if (sum == 7) {
      for (const auto& b : B) { cout << b << std::showpos; }
      cout << "=7" << CRLF;
      return;
    }
    --it;
  }

  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

int main(){
  int n,l;
  cin >> n >> l;
  int eat=1000, pie=0;
  
  rep(i,n){
    int flavor = l+i;
    pie += flavor;
    if(abs(l+i) < abs(eat)) eat = flavor;
  }
  
  pie -= eat;
  
  cout << pie << endl;

  return 0;
}

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

int main(){
	int w,h,n,ans=0;
	cin>>w>>h>>n;
	for(int i=0,x,y,z,w; i<n; i++){
		if(i) cin>>x>>y;
		else{
			cin>>z>>w;
			continue;
		}
		z-=x;
		w-=y;
		ans+=z*w>0?max(abs(z),abs(w)):abs(z)+abs(w);
		z=x;
		w=y;
	}
	cout<<ans<<endl;
}

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

int main() {
  int N,M,X;
  cin >> N >> M >> X;
  vector<int> vec(M);
  for(int i = 0;i < M;i++) {
    cin >> vec.at(i);
  }
  int a = 0;
  int b = 0;
  for(int j = 0;j < M;j++) {
    if(vec.at(j) > X) {
      a++;
    }
    else {
      b++;
    }
  }
  cout << min(a,b) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <ostream>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstring>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;

template <typename T, typename U>
std::ostream& operator << (std::ostream& out, std::pair<T, U> p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}

template <typename T>
std::ostream& operator << (std::ostream& out, std::vector<T> v) {
  out << "[";
  for (int i = 0; i < v.size(); ++i) {
    out << v[i] << (i == (v.size() - 1) ? "" : ", ");
  }
  out << "]";
  return out;
}



int main() {
  int path[4][4];
  std::memset(path, 0, sizeof path);

  for (int i = 0; i < 3; ++i) {
    int a, b;
    cin >> a >> b, a--, b--;
    path[a][b] = path[b][a] = 1;
  }

  int city[] = { 0, 1, 2, 3 };

  bool flag = false;

  do {
    if (path[city[0]][city[1]] == 1 && path[city[1]][city[2]] == 1 && path[city[2]][city[3]] == 1) {
      flag = true;
      break;
    }
  } while (std::next_permutation(city, city + 4));

  if (flag) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

const int MaxN = 2000;
int n, m;
int a[MaxN + 5][MaxN + 5];
int b[MaxN + 5][MaxN + 5];
int l[MaxN + 5], r[MaxN + 5], h[MaxN + 5];
char s[MaxN + 5];

bool Check(int x, int y)
{
	int cnt = 0;
	cnt += b[x][y];
	cnt += b[x + 1][y];
	cnt += b[x][y + 1];
	cnt += b[x + 1][y + 1];
	return (!(cnt & 1));
}

void Init()
{
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));
	for (int i = 1; i <= n; i++) {
		scanf("%s", s);
		for (int j = 0; j < m; j++)
			b[i][j + 1] = (int)(s[j] == '#');
	}
	for (int i = 1; i <= n - 1; i++)
		for (int j = 1; j <= m - 1; j++)
			if (Check(i, j)) a[i][j] = 1;
				else a[i][j] = 0;
}

void Solve()
{
	int i = 0, j = 0, lmax = 0, rmax = 0, ans = max(n, m);
	n--; m--;
	memset(l, 0, sizeof(l));
	memset(r, 0, sizeof(r));
	memset(h, 0, sizeof(h));
	for (i = 1; i <= m; i++) l[i] = 1, r[i] = m;
	for (i = 1; i <= n; i++) {
		for (lmax = j = 1; j <= m; j++) if (a[i][j]) {
			h[j]++;
			if (lmax > l[j]) l[j] = lmax;
		}else h[j] = 0, l[j] = 1, r[j] = m, lmax = j + 1;
		for (rmax = j = m; j; j--) if (a[i][j]) {
			if (rmax < r[j]) r[j] = rmax;
			ans = max(ans, (r[j] - l[j] + 2) * (h[j] + 1));
		}else rmax = j - 1;
	}
	printf("%d\n", ans);
}

int main()
{
	while (~scanf("%d%d", &n, &m)) {
		Init();
		Solve();
	}
	return 0;
}

Measured memory_bytes: 31616
function prime(max){
   var arr=[];
   for(var i=0;i<=max;i++)arr[i]=i;
   arr[0]=false;
   arr[1]=false;
   var sqrt=Math.floor(Math.sqrt(max));
   for(var i=2;i<=sqrt;i++){
      if(arr[i]==false)continue;
      for(var j=i+i;j<=max;j+=i){
         arr[j]=false;
      }
   }
   var result={};
   for(var i=0;i<=max;i++){
      if(arr[i]!==false)result[arr[i]]=true;
   }
   return result;
}
var p=prime(10000);
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n").map(Number);
for(var i=0;i<Arr.length;i++){
   var a=Arr[i];
   var A=[];
   var B=[];
   for(var j=1;j<=a;j++)A.push(j);
   for(var j=a;j>=1;j--)B.push(j);
   var pair=0;
   for(var j=0;j<a;j++){
      if(p.hasOwnProperty(A[j]) && p.hasOwnProperty(B[j]))pair++;
   }
   console.log(pair);
}

Measured memory_bytes: 17428
#include <bits/stdc++.h>
#include<iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,r;
    cin >> n >> r;
    if(n>=10) cout << r;
    else cout << r+100*(10-n);
    cout << "\n";
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Solve{
    public int n;
    public long x;
    public long[] a;
    public Solve(){}
    public static int Main(){
        new Solve().Calc();
        return 0;
    }
    void Calc(){
        getinput();
        long[] bonus = new long[n-1];
        long ans = 0;
        long temp;
        for(int i = 0;i < n-1;i++){
            bonus[i] = 0;
        }
        for(int i = 0;i < n;i++){
            long min;
            min = a[i];
            for(int j = 1;j < i+1;j++){
                if(min > a[i-j]){
                    bonus[j-1] += min - a[i-j];
                    min = a[i-j];
                }
            }
            for(int j = i+1;j < n;j++){
                if(min > a[i-j+n]){
                    bonus[j-1] += min - a[i-j+n];
                    min = a[i-j+n];
                }
            }
        }
        for(int i = 0;i < n;i++){
            ans += a[i];
        }
        temp = ans;
        for(int i = 0;i < n-1;i++){
            temp += x;
            temp -= bonus[i];
            if(ans > temp){
                ans = temp;
            }
        }
        Console.WriteLine(ans);
    }
    void getinput(){
        string[] str = Console.ReadLine().Split(' ');
        n = int.Parse(str[0]);
        x = int.Parse(str[1]);
        str = Console.ReadLine().Split(' ');
        a = new long[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = int.Parse(str[i]);
        }
    }    
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &x : a) {
		cin >> x;
	}
	map<int, int> mp;
	for(auto &x: a) {
		mp[x]++;
		mp[x - 1]++;
		mp[x + 1]++;
	}
	int res{};
	for(auto x : mp) {
		chmax(res, x.second);
	}
	out(res);

	return 0;
}

Measured memory_bytes: 5120
#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>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  bool ans = true;
  for (int i = 0; i < s.length(); i++) {
    if (i % 2 == 0) {
      if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') {
        ans = false;
        break;
      }
    } else {
      if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
        ans = false;
        break;
      }
    }
  }
  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

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

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

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

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

ll MOD = 1e9+7;
const ll MAXN = 2 * 1e5 + 10;
vll fact (MAXN);
vll invfact (MAXN);
vll pow2(MAXN);
vll inv (MAXN);

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        res %= MOD;
        a = a * a;
        a %= MOD;
        b >>= 1;
    }
    return res;
}

ll inverse(ll n) {
    return binpow(n, MOD-2);
}

ll choose(ll n, ll k) {
    return fact[n] * invfact[k] % MOD * invfact[n-k] % MOD;
}



int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll N, K; cin >> N >> K;

	fact[0] = 1;
    FOR(i, 1, MAXN) fact[i] = fact[i-1] * i % MOD;

    inv[1] = 1;
    FOR(i, 2, MAXN) inv[i] = (MOD - (MOD/i) * inv[MOD%i] % MOD) % MOD;

    invfact[0] = 1;
    FOR(i, 1, MAXN) invfact[i] = invfact[i-1] * inv[i] % MOD;

    pow2[0] = 1;
    FOR(i, 1, MAXN) pow2[i] = 2 * pow2[i-1] % MOD;

	vll ans (K+1);
	ll res = 0;
	ROF(k, 1, K + 1) {
		ll options = K/k;
		ll cur = binpow(options, N);
		for (int x = k * 2; x <= K; x += k) {
			cur -= ans[x] - MOD; cur %= MOD;
		}
		ans[k] = cur;
		res += k * ans[k]; res %= MOD;
	}
	print(res);
}

Measured memory_bytes: 10296
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var KX = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (K, X) = (KX[0], KX[1]);

        if (K * 500 >= X)
            WriteLine("Yes");
        else
            WriteLine("No");
    }
}


Measured memory_bytes: 28196
#include<stdio.h>
int main(void){
    int a;
    scanf("%d",&a);
    int b[3];
    for(int i = 0; i < 3; i++){
        b[i] = a%10; a /= 10;
        if(b[i] == 1) b[i] = 9;
        else if(b[i] == 9) b[i] = 1;
    }
    for(int i = 2; i >= 0; i--){
        printf("%d",b[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int ans=0,num=0,n=sc.nextInt();
		String s=sc.next();
		for(int i=0;i<n;i++) {
			if(s.charAt(i)=='I')num++;
			else if(s.charAt(i)=='D')num--;
			ans=Math.max(ans, num);
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 23636
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
void solve(); int main() { solve(); return 0; }

void solve() {
  int n,m;cin >> n>>m;
  vector<pair<int,int>> K;
  loop(i,0,m) {
    int a, b, c;
    cin >> a >> b;
    int S = 0;
    loop(j,0,b) {
      cin >> c; c--;
      S |= 1<<c;
    }
    K.emplace_back(S, a);
  }
  
  const int INF = 1001001001;
  vector<int> dp(1<<n, INF);
  dp[0] = 0;
  for (int S=0; S<1<<n; S++) {
    for (auto&&k: K) {
      int T = S|k.first;
      dp[T] = min(dp[T], dp[S] + k.second);
    }
  }
  
  int ans = dp.back();
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 3632
// failed to generate code

#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pii; // p.first p.second

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

ll N;
ll o[301][301];
ll d[301][301];

void think() {
  ll ans = 0;
  bool f[301][301]{};
  REP(k, N) {
    REP(i, N) {
      REP(j, N) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

        if (k == i || k == j)
          continue;
        if (d[i][j] == d[i][k] + d[k][j]) {
          f[i][j] = f[j][i] = true;
        }
      }
    }
  }

  // check
  REP(y, N) REP(x, N) {
    if (o[y][x] > d[y][x]) {
      cout << "-1" << endl;
      return;
    }
  }

  REP(i, N - 1) {
    for (int j = i + 1; j < N; ++j) {
      if (f[i][j])
        continue;
      ans += d[i][j];
    }
  }

  cout << (ans) << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin >> N;
  REP(y, N) REP(x, N) {
    cin >> d[y][x];
    o[y][x] = d[y][x];
  }

  think();
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() 
{
 
	int n,ir;
	cin>>n;
	cin>>ir;
	if(n<10)
	   {
	ir=(ir+100*(10-n));   
	   cout<<ir;
	   }
	   else{
	   cout<<ir;
	   }
	   

}


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

#define ll          long long
#define endl        "\n"
#define inf         10000000002
#define pb          push_back
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define MAX         100
#define yes         cout<<"YES"<<endl
#define no          cout<<"NO"<<endl
#define bye         return 0

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      //freopen("inputNew.txt", "r", stdin);

      ll n;
      cin>>n;

      ll limit=sqrt(n);
      if((limit*limit)==n) limit--;

      ll cnt=0;
      for(ll i=1; i<=limit; i++){
            ll temp=0;
            for(ll j=i; j<n; j++){
                  if(i*j <n) temp++;
                  else break;
            }
            cnt+=(temp)+temp-1;
      }
      cout<<cnt<<endl;


      bye;
}


Measured memory_bytes: 3692
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#define ll long long
using namespace std;
#define N 100009

int main(){
    int h,w;
    cin>>h>>w;
    char data[h+1][w+1];
    for (int i=1; i<=h; i++){
        for (int j=1; j<=w; j++){
            cin>>data[i][j];
        }
    }
    
    int right[h+1][w+1], left[h+1][w+1], up[h+1][w+1], down[h+1][w+1];
    for (int i=1; i<=h; i++){
        right[i][w]=1;
        left[i][1]=1;
    }
    for (int i=1; i<=w; i++){
        up[1][i]=1;
        down[h][i]=1;
    }
    for (int i=1; i<=h; i++){
        for (int j=1; j<=w; j++){
            if (data[i][j]=='#'){
                right[i][j]=0;
                left[i][j]=0;
                up[i][j]=0;
                down[i][j]=0;
            }
        }
    }
    
    for (int i=1; i<=h; i++){
        for (int j=w-1; j>=1; j--){
            if (data[i][j]=='#') right[i][j]=0;
            else right[i][j]=right[i][j+1]+1;
        }
        for (int j=2; j<=w; j++){
            if (data[i][j]=='#') left[i][j]=0;
            else left[i][j]=left[i][j-1]+1;
        }
    }
    for (int j=1; j<=w; j++){
        for (int i=2; i<=h; i++){
            if (data[i][j]=='#') up[i][j]=0;
            else up[i][j]=up[i-1][j]+1;
        }
        for (int i=h-1; i>=1; i--){
            if (data[i][j]=='#') down[i][j]=0;
            else down[i][j]=down[i+1][j]+1;
        }
    }
    
    vector<ll> amount;
    
    for (int i=1; i<=h; i++){
        for (int j=1; j<=w; j++){
            ll p=right[i][j]+left[i][j]+up[i][j]+down[i][j]-3;
            amount.push_back(p);
        }
    }
    
    sort(amount.begin(),amount.end());
    cout<<amount.back()<<endl;
}

Measured memory_bytes: 101476
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define BUFSIZE 100000	


int n;
int h[BUFSIZE] = {0};
int dp[BUFSIZE] = {0}; 

int min(int a,int b){
  if(a > b) return b;
  else return a;
}

int k;

int main(void){
   scanf("%d %d",&n,&k);
   for(int i = 0;i < n;i++) scanf("%d",&h[i]);
  
   dp[0] = 0;   

  for(int i = 1;i < n;i++){
     dp[i] = dp[i-1] + abs(h[i-1] - h[i]);
  }

 
  for(int i = 0;i < n;i++){
     for(int j = i;j <=  i + k;j++){
	if(j >  n) break;       
         dp[j] = min(dp[j] , dp[i] + abs(h[i] - h[j]));
     }
  }

  
   printf("%d\n",dp[n-1]);

}


Measured memory_bytes: 2516
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100010
int dp[MAXN];
bool been[MAXN];
int n,v[110];
//taro = false
bool f(int s){
    if(s == 0) return false;
    if(been[s]) return dp[s];
    been[s] = true;
    for(int i = 0;i<n;i++){
        if(s-v[i] < 0) break;
        if(!f(s-v[i])) return dp[s] = true;
    }   
    return dp[s] = false;
}

int main(){
    cin >> n;
    int k;cin >> k;
    for(int i = 0;i<n;i++) cin >> v[i];
    sort(v,v+n);
    cout << (f(k) ? "First\n" : "Second\n");
    return 0;
}

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

#define PI 4*atan(1)
#define INF 1e8

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

int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  for(int i = 0; i < N; i++){
    cin >> S[i];
  }

  int cnt = 0;
  int a = 0, a_cnt = 0, un_cnt = 0;
  bool flag = true;
  for(int i = 0; i < N; i++){
    if(S[i] == "A"){
      a++;
      a_cnt++;
    }
    if(S[i] == "Un"){
      un_cnt++;
      if(a){
        a--;
        cnt++;
      }
      else flag = false;
    }
  }
  if(flag && cnt && a_cnt == un_cnt)cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3152
#include <iostream>
#include <string>
using namespace std;
string s,num = "0123456789";
int solve(string &t){
	int i,n = s.size();
	int cnt = 0;
	for(i=0;i<n;i++){
		if(s[i]==t[cnt]){
			cnt++;
			if(cnt==3){
				return 1;
			}
		}
	}
	return 0;
}

int main(){
	int i,j,k,n,ans = 0;
	cin >> n >> s;
	for(i=0;i<10;i++){
		for(j=0;j<10;j++){
			for(k=0;k<10;k++){
				string t;
				t.push_back(num[i]);
				t.push_back(num[j]);
				t.push_back(num[k]);
				ans += solve(t);
			}
		}
	}
	cout << ans << endl;
}
	

Measured memory_bytes: 256