akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
#define pb push_back

using namespace std;

const int N=1e5+5, INF=1e18;

int n, arr[N], mx=-INF;
signed main()
{
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	for(int c = 1; c < n; c++)
	{
		int currmx=-INF;
		vector<int> jc, jcpd, pjc, sjcpd;
		int d = c + (n-1)%c, sz = 0;
		if(d==c) while(n+c-1>2*d) d+=c;
	//	cout << c << " - " << d << endl;
		jc.pb(0); jcpd.pb(0);	pjc.pb(0); sjcpd.pb(0);
		for(int j = d; j < n; j+=c)
		{
			sz++;
			//if(j!=n-1) 
				jc.pb(arr[sz*c]);
			//else jc.pb(0);
			jcpd.pb(arr[j]);
			pjc.pb(pjc.back()+jc.back());
			sjcpd.pb(0);
		}
		sjcpd[sz]=jcpd[sz];
		for(int j = sz - 1; j >= 0; j--)
		{
			sjcpd[j]=sjcpd[j+1]+jcpd[j];
		}
		/*for(int j = 0; j <= sz; j++)
		{
			cout << jc[j] << "  ";
		}
		cout << endl;
		for(int j = 0; j <= sz; j++)
		{
			cout << jcpd[j] << "  ";
		}
		cout << endl;*/
		for(int j = 1; j <= sz; j++)
		{
	//		cout << j << " - " << sjcpd[j] << " " << pjc[sz - j] << endl;
			currmx = max(currmx, sjcpd[j] + pjc[sz - j]);
		}
		mx = max(currmx, mx);
	}
	cout << mx;
}


Measured memory_bytes: 3780
// Vicfred
// https://atcoder.jp/contests/abc175/tasks/abc175_b
// implementation, math
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    long N = readln.chomp.to!long;
    long[] L = readln.split.map!(to!long).array;

    L.sort;

    long ans = 0;
    for(int i = 0; i < N; ++i) {
        for(int j = i+1; j < N; ++j) {
            for(int k = j+1; k < N; ++k) {
                if(L[i] == L[j] || L[j] == L[k] || L[i] == L[k])
                    continue;
                if(L[i] + L[j] > L[k]) 
                    ans += 1;
            }
        }
    }
    ans.writeln;
}



Measured memory_bytes: 2732
using System;
using System.Collections.Generic;

namespace abc174_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var N = CIn.ReadInt();
      var D = CIn.ReadInt();

      var d2 = (long)D * D;

      var ans = 0;

      var hs = new HashSet<(int, int)>();

      for (int i = 0; i < N; i++)
      {
        var X = CIn.ReadInt();
        var Y = CIn.ReadInt();

        if ((long)X * X + (long)Y * Y <= d2)
        {
          ans++;
        }
      }

      Console.WriteLine(ans);
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(int n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(int n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(int n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(int n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }

    public static char[,] ReadCharMatrix(int h, int w)
    {
      var array = new char[h, w];
      for (var i = 0; i < h; i++)
      {
        var l = Console.ReadLine().ToCharArray();
        for (var j = 0; j < w; j++)
        {
          array[i, j] = l[j];
        }
      }
      return array;
    }
  }
}


Measured memory_bytes: 40936
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,f,l;
    cin>>n;
    f=n/100;
    l=n%100;
    if(f<=12&&l<=12&&f!=0&&l!=0)
        cout<<"AMBIGUOUS"<<endl;
    else if((f>12||f==0)&&l<=12&&l!=0)
        cout<<"YYMM"<<endl;
    else if((l>12||l==0)&&f<=12&&f!=0)
        cout<<"MMYY"<<endl;
    else
        cout<<"NA"<<endl;
}


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

int main() {
    int n, m, k; cin >> n >> m >> k;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            if (i * m + j * n - 2 * i * j == k) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No\n";
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { cout << p.first << ' ' << p.second; return os; }

void solve() {
  int K; cin >> K;

  vector<bool> seen(K);

  deque<pair<int, int>> q;
  q.emplace_front(1, 1);
  while (true) {
    int v, c;
    tie(v, c) = q.front(), q.pop_front();
    if (seen[v]) continue;
    seen[v] = true;
    if (v == 0) {
      cout << c << '\n';
      return;
    }
    q.emplace_front((v * 10) % K, c);
    q.emplace_back((v + 1) % K, c + 1);
  }
}


Measured memory_bytes: 1152
#include <iostream>
using namespace std;
int main(void){
    int N, i, a, b, c, d, x=1, y=0;
    int bm, dm, as;

    cin >> N;
    for (i = 0;i < N; i++) {
        cin >> a;
        if (a == 0) x = 0;
        x++;
        if (x > y) y = x;
    }

    cout << y << endl;
    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <math.h>
using namespace std;
 
int main(void){
	int n,i;
	long t,a,x,y,r;
	cin >> n;
	cin >> x;
	cin >> y;
	for(i=1;i<n;i++){
		cin >> t >> a;
		if(x/t>y/a){
			r=x/t;
			if(x%t==0){
				y=a*r;
			}else{
				x=t*(r+1);
				y=a*(r+1);
			}
		}else if(x/t<y/a){
			r=y/a;
			if(y%a==0){
				x=t*r;
			}else{
				x=t*(r+1);
				y=a*(r+1);
			}
		}else{
			r=y/a;
			if((x%t==0)&&(y%a==0)){
				x=t*r;
				y=a*r;
			}else{
				x=t*(r+1);
				y=a*(r+1);
			}
		}
	}
	cout << (x+y);
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		int p[][] = new int[M][3];

		for(int i=0;i<M;i++) {
			p[i][0]=i+1;
			p[i][1]= in.nextInt();
			p[i][2]= in.nextInt();

		}
	    Arrays.sort(p, new Comparator<int[]>() {
	        @Override
	        public int compare(int[] o1, int[] o2) {
	            return o1[2] - o2[2];    //[0] をキーにソート(昇順)
	            //return o2[0] - o1[0];    //[0] をキーにソート(降順)
	        }
	    });
	    Arrays.sort(p, new Comparator<int[]>() {
	        @Override
	        public int compare(int[] o1, int[] o2) {
	            return o1[1] - o2[1];    //[0] をキーにソート(昇順)
	            //return o2[0] - o1[0];    //[0] をキーにソート(降順)
	        }
	    });
	    int p1=1;
	    int sum=0;
	    for (int i = 0; i < M; i++) {
	    	if(p1!=p[i][1]) {
	    		p1=p[i][1];
	    		sum=0;
	    	}
	    	sum++;
	    	p[i][2]=sum;
	    }
	    
	    
	    Arrays.sort(p, new Comparator<int[]>() {
	        @Override
	        public int compare(int[] o1, int[] o2) {
	            return o1[0] - o2[0];    //[0] をキーにソート(昇順)
	            //return o2[0] - o1[0];    //[0] をキーにソート(降順)
	        }
	    });
	    StringBuilder val = new StringBuilder();
		for (int i = 0; i < M; i++) {

			val.append(String.format("%06d",p[i][1])).append(String.format("%06d",p[i][2])).append("\n");
			
		}
		System.out.println(new String(val));
	}
}

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

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)
typedef long long ll;

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);
int gcd(int a, int b);

int main() {
    string s;
    cin >> s;
    int a = (s[0] - '0') * 10 + (s[1] - '0');
    int b = (s[2] - '0') * 10 + (s[3] - '0');

    if(0 < a && a <= 12 && 0 < b && b <= 12) {
        cout << "AMBIGUOUS" << endl;
    } else if(0 < a && a<=12) {
        cout << "MMYY" << endl; 
    } else if(0 < b && b<=12) {
        cout << "YYMM" << endl;
    } else {
        cout << "NA" << endl;
    }

    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}

// ユークリウッドの互除法
int gcd(int a, int b) {
    if(b==0) return a;
    else return gcd(b, a % b);
}



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


signed main(){
    int value, i=1;

    while(1){
        std::cin >> value;
        if(value == 0){
            break;
        }
        std::cout << "Case " << i << ": " << value << std::endl;
        i++;
    }

    return 0;
}


Measured memory_bytes: 3016
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

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

  int A[N];
  int sum = 0;
  rep(i, N) {
    cin >> A[i];
    sum += A[i];
  }

  double criterion = double(sum) / double((4 * M));

  sort(A, A + N);

  bool ans = true;
  rep(i, M) {
    double item = A[N - 1 - i];
    if (item < criterion) {
      ans = false;
    }
  }

  if (ans == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque
def main():
    N = int(input())
    P = list(map(int, input().split()))
    costs = [-1 for _ in range(N**2)]
    sit = [1 for _ in range(N**2)]
    for i in range(N**2):
        q, mod = divmod(i, N)
        up, down, left, right = q, N-q-1, mod, N-mod-1
        costs[i] = min(up, down, left, right)
    ans = 0
    for p in P:
        ans += costs[p-1]
        sit[p-1] = 0
        que = deque([])
        que.append((p-1, costs[p-1]))
        while len(que) != 0:
            v, d = que.popleft()
            if v > N and costs[v-N] > d:
                costs[v-N] = d
                que.append((v-N, d+sit[v-N]))
            if v < N**2-N-1 and costs[v+N] > d:
                costs[v+N] = d
                que.append((v+N, d+sit[v+N]))
            if v % N != 0 and costs[v-1] > d:
                costs[v-1] = d
                que.append((v-1, d+sit[v-1]))
            if (v+1) % N != 0 and costs[v+1] > d:
                costs[v+1] = d
                que.append((v+1, d+sit[v+1]))
    print(ans)
if __name__ == "__main__":
    main()

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b)* b; }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n,m; cin>>n>>m;
  string s,t; cin>>s>>t;
  int g = GCD(n,m);
  ll ans = (ll)n/g*m;
  bool ok = true;
  rep(i,g){
    if(s[i*n/g]!=t[i*m/g]) ok=false;
  }
  if(!ok) cout<<-1<<endl;
  else cout<<ans<<endl;
}

Measured memory_bytes: 640
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = []
for i in range(n):
    a.append(na())

def code(l, r, of):
    if l > r:
        l, r = r, l
    return of[l] + r-l-1

of = [0] * (n+1)
for i in range(n):
    of[i+1] = of[i] + n-i-1
g = [[] for _ in range(n*(n-1)//2)]
for i in range(n):
    for j in range(n-2):
        fcode = code(i, a[i][j]-1, of)
        tcode = code(i, a[i][j+1]-1, of)
        g[fcode].append(tcode)

def sort_topologically(g):
    n = len(g)
    ec = [0] * n
    for i in range(n):
        for e in g[i]:
            ec[e] += 1
    ret = [0] * n
    q = 0

    for i in range(n):
        if ec[i] == 0:
            ret[q] = i
            q += 1

    p = 0
    while p < q:
        for to in g[ret[p]]:
            ec[to] -= 1
            if ec[to] == 0:
                ret[q] = to
                q += 1
        p += 1

    for i in range(n):
        if ec[i] > 0:
            return None
    return ret

od = sort_topologically(g)
if not od:
    print(-1)
else:
    dp = [1] * (n*(n-1)//2)
    for i in range(n*(n-1)//2):
        for e in g[od[i]]:
            dp[e] = max(dp[e], dp[od[i]] + 1)
    print(max(dp))


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

int main() {
  int A, B, C;
  vector<int> vec(3);

  for(int i=0;i<3;i++){
    cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  int max;
  max = vec.at(0) * 10 + vec.at(1) + vec.at(2);

  cout << max << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std ; 

typedef long long ll ; 

int r[111111] ; 
int stat[111111] ;

int main()
{
    int N, M ; 
    scanf("%d%d", &N, &M) ; 
    for(int i = 1 ; i <= N ; i++)
        stat[i] = 1 ; 
    r[1] = true ;
    for(int i = 0 ; i != M ; i++){
        int x, y ; 
        scanf("%d%d", &x, &y) ; 
        stat[x]-- ; 
        stat[y]++ ; 
        r[y] |= r[x] ; 
        if(stat[x] == 0)
            r[x] = false ; 
    }
    int ans = 0 ;
    for(int i = 1 ; i <= N ; i++){
        if(stat[i] && r[i])
            ans++ ; 
    }
    printf("%d\n", ans) ; 
    return 0 ; 
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
  int N,K;cin>>N>>K;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  sort(v.begin(),v.end());
  int ans=1e12;
  for(int i=0;i<N-K+1;i++){
    ans=min(ans,v[i+K-1]-v[i]);
  }
  cout<<ans<<endl;
}


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

int main() {
	int n;
	cin >> n;

	string s;
	vector<int> ans(4,0);

	for (int i = 0; i < n; i++) {
		cin >> s;
		if		(s == "AC")	ans[0]++;
		else if	(s == "WA")	ans[1]++;
		else if	(s == "TLE")ans[2]++;
		else				ans[3]++;
	}

	cout << "AC x " << ans[0] << endl;
	cout << "WA x " << ans[1] << endl;
	cout << "TLE x " << ans[2] << endl;
	cout << "RE x " << ans[3] << endl;
}

Measured memory_bytes: 3628
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(a%b,b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}


int main(){
    init();
	ll N,K;cin>>N>>K;
	//1-indexedで管理
	vector<pair<ll,ll>>G;
	for(int i=2;i<=N;i++){
		G.push_back(make_pair(1,i));
	}

	ll nowK=(N-1)*(N-2)/2;
	if(K>nowK){
		cout<<-1<<endl;
		return 0;
	}
	ll start=2;
	ll fin=2;
	while(nowK>K){
		//削除してく
		fin++;
		if(fin>N){
			start++;
			fin=start;
			continue;
		}
		G.push_back(make_pair(start,fin));
		nowK--;
	}
	cout<<G.size()<<endl;
	for(int i=0;i<G.size();i++){
		cout<<G[i].first<<" "<<G[i].second<<endl;
	}
}

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

int arr1[111111],arr2[111111],m1=1e9,m2=1e9;
int main(void){
	int a,b,m;
	scanf("%d%d%d",&a,&b,&m);
	for(int e=0;e<a;e++){
		scanf("%d",&arr1[e]);
		m1 = min(m1,arr1[e]);
	}
	for(int e=0;e<b;e++){
		scanf("%d",&arr2[e]);
		m2 = min(m2,arr2[e]);
	}
	int ans = m1+m2;
	for(int e=0;e<m;e++){
		int x,y,c;
		scanf("%d%d%d",&x,&y,&c);
		x--;
		y--;
		ans = min(ans,arr1[x]+arr2[y]-c);
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void run() {
		Map<Character, Character> map = new HashMap<Character, Character>();
		int n, m;
		String s;
		StringBuilder sb = new StringBuilder();
		char c;
		while (true) {
			n = sc.nextInt();
			if (n == 0) break;
			sc.nextLine();
			map.clear();
			for (int i = 0; i < n; i++) {
				s = sc.nextLine();
				map.put(s.charAt(0), s.charAt(2));
			}
			m = sc.nextInt();
			sc.nextLine();
			sb.setLength(0);
			for (int i = 0; i < m; i++) {
				s = sc.nextLine();
				c = s.charAt(0);
				if (map.containsKey(c)) {
					sb.append(map.get(c));
				} else {
					sb.append(c);
				}
			}
			out.println(sb);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 139656
const main = (input) => {
  input = input.split(' ');
  const X = parseInt(input[0], 10);
  const A = parseInt(input[1], 10);
  const B = parseInt(input[2], 10);
  
  if (X+A<B) {
    console.log("dangerous");
  }else if (A-B>=0) {
    console.log("delicious");
  }else{
    console.log("safe");
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma") 
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD=1e9+7;
template <class Q>
void clearQueue(Q & q) {
    q=Q();
}
void solve(){
	int x;cin>>x;
	if(x==0) cout<<1;
	else cout<<0;
}	
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL); 
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
//#endif
	int T=1;
	// cin>>T;
	while(T--){
		solve();
	}
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

void solve(){
    ll n;
    cin>>n;
    
    ll ans=n-1;
    for(ll a=2;a*a<=n;a++){
        if(n%a==0){
            ans=min(ans,a + n/a -2);
        }
    }
    cout<<ans<<endl;
}

int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
#define MOD 1000000007
using namespace std;
typedef long long ll;



int main(void) {
	int n, k; cin >> n >> k;
	vint s(n+1);
	rep(i, k) {
		int d; cin >> d;
		rep(i, d) {
			int a;
			cin >> a;
			s[a]++;
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (s[i] == 0) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
			int a=scan.nextInt();
			int b=scan.nextInt();
			int c=scan.nextInt();
			int x,y=0;
			for(x=a;x<=b;x++) {
				if(c%x == 0)
					y=y+1;
			}
			System.out.println(y);
		scan.close();
}
}


Measured memory_bytes: 26384
#include <stdio.h>

int cnt=0;

void merge(int A[],int left,int mid,int right)
{
  int n1,n2,i,j,k;
  n1=mid-left;
  n2=right-mid;
  int L[n1+1];
  int R[n2+1];
  for(i=0;i<n1;i++) L[i]=A[left+i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  L[n1]=1000000001;
  R[n2]=1000000001;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    cnt++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }else{
      A[k] = R[j];
      j++;
    }
  }
}

void mergeSort(int A[],int left,int right)
{
  if(left+1<right){
    int mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}


int main()
{
  int n,i,A[500000];
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  mergeSort(A,0,n);
  for(i=0;i<n;i++) {
    printf("%d",A[i]);
    if(i==n-1) printf("\n");
    else printf(" ");
  }
  printf("%d\n",cnt);
  return 0;
}



Measured memory_bytes: 5612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();


		int[] hana = new int[N];

		for(int i = 0; i< N; i++) {
			hana[i] = sc.nextInt();
		}


		int water = 0;

		int max = hana[0];
		int maxnum = 0;
		for(int i = 0; i< N;i++) {

			if(max < hana[i]) {
				maxnum = i;
				max = hana[i];
			}
		}//最大みつけて場所をmaxnumに



		for(;;) {

			int nzmin =  100;
			
			int divCnt = 0;

			for(int i = 0; i< N;i++) {

				if(nzmin > hana[i] && hana[i] > 0) {
					nzmin = hana[i];
				}
			}//0以外の最小値をnzminに
			boolean lastExit =false;
			for(int i = 0; i< N;i++) {
				
				if(!(lastExit) &&hana[i] > 0) {
					divCnt++;
					lastExit = true;
				}
				
				if(hana[i] <= 0) {
					
					lastExit = false;
				}
			}
			
			

			water += (nzmin * divCnt);

			for(int i = 0; i<N;i++) {
				if(hana[i] > 0) {
					hana[i] -= nzmin;
				}
			}//0以外からnzmin(最小値)を引く



			if(hana[maxnum] <= 0) {
				break;
			}
		}
		System.out.println(water);

	}

}


Measured memory_bytes: 21844
import scala.io.StdIn.readInt

object Main {
  val r = Array(2,3,5,7)

  def twoPow(d:Int,s:Int):(Int,Int) = {
    if(d%2 == 1) (d,s)
    else twoPow(d>>1,s+1)
  }

  def maybePrime(i:Int,d:Int,s:Int, n:Int):Boolean = {
    if(i>3) true
    else {
      val a = r(i)
      val x = BigInt(a).modPow(d,n).toInt

      if(x==1 || x==n-1) maybePrime(i+1,d,s,n)
      else repeat(s-1,BigInt(x).modPow(2,n).toInt, i, d, s, n)
    }
  }

  def repeat(j:Int, x:Int, i:Int, d:Int, s:Int, n:Int):Boolean = {
    if(j==0) false
    else if(x==1) false
    else if(x==n-1) maybePrime(i+1,d,s,n)
    else repeat(j-1,BigInt(x).modPow(2,n).toInt,i,d,s,n)
  }

  def isPrime(n:Int):Boolean = {
    if(n<5000) (2 to Math.sqrt(n).toInt).forall(n%_ != 0)
    else if(n%2==0) false
    else {
      val (d,s) = twoPow(n-1,0)
      maybePrime(0,d,s,n)
    }
  }

  def main(args:Array[String]) = {
    val n = readInt
    println((0 until n).count{ _=> isPrime(readInt) })
  }
}

Measured memory_bytes: 67352
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

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

    ll N;
    cin >> N;
    print(devc(N, 2));

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <vector>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
	int n;
	cin >> n;

	double x = 1;

	while (x <= n)
	{
		if (floor(x * 1.08) == n)
		{
			cout << x;
			return 0;
		}
		x++;
	}
	cout << ":(";
}

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

int main()
{
	long long x;
	cin >> x;
	cout << (x / 11 * 2 + (x % 11 == 0 ? 0 : x % 11 <= 6 ? 1 : 2)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long
template<class T> void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }
using namespace std;

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

	vector<vector<int> > abc(100010,vector<int>(3));
	rep(i, N) cin >> abc[i][0] >> abc[i][1] >> abc[i][2];

	vector<vector<int> > dp(100010,vector<int>(3));
	rep(i, 3) dp[0][i] = abc[0][i];

	for (int i = 1; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			dp[i][j] = max(dp[i - 1][(j + 1) % 3] + abc[i][j], dp[i - 1][(j + 2) % 3] + abc[i][j]);
		}
	}

	cout << *max_element(dp[N - 1].begin(), dp[N - 1].end()) << endl;
}

Measured memory_bytes: 11136
#include <cstdio>

int main()
{
	int k,a,b;
	scanf("%d", &k);
	scanf("%d %d", &a, &b);
	bool flag = false;

	for(int i = a; i <= b && !flag; i++) {
		// printf("%d , %d, %d\n", i, k, i%k);
		if((i % k) == 0) {
			flag = true;
		}
	}

	if(flag) {
		printf("OK");
	} else {
		printf("NG");
	}

	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
 
long GCD(long x, long y){
    if(x<y){
        long tmp;
        tmp=x;
        x =y;
        y =tmp;
    }
 
    long r=x%y;
    while(r!=0){
        x=y;
        y=r;
        r=x%y;
    }
 
    return y;
}

int main(){

    long K;
    cin >> K;

    long tmp, ans;
    ans=0;

    for(long a=1; a<=K; a++){
        for(long b=1; b<=K; b++){
            for(long c=1; c<=K; c++){
                tmp = GCD(a,b);
                tmp = GCD(tmp,c);
                //cout << "a b c tmp ans" << a << " " << b << " " << c << " " << tmp << " " << ans << endl;
                ans += tmp;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
m = list(map(int, input().split()))
count = 0
k = m[3]
if m[0] < k:
    count = m[0]
    k = k - m[0]
    if m[1] < k:
        k = k - m[1]
        if m[2] < k:
            count -= m[2]
        else:
            count -= k
    else:
        count
else:
    count = k
print(count)

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

#define MAXSIZE 1000000
#define DIV 1000000007

long long frac[MAXSIZE];
long long inv[MAXSIZE];

long long mypow(long long x, long long n){
    long long ret=1,p,l=1,p2=1;
    p=x;
    while(1){
        if(n&p2) ret*=p;
        p*=p;
        ret%=DIV;
        p%=DIV;
        p2*=2;
        if(p2>n) break;
    }
    return ret;
}

void nCk_init(){
    //cout << "nCk_init start\n";
    frac[0]=1;
    inv[0]=1;
    for(int i=1; i<MAXSIZE; i++){
        frac[i]=(long long)frac[i-1]*i;
        frac[i]%=DIV;
        inv[i]=mypow(frac[i],DIV-2);
        inv[i]%=DIV;
    }
    //cout << "nCk_init finished\n";
}
long long nCk(long long n,long long k){
    //printf("nCk(%d,%d) start\n",n,k);
    long long ret;
    ret = frac[n];
    ret = ((long long)ret*inv[n-k])%DIV;
    ret = ((long long)ret*inv[k])%DIV;
    return ret;
    //cout << "nCk finished\n";
}
long long nHk(long long n,long long k){
    return nCk(n+k-1,n-1);
}

int main(){
    nCk_init();
    long long n,k,ans=0;
    cin >> n >> k;
    if(n<k) k=n-1;
    for(long long m=k; m>=0; m--){
        ans += ((long long)nCk(n,m)*nHk(n-m,m));
        ans %=DIV;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 15872
import itertools
import numpy as np
n,m,x = map(int, input().split())
book = list()*n
for i in range(n):
    temp = input().split()
    book.append(temp)

matrix = np.array(book, dtype="int")
decide = np.array(list(itertools.product([True,False],repeat=n)))
decide = decide[:-1]
money = -1
for i in range(len(decide)):
    test = np.sum(matrix[np.where(decide[i,:]),:], axis = 0)
    test = np.sum(test, axis = 0)
    #print(test)
    #print(test[0])
    #print(np.sum(test[1:]>=x))
    if np.sum(test[1:]>=x) == m and (money > test[0] or money == -1):
        #print("koko")
        money = test[0]
if money == 1e6:
    print("-1")
else :
    print(money)

Measured memory_bytes: 27772
=begin
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------hoi-------         |
  |_________________________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
=end
a, b, c, d = 0, 0, 0, 0
s = gets.chomp
s.each_char { |x| a += 1 if x == 'N'; b += 1 if x == 'S'; c += 1 if x == 'W'; d += 1 if x == 'E'}
if((a > 0 && b == 0) || (b > 0 && a == 0) || (c > 0 && d == 0) || (c == 0 && d > 0))
    puts("No")
else
    puts("Yes")
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
namespace Flandre_Scarlet
{
	#define N 2333
	#define F(i,l,r) for(int i=l;i<=r;++i)
	#define D(i,r,l) for(int i=r;i>=l;--i)
	#define Fs(i,l,r,c) for(int i=l;i<=r;c)
	#define Ds(i,r,l,c) for(int i=r;i>=l;c)
	#define MEM(x,a) memset(x,a,sizeof(x))
	#define FK(x) MEM(x,0)
	#define Tra(i,u) for(int i=G.Start(u),v=G.To(i);~i;i=G.Next(i),v=G.To(i))
	#define p_b push_back
	#define sz(a) ((int)a.size())
	#define iter(a,p) (a.begin()+p)
	int I()
	{
	    int x=0;char c=getchar();int f=1;
	    while(c<'0' or c>'9') f=(c=='-')?-1:1,c=getchar();
	    while(c>='0' and c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	    return (x=(f==1)?x:-x);
	}
	void Rd(int cnt,...)
	{
	    va_list args; va_start(args,cnt);
	    F(i,1,cnt) {int* x=va_arg(args,int*);(*x)=I();}
	    va_end(args);
	}

	int n,a[N];
	void Input()
	{
		n=I(); F(i,1,n) a[i]=I();
	}

	vector<int> g[N],g2[N];
	bool vis[N];int ideg[N];
	void DFS(int u)
	{
		vis[u]=1;
		F(i,0,sz(g[u])-1)
		{int v=g[u][i];
			if (vis[v]) continue;
			++ideg[v]; g2[u].p_b(v);
			DFS(v);
		}
	}
	priority_queue<int> Q;
	void TopoSort()
	{
		F(i,1,n) if (!ideg[i]) Q.push(i);
		while(!Q.empty())
		{
			int u=Q.top(); Q.pop();
			printf("%d ",a[u]);
			F(i,0,sz(g2[u])-1) Q.push(g2[u][i]);
		}
	}
	void Soviet()
	{
		sort(a+1,a+n+1);
		F(i,1,n) F(j,i+1,n) if (__gcd(a[i],a[j])!=1) g[i].p_b(j),g[j].p_b(i);
		F(i,1,n) if (!vis[i]) DFS(i);
		TopoSort();
	}

	#define Flan void
	Flan IsMyWife()
	{
		Input();
		Soviet();
	}
}
int main()
{
	Flandre_Scarlet::IsMyWife();
	getchar();getchar();
	return 0;
}

Measured memory_bytes: 17792
import java.util.*;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String input = s.nextLine();
		Integer number = Integer.parseInt(input.split(" ")[0]);
		Integer quantum = Integer.parseInt(input.split(" ")[1]);
		Integer current_time = 0;
		ArrayList<String> queue = new ArrayList<String>();
		while(s.hasNext()){
			queue.add(s.nextLine());
		}
		s.close();
		String output = "";
		while(queue.size() > 0){
			String process = queue.remove(0);
			Integer result = get_time(process, quantum);
			if(result <= 0){
				current_time = current_time + quantum + result;
				output = output + process.split(" ")[0] + " " + current_time + "\n";
			}
			else{
				current_time += quantum;
				String process_result = process.split(" ")[0] + " " + result.toString();
				queue.add(process_result);
			}
			if(output.length() > 1000){
				System.out.print(output);
				output = "";
			}
		}
		System.out.print(output);

	}
	
	private static Integer get_time(String process, Integer quantum){
		Integer time = Integer.parseInt(process.split(" ")[1]);
		return time - quantum;
	}

}

Measured memory_bytes: 252360
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

typedef struct Plan {
	int t;
	int x;
	int y;
}Plan;
int main(void) {
	int n;
	cin >> n;
	vector<Plan> p(100005);
	int dt, dist = 0;
	p[0].t = p[0].x = p[0].y = 0;
	REPS(i, n) {
		cin >> p[i].t >> p[i].x >> p[i].y;
	}
	bool can = true;
	REP(i,n) {
		dt = abs(p[i + 1].t - p[i].t);
		dist = abs(p[i].x - p[i+1].x) + abs((p[i].y - p[i+1].y));
		if (dt < dist || (dt % 2 != dist % 2)) {
			can = false;
			break;
		}
	}
	if (can)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1408
k=int(input())
if k%7==0:
    q=9*k//7
else:
    q=9*k


now=10%q
if now==1:
    print(1) ;exit()
for ans in range(2,1000000):
    now= now*10%q
    if now==1:
        print(ans)
        exit()
print(-1)

Measured memory_bytes: 8892
//#define DEB1 //output check function
//#define DEB2 //same output, input from input.txt

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <thread>
#include <mutex>
#include <iomanip>

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define ALL(t) (t).begin(),(t).end()
#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define IN(a, x, b) (a<=x && x<b)
#define PB push_back

using namespace std;

using LL = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<LL,LL>;
using VI = vector<int>;
using VVI = vector<VI>;


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


#ifdef DEB1
#define DPRINT(x) cout<< #x << "=" << (x) << endl; // print at debug mode
#else
#define DPRINT(x) ;
#endif
#ifdef DEB1
#define DCHECK(x) cout<< "debug check" << #x << endl;
#else
#define DCHECK(x) ;
#endif
 


/*
constant values
*/

//const int dx[] = {1,0,-1,0};
//const int dy[] = {0,1,0,-1};
//const int MX = 31001;

//const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9

// Main program
LL dp[4][30000000]; //dp table

void solve(){
    int v[3],w[3],a[3],b[3];
    LL N; cin >> N;
    REP(i,3){
        cin >> a[i];
    }
    REP(i,3){
        cin >> b[i];
    }
    // A -> B
    REP(i,3){
        w[i] = a[i];
        v[i] = b[i] - a[i];
    }

    REP(j,30000000){
        dp[0][j]=0;
    }

    REP(i,3){
        REP(j,N+1){
            if (j < w[i]){ // too much
                dp[i + 1][j] = dp[i][j];
            }
            else{
                dp[i+1][j] = max(dp[i][j],dp[i+1][j - w[i]] + v[i]);
            }
        }
    }
    DPRINT(dp[3][N])
    N = N + dp[3][N];

    // B -> A
    REP(i,3){
        w[i] = b[i];
        v[i] = a[i] - b[i];
    }


    REP(i,3){
        REP(j,N+1){
            if (j < w[i]){ // too much
                dp[i + 1][j] = dp[i][j];
            }
            else{
                dp[i+1][j] = max(dp[i][j],dp[i+1][j - w[i]] + v[i]);
            }
        }
    }
    cout << N + dp[3][N] << endl;

}



// ----------------------------------------------
int main() {

#ifdef DEB2
    cout << "DEBUG MODE"  << endl;
	ifstream in("input.txt"); //for debug
	cin.rdbuf(in.rdbuf()); //for debug
#endif

	int T=1; 

	for (int i = 0; i < T; ++i) {
		solve();
	}
}

Measured memory_bytes: 825600
/***** TheAnshul *****/

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
#define N  3005
double dp[N][N];
bool vis[N][N];
double a[N];
ll n;
double fun(ll i,ll j)
{
	if(i-j-1>(n/2))
		return 0;
	if(i==n+1)
		return 1;
	if(vis[i][j])
	{
		// what_is(i);
		return dp[i][j];
	}
	vis[i][j]=1;
	// ll v1=fun(i+1,j+1)*a[i];
	// what_is(v1);
	// v1=fun(i+1,j)*(1-a[i]);
	// what_is(v1);
	dp[i][j]=fun(i+1,j+1)*a[i]+fun(i+1,j)*(1-a[i]);
	return dp[i][j];
}
void solve()
{
	cin>>n;
	rep(i,1,n+1)
	{
		rep(j,1,n+1)
		{
			dp[i][j]=-1.0;
		}
	}
	rep(i,1,n+1)
	cin>>a[i];
	cout<<setprecision(15)<<fun(1,0);
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	time
	return 0;
}

Measured memory_bytes: 79744
//作者：中国江苏省南京市李硕睿
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int n, m;
int a[200055];
int cnt[200055];
int d[200055];
int main(){
	cin>>n>>m;
	for (int i=0;i<n;i++){
		cin>>a[i];
		a[i]--;
		cnt[a[i]]++;
	}
	int res=0;
	for (int i=0;i<n;i++){
		for (int j=i;j>=max(0,i-cnt[i]+1);j--){
			d[j]++;
		}
	}
	for (int i=0;i<n;i++){
		if (d[i]==0){
			res++;
		}
	}
	while (m--){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		if (a[x]-cnt[a[x]]+1>=0){
			d[a[x]-cnt[a[x]]+1]--;
			if (d[a[x]-cnt[a[x]]+1]==0){
				res++;
			}
		}
		cnt[a[x]]--;
		cnt[y]++;
		if (y-cnt[y]+1>=0){
			d[y-cnt[y]+1]++;
			if (d[y-cnt[y]+1]==1){
				res--;
			}
		}
		a[x]=y;
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 3712
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

constexpr unsigned Mod = 1000000007;

constexpr unsigned Add(unsigned a, unsigned b) { return (a + b) % Mod; }

int main() {
  static char K[10001];
  int D;
  scanf("%s%d", K, &D);
  auto N = (int) strlen(K);
  static unsigned F[10001][100][2];
  F[0][0][1] = 1;
  for (auto i = 1; i <= N; ++i) {
    for (auto j = 0; j < D; ++j) {
      for (auto k = 0; k < 10; ++k) {
        auto l = (j + k) % D;
        F[i][l][0] = Add(F[i][l][0], F[i - 1][j][0]);
        if (k < K[i - 1] - '0')
          F[i][l][0] = Add(F[i][l][0], F[i - 1][j][1]);
        if (k == K[i - 1] - '0')
          F[i][l][1] = Add(F[i][l][1], F[i - 1][j][1]);
      }
    }
  }
  printf("%u\n", Add(F[N][0][0] + F[N][0][1], Mod - 1));
  return 0;
}


Measured memory_bytes: 8064
int main (){
 
  int n,h[500];
  int m[500];
  int M,k,g;
  int i,j;
  int t;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++) {
    scanf("%d %d",&h[i],&m[i]);
    //  printf("h[%d] = %d\n",i,h[i]);
  }
 
  scanf("%d",&M);
 
  t = n+M;
  for(i=n;i<t;i++) {
    scanf("%d %d",&h[i],&m[i]);
    // printf("h[%d] = %d\n",i,h[i]);
    for(j=0;j<n;j++) {
      if(h[i] == h[j] && m[i] == m[j]) {
    if(i == t -1) t--;
    else {
      i--;
      t--;
      break;
      //      printf("t = %d\n",t);
    }
      }
    }
  }
 
  // printf("t = %d\n",t);
 
    k = t;
    for(i=0;i<k;i++) {
      for(j=i;j<k;j++) {
    if(h[i] > h[j]) {
      t = h[i];
      h[i] = h[j];
      h[j] = t;
 
      t = m[i];
      m[i] = m[j];
      m[j] = t;
    } else if(h[i] == h[j]) {
      if(m[i] > m[j]) {
        t = m[i];
        m[i] = m[j];
        m[j] = t;
     
      }
    }
      }
    }
 
      for(i=0;i<k;i++) {
      printf("%d:%02d",h[i],m[i]);
      if(i != k-1) {
        printf(" ");
       
    }
      }
   
      printf("\n");
 
      return 0;
   
     
  }

Measured memory_bytes: 620
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1e9+7;

int main() {
  int n,k;
  cin>>n>>k;
  int count=1;
  while(n>=k){
    count++;
    n/=k;
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 256
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    int n;
    double m;
    cin >> n >> m;
    int a[n+1];
    double sum = 0;
    rep(i,n) {
        cin >> a[i];
        sum += a[i];
    }

    double border = sum / (m* 4.0);
    double counter = 0;
    rep(i, n) {
        double t = (double)a[i];
        if(t>=border) {
            counter+=1;
        }
    }

    print(counter>=m ? "Yes": "No");
    return 0;
}


Measured memory_bytes: 256