akhauriyash/Code-Regression huggingface dataset:
import numpy as np

h, w = map(int, input().split())
A = [0]*h
B = [0]*h
for _ in range(h):
  A[_] = list(map(int, input().split()))
  
for _ in range(h):
  B[_] = list(map(int, input().split()))

C = [[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    C[i][j] = abs(A[i][j]-B[i][j])
    
dp = [[0]*w for _ in range(h)]
D = 80 * (h + w)
L = 2*D + 1
dp[0][0] = np.zeros(L, np.bool)
dp[0][0][D+C[0][0]] = 1
for i in range(h):
  for j in range(w):
    if i == 0 and j == 0:
      continue
    x = np.zeros(L, np.bool)
    if i != 0:
      x[C[i][j]:] |= dp[i-1][j][:L-C[i][j]]
      x[:L-C[i][j]] |= dp[i-1][j][C[i][j]:]
    if j != 0:
      x[C[i][j]:] |= dp[i][j-1][:L-C[i][j]]
      x[:L-C[i][j]] |= dp[i][j-1][C[i][j]:]
    dp[i][j] = x
    
temp = np.where(dp[-1][-1]>0)[0]-D
temp = np.abs(temp)
print(np.min(temp))

Measured memory_bytes: 173840
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

//string str[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
    string s;
    cin >> s;
    string t = "";
    
    string str[4] = {"maerd", "remaerd", "esare", "resare"};
    string tmp = "";
    for(int i = s.size()-1; i > -1; i--) {
        tmp += s[i];
        for(int j = 0; j < 4; j++) {
            if(str[j] == tmp) {
                t += tmp;
                tmp = "";
                break;
            }
        }
    }
    reverse(t.begin(), t.end());
    if(t == s) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define f first
#define s second
const int INF = 0x3f3f3f3f, MAXN = 405;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
int N;
ll dp[MAXN][MAXN], ar[MAXN], psa[MAXN];
ll f(int l, int r){
	if (dp[l][r]!=-1) return dp[l][r];
	if (l==r) return dp[l][r]=0;
	dp[l][r]=LINF;
	for (int i = l; i<r; i++){
		dp[l][r] = min(dp[l][r], psa[r]-psa[l-1]+f(l, i)+f(i+1, r));
	}	
	//printf("%d %d %lld %lld\n", l, r, dp[l][r], psa[r]-psa[l-1]);
	return dp[l][r];
}
int main(){
	//ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	scanf("%d", &N);
	for (int i = 1; i<=N; i++) scanf("%lld", &ar[i]);
	for (int i = 1; i<=N; i++) psa[i] = psa[i-1]+ar[i];
	memset(dp, -1, sizeof dp);
	printf("%lld\n", f(1, N));
}	

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

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
#define debug( fmt, ... ) \
        fprintf( stderr, \
                  fmt "\n", \
                  ##__VA_ARGS__ \
        )

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1 << 29;
const double EPS = 1e-10;

double zero(double d) {
    return d < EPS ? 0.0 : d;
}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, a.size()) os << (i ? " " : "") << a[i];
    return os << ']';
}

string toString(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

const int MOD = 1000000007;
// a^k
ll fpow(ll a, ll k, int M) {
    ll res = 1ll;
    ll x = a;
    while (k != 0) {
        if ((k & 1) == 1)
            res = (res * x) % M;
        x = (x * x) % M;
        k >>= 1;
    }
    return res;
}

struct prepare {
	prepare() {
	    cout.setf(ios::fixed, ios::floatfield);
	    cout.precision(8);
	    ios_base::sync_with_stdio(false);
	}
} _prepare;

int main() {
	int N, L;
    cin >> N >> L;

    vi a(N);
    rep(i, N)
        cin >> a[i];

    int ind = -1;
    rep(i, N-1) {
        if(a[i] + a[i+1] >= L) {
            ind = i;
            break;
        }
    }

    if(ind == -1) {
        cout << "Impossible" << endl;
        return 0;
    }

    cout << "Possible" << endl;
    rep(i, ind)
        cout << i+1 << endl;
    for(int i=N-1; i>=ind+1; i--)
        cout << i << endl;

    return 0;
}

Measured memory_bytes: 1280
using System;

    public class Program
    {
        public static bool[] used=new bool[200000];
        public static int[] root=new int [200000];
        public static int[] size=new int [200000];
        public static int FindRoot(int _)
        {
            if (root[_]==_) return _;
            else return FindRoot(root[_]);
        }
        public static void Merge(int _x, int _y)
        {
            int x=FindRoot(_x);
            int y=FindRoot(_y);
            if (x==y) return;
            else
            {
                if (size[x]<size[y])
                {
                    root[x]=y;
                    size[y]=size[y]+size[x];
                }
                else
                {
                    root[y]=x;
                    size[x]=size[y]+size[x];
                }
            }
        }
        public static void Main(string[] args)
        {
            string[] input=Console.ReadLine().Split(' ');
            int n=int.Parse(input[0]);
            int m=int.Parse(input[1]);
            int u=1;
            int v=1;
            bool ans=true;
            for (int i=1;i<=m;i++)
            {
                used[i]=false;
                root[i]=i;
                size[i]=1;
            }
            for (int i=0;i<n;i++)
            {
                string[] ip2=Console.ReadLine().Split(' ');
                u=int.Parse(ip2[1]);
                used[u]=true;
                for (int j=1;j<int.Parse(ip2[0]);j++)
                {
                    v=int.Parse(ip2[j+1]);
                    used[v]=true;
                    Merge(u,v);
                }
            }
            u=FindRoot(u);
            for (int i=1;i<=m;i++)
                if (used[i])
                    if (FindRoot(i)!=u) 
                        ans=false;
            if (ans) Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }
    }

Measured memory_bytes: 12368
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  int s, w;
  cin >> s >> w;
  if (s <= w){
    cout << "unsafe" << endl;
  }else{
    cout << "safe" << endl;
  }
  return 0;
}

Measured memory_bytes: 3640
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
#define double long double
typedef long long ll;
typedef unsigned long long ull;

template<typename T>
void __read(T &a) { cin >> a; }

template<typename T, typename ... Args>
void __read(T &a, Args &... args) {
    cin >> a;
    __read(args...);
}

#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T>
void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
template<class T>
static auto __super_speed__ = (ios_base::sync_with_stdio(0), cin.tie(
        0)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
//endregion


int32_t main() {
    make(int, n, m);
    VVI a(n);
    FOR(m){
        make(int, t);
        make(string, s);
        a[t - 1].push_back(s == "AC");
    }
    int ans1 = 0, ans2 = 0;
    for(int i = 0; i < n; ++i){
        int z = 0;
        while(z < a[i].size() && a[i][z] == 0){
            z++;
        }
        if (z < a[i].size()){
            ans1++;
            ans2 += z;
        }
    }
    cout << ans1 << ' ' << ans2;
    return 0;
}

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

using namespace std;

const int maxn = 1e5 + 9;
long long result[maxn];

class dsu {
public:
	vector<int> parent, size, rank;
	dsu(int n) : parent(n + 1), size(n + 1, 1), rank(n + 1, 0) {
		for (int i = 0; i < n + 1; i++) {
			parent[i] = i;
		}
	}
	int find(int u) {
		if (u == parent[u]) return u;
		return parent[u] = find(parent[u]);
	}
	long long merge(int u, int v) {
		u = find(u); v = find(v);
		if (u == v) return -1LL;
		long long ret = size[u] * (size[u] - 1LL) * 1LL / 2LL + size[v] * (size[v] - 1LL) * 1LL / 2LL;
		if (rank[u] >= rank[v]) swap(u, v);
		parent[u] = v;
		size[v] += size[u];
		size[u] = 0;
		if (rank[u] == rank[v]) rank[u]++;
		return ret;
	}
};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> edges;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		edges.push_back(make_pair(a, b));
	}
	long long inf = n * (n - 1LL) * 1LL / 2LL, tmp = inf;
	dsu uf(n);
	for (int i = 0; i < m; i++) {
		result[m - i - 1] = tmp;
		pair<int, int> edge = edges[m - i - 1];
		long long d = uf.merge(edge.first, edge.second);
		if (d == -1LL) continue;
		tmp += d;
		int size = uf.size[uf.find(edge.first)];
		tmp -= size * (size - 1LL) * 1LL / 2LL;
	}
	for (int i = 0; i < m; i++) {
		cout << result[i] << '\n';
	}
	
	return 0;
}


Measured memory_bytes: 4084
def cal_min_cost(cnt):
    return min([
      abs(hight_list[i] - hight_list[i-diff]) + cost_list[i-diff]
      for diff in range(1,3)
      ])

hight_list = []
cost_list = [0,0]
N = int(input())
hight_list = list(map(int, input().split()))
hight_list.insert(0,hight_list[0])
for i in range(2, N+1):
    cost_list.append(cal_min_cost(i))
print(cost_list[-1])

Measured memory_bytes: 13924
import java.util.Scanner

import scala.collection.{immutable, mutable}
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(start: Int, N: Int, S: Array[Seq[Int]]): Int = {
    val Q = mutable.Queue[(Int, Int)]()
    val T = ArrayBuffer.fill(N)(0)

    T(start) = 1
    Q += Tuple2(start, 1)

    while (Q.nonEmpty) {
      val (i, t) = Q.dequeue()
      for (next <- S(i)) {
        if (T(next) == 0) {
          T(next) = t + 1
          Q += Tuple2(next, t + 1)
        } else if (T(next) != t - 1 && T(next) != t + 1) {
          return -1
        }
      }
    }

    T.max
  }

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    val S: Array[Seq[Int]] = Array.fill(N)(sc.next.zipWithIndex.filter(_._1 == '1').map(_._2))

    val answers = for (i <- 0 until N) yield solve(i, N, S)

    if (answers.isEmpty) {
      "-1"
    } else {
      answers.max.toString
    }
  }
}


Measured memory_bytes: 38408
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

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

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        return a;
    }
    gcd(b, a % b)
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<i64>();

    let ans = a.iter().map(|&x| (x - 1)).sum::<i64>();
    println!("{}", ans);
}

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

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


Measured memory_bytes: 2076
A = []
b = []
row = 0
col = 0
row, col = map(int, raw_input().split())
A = [[0 for i in range(col)] for j in range(row)]

for i in range(row):
    r = map(int, raw_input().split())
    for index, j in enumerate(r):
        A[i][index] = j

for i in range(col):
    b.append(int(raw_input()))

for i in A: 
    ret = 0 
    for j,k in zip(i,b):
        ret += j*k
    print ret

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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int count = 0;
  rep(i, n - 2) {
    if(s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C') count++;
  }
  cout << count << endl;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;

int f[1010];
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++) scanf("%d",&f[i]);
    sort(f,f+n);
    int ans=0;
    for(int i=0;i<k;i++) ans+=f[i];
    printf("%d",ans);
}


Measured memory_bytes: 3780
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

//#define int ll

using namespace std;



signed main(void)
{
	//変数の宣言
	int n,m;
	int h,w;
	int a[200010];
	static char s[20];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int temp3=0;
	static int vec[1010];
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	char dummy;
	static char stemp[100010];
	
	//データの読み込み


	scanf("%d %d",&m,&n);
//	scanf_s("%d %d",&m,&n);


//	scanf("%s",&s);
//	scanf_s("%s",&s,20);


/*	//scanf("%c",&dummy);
	scanf_s("%c",&dummy);
	for(i=0;i<n;i++){
//		scanf("%c",&s[i]);
		scanf_s("%c",&s[i]);
	}*/


	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
//		scanf_s("%d",&a[i]);
	}


	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

//	clock_t start=clock();

	a[n]=m+a[0];
	for(i=0;i<n;i++){
		max=max(max,a[i+1]-a[i]);
		ans=ans+a[i];
	}
	
	printf("%d",m-max);

//	clock_t end=clock();

	//	printf("計算部分終了\n");

	//出力
	
	//printf("%d",(d[i-1][j-1]+1)/2);

//	printf("time=%lf",(double)(end-start)/CLOCKS_PER_SEC);
	//	printf("結果の出力終了\n");

	return 0;
}



Measured memory_bytes: 1024
use std::io::*;
use std::str::FromStr;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    loop {
        let s: String = sc.read();
        if s == "-" {
            break;
        }
        let len = s.len();
        let n = sc.read();
        let mut pos: usize = 0;
        for _ in 0..n {
            let k: usize = sc.read();
            pos += k;
        }
        pos %= s.len();
        let s = s.clone() + &s;
        println!("{}", s[pos..pos+len].to_string());
    }
}



Measured memory_bytes: 5032
#include <stdio.h>

int a[2222];

int main(void)
{
	int L, R, i, j;

	scanf("%d %d", &L, &R);

	for (i = L; i <= R; i++)
	{
		a[i % 2019]++;
		if (i - L > 2019 * 2)
			break;
	}

	int ans = 2019 * 2019;
	for (i = 0; i < 2018; i++)
		for (j = i + 1; j < 2019; j++)
			if (a[i] >= 1 && a[j] >= 1)
				if (ans > i * j % 2019)
					ans = i * j % 2019;

	for (i = 0; i < 2019; i++)
		if (a[i] >= 2)
			if (ans > i * i % 2019)
				ans = i * i % 2019;

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

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

template <typename T>
class Vector {
  private:
  unsigned int end;
  unsigned int alloc;
  public:
  T* A;
  Vector(): end(0), alloc(1), A((T *)malloc(sizeof(T))){}
  // Vector(){
  //   end = 0;
  //   alloc = 1;
  //   A = (T *)malloc(sizeof(T));
  // }
  Vector(const unsigned int initial_size){
    end = initial_size;
    alloc = max((unsigned int)1, initial_size);
    A = (T *)malloc(sizeof(T) * initial_size);
  }
  Vector(const Vector &other){
    end = other.end;
    alloc = other.alloc;
    A = (T *)malloc(sizeof(T) * alloc);
    memcpy(A, other.A, sizeof(T) * alloc);
  }
  Vector &operator=(const Vector &other){
    if(this != &other){
      end = other.end;
      alloc = other.alloc;
      A = (T *)malloc(sizeof(T) * alloc);
      memcpy(A, other.A, sizeof(T) * alloc);
    }
    return *this;
  }
  unsigned int size()const{
    return end;
  }
  void push_back(T v){
    if(end < alloc){
    }else{
      if(alloc == 0 || A == NULL){
        A = (T *)malloc(sizeof(T));
        alloc++;
      }else{
      unsigned int nalloc = alloc * 2;
      T* nA = (T *)malloc(sizeof(T) * nalloc);
      memcpy(nA, A, sizeof(T) * end);
      free(A);
      A = nA;
      alloc = nalloc;
      }
    }
    A[end] = v;
    end++;
  }
  void pop_back(){
    if(end == 0) return;
    end--;
  }
  T &operator[](const unsigned int idx)const{
    return A[idx];
  }
  ~Vector(){
    free(A);
  }
};

int root(int x, Vector<int>& par){
  if(par[x] == x) return x;
  par[x] = root(par[x], par);
  return par[x];
}

void unite(int x, int y, Vector<int>& par, Vector<int>& rank){
  int xpar = root(x, par);
  int ypar = root(y, par);
  if(rank[xpar] > rank[ypar]){
    par[ypar] = xpar;
  }else{
    par[xpar] = ypar;
    if(rank[xpar] == rank[ypar]){
      rank[ypar]++;
    }
  }
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q; cin >> n >> q;
  Vector<int> par(n);
  Vector<int> rank(n);
  for(int i = 0; i < n; i++){
    par[i] = i;
		rank[i] = 0;
  }
  
  for(int i = 0; i < q; i++){
    int op, x, y; cin >> op >> x >> y;
    if(op == 0){
      unite(x, y, par, rank);
    }else{
      if(root(x, par) == root(y, par)){
        cout << 1 << endl;
      }else{
        cout << 0 << endl;
      }
    }
  }
}



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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define fastt ios_base::sync_with_stdio(false); cin.tie(NULL)
#define debug1(x) cout<<#x<<" : "<<x<<endl
#define debug2(x,y) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define debug3(x,y,z) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define visited check

typedef long long ll;
typedef pair<ll,ll> pii;
const ll modd=1e9+7;

ll poww(ll a,ll b){
    ll ans=1;
    while(b>0){
      if(b%2==1) ans=(ans*a);
      a=(a*a);
      b=b/2;
  }
  return ans;
}

/*-----------------------------------------------------------------------*/

vector <ll> adj[100001];
vector <ll> topo;
ll check[100001];
ll ans=0;

void dfs(ll node){
  visited[node]=1;
  for(ll i=0;i<adj[node].size();i++)
    if(visited[adj[node][i]]==0)
      dfs(adj[node][i]);
  topo.pb(node);
}

ll dfst(ll node){
  visited[node]=1;
  for(ll i=0;i<adj[node].size();i++)
    if(visited[adj[node][i]]==0){
      visited[node]=max(visited[node],1+dfst(adj[node][i]));
    }
    else
      visited[node]=max(visited[node],1+visited[adj[node][i]]);
  ans=max(ans,visited[node]-1);
  return visited[node];
}

int main(){
   fastt;

   ll n,m;
   cin>>n>>m;

   for(ll i=1;i<=m;i++){
      ll x,y;
      cin>>x>>y;
      adj[x].pb(y);
   }

   for(ll i=1;i<=n;i++)
       if(check[i]==0)
         dfs(i);

   for(ll i=0;i<topo.size();i++)
       swap(topo[i],topo[topo.size()-i-1]);

   memset(check,0,sizeof(check));

   for(ll i=0;i<topo.size();i++)
       if(check[topo[i]]==0)
        dfst(topo[i]);

   cout<<ans<<endl;

   return 0;
}

Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

typedef double ld;
typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

int main(){ _

	int a,b;

	cin >> a >> b;

	if(a == 1) a += 13;
	if(b == 1) b += 13;

	if(a < b) cout << "Bob" << endl;
	else if(a == b) cout << "Draw\n";
	else cout << "Alice" << endl;

	return 0;
}


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

void solve(void)
{
    int k;
    cin >> k;
    rep(i, k) cout << "ACL";
    cout << endl;
}
int main(void)
{
    solve();
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ull unsigned long long
#define FI(i,a,n) for(int i=a; i<=n; i++)
#define RFI(i,n,a) for(int i=n; i>=a; i--)
#define FLL(i,a,n) for(ll i=a; i<=n; i++)
#define RFLL(i,n,a) for(ll i=n; i>=a; i--)
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define pi pair<int, int>
#define GCD(a,b) __gcd(a,b)
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define debug(x) cout << x << endl
#define MOD 1000000007
#define INF LLONG_MAX
#define PI 3.14159265359
using namespace std;



int main()
{
	fastio
  ll a, b, c, k;
  ll sum=0;
  cin >> a >> b >> c >> k;
  sum = min(a, k);
  k -= sum;
  if(k>0) k -= min(k, b);
  if(k>0) sum -= min(k, c);
  cout << sum ;


	return 0;
}






Measured memory_bytes: 3656
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
#include <cmath>
#include <iomanip>

const int MOD = 1000000007;


ll POWER(ll x,ll y)
{
	ll ret=1;
	ll p=x;
	for (ll i=y;i>0;i/=2)
	{
		if (i%2) ret=(ret*p)%MOD;
		p=(p*p)%MOD;
	}
	return ret;
}
ll gcm(ll a, ll b)
{
	if (b>a) {ll c=a; a=b; b=c;}
	while (b>0)
	{
		ll r=a%b;
		a=b;
		b=r;
	}
	return a;
}


int main(int argc, char *argv[])
{
	int k,a,b;
	cin>>k>>a>>b;
	int x,y;
	x=(a+k-1)/k;
	y=b/k;

	cout<<((x<=y) ? "OK":"NG")<<endl;

	return 0;
}



Measured memory_bytes: 3636
import sys
import numpy as np


def main():
    w, h, x, y = [int(e) for e in input().split()]
    s = (w * h) / 2.0
    if x * 2 == w and y * 2 == h:
        print(s, 1)
    else:
        print(s, 0)


main()


Measured memory_bytes: 12388
n = int(input())
a = list(map(int, input().split()))

from collections import Counter

ttl = 0
cnt = Counter(a)
for i in cnt.values():
    ttl += i * (i - 1) // 2

k_ttl = 0
for i in range(n):
    print(ttl - (cnt[a[i]] - 1))

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

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

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int k; cin >> k;
	int a, b;
	cin >> a >> b;

	ll ans = 0;
	rep(i, 1000){
		ans += k;
		if(ans >= a && ans <= b){
			cout << "OK\n";
			return 0;
		}
	}
	cout << "NG\n";
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int u,k,v,c;
	int i,j;
	int MAX=INT_MAX;
	int box[101][101];
	cin>>n;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(i==j)	box[i][j]=0;
			else		box[i][j]=MAX;
		}
	}
	for(i=0;i<n;i++){
		cin>>u>>k;
		for(j=0;j<k;j++){
			cin>>v>>c;
			box[u][v]=c;
		}
	}
	// for(i=0;i<n;i++){
		// for(j=0;j<n;j++){
			// if(box[i][j]==MAX)	cout<<"★"<<" ";
			// else				cout<<box[i][j]<<" ";
		// }
		// cout<<endl;
	// }
	for(k=0;k<n;k++){
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(box[i][k]!=MAX&&box[k][j]!=MAX){
					box[i][j]=min(box[i][j],box[i][k]+box[k][j]);
				}
			}
		}
	}
	// for(i=0;i<n;i++){
		// for(j=0;j<n;j++){
			// if(box[i][j]==MAX)	cout<<"★"<<" ";
			// else				cout<<box[i][j]<<" ";
		// }
		// cout<<endl;
	// }
	for(i=0;i<n;i++){
		cout<<i<<" "<<box[0][i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3036
#include <iostream>

using namespace std;

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if(a + b == c || b + c == a || c + a == b)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define INFTY 999999

//char型のポインタ(=配列と意味は同じ)をString型と定義
typedef char* String;

//文字列の長さを求める関数
int string_len(String str){
    int len=0;
    while(str[len]!=0){
        len++;
    }
    return len;
}

//文字列を標準入力から読み込み、それをString型のメモリを確保し直してくれる関数
String string_input(void){
    int i,len;
    char buf[200];
    String str;
    scanf("%s",buf);//buf=入力した文字列が入るchar型の配列
    //ここまでは文字列の長さがわからなかったから、一旦1000個分のメモリを用意しそこに入力させる
    
    len=string_len(buf);//len=文字列の長さを表すint型変数
    NEW(str,len+1);//strはただのポインタだから、ここでNEWを使ってメモリを確保しなくちゃいけない
    for(i=0;i<len;i++){
        str[i]=buf[i];
    }
    str[len]=0;
    
    return str;
}

int main(void){
    String S;
    S=string_input();

    String T="keyence";

    int n=string_len(S);

    //keyenceが分割or最初にあるかどうか
    if(S[0]==T[0]){
        int k=1;
        if(S[1]==T[1]){
            k++;
            if(S[2]==T[2]){
                k++;
                if(S[3]==T[3]){
                    k++;
                    if(S[4]==T[4]){
                        k++;
                        if(S[5]==T[5]){
                            k++;
                            if(S[6]==T[6]){
                                k++;
                            }
                        }
                    }
                }
            }
        }

        if(k==7){
            printf("YES\n");
        }
        else{
            int d=7-k;
            int ans=1;
            while(d!=0){
                if(S[n-d]==T[k]){
                    d--;
                    k++;
                }
                else{
                    printf("NO\n");
                    ans=0;
                    break;
                }
            }
            if(ans==1){
                printf("YES\n");
            }
        }

    }
    //そうじゃ無いなら最後にあるしかない
    else{
        if(S[n-7]==T[0]&&S[n-6]==T[1]&&S[n-5]==T[2]&&S[n-4]==T[3]&&S[n-3]==T[4]&&S[n-2]==T[5]&&S[n-1]==T[6]){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
    
    return 0;
    
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> s(n), t(m);
    rep(i, n)cin >> s[i];
    rep(i, m)cin >> t[i];
    ll mod = 1000000007;
    vector<vector<ll>> dp(n+1, vector<ll>(m+1, 1));
    rep(i, n)rep(j, m){
        if(s[i] == t[j]){
            dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1]) % mod;
        }else{
            dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j] + mod) % mod;
        }
    }
    cout << dp[n][m] << endl;
}

Measured memory_bytes: 31616
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func strsort(s string) string {
	b := SortBy(s)
	sort.Sort(b)
	return string(b)
}

type SortBy []byte

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] < a[j] }

func main() {
	defer write.Flush()

	var n int
	fmt.Fscan(read, &n)
	mp := make(map[string]int)
	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(read, &s)
		mp[strsort(s)]++
	}

	ans := 0
	for _, v := range mp {
		ans += v * (v - 1) / 2
	}
	fmt.Fprintln(write, ans)
}


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

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

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

def ii(): return int(input())
def fi(): return float(input())
def si(): return input()
def lii(): return list(map(int, input().split()))
def lfi(): return list(map(float, input().split()))
def vvi(a,b,d): return [[d] * a for i in range(b)]

inf = 10**18
mod = 10**9+7

n = ii()
ans = 0
for i in range(n):
    a = i+1
    t = n//a
    ans += a*t*(t+1)//2

print(ans)




Measured memory_bytes: 10896
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
  int i,sum=0;
  char a[200001];
  cin>>a;
  for(i=0;i<strlen(a);i++)
  {
    sum=sum+(a[i]-'0');
  }
  if(sum%9==0)
    cout<<"Yes\n";
  else
    cout<<"No\n";
  return 0;
}
  

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int a, b, c, d, ans, i, v[N];
int main() {
	cin >> a >> b >> c >> d;
	for (i = a + 1; i <= b; i++) v[i] = 1;
	for (i = c + 1; i <= d; i++) if (v[i]) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
	int n, q;
	
	while (scanf("%d", &n) && n){
		vector<pair<string, int> > store[16];
		map<string, int> minCost;
		
		for (int i = 0; i < n; i++){
			int k;
			scanf("%d", &k);
			for (int j = 0; j < k; j++){
				char tmp1[1024]; int tmp2;
				scanf("%s %d", tmp1, &tmp2);
				store[i].push_back(make_pair(string(tmp1), tmp2));
				if (minCost.count(string(tmp1)) == 0) minCost[string(tmp1)] = tmp2;
				else minCost[string(tmp1)] = min(minCost[string(tmp1)], tmp2);
			}
		}
		
		bool nxt = false;
		scanf("%d", &q);
		int bits[16] = {0};
		int ansCost = 0;
		for (int i = 0; i < q; i++){
			char tmp[1024];
			scanf("%s", tmp);
			for (int j = n - 1; j >= 0; j--){
				bits[i] <<= 1;
				for (int k = 0; k < store[j].size(); k++){
					if (store[j][k].first == string(tmp)
						&& store[j][k].second == minCost[string(tmp)]){
						bits[i] |= 1;
					}
				}
			}
			if (!nxt && bits[i] == 0){
				printf("impossible\n");
				nxt = true;
			}
			if (!nxt)
				ansCost += minCost[string(tmp)];
		}
		
		int wf[16][16];
		memset(wf, 0, sizeof(wf));
		for (int i = 0; i < 16; i++)
			for (int j = 0; j < 16; j++)
				if (i != j) wf[i][j] = 1000000000;
		
		int m;
		scanf("%d", &m);
		for (int i = 0; i < m; i++){
			int a, b, c;
			scanf("%d %d %d", &a, &b, &c);
			wf[a][b] = wf[b][a] = min(wf[a][b], c);
		}
		if (nxt == true) goto next;
		
		for (int k = 0; k < 16; k++)
			for (int i = 0; i < 16; i++)
				for (int j = 0; j < 16; j++)
					wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);
		
		int dp[2048][16];
		for (int i = 0; i < 2048; i++) for (int j = 0; j < 16; j++) dp[i][j] = 1000000000;
		for (int i = 0; i < n; i++) dp[1 << i][i] = wf[0][i + 1];
		
		for (int i = 1; i < 1 << n; i++){
			for (int j = 0; j < n; j++){
				if (i >> j & 1){
					for (int k = 0; k < n; k++){
						dp[i][j] = min(dp[i][j], dp[i ^ (1 << j)][k] + wf[j + 1][k + 1]);
					}
				}
			}
		}
		
		int pathMin;
		pathMin = 1000000000;
		for (int i = 0; i < 1 << n; i++){
			bool ok = true;
			for (int j = 0; j < q; j++) if ((i & bits[j]) == 0) ok = false;
			if (!ok) continue;
			for (int j = 0; j < n; j++){
				pathMin = min(pathMin, dp[i][j] + wf[j + 1][0]);
			}
		}
		if (q == 0) pathMin = 0;
		printf("%d %d\n", ansCost, pathMin);
		
		next:;
	}
	
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
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 (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin >> n;
    vector<ll> a(n),sm(n+1);
    REP(i,n){
        cin >> a[i];
        sm[i+1]=sm[i]+a[i];
    }
    ll ans=INF;
    REP(i,n-1){
        ll sm1=sm[i+1],sm2=sm[n]-sm[i+1];
        int p=lower_bound(ALL(sm),sm1/2)-sm.begin();
        int r=lower_bound(ALL(sm),sm1+sm2/2)-sm.begin();
        REP(j,2){
            REP(k,2){
                vector<ll> d(4);
                d[0]=sm[p-j];
                d[1]=sm1-sm[p-j];
                d[2]=sm[r-k]-sm1;
                d[3]=sm[n]-sm[r-k];
                sort(ALL(d));
                chmin(ans,d[3]-d[0]);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6328
#include<stdio.h>
int strcompare(char str[], char str2[]){
    int flag = 1;
    int i, j, k;
    for(i=0; str[i] != '\0'; i++){
        if(str[i] != str2[i]) {
            flag = 0;
            break;
        }
    }
    return flag;
}
int main()
{
    char temp;
    char str[103], str2[103];
    scanf("%s %s", str, str2);
    int i, j, k, len, flag;
    i = 0;
    while(str[i] != '\0') i++;
    i--;
    len = i;
    flag = 1;
    for(i=0; i<=len; i++){
        temp = str[0];
        for(k=0; k<len; k++){
            str[k] = str[k+1];
        }
        str[len] = temp;
        if(strcompare(str, str2) == 1){
          flag = 0;
          break;
        }
    }
    if(flag == 0) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
int main()
{
	
   string s,ss;
   cin>>s>>ss;
   int k=0,i;
   for(i=0;i<3;i++)
   if(s[i]==ss[i])
   k++;
   cout<<k<<endl; 
}

Measured memory_bytes: 256
# C - H and V
import itertools

H, W, K = map(int, input().split())
grid = [[''] * W for _ in range(H)]
for i in range(H):
    grid[i] = list(str(input()))

ans = 0
for i in itertools.product((0, 1), repeat=H):
    for j in itertools.product((0,1), repeat=W):
        tmp = 0
        for hi, h in enumerate(i):
            for wj, w in enumerate(j):
                if h == 1 and w == 1 and grid[hi][wj] == '#':
                    tmp += 1
        if tmp == K:
            ans += 1
print(ans)

Measured memory_bytes: 9204
N = int(input())
T, A = map(int, input().split())
Hs = list(map(int, input().split()))

temparatures = [T-x*0.006 for x in Hs]
differences = [abs(A-t) for t in temparatures]
best_location = differences.index(min(differences)) + 1

print(best_location)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 3e3+5;
const lli INF = 1e18;
const lli MOD = 1e9+7;

vi m;
vi primes(1,2);
vector<vector<ld>>nk;
void sieve(){
	m = vi(N+1,0);
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	nk =vector<vector<ld>>(N,vector<ld>(N,0.0));
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

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

// ---- コーディングはここから！ ('-')7
ii dp[2][N][N];
void solve(){
	int n; cin>>n; vl v(n); fore(i,0,n)cin>>v[i];
	fore(i,0,2)fore(j,0,N)fore(k,0,N)dp[i][j][k]={-1,0};
	ii aux = {-1,0};
	auto f=[&](auto f, int p, int a, int b)->ii{
			if(a>b)return ii{0,0};
			
			if(dp[p][a][b]!=aux)return dp[p][a][b];
			ii resa=f(f,p^1,a+1,b);
			if(p)resa.s+=v[a];
			else resa.f+=v[a];
			ii resb = f(f,p^1,a,b-1);
			if(p)resb.s+=v[b];
			else resb.f+=v[b];
			if(p==0){
				if(resa.f-resa.s > resb.f-resb.s)return dp[p][a][b]=resa;
				else return dp[p][a][b]=resb;
			}
			if(resa.f-resa.s < resb.f-resb.s)return dp[p][a][b]=resa;
			else return dp[p][a][b]=resb;
	};
	cout<<f(f,0,0,n-1).f - f(f,0,0,n-1).s<<ENDL;
//	cout<<

}

int main(){_
	//int t; cin>>t; while(t--)
	solve();
}


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

static const int NUM = 1000000;
bool isPrime[NUM];
vector<int> prime;

void primeCalc()
{
	for(int i = 0; i < NUM; ++i)
	{
		isPrime[i] = true;
	}
	isPrime[0] = isPrime[1] = false;
	for(int i = 2; i < NUM; ++i)
	{
		if(isPrime[i])
		{
			prime.push_back(i);
			for(int j = 2 * i; j < NUM; j += i)
			{
				isPrime[j] = false;
			}
		}
	}
}

void solve()
{
	primeCalc();
	int N, P;
	while(cin >> N >> P)
	{
		if(N == -1 && P == -1)
		{
			break;
		}
		vector<int> vec;
		int pos = 0;
		while(N >= prime[pos])
		{
			++pos;
		}
		for(int i = pos; i < pos + P; ++i)
		{
			int p = i;
			for(int j = p; j < p + P; ++j)
			{
				vec.push_back(prime[i] + prime[j]);
			}
		}
		sort(vec.begin(), vec.end());
		cout << vec[P - 1] << endl;
	}
}

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

Measured memory_bytes: 2568
a = int(input())
ans = 0
for i in range(1,a+1):
    s = str(i)
    if s[-1]== '0':continue
    elif len(s) == 1:
        ans+=1
    elif s[0] == s[1] and len(s)==2:
        ans+=3
    elif int(s[0])>int(s[1]) and len(s)==2 and '0' not in s:
        ans+=2
    elif len(s)==2:continue
    elif s[0] == s[2] and len(s)==3:
        ans += 3+2*(int(s[1])+1)
    elif len(s) == 3 and int(s[0])>int(s[2]):
        ans +=22
    elif len(s) == 3 and s[2] != '0':
        ans +=2 

    elif len(s) == 4 and s[0] == s[-1]:
        ans += 3+2*(10+int(s[1]+s[2])+1)
    elif len(s) == 4 and int(s[0])>int(s[-1]):
        ans += 222
    elif len(s)==4:
        ans +=22

    elif len(s) == 5 and s[0] == s[-1]:
        ans += 3+2*(110+int(s[1]+s[2]+s[3])+1)
    elif len(s) == 5 and int(s[0])>int(s[-1]):
        ans += 2222
    elif len(s)==5:
        ans +=222

    elif len(s) == 6 and s[0] == s[-1]:
        ans += 3+2*(1110+int(s[1]+s[2]+s[3]+s[4])+1)
    elif len(s) == 6 and int(s[0])>int(s[-1]):
        ans += 22222
    elif len(s)==6:
        ans +=2222
print(ans)

Measured memory_bytes: 57692
import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    k = int(input())
    if k % 2 == 0:
        print(-1)
        sys.exit()
    rems = defaultdict(int)
    n = 7 % k
    next_digit = 70 % k
    r = 1
    while True:
        if n == 0:
            print(r)
            sys.exit()
        elif rems[n]:
            print(-1)
            sys.exit()
        else:
            rems[n] = 1
            n += next_digit
            n = n % k
            next_digit = (next_digit * 10) % k
            r += 1
if __name__ == '__main__':
    main()


Measured memory_bytes: 92812
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 1,0 },{ 0,1 }
};


template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) {}
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int) x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if (u < 0) u += Mod;
		ModInt res; res.x = (unsigned) u;
		return res;
	}
};
typedef ModInt<1000000007> mint;

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x%mod;
		x = x*x%mod;
		n >>= 1;
	}
	return res;
}

signed main() {
	int n;
	scnaf("%d", &n);
	vector<int> kusi(2*n);
	REP(i, 2*n) {
		scanf("%d", &kusi[i]);
	}

	sort(ALL(kusi));
	int ans = 0;

	REP(i, n) {
		ans += min(kusi[2 * i], kusi[2 * i + 1]);
	}
	printf("%d\n" ,ans);

	return 0;
}

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

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

constexpr size_t    operator""_sz(unsigned long long value) { return value; };
constexpr intmax_t  operator""_im(unsigned long long value) { return value; };
constexpr uintmax_t operator""_um(unsigned long long value) { return value; };
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    size_t N;
    cin >> N;

    unordered_map<intmax_t, int> cnt;
    set<intmax_t> st;
    for (size_t i = 0; i < N; ++i) {
        intmax_t a; cin >> a;
        st.insert(a);
        cnt[a]++;
    }

    intmax_t res = 0;
    for (auto &si: st) {
        if (cnt[si] < si) {
            res += cnt[si];
        } else if (cnt[si] > si) {
            res += cnt[si] - si;
        }
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 8740