akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>

const long long INF = 1e18;

// 枝
struct Edge{
	int to; //行き先
	int a, b; //-お金、+時間
	Edge(int to, int a, int b) : to(to), a(a), b(b) {}
};

// 頂点と所持金と最小時間のdistコンテナ
struct Data{
	int v, coins;
	long long time;
	Data(int v, int coins, long long time) : v(v), coins(coins), time(time) {}
	bool operator < (const Data& a) const{
		return time > a.time;
	}
};

int main(){
	//入力
	int n, m, coins;
	std::cin >> n >> m >> coins;
	std::vector<std::vector<Edge>> g(n); //隣接頂点
	int Amax = -1;
	for(int i=0; i<m; i++){
		int u, v, a, b;
		std::cin >> u >> v >> a >> b;
		--u; --v;
		g[u].emplace_back(v, a, b);
		g[v].emplace_back(u, a, b);
		Amax = std::max(Amax, a);
	}

	std::vector<int> c(n), d(n);
	for(int i=0; i<n; i++){
		std::cin >> c[i] >> d[i];
	}
	int MAX_COINS = Amax * (n-1);

	//dijkustra 初期化
	std::vector<std::vector<long long>> dist(n, std::vector<long long>(MAX_COINS+1, INF));
	std::priority_queue<Data> q;
	auto push = [&](int v, int s, long long t){
		if(s < 0) return;
		if(dist[v][s] <= t) return;
		dist[v][s] = t;
		q.emplace(v, s, t);
	};

	coins = std::min(coins, MAX_COINS);
	push(0, coins, 0);

	//dijkustra start!
	while(!q.empty()){
		Data hoge = q.top();
		q.pop();
		int v = hoge.v;
		int coins = hoge.coins;
		long long time = hoge.time;
		//std::cout << "pop: " << v << " " << coins << " " << time << std::endl;
		if(dist[v][coins] != time) continue;
		//両替
		int next_coins = std::min(coins + c[v], MAX_COINS);
		push(v, next_coins, time + d[v]);
		//std::cout << "両替: " << v << " " << coins+c[v] << " " << time+d[v] << std::endl;
		
		for(Edge e : g[v]){
			push(e.to, coins - e.a, time + e.b);
			//std::cout << "移動: " << e.to  << " " << coins-e.a << " " << time+e.b << std::endl;
		}
	}

	//答えの出力
	for(int i=1; i<n; i++){
		long long ans = INF;
		for(int j=0; j<=MAX_COINS; j++){
			ans = std::min(ans, dist[i][j]);
		}
		std::cout << ans << std::endl;
	}

	return 0;
}

Measured memory_bytes: 6276
# -*- coding: utf-8 -*-
import sys
N,K=map(int, sys.stdin.readline().split())
A=[ int(sys.stdin.readline().strip()) for _ in range(N) ]
max_A=max(A)

# 処理する区間の長さはmax_A
N0 = 2**(max_A).bit_length()
data = [0]*(2*N0)
# a_k の値を x に更新
def update(k, x):
    k += N0-1
    data[k] = x
    while k > 0:
        k = (k - 1) / 2
        data[k] = max(data[2*k+1], data[2*k+2])
# 区間[l, r)の最大値
def query(l, r):
    L = l + N0; R = r + N0
    s = float("-inf")
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])

        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

for i,a in enumerate(A):
    update(a,query(max(a-K,0),min(a+K+1,max_A+1))+1)

print query(0,max_A+1)


Measured memory_bytes: 104100
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;

int main(){
  int n;
  while(cin >> n ,n){
    int num[100];
    for(int i=0;i<n;i++){
      cin >> num[i];
    }
    int now = 32;
    int idx = 0;
    while(now != 0){
      if(idx % 2 == 0){
	now = max(0,now-(now-1)%5);
      } else {
	now = max(0,now-num[(idx/2)%n]);
      }
      cout << now << endl;
      idx++;
    }
  }
}

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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}



int main(void){
    int x, a, b;
    scanf("%d %d %d", &x, &a, &b);
    x -= a;
    x %= b;
    printf("%d\n", x);
    return 0;

}


Measured memory_bytes: 128
import java.util.Scanner;
import javax.sound.midi.SysexMessage;
  
public class Main{      
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        for(int l = 0;l<100;l++){
            String str = sc.nextLine();
            String str2[] = str.split(" ");
            int n = Integer.parseInt(str2[0]);
            int x = Integer.parseInt(str2[1]);
            if(n==0&&x==0)
                break;
            int count = 0;
            for(int i=1;i<=n;i++)
            {
                for(int j=i+1;j<=n;j++)
                {
                    for(int k=j+1;k<=n;k++)
                    {
                        if(i+j+k==x)
                            count++;
                    }
                }
            }
            System.out.println(count);
        }
    }   
}              

    


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

using namespace std;

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

int main(){
	int a, b;
	scanf("%d %d", &a, &b);
	printf("%lld\n", a / gcd(a, b) * 1LL *  b);
	return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] line1 = br.readLine().split(" ");
    
    int n = Integer.parseInt(line1[0]);
    int q = Integer.parseInt(line1[1]);
    int[] numAC = new int[n];
    
    char[] s = br.readLine().toCharArray();
    
    boolean a = false;
    boolean c = false;
    int sum = 0;
    for (int i=0; i<n; i++){
      c = s[i] == 'C';
      if (a && c) sum++;
      a = s[i] == 'A';
      numAC[i] = sum;
    }
    
    StringBuilder result = new StringBuilder();
    
    int l;
    int r;
    String[] question;
    for (int i=0; i<q; i++){
      question = br.readLine().split(" ");
      l = Integer.parseInt(question[0]);
      r = Integer.parseInt(question[1]);
      
      result.append(numAC[r-1]-numAC[l-1]);
      result.append("\n");
    }
    System.out.println(result);
  }
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    vector<int> a;
    vin(a,3);
    sort(a.begin(), a.end());
    int sum = 0;
    rep(i, 3) sum += a[i];
    int ma = a[2], ans = 1e8;
    for (int x=ma; x<=100; ++x) {
        if (x%2 == sum%2) {
            ans = min(ans, (3*x-sum)/2);
        }
    }
    cout << ans << endl;
    return 0;
}


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

struct data {
  long long a, b, c;
};

long long n, k;
vector<data> ans;

long long solve() {
  int state = 0, now = 0;
  ans.resize(n);
  for(int i = 0; i < n; ++i) ans[i].c = k + 2 * n + i;
  for(int i = 0; i < 2 * n; ++i) {
    if(state % 2 == 0)
      ans[now].a = k + i;
    else
      ans[now].b = i + k;
    now += 2;
    while(now >= n) {
      ++state;
      now = (state == 1) || (state == 2);
    }
  }
  for(int i = 0; i < n; ++i)
    if(ans[i].a + ans[i].b > ans[i].c) return -1;
  return 0;
}

int main() {
  cin >> n >> k;
  if(solve() == -1)
    cout << -1;
  else
    for(int i = 0; i < n; ++i)
      cout << ans[i].a << " " << ans[i].b << " " << ans[i].c
           << endl;
  return 0;
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    int ans=0;
    for (int i=1;i<=x;i++){
        if (i%2==1){
                int cnt=0;
            for (int j=1;j<=i;j++){
                if (i%j==0)
                cnt++;
            }
            if (cnt==8)
                ans++;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	ll n, k, ans=0;

	cin>>n>>k;

	if(k!=0){
		repr(i, k+1, n+1){
			ans+=(n/i)*(i-k);
			ll temp=n%i-k+1;
			ans+=(temp>0)?temp:0;
		}
		cout<<ans<<endl;
	}else{
		cout<<n*n<<endl;
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int n;
int g[505][505];
int ans = 0;
queue<ii> q;
int d[505][505];
int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
int main(){
    scanf("%d",&n);
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            g[i][j] = min(min(i+1,n-i),min(j+1,n-j));
            d[i][j] = 1;
        }
    }
    for (int i =0;  i < n*n; i++){
        int X;
        scanf("%d",&X);
        X--;
        int _x = X/n, _y = X%n;
        g[_x][_y]--;
        d[_x][_y] = 0;
        ans += g[_x][_y];
        //printf("%d %d takes %d\n",_x,_y,g[_x][_y]);
        q.push({_x,_y});
        while (q.size()){
            int x,y;
            tie(x,y) = q.front(); q.pop();
            for (int k = 0; k < 4; k++){
                int nx = x+dx[k], ny = y+dy[k];
                if (nx >= 0 && nx < n && ny >= 0 && ny < n){
                    if (g[nx][ny] > g[x][y]+d[nx][ny]){
                        g[nx][ny] = g[x][y]+d[nx][ny];
                        q.push({nx,ny});
                    }
                }
            }
        }
    }
    printf("%d",ans);


}


Measured memory_bytes: 5728
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <complex>
#include <tuple>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
// #define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define repr(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define reprs(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define LF "\n"

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;

ll n;
string s,t;

int main(){
	FAST;
	cin >> n;
	cin >> s >> t;

	rep(i,n+1) {
		string u = string(s.substr(0,i))+t;
		if (u.substr(0,n) == s) {
			cout << u.size() << LF;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int A, B;
	
	scanf("%d", &A);
	scanf("%d", &B);
	
	if (A <= 8 && B <= 8) {
		printf("Yay!\n");
	}
	else {
		printf(":(\n");
	}
	return (0);
}

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

const int64_t MOD = 1000000007;

int main() {
  int64_t N, K;
  cin >> N >> K;

  int64_t sum = 0;
  for (int64_t i = K; i <= N + 1; i++) {
    int64_t mx = N * (N + 1) / 2 - (N - i) * (N - i + 1) / 2;
    int64_t mn = i * (i - 1) / 2;
    sum += (mx - mn + 1) % MOD;
    sum %= MOD;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3636
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = str(input())
score = 0
for i in range(0,K):
    prev = ""
    for j in range(i,N,K):
        if prev != T[j:j+1]:
            if T[j:j+1] == "r":
                score += P
            elif T[j:j+1] == "s":
                score += R
            else:
                score += S
            prev = T[j:j+1]
        else:
            prev = ""
print(score)

Measured memory_bytes: 3316
#include <iostream>
#include <string>
int main() {
  std::string s;
  std::cin >> s;
  int a, k=0;
  for(int i=0;i<1<<(s.size()-1);++i){
    a=s[0]-'0';
    for(int j=0;j<s.size()-1; ++j){(i>>j&1?a+=(s[j+1]-'0'):a-=(s[j+1]-'0'));}
    if(a==7){k=i; break;}
  }
  for(int i=0;i<s.size()-1;++i){
    std::cout << s[i] << (k>>i&1?'+':'-');
  }
  std::cout<<s.back()<<"=7"<<"\n";
}

      

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int A,B;
  cin >> A >> B;
  string S;
  cin >> S;
  if(sz(S) != A+B+1) {
    cout << "No" <<endl;
    return 0;
  }
  rep(i,A) {
    if(!(S[i] - '0' >= 0 && S[i] - '0' < 10)) {
      cout << "No" <<endl;
      return 0;
    }
  }
  if(S[A] != '-') {
    cout << "No" <<endl;
    return 0;
  }
  srep(i,A+1,A+B+1) {
    if(!(S[i] - '0' >= 0 && S[i] - '0' < 10)) {
      cout << "No" <<endl;
      return 0;
    }
  }
  cout << "Yes" <<endl;
  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++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
//#define int long long

signed main(){
    string s,t;
    cin >> s >> t;
    sort(ALL(s)); sort(ALL(t));
    vector<int> alpha_s(26,0), alpha_t(26,0);
    
    rep(i,s.length()){
        alpha_s[s[i]-'a']++;
        alpha_t[t[i]-'a']++;
    }
    
    sort(ALL(alpha_s));
    sort(ALL(alpha_t));
    
    cout << (alpha_s == alpha_t ? "Yes" : "No") << endl;
}

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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


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


auto solve() {
    int N;
    cin >> N;
    vector<vi> hv(N, vi(3));
    for (auto &&e: hv) for (auto &&t:e) cin >> t;

    vector<vi> dp(N+1, vi(3, 0));
    REP(i, N) {
        REP(j, 3) {
            REP(k, 3) {
                if (j == k) continue;
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + hv[i][j]);
            }
        }
    }

    return *max_element(all(dp[N]));
}


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

    cout << solve() << endl;
//    solve();

    return 0;
}


Measured memory_bytes: 11264
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
using namespace std;

const double PI=acos(-1);

int main(){
    int n, a, b, sum = 0, sumb = 0;
    string s;
    cin >> n >> a >> b >> s;
    for(int i = 0; i < n; i++){
        if(s[i] == 'a' && sum < a+b){
            cout << "Yes" << endl;
            sum++;
        }else if(s[i] == 'b' && sum < a+b && sumb < b){
            cout << "Yes" << endl;
            sum++;
            sumb++;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
namespace /* debug */{
  #define DEBUG(...) do{cout<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数
  #define ldebug(...) do{cout<<"["<<setw(3)<<__LINE__<<"] ";debug(__VA_ARGS__);}while(0) //行数
  #define lDEBUG(...) do{cout<<"["<<setw(3)<<__LINE__<<"] "<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数, 行数
  template<class T>void show(T&x){cout<<x<<" ";} //出力
  template<class T>void showendl(T&x){cout<<x<<endl;} //出力改行
  template<class P,class Q>void show(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<") ";} //pair出力
  template<class P,class Q>void showendl(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<")"<<endl;} //pair出力改行
  template<class H>void debug(H&&h){showendl(h);} //引数1つ
  template<class H,class...Ts>void debug(H&&h,Ts&&...ts){show(h);debug(forward<Ts>(ts)...);} //可変引数
  template<class T>void debug(vector<T>&vt){int i=0;for(auto x:vt)++i!=vt.size()?show(x):showendl(x);} //vector出力
  template<class T>void debug(initializer_list<T>init){int i=0;for(auto x:init)++i!=init.size()?show(x):showendl(x);} //初期化子リスト出力
}

long long divisor(long long n, vector<long long> &d){
  long long cnt = 0;
  for(long long i=1; i*i<=n; i++){
    if(n%i==0){
      d.push_back(i);
      if(i*i!=n){
        d.push_back(n/i);
      }
      cnt++;
    }
  }
  return cnt;
}

int main(){
  int N;cin>>N;
  vector<int> A(N);
  map<int,int> mp;
  for(int i=0; i<N; i++){
    cin>>A[i];
    mp[A[i]]++;
  }
  sort(all(A), greater<int>());
  //DEBUG(A);
  int cnt = N;
  for(int i=0; i<N; i++){
    int s = A[i];
    if(mp[s]>1){
      //DEBUG(s);
      cnt--;
      continue;
    }
    vector<long long> d;
    divisor(s,d);
    for(auto x: d){
      if(x==s)continue;
      if(mp.find(x)!=mp.end()){
        //DEBUG(s,x);
        cnt--;
        break;
      }
    }
  }
  

  cout<<cnt<<endl;
}

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

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll K,N;
    cin >> N >> K;
    if(K==1){
        cout << 0 << endl;
        return 0;
    }
    cout << N-K << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int N;
int A, B;
int C;
int D[110];

int main() {
  cin >> N >> A >> B >> C;
  for (int i=0; i<N; i++) {
    cin >> D[i];
  }
  sort(D, D+N);
  int s = C;
  int ans = (int)floor((double)C / (double)A);
  for (int k=0; k<N; k++) {
    s += D[N-1-k];
    ans = max(ans, (int)floor((double)s / (double)(A + (k+1)*B)));
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   string s;
   cin >> s;
   int q;
   cin >> q;
   string t;
   rep(qi, 0, q) {
      int ti;
      cin >> ti;
      if (ti == 1) {
         swap(s, t);
      } else {
         int f;
         char c;
         cin >> f >> c;
         if (f == 1) {
            t += c;
         } else {
            s += c;
         }
      }
   }
   reverse(t.begin(), t.end());
   t += s;
   cout << t << endl;
   return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  int N;
  cin >> N;

  while (!(N % 10 == (N%100)/10 && N % 10 == N/100)) {
    N++;
  }
  cout << N << endl;
  return 0;
}


Measured memory_bytes: 256
n,k = [int(x) for x in input().split()]

l = []

for i in range(k):
  d = input()
  l.append(set([int(x) for x in input().split()]))
  
s = set()
for i in l:
  s = s.union(i)
  
all_set = set([x+1 for x in range(n)])
def_set = all_set.difference(s)
print(len(def_set))

Measured memory_bytes: 9752
N = int(input()) 
insist_num = []
insists = []

for i in range(N):
    insist_num.append(int(input()))
    insists.append([list(map(int,input().split())) for _ in range(insist_num[-1])])

all_patterns = ["0","1"] # 1が正直者とする
for _ in range(N-1):
    all_patterns = [j+i for i in ["0","1"] for j in all_patterns]

ok = [True for _ in range(len(all_patterns))]

for h, pattern in enumerate(all_patterns):
    for i, honest in enumerate(list(pattern)):
        if honest == "1":
            for j in range(insist_num[i]):
                if str(insists[i][j][1]) != str(list(pattern)[insists[i][j][0]-1]):
                    ok[h] = False
                    break
            else:
                continue
            break

max_val = 0
for i, pp in enumerate(ok):
    if pp==True and all_patterns[i].count("1") > max_val:
        max_val = all_patterns[i].count("1")
print(max_val)

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


bool issquare(int n) {
    int s = sqrt(n);
    return s*s == n;
}

int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int n,d;
    cin>>n>>d;
    int a[n][d];
    for(int i = 0;i < n;i++) {
        for(int j = 0;j < d;j++) cin>>a[i][j];
    }

    int ans = 0;

    for(int i = 0;i < n;i++) {
        for(int j = i+1;j < n;j++) {
            int sum = 0;
            for(int k = 0;k < d;k++) sum += (a[i][k] - a[j][k])*(a[i][k] - a[j][k]);
            if(issquare(sum)) ans++;
        }
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 256
s=input()
l=[]
for i in range(len(s)):
    if s[i]=='0':
        l.append('0')
    elif s[i]=='1':
        l.append('1')
    elif s[i]=='B' and len(l)!=0:
        l.pop()
    
for i in l:
    print(i,end='')

Measured memory_bytes: 3060
def ff(n):
    i = 1
    r = set()
    while i * i <= n:
        if n % i == 0:
            r.add(i)
            if i != n // i:
                r.add(n // i)
        i += 1
    return sorted(r)

def main():
    N, K = map(int, input().split())
    mod = 10**9 + 7
    T = [[] for _ in range(K + 1)]
    F = [ff(i) for i in range(K + 1)]
    for i, f in enumerate(F[1:], 1):
        for j in f:
            T[j].append(i)
    r = 0
    t = [0] * (K + 1)

    for i in reversed(range(1, K + 1)):
        q = (pow(len(T[i]), N, mod) - t[i]) % mod
        for j in F[i][:-1]:
            t[j] = (t[j] + q) % mod
        r = (r + i * q) % mod

    return r

print(main())


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

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

        c=a+b;
        if(a-b>=c){
                c=a-b;
        }
        if(a*b>=c){
                c=a*b;
        }

        cout<<c<<endl;
}


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

int gcd(int x,int y){
    return y ? gcd(y,x%y) : x;
}

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];

    int ans=0;
    for(int i=0;i<n;i++){
        ans=gcd(ans,a[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3748
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
#define int long long
const int maxn = 1e5 + 10;
inline int Max(int a, int b) { return a > b ? a : b; }
inline int Min(int a, int b) { return a > b ? b : a; }
namespace FastIO {
inline int read()
{
    int f = 1, r = 0;
    char c = getchar();
    while (!isdigit(c)) {
        if (c == '-') {
            f = -1;
        }
        c = getchar();
    }
    while (isdigit(c)) {
        r = 10 * r + c - '0';
        c = getchar();
    }
    return f * r;
}
inline void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) { write(x), puts(""); }
};
using namespace FastIO;
int N, arr[maxn], ans[maxn], tot, sum, L;
/**
 * 智障型选手错误的贪心策略：从左右两个端点删除，哪边小就删除哪个。因为删除中间的点必须要将序列分为两半，所以贪心地认为先从两侧删就可以。
 * 但是有可能左右两侧都是一个很大的相等的数，这样就会必须删除一个。
 * 换一个思路：不管怎么删，最后一定会有两个相邻，如果这两个无法删除，那么就不可能了，所以尽量选最大的最后删除。
 * 选定最后删除的knot后，从两侧依次删除即可。
*/
signed main()
{
    //freopen("C:\Users\hjw\Downloads\testdata (4).in", "r", stdin);
    N = read(), L = read();
    for (ri i = 1; i <= N; ++i) {
        arr[i] = read();
    }
    int j = 1;
    for (ri i = 1; i < N; ++i) {
        if (arr[i] + arr[i + 1] > arr[j] + arr[j + 1]) {
            j = i;
        }
    }
    if (arr[j] + arr[j + 1] < L) {
        puts("Impossible");
    } else {
        puts("Possible");
        for (ri i = 1; i < j; ++i) {
            writeln(i);
        }
        for (ri i = N - 1; i > j; --i) {
            writeln(i);
        }
        writeln(j);
    }
    return 0;
}

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




int countsuitable(int x, int k, int n){
  
  if (x>=1){

    int a=(k+pow(2,x)-1)/pow(2,x);
    int b=(k-1)/pow(2,x-1);
  
    if (a>n){
      return 0;
    }
    else {
      return max(min(b,n)-a+1,0);
    }
  }
  
  if (x==0){
    return max(n-k+1,0);
  }
}




int main(){
  
  double n,k;
  cin>>n>>k;
  
  double answer=0;
  

  
  for (int i=0;i<20;i++){
    double tmp=(countsuitable(i,k,n)*pow(0.5,i))/n;
    answer+=tmp;
  }
  
  cout<<fixed<<setprecision(12);
  
  cout<<answer<<endl;

    

}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <cstdio>
#include <utility>
#include <complex>

using namespace std;

static const double EPS=1e-12;
static const double INF=1e24;
static const double PI=3.141592653589793;

using Point=complex<double>;
using Plane=vector<Point>;

namespace std {
    bool operator<(const Point &a, const Point &b) {
        return real(a)!=real(b)? real(a)<real(b) : imag(a)<imag(b);
    }
}

double cross_prod(const Point &a, const Point &b) {
    return imag(conj(a)*b);
}

double dot_prod(const Point &a, const Point &b) {
    return real(conj(a)*b);
}

struct Line: public pair<Point, Point> {
    Line() {}
    Line(const Point &a, const Point &b) {
        first = a;
        second = b;
    }
};

struct LineSeg: public pair<Point, Point> {
    LineSeg() {}
    LineSeg(const Point &a, const Point &b) {
        first = a;
        second = b;
    }
};

struct Circle {
    Point p;
    double r;
    Circle() {}
    Circle(const Point &p, const double r): p(p), r(r) {}
};

Point get_ipoint(const Line &l, const Line &m) {
    double x1=l.first.real(), x2=l.second.real();
    double x3=m.first.real(), x4=m.second.real();
    double y1=l.first.imag(), y2=l.second.imag();
    double y3=m.first.imag(), y4=m.second.imag();

    double x=(y4-y3)*(x4-x1)-(x4-x3)*(y4-y1);
    double d=(y4-y3)*(x2-x1)-(x4-x3)*(y2-y1);

    return Point(x1, y1) + (x/d)*Point(x2-x1, y2-y1);
}

bool testcase_ends() {
    double x, y;
    if (scanf("%lf %lf", &x, &y) == EOF)
        return 1;

    Point A(x, y);
    scanf("%lf %lf", &x, &y);
    Point B(x, y);
    scanf("%lf %lf", &x, &y);
    Point C(x, y);

    Line l((A+B)/2.0, (A+B)/2.0+(B-A)*polar(1.0, PI/2));
    Line m((B+C)/2.0, (B+C)/2.0+(C-B)*polar(1.0, PI/2));

    Point P=get_ipoint(l, m);
    double r=abs(P-A);
    printf("%.3f %.3f %.3f\n", P.real(), P.imag(), r);

    return 0;
}

int main() {
    size_t n;
    scanf("%zu", &n);

    for (size_t i=0; i<n; ++i)
        if (testcase_ends())
            return 1;

    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
ll X[202020];
int Q;
int L,R;
int le[21][202020];
int ri[21][202020];
ll LS[21][202020];
ll RS[21][202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	FOR(i,N) cin>>X[i+1];
	X[0]=-1LL<<60;
	X[N+1]=1LL<<60;
	for(i=1;i<=N;i++) {
		ri[0][i]=lower_bound(X,X+N+2,X[i]+K)-X;
		le[0][i]=lower_bound(X,X+N+2,X[i]-K+1)-X-1;
		LS[0][i]=le[0][i];
		RS[0][i]=ri[0][i];
	}
	
	le[0][0]=0;
	ri[0][N+1]=N+1;
	FOR(j,20) {
		for(i=0;i<=N+1;i++) {
			le[j+1][i]=le[j][le[j][i]];
			ri[j+1][i]=ri[j][ri[j][i]];
			LS[j+1][i]=LS[j][i]+LS[j][le[j][i]];
			RS[j+1][i]=RS[j][i]+RS[j][ri[j][i]];
		}
	}
	
	
	cin>>Q;
	FOR(i,Q) {
		cin>>L>>R;
		ll dif=R-L+1;
		x=L,y=R;
		for(j=19;j>=0;j--) {
			if(ri[j][x]<=R) {
				dif+=LS[j][y]-RS[j][x]+(1<<j);
				x=ri[j][x];
				y=le[j][y];
			}
		}
		cout<<dif<<endl;
	}
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

string s,t;
int rotate[10][10];
int n,ans;

void solve(int idx,int cost){
	if(idx == n) ans = cost;
	if(cost >= ans) return;

	if(s[idx] == t[idx]){
		solve(idx+1,cost);
	}
	else{
		for(int i=idx;i<n;i++){
			int r = rotate[s[idx]][t[idx]];
			for(int j=idx;j<=i;j++) s[j] = (s[j] + 10 + r) % 10;
			solve(idx+1,cost+1);
			for(int j=idx;j<=i;j++) s[j] = (s[j] + 10 - r) % 10;
		}
	}
}

int main(void){
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			int d = j - i;
			int x = abs(d);
			if(j < i && x > 10-x)
				d = 10-x;
			else if(j > i && x > 10-x)
				d = -(10-x);

			rotate[i][j] = d;
		}
	}

	while(cin>>n,n){
		cin>>s>>t;
		for(int i=0;i<n;i++){
			s[i] -= '0';
			t[i] -= '0';
		}

		ans = 999999999;
		solve(0,0);
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 924
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;

int s0[4096][4096],s1[4096][4096],n,k;

void sp(int s[][4096]){
	fore(i,1,4096)fore(j,1,4096)s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
}
int get(int s[][4096], int i0, int i1, int j0, int j1){
	return s[i1][j1]-s[i1][j0]-s[i0][j1]+s[i0][j0];
}

int main(){
	scanf("%d%d",&n,&k);
	fore(i,0,n){
		int x,y;char s[4];
		scanf("%d%d%s",&x,&y,s);
		if(s[0]=='W'){
			s0[1+x%(2*k)][1+y%(2*k)]++;
			s0[1+x%(2*k)+2*k][1+y%(2*k)]++;
			s0[1+x%(2*k)][1+y%(2*k)+2*k]++;
			s0[1+x%(2*k)+2*k][1+y%(2*k)+2*k]++;
		}
		else {
			s1[1+x%(2*k)][1+y%(2*k)]++;
			s1[1+x%(2*k)+2*k][1+y%(2*k)]++;
			s1[1+x%(2*k)][1+y%(2*k)+2*k]++;
			s1[1+x%(2*k)+2*k][1+y%(2*k)+2*k]++;
		}
	}
	sp(s0);sp(s1);
	int r=0;
	fore(i,0,2*k)fore(j,0,2*k)r=max(r,get(s0,i,i+k,j,j+k)+get(s0,i+k,i+2*k,j+k,j+2*k)+get(s1,i,i+k,j+k,j+2*k)+get(s1,i+k,i+2*k,j,j+k));
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 131328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)

typedef pair<int, int> P;
ll modnum = 1e9+7;


const int MAX_V = 50;
const int MAX_S = MAX_V*50+5;
const ll INF = 1e18;

struct Edge {
    int to,a,b;
    Edge(int to, int a, int b): to(to), a(a), b(b) {}
};

struct Data {
    int v,s;
    ll x;
    Data(int v, int s, ll x): v(v),s(s),x(x) {}
    bool operator<(const Data& a) const {
        return x > a.x;
    }
};

vector<Edge> g[MAX_V];
ll dp[MAX_V][MAX_S+5];

int main() {
    int n,m,s; cin >> n >> m >> s;
    rep(i, m) {
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        --u; --v;
        g[u].emplace_back(v,a,b);
        g[v].emplace_back(u,a,b);
    }
    vector<int> c(n), d(n);
    rep(i, n) cin >> c[i] >> d[i];
    rep(i, n) rep(j, MAX_S+5) dp[i][j] = INF;

    // ダイクストラ
    priority_queue<Data> que;

    // queに突っ込む関数
    auto push = [&](int v, int s, ll x) {
        // 所持金がマイナスになる移動は不可なのでNG
        if(s < 0) return;
        // 更新先が今の移動時間より小さかったら、やる意味ないので終わり
        if(dp[v][s] <= x) return;
        dp[v][s] = x;
        que.emplace(v,s,x);
    };


    // 所持金が不要にあれば、捨てる
    s = min(s, MAX_S);
    // 開始地点を突っ込む
    push(0, s,0);

    // ダイクストラを回していく
    while(!que.empty()) {
        // 一番小さい時間のを取り出す
        Data da = que.top(); que.pop();
        int v = da.v;
        int s = da.s;
        ll x = da.x;
        
        // dp[v][s] = 10 となるようなのがqueにpushされた後, これが取り出される前に
        // dp[v][s] = 5 となるようなのがqueにpushされることはありえる
        // この場合、dp[v][s] = 5を取り出して、処理した後にdp[v][s] = 10というのを取り出すということが発生して、計算量が増えるので
        // 以下で、queに突っ込まれた後に、最小値が更新されてたら抜けるというのをいれている.
        // queは常に最小時間を先に取り出すし、dpテーブルも常に最新の最小時間情報が保存されているので、一致しない = 最小時間ではない
        if (dp[v][s] != x) continue;

        // 今の地点で、銀貨を1枚金貨に交換する
        {
            int ns = min(s + c[v], MAX_S);
            push(v, ns, x + d[v]);
        }
        // 隣接する頂点に交通量を払って移動する
        for(Edge e : g[v]) {
            push(e.to, s-e.a, x+e.b);
        }
    }

    for(int i=1; i < n; i++) {
        ll ans = INF;
        rep(j, MAX_S+5) {
            ans = min(ans, dp[i][j]);
        }
        cout << ans << endl;
    }



    return 0;
}

Measured memory_bytes: 6224
import java.util.*

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val S = readLine()!!

    val v = S.map { if (it == 'B') 1L else 0L }
    val MOD = 1000000007L

    var c = 0L
    var res = ModInt(1, MOD)

    for (i in v.indices) {
        if (c % 2L == v[i]) {
            if (c == 0L) {
                println(0)
                return
            }

            res *= c
            c--
        } else {
            c++
        }
    }

    if (c != 0L) {
        println(0)
        return
    }

    for (i in 1L .. N) {
        res *= i
    }

    println(res.value)
}

class ModInt (value: Long, val mod: Long) {
    init {
        if (mod <= 0) {
            throw IllegalArgumentException("ModInt cannot be created for non-positive modulus: $mod")
        }
    }

    val value = (value % mod + mod) % mod

    private fun assertSameMod(other: ModInt) {
        if (mod != other.mod) {
            throw IllegalArgumentException(
                "You cannot operate summation, subtraction and multiplication for ModInts with different moduli: $mod, ${other.mod}"
            )
        }
    }

    operator fun unaryMinus() = ModInt(mod - value, mod)

    operator fun plus(other: ModInt): ModInt {
        assertSameMod(other)

        return ModInt((value + other.value) % mod, mod)
    }

    operator fun plus(other: Long) = plus(ModInt(other, mod))

    operator fun minus(other: ModInt): ModInt {
        assertSameMod(other)

        return plus(-other)
    }

    operator fun minus(other: Long) = minus(ModInt(other, mod))

    operator fun times(other: ModInt): ModInt {
        assertSameMod(other)

        return ModInt((value * other.value) % mod, mod)
    }

    operator fun times(other: Long) = times(ModInt(other, mod))

    fun pow(k: Long): ModInt {
        var res = 1L
        var a = value
        var l = k

        while (l > 0) {
            if ((l and 1L) == 1L) {
                res = (res * a) % mod
            }

            a = a * a % mod
            l /= 2L
        }

        return ModInt(res, mod)
    }

    /**
     * Returns an inverse element of the value.
     * To ensure `m * m.inv() = 1`, the modulus should be prime, since it uses Fermat's little theorem.
     */
    fun inv() = pow(mod - 2)

    operator fun div(other: ModInt): ModInt {
        assertSameMod(other)
        if (other.value == 0L) {
            throw ArithmeticException()
        }

        return times(other.inv())
    }

    operator fun div(other: Long) = div(ModInt(other, mod))
}


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

int main() {
  int N; cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a.at(i);
  vector<vector<long long>> dp(3010, vector<long long>(3010, 0));
  for (int len = 1; len <= N; len++) {
    for (int i = 0; i <= N - len; i++) {
      int j = i + len;
      if ((N - len) % 2 == 0) {
        dp.at(i).at(j) = max(dp.at(i+1).at(j) + a.at(i), dp.at(i).at(j-1) + a.at(j-1));
      }
      else {
        dp.at(i).at(j) = min(dp.at(i+1).at(j) - a.at(i), dp.at(i).at(j-1) - a.at(j-1));
      }
    }
  }
  cout << dp.at(0).at(N) << endl;
}

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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    int A,B,C; cin >>A>>B>>C;

    int ans = A==B?C:(B==C?A:B);

    cout << ans << endl;
}

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

class MainClass
{
    static void Main()
    {
        string[] S = new string[3];
        S[0] = Console.ReadLine();
        S[1] = Console.ReadLine();
        S[2] = Console.ReadLine();

        int[] index = new int[3];
        int num = 0;
        while (true)
        {
            if (S[num].Length <= index[num])
            {
                Console.WriteLine(indexToS(num));
                return;
            }
            char c = S[num][index[num]];
            index[num]++;

            num = c - 'a';
        }
    }
    static string indexToS(int index)
    {
        if (index == 0) return "A";
        else if (index == 1) return "B";
        else return "C";
    }
}

Measured memory_bytes: 25888
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}

ll gcd(ll a,ll b){return b ? gcd(b,a%b) :a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

ll kosuu(ll a){
    ll sum=0;
    for(ll i=1;i*i<=a;i++){
        if(a%i==0){
            if(a!=1&&i*i!=a){
            sum+=2;
            }else{
             sum++;   
            }
        }
    }
    return sum;
}

ll n;



    vector<pair<ll,ll>>p;
void fs(ll a){
    for(ll i=2;i*i<=n;i++){
        ll cnt=0;
        while(n%i==0){
            n/=i;
            cnt++;
        }
        p.emplace_back(i,cnt);
    }
    return;
}


int main()
{
cin>>n;
 fs(n);
 if(n!=1)p.emplace_back(n,1);
 ll ans=0;
 for(auto x:p){
     ll b=1;
     while(0<=x.second-b){
         ans++;
         x.second-=b;
         b++;
     }
 }
cout<<ans<<endl;
}



Measured memory_bytes: 19748
#include <set>
#include <map>
#include <list>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;

int main(){
    int n;
    float A[10000];
    cin >> n;
    for(int i=0;i<n;i++)cin >> A[i];
    float ans = 0;
    for(int i=0;i<n;i++)ans += 1/A[i];
    cout << 1/ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


void solve(){
	int a;
	cin >> a;
	cout << (a + a*a + a*a*a) << endl;
}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

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


Measured memory_bytes: 3640
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        int reader = int.Parse(ReadLine());
        long[] ryuka = new long[reader+1];
        ryuka[0] = 2;
        ryuka[1] = 1;
        for(int i=2;i<=reader;i++){
            ryuka[i] = ryuka[i-1]+ryuka[i-2];
        }
        WriteLine(ryuka[reader]);
    }
}

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

void rot4(int& a,int& b,int& c,int& d){
	int tmp;
	tmp=a;
	a=b;
	b=c;
	c=d;
	d=tmp;
}

int main(){
	int n,sum,dice[6];
	string order;
	while(true){
		cin>>n;
		if(n==0)break;
		for(int i=0;i<6;i++)dice[i]=i+1;
		sum=1;
		for(int i=0;i<n;i++){
			cin>>order;
			if(order=="North"){
				rot4(dice[0],dice[1],dice[5],dice[4]);
			}else if(order=="East"){
				rot4(dice[0],dice[3],dice[5],dice[2]);
			}else if(order=="West"){
				rot4(dice[0],dice[2],dice[5],dice[3]);
			}else if(order=="South"){
				rot4(dice[0],dice[4],dice[5],dice[1]);
			}else if(order=="Right"){
				rot4(dice[1],dice[2],dice[4],dice[3]);
			}else if(order=="Left"){
				rot4(dice[1],dice[3],dice[4],dice[2]);
			}
			sum+=dice[0];
		}
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
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 main() {
    let s: String = read();
    let t: String = read();
    let s: Vec<char> = s.chars().collect();
    let t: Vec<char> = t.chars().collect();

    let mut count: u32 = 0;

    for (c1, c2) in s.iter().zip(t.iter()) {
        if c1 != c2 {
            count += 1
        }
    }
    
    println!("{}", count);
}


Measured memory_bytes: 4104
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

void dfs(int c, int p, vvi &edges, vi &group, int i) {
    group[c] = i;
    for (auto &n : edges[c]) {
        if (n == p)
            continue;
        dfs(n, c, edges, group, i);
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vvi edges(n);
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }
    // already a tree
    if (n - 1 == m) {
        cout << 0 << "\n";
        return 0;
    }
    priority_queue<ll, vl, greater<ll>> pq;
    vi group(n, -1);
    int idx = 0;
    for (int i = 0; i < n; ++i) {
        if (group[i] == -1) {
            dfs(i, -1, edges, group, idx);
            idx++;
        }
    }
    if (2 * (idx - 1) > n) {
        cout << "Impossible"
             << "\n";
        return 0;
    }
    vector<priority_queue<ll, vl, greater<ll>>> nodes(idx);
    for (int i = 0; i < n; ++i) {
        nodes[group[i]].push(a[i]);
    }
    ll ret = 0;
    for (int i = 0; i < idx; ++i) {
        ret += nodes[i].top();
        nodes[i].pop();
        while (!nodes[i].empty()) {
            pq.push(nodes[i].top());
            nodes[i].pop();
        }
    }
    for (int i = 0; i < 2 * (idx - 1) - idx; ++i) {
        ret += pq.top();
        pq.pop();
    }
    cout << ret << "\n";

    return 0;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n,m,q;
  cin >> n >> m >> q;

  vector<int> a(q),b(q),c(q),d(q);

  rep(i,q){
    cin >> a[i] >> b[i]>> c[i] >> d[i];
    --a[i];--b[i];
  }
  ll ans = 0;
  rep(i,1<<(n+m-1)){
    if(__builtin_popcount(i) != n) continue;
    int cn = 1;
    vector<int> arr;
    rep(j,n+m-1){
      if((1<<j) & i){
        arr.pb(cn);
      }
      else{
        cn++;
      }
    }
    ll tans = 0;
    rep(j,q){
      if(arr[b[j]] - arr[a[j]] == c[j]) tans += d[j];
    }
    ans = max(tans,ans);
  }
  cout << ans << endl;

  return 0;
    



}


Measured memory_bytes: 3636