akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;
class UnionFind {
  private:
    int num;
    vector<int> par;
    vector<int> sizes;
    vector<int> rank;

  public:
    UnionFind(int n) { init(n); }

    ~UnionFind() {}

    int init(int n) {
        num = n;
        par.resize(n);
        sizes.resize(n);
        rank.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            sizes[i] = 1;
            rank[i] = 0;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        if (rank[rx] < rank[ry]) {
            par[rx] = ry;
        } else {
            par[ry] = rx;
            if (rank[rx] == rank[ry]) {
                rank[rx]++;
            }
        }
        int temp = sizes[rx] + sizes[ry];
        sizes[rx] = temp;
        sizes[ry] = temp;
    }

    int get_size(int x) { return sizes[root(x)]; }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
source:
    ll n, m;
    cin >> n >> m;
    ll p[n];
    rep(i, n) { cin >> p[i]; }
    UnionFind u(n);
    rep(i, m) {
        ll x, y;
        cin >> x >> y;
        u.unite(x - 1, y - 1);
    }
    ll ans = 0;
    rep(i, n) {
        if (u.same(p[i] - 1, i)) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define ll long long
#define sort(x) sort(x.begin(), x.end())
#define loop(n) for(ll i = 0; i<n; i++)
using namespace std;

int main(){
    ll n; cin>>n;
    vector<ll> arr(n);
    loop(n) cin>>arr[i];

    sort(arr);
    ll count = 0;
    loop(n-2){
        for(ll j = i+1; j<n-1; j++){
            if(arr[i]+arr[j]>arr[j+1]){
                for(ll k = j+1; k<n; k++)
                    if(arr[i]+arr[j]>arr[k]) count++;
            }
            
        }
    }
    cout<<count;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 1e5 + 5;
const int OO = 1e9;
const int mod = 1e9 + 7;

int n,m,x[N],y[N];
ll ans,cum,dif;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;

    for(int i=0;i<n;++i) cin >> x[i];
    for(int i=0;i<m;++i) cin >> y[i];

    sort(x,x+n);
    sort(y,y+m);

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

        dif = (dif + (1LL*x[i]*i - 1LL*x[i]*(n-1-i))%mod)%mod;

    }

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

        ans = (ans+(((1LL*y[i]*i - cum)%mod)*dif)%mod)%mod;
        cum = (cum+y[i])%mod;

    }

    cout << ans << '\n';

    return 0;

}

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

void print(int N,char A[][2]){
   for(int i=0;i<N;i++){
    if(i>0)cout<<" ";
    cout<<A[i][0];
    cout<<A[i][1];
   }
   cout<<endl;

}

bool isStable(int N,char in[][2],char out[][2]){
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
        for(int a=0;a<N;a++){
            for(int b=a+1;b<N;b++){
             //   if(in[i][1]==in[j][1]&&in[i][1]==out[a][1]&&in[j][1]==out[b][1])
             //       if(in[i][0]!=out[a][0]||in[j][0]!=out[b][0])
                  if(in[i][1]==in[j][1]&&out[a][1]==out[b][1]&&in[i][0]==out[b][0]&&in[j][0]==out[a][0])
                      return false;

            }
        }
    }
  }
  return true;

}

/*bool isStable(int N,char C1[][2],char C2[][2]){
  for(int i=0;i<N;i++){
    if(C1[i][0]!=C2[i][0])return false;

  }
  return true;


}*/

void BubbleSort(int N,char A[][2]){
  for(int i=0;i<N;i++){
    for(int j=N-1;j>i;j--){
        if(A[j][1]<A[j-1][1]){
            char t1=A[j][1],t2=A[j][0];
            A[j][1]=A[j-1][1]; A[j][0]=A[j-1][0];
            A[j-1][1]=t1; A[j-1][0]=t2;
        }
    }

  }


}

void SelectionSort(int N,char A[][2]){
  for(int i=0;i<N-1;i++){
    int minj=i;
    for(int j=i;j<N;j++){
        if(A[j][1]<A[minj][1])minj=j;

    }
    char t1=A[i][0],t2=A[i][1];
    A[i][0]=A[minj][0];A[i][1]=A[minj][1];
    A[minj][0]=t1;A[minj][1]=t2;

  }


}

int main(){
  int N;
  cin>>N;
  char A[N][2],A1[N][2],A2[N][2];
 // for(int i=0;i<N;i++)cin>>A[i];//空格回车为字符结束标志，空格不计算字符
//  for(int i=0;i<N;i++)scanf("%c",&B[i]);//空格回车计算字符
  for(int i=0;i<N;i++)
  for(int j=0;j<2;j++){
    cin>>A[i][j];
  }
  memcpy(A1,A,sizeof(A));
  memcpy(A2,A,sizeof(A));
   // cout<<A[0][1]<<endl;
 //   cout<<A[1][1]<<endl;
  //  cout<<(A[0][1]>A[1][1])<<endl;
  BubbleSort(N,A1);
  print(N,A1);
  //if(isStable(N,A,A1))cout<<"Stable"<<endl;
 // else cout<<"Not stable"<<endl;
  cout<<"Stable"<<endl;
  SelectionSort(N,A2);
  print(N,A2);
  if(isStable(N,A1,A2))cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;

  //for(int i=0;i<N;i++)cout<<A[i]<<" ";
 // for(int i=0;i<N;i++)printf("%c",B[i]);



  return 0;
}


Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000000
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define mip map<int, pair<int,int> >
#define inf INT_MAX
#define inf1 LONGLONG_MAX
#define sz(v) v.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<#x<<"is "<<x<<endl;
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
vector<int>adj [T];
			/*brownsands IIITA*/

void solve()
{  int n ,i,ans=0,a,k,b,mx,last=0;
   cin >> n;int l[n+5],x[n+5];vp v;
   for(i=0; i<n; i++)
   {
      cin >> x[i] >> l[i];
      a=x[i]-l[i]; b=x[i]+l[i];
      v.pb({b,a});
      
   }
   sort(all(v));
mx=INT_MIN;
for(i=0;i<v.size();i++)
{
   if(v[i].S>=mx)
   {
      ans++;
      mx=v[i].F;
   }
}
cout << ans;

   
   
}
signed main()
{
   boost
        int test=0,t;
		//cin>>t;
		t=1;
		while(test++ <t){
            //cout<<"Case "<<test<<": ";
            solve();
            //cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
               }		
} 
               
			
 

				
		
		




Measured memory_bytes: 26992
#include<bits/stdc++.h>
#define ll long long
#define dl double
using namespace std;
 
//***********************************************************************
int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************
 
void solve()
{
    int r;
    cin >> r;
    cout << setprecision(7) << fixed << (dl)2*3.14159265358979323*r << endl;
}
 
 
int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}
 
	return 0;
}

Measured memory_bytes: 3816
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int N; cin >> N;
	vector<int> r(N);
	for (int i = 0; i < N; i++)
		cin >> r[i];
	sort(r.begin(), r.end());
	double ma = 0;
	for (int n = 3; n <= N; n++) {
		vector<int> a(r.end() - n, r.end());
		do {
			vector<double> x(n), y(n);
			for (int i = 0; i < n; i++) {
				x[i] = a[i] * cos(M_PI*2 / n * i);
				y[i] = a[i] * sin(M_PI*2 / n * i);
			}
			for (int t = 0; t < 100; t++) {
				int i = rand() % n;
				int j = (i + n - 1) % n, k = (i + 1) % n;
				double dx = x[k] - x[j], dy = y[k] - y[j];
				double _dx = dy, _dy = -dx;
				double r = sqrt(_dx * _dx + _dy * _dy);
				x[i] = _dx / r * a[i];
				y[i] = _dy / r * a[i];
			}
			double sum = 0;
			for (int i = 0; i < n; i++) {
				int j = (i + 1) % n;
				sum += x[i] * y[j] - y[i] * x[j];
			}
			ma = max(ma, sum);
		} while (next_permutation(a.begin() + 1, a.end()));
	}
	printf("%.15f\n", ma / 2);
}

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

using namespace std;


int main()
{
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);

    //freopen( ".in", "r", stdin );

    int a, b;
    cin >>a >>b;

    int mn = 22002;

    for( int i = a; i <= b; i++ ){
        for( int j = i + 1; j <= b; j++){
            int mod = (( i % 2019 ) * ( j % 2019 )) % 2019;

            if( mod < mn ){
                mn = mod;

                if( mn == 0 ){
                    cout <<'0' <<'\n';
                    return 0;
                }
            }
        }
    }

    cout <<mn <<'\n';

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Collections;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] A = new int[N];
        
        int max = 0;
        int maxidx = 0;
        int secmax = 0;
        int secmaxidx = 0;
        for(int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
            if(A[i] > max) {
                max = A[i];
                maxidx = i;
            }
        }
        
        for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                continue;
            }
            if(A[i] > secmax) {
                secmax = A[i];
                secmaxidx = i;
            }
        }
        
        for(int i = 0; i < N; i++) {
            if(i == maxidx) {
                System.out.println(secmax);
            }else {
                System.out.println(max);
            }
        }
    }
}

Measured memory_bytes: 92928
#include <iostream>
#include <queue>
#include <utility>
using namespace std;

int main(){
  int n,q,a,v;
  int c[1000001]={0};
  typedef pair<int,int> P;
  priority_queue<P> s;
  cin>>n>>q;
  while(q--){
    cin>>a>>v;
    c[a]+=v;
    s.push(P(c[a],-a));
    while(1){
      P t=s.top();
      if(t.first==c[-t.second]){
	cout<<-t.second<<' '<<t.first<<endl;break;
      }
      s.pop();
    }
  }
  return 0;
}

Measured memory_bytes: 6016
N=input()
A=list(map(int, input().split())) 

B=[]
for i in range(int(N)):
  if i==0:
    continue
  else:
    if A[i-1]>A[i]:
      B.append(A[i-1]-A[i])
      A[i]=A[i]+B[i-1]
    else:
      B.append(0)
      
print(sum(B))

Measured memory_bytes: 32096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

vector<pair<ll, int>> factorize(ll n){
    vector<pair<ll, int>> res;
    for (ll i = 2; i*i <= n; ++i){
        if (n%i) continue;
        res.emplace_back(i, 0);
        while (n%i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}

int main(){
    ll n;
    cin >> n;
    vector<pair<ll, int>> res = factorize(n);
    int ans = 0;
    rep(i, res.size()){
        int num = res[i].second;
        int j = 1;
        while(j <= num){
            ans++;
            num -= j;
            j++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 100005;
const int MM = 1000000007;

int main()
{
	int L;
	string A, B;
	cin >> L >> A >> B;
	if( A+B > B+A ) swap(A, B);
	string P, Q;
	while((L-Q.size())%A.size() != 0) Q += B;
	for(int i = 0; i < (L-Q.size()) / A.size(); i++) P += A;
	cout << P << Q << "\n";
}


Measured memory_bytes: 1544
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  ;; (return-from read-fixnum 0)
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (the fixnum (* result 10))))
              (return (if minus (- result) result))))))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((n (read))
         (as (make-array n :element-type 'int32))
         (num-neg 0)
         (least-abs most-positive-fixnum))
    (dotimes (i n)
      (let ((a (read-fixnum)))
        (when (<= a 0)
          (incf num-neg))
        (setf least-abs (min least-abs (abs a)))
        (setf (aref as i) a)))
    (if (evenp num-neg)
        (println (reduce #'+ as :key #'abs))
        (println
         (loop for mark = nil
               for a across as
               sum (if (and (not mark) (= (abs a) least-abs))
                       (progn (setf mark t)
                              (- (abs a)))
                       (abs a)))))))

#-swank(main)



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

int main(){
    int N,M; cin >> N >> M;
    N == M ? cout << "Yes" << endl :cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		System.out.println((long)((1900*M + 100*(N-M))*Math.pow(2, M)));
	}
}


Measured memory_bytes: 21844
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto X = RD;
	auto t = RD;

	writeln(max(X - t, 0));
	stdout.flush();
	debug readln();
}

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

using namespace std;

int n;
char a[110];

void f(int here, int last)
{
	if(here == n)
	{
		printf("%s\n", a);
		return;
	}
	
	for(int i = 0 ; i <= last + 1 ; i++)
	{
		a[here] = i + 'a';
		f(here + 1, max(last, i));
	}
}

int main(void)
{
	scanf("%d", &n);
	
	f(0, -1);
	
	return 0;
}

Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
        }
        int count = 0;
        for (int i = 0 ; i < n ; i++) {
            if (a[i] == count + 1) {
                count++;
            }
        }
        if (count == 0) {
            System.out.println(-1);
        } else {
            System.out.println(n - count);
        }
    }

}


Measured memory_bytes: 84544
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


int x;

void solve()
{
    cin >> x; int i=2;
    while (true) {
        if ((i*x)%360==0) {
            nout(i); return;
        }i++;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3600
import sys
import numpy as np
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


def main():
    mod = 10**9+7
    h, w = mi()
    g = [[] for _ in range(h+1)]
    g[0] = '#'*(w+1)
    for i in range(h):
        g[i+1] = '#'+input()
    dp = np.zeros((h+1, w+1), dtype=int)
    dp[1][1] = 1
    for i in range(1, h+1):
        for j in range(1, w+1):
            if g[i][j] == '#':
                dp[i][j] = 0
                continue
            dp[i][j] = max(dp[i][j], dp[i-1][j]+dp[i][j-1])
            dp[i][j] %= mod
    print(dp[h][w])
            
            

    


if __name__ == '__main__':
    main()

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

int main(int argc, char const *argv[]) {
  int N, a; cin>>N;
  map<int, int> table;

  for (size_t i = 0; i < N; i++) {
    cin>>a;
    if(table.find(a) == table.end()) table[a] = 0;
    table[a]++;
  }

  int needCount = 0;
  for(auto iter = table.begin(); iter != table.end(); ++iter){
    int key = iter->first;
    int count = iter->second;

    if(key != count){
      if(key < count){
        needCount += count - key;
      }else{
        needCount += count;
      }
    }
  }
  cout << needCount << "\n";
  return 0;
}


Measured memory_bytes: 4736
import sys
sys.setrecursionlimit(500000)

N=int(input())


depth=[-1]*N
parent=[-1]*N
childs=[[] for i in range(N)]

depth[0]=0
def calc_depth(n):
    for child in childs[n]:
        depth[child]=depth[n]+1
        calc_depth(child)

def calc_height(n):
    if childs[n]==[]:
        return 0 
    childs_height=[]
    for child in childs[n]:
        childs_height.append(calc_height(child))
    childs_height.sort(reverse=True)
    heightlist=[childs_height[i]+i for i in range(len(childs_height))]
    return max(heightlist)+1

for i in range (1,N):
    a=int(input())-1
    childs[a].append(i)

print(calc_height(0))


Measured memory_bytes: 139440
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#define MAXN 3005
#define INF 0x3f3f3f3f
#define p 1000000007
#define rint register int
#define LL long long
#define LD long double
using namespace std;

int n, a[MAXN];
LL f[MAXN][MAXN];

LL solve(int l, int r, int op)
{
	if(f[l][r]!=-1) return f[l][r];
	LL temp=0;
	if(l==r) return f[l][l]=(op==1?a[l]:-a[l]);
	if(op==1)
	{
		temp=max(a[l]+solve(l+1, r, 1-op), a[r]+solve(l, r-1, 1-op));
		return f[l][r]=temp;
	}
	else
	{
		temp=min(solve(l+1, r, 1-op)-a[l], solve(l, r-1, 1-op)-a[r]);
		return f[l][r]=temp;
	}
}

int main()
{
	memset(f, -1, sizeof(f));
	scanf("%d", &n);
	for(rint i=1; i<=n; ++i) scanf("%d", &a[i]);
	printf("%lld\n", solve(1, n, 1));
	return 0;
}

Measured memory_bytes: 70912
#include <iostream>

#define NIL -1

using namespace std;

struct Node
{
	int parent;
	int lchild;
	int rchild;
};

void init_tree(Node T[], int n);
void preorder(Node T[], int n);
void inorder(Node T[], int n);
void postorder(Node T[], int n);
void preorder_rec(Node T[], int root);
void inorder_rec(Node T[], int root);
void postorder_rec(Node T[], int root);

int main()
{
	int n;
	cin >>n;
	
	Node * T = new Node [n];
	
	init_tree(T, n);
	
	preorder(T, n);
	
	inorder(T, n);
	
	postorder(T, n);
	
	return 0;
}



void init_tree(Node T[], int n)
{
	
	int ID, k;
	
	for (int i = 0; i < n; i++) T[i].parent = NIL;
	
	for (int i = 0; i < n; i++)
	{
		int ID, lcld, rcld;
		cin >> ID >> lcld >> rcld;
		T[ID].lchild = lcld;
	 	T[ID].rchild = rcld;
		
		if (lcld != NIL) T[lcld].parent = ID;
		if (rcld != NIL) T[rcld].parent = ID;		
	}	
}


void preorder(Node T[], int n)
{
	int root = 0;	
	if (n == 0) return;
	
	cout << "Preorder" <<endl;
	while (T[root].parent != NIL) root = T[root].parent;
	preorder_rec(T, root);
	cout << endl;
}

void preorder_rec(Node T[], int root)
{
	if (root == NIL) return;
	cout << ' ' << root;
 	preorder_rec(T, T[root].lchild);
 	preorder_rec(T, T[root].rchild);
}

void inorder(Node T[], int n)
{
	int root = 0;	
	if (n == 0) return;

	cout << "Inorder" << endl;
	while (T[root].parent != NIL) root = T[root].parent;
	inorder_rec(T, root);
	cout << endl;
}

void inorder_rec(Node T[], int root)
{
	if (root == NIL) return;
 	inorder_rec(T, T[root].lchild);
	cout << ' ' << root;
 	inorder_rec(T, T[root].rchild);
}

void postorder(Node T[], int n)
{
	int root = 0;	
	if (n == 0) return;
	
	cout << "Postorder" << endl;
	while (T[root].parent != NIL) root = T[root].parent;
	postorder_rec(T, root);
	cout << endl;
}

void postorder_rec(Node T[], int root)
{
	if (root == NIL) return;
 	postorder_rec(T, T[root].lchild);
 	postorder_rec(T, T[root].rchild);
	cout << ' ' << root;
}


Measured memory_bytes: 3120
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(" ", $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int)$this->next();
    }

    public function nextDouble()
    {
        return (double)$this->next();
    }
}

class out
{
    public static function printIn($str = "")
    {
        echo $str . PHP_EOL;
    }
}

$sc = new Scanner;

$s = $sc->next();

$s = str_replace('2017', '2018', $s);

echo $s;

Measured memory_bytes: 5112
#include<stdio.h>

void trace(int A[],int N){
	int i;
	for(i=0;i<N;i++){
		if(i>0)printf(" ");
		printf("%d",A[i]);
	}
	printf("\n");
}

void insertionSort(int A[],int N){
	int j,i,v;
	for(i=1;i<N;i++){
		v=A[i];
		j=i-1;
		while(j>=0&&A[j]>v){
		A[j+1]=A[j];
		j--;
		}
	    A[j+1]=v;
		trace(A,N);
	}
}

int main(){
	int N,i,j;
	int A[100];
	
	scanf("%d",&N);
	for(i=0;i<N;i++)scanf("%d",&A[i]);
	
	trace(A,N);
	insertionSort(A,N);
	
	return 0;
}	

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,x;
    cin>>n>>x;
    cout << 3*(n-__gcd(n,x))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(void){
        int n,m,i,j,num,tmp;
        int *B,**A;
        scanf("%d %d",&n,&m);
        B = (int *)malloc(sizeof(int)*m);
        A = (int **)malloc(sizeof(int*)*n);
        for(i=0;i<n;i++){
                A[i] = (int *)malloc(sizeof(int)*m);
        }
        for(i=0;i<n;i++){
                for(j=0;j<m;j++){
                        scanf("%d",&A[i][j]);
                }
        }
        for(i=0;i<m;i++){
                scanf("%d",&B[i]);
        }
        for(i=0;i<n;i++){
                tmp = 0;
                for(j = 0;j<m;j++){
                        tmp = tmp + A[i][j] * B[j];
                }
                printf("%d\n",tmp);
        }
        for(i=0;i<n;i++){
                free(A[i]);
        }
        free(A);
        return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,string> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
ll n,m;
ll f(ll a){
	if(a<0)a+=m;
	return a;
}
int main(){
	cin>>n>>m;
	vi in(n);
	rep(i,n)cin>>in[i];
	vp dp(m+1);
	vi co(m+1);
	rep(i,n-1)co[in[i]]++;
	loop(i,1,n){
		dp[in[i]].first++;
		if(i)dp[in[i]].second+=f(in[i]-in[i-1]);
	}
//	rep(i,m)cout<<dp[i+1].first<<" "<<dp[i+1].second<<endl;
//	cout<<endl;
//	rep(i,m+1)cout<<co[i]<<endl;
	ll out=INF;
	ll now=0;
	ll c=0;
	rep(i,n-1){
		if(in[i]<in[i+1]&&in[i]<1&&1<=in[i+1]||in[i]>in[i+1]&&(in[i]<1||1<=in[i+1])){
			now+=f(in[i+1]);
			c++;
		}
		else{
			now+=f(in[i+1]-in[i]);
		}
	}
//	cout<<endl;
	out=now;
	loop(i,2,m+1){
		c-=dp[i-1].first;
		now-=dp[i-1].first;
		now+=dp[i-1].second;
		now-=c;
//		cout<<now<<" "<<c<<endl;
//		cout<<now<<endl;
		out=min(out,now);
		c+=co[i-1];
	}
	cout<<out<<endl;
}










Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF pow(10,10)

int main(void){
    ll n,k; cin >> n >> k;
    vector<ll>h(n);
    for(int i=0;i<n;i++) cin >> h[i];
    vector<ll>cost(n,INF);
    cost[0]=0;
    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i+j<n){
                cost[i+j] = min(cost[i+j],cost[i]+abs(h[i+j]-h[i]));
            }
        }
    }
    cout << cost[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	string S, T;

	while (cin >> S >> T)
	{
		vector<vector<short> > dp(T.size() + 1, vector<short>(S.size() + 1, 0));

		for (int i = 0; i <= S.size(); i++) { dp[0][i] = 0; }
		for (int i = 0; i <= T.size(); i++) { dp[i][0] = 0; }

		int ret = 0;

		for (int i = 1; i <= T.size(); i++)
		{
			for (int j = 1; j <= S.size(); j++)
			{
				if (T[i - 1] == S[j - 1])
				{
					dp[i][j] = dp[i - 1][j - 1] + 1;
				}
				else
				{
					dp[i][j] = 0;
				}

				ret = max(ret, (int)(dp[i][j]));
			}
		}

		printf("%d\n", ret);
	}

	return 0;
}

Measured memory_bytes: 34348
program sequence_sum
  implicit none
  integer(8) :: n, num, tmp, a(0:100000) = 0
  integer :: x, m, b(0:100000) = 0, period, offset, rem, i
  read(*,*) n, x, m
  if (n == 1) then
    write(*,'(i0)') x
    stop
  end if
  tmp = m
  a(1) = x
  b(x) = 1
  do i = 2, m + 1
    x = int(mod(int(x, 8) * x, tmp))
    a(i) = a(i - 1) + x
    if (i == n) then
      write(*,'(i0)') a(i)
      stop
    end if
    if (b(x) > 0) then
      offset = b(x) - 1
      period = i - offset - 1
      exit
    end if
    b(x) = i
  end do
  num = (n - offset) / period
  rem = int(n - offset - num * period)
  write(*,'(i0)') (a(offset + period) - a(offset)) * num + a(offset + rem)
end program sequence_sum

Measured memory_bytes: 3464
delta = 1e-11
while input = gets
  n = input.chomp.to_i
  n.times do
    isParallel = false
    x1, y1, x2, y2, x3, y3, x4, y4 = gets.chomp.split(" ").map(&:to_f) 
    if x1 != x2
      if x3 != x4  
        d = ((y1-y2)/(x1-x2) - (y3-y4)/(x3-x4)).abs
        isParallel = true if d < delta 
      end
    else x1 == x2
      isParallel = true if x3 == x4
    end
    puts isParallel ? "YES" : "NO"
  end
end



Measured memory_bytes: 6864
#include<cstdio>
#define F(i,l,r) for(int i=l;i<=r;i++)
int m=1e9+7,n,k,d[2333][2333];main(){scanf("%d%d",&n,&k);d[1][1]=1;F(i,2,n)F(j,1,i)d[i][j]=(d[i][j-1]+d[i-1][j])%m;F(i,1,n-k-1)(d[n][k]*=2)%=m;printf("%d\n",d[n][k]);}

Measured memory_bytes: 15104
#include <stdio.h>

int main(){
    int a, b, i, check=0;
    char s[11];

    scanf("%d %d", &a, &b);
    scanf("%s", s);

    for(i=0; i<a+b+1; i++){
        if(i < a){
            if(s[i] < '0' || '9' < s[i])
                check=1;
        }
        else if(i == a){
            if(s[i] != '-')
                check=1;
        }
        else{
            if(s[i] < '0' || '9' < s[i])
                check=1;
        }
    }

    if(check == 0)
        printf("Yes\n");
    else
        printf("No\n");
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    char a, b; cin >> a >> b;
    cout << ((a == 'H' && b == 'H') ? 'H' : (a == 'H' && b == 'D' ? 'D' : (a == 'D' && b == 'H' ? 'D' : 'H'))) << endl;
    // if (a == 'H' && b == 'H') cout << 'H' << endl;
    // else if (a == 'H' && b == 'D') cout << 'D' << endl;
    // else if (a == 'D' && b == 'H') cout << 'D' << endl;
    // else cout << 'H' << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]

for i in range(n-2):
  if x[i] == y[i] and x[i+1] == y[i+1] and x[i+2] == y[i+2]:
    print('Yes')
    exit()
  else:
    i += 1
    if i == n-2:
      print('No')
      exit()

Measured memory_bytes: 9220
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<numeric>
#include<climits>
#include<queue>
 
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<bool> ans(n,false);
	int ab;
	for (int i = 0; i < 2 * m; ++i) {
		cin >> ab;
		ans[ab - 1] = !ans[ab - 1];
	}
	for (int i = 0; i < n; ++i) {
		if (ans[i]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

priority_queue<ll, vll, greater<ll>> pq;
ll maxl = 3234566667;
void bfs(ll i) {
	if (i > maxl) return;
	pq.push(i);
	ll x = i % 10;
	i *= 10;
	bfs(i + x);
	if (x > 0) bfs(i + x - 1);
	if (x < 9) bfs(i + x + 1);
}

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

	ll k;
	cin >> k;


	for (ll i = 1; i < 10; i++) {
		bfs(i);
	}

	while (k > 1) {
		pq.pop();
		k--;
	}
	cout << pq.top() << endl;
}


Measured memory_bytes: 1400
N = int(input())
P = [int(_) for _ in input().split()]

t = 0
j = 0

for i in range(N):
    while i >= j:
        if i == j:
            t += 1
            break
        elif P[i] >= P[j]:
            break
        else:
            j += 1
    

print(t)

Measured memory_bytes: 24744
#include<iostream>
#include<math.h>

#define PI 3.141592653589793238

using namespace std;

int main() {

	double a = 0;
	double b = 0;
	double C = 0;
	double radC = 0;
	double c = 0;
	double S = 0;
	double L = 0;
	double h = 0;
	
	cin >> a >> b >> C;

	radC = C * PI / 180;

	c = sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(radC));

	S = a * b * sin(radC) / 2;

	L = a + b + c;

	h = 2 * S / a;

	cout << fixed << S << endl << L << endl << h << endl;

	return 0;

}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	int a, b, c;
	cin >> a >> b >> c;

	if (a != b && b != c && a != c)
	{
		cout << "No";
	}
	else if (a == b && b == c && a == c)
	{
		cout << "No";
	}
	else
	{
		cout << "Yes";
	}
	
	
}

int main()
{
	fastio;
	solve();

	return 0;
}

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

int main() {
 int r; cin>>r;
 r=1999-r;
 r=r/200;
 r+=1;
 cout<<r<<endl;
}



Measured memory_bytes: 3632
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    String s=sc.next();
    String t=sc.next(); 
    String ans=""; 
    for(int i=0;i<n;i++) {
      ans+= s.charAt(i);
      ans+= t.charAt(i);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define int ll

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

    int n,d,a;cin>>n>>d>>a;
    vector<pair<ll,ll>> v(n);
    rep(i,n) cin>>v[i].first>>v[i].second;
    sort(ALL(v));
    vector<ll> imos(n+10,0);ll sum=0,ans=0;
    vector<ll> x(n);
    rep(i,n) x[i]=v[i].first;
    rep(i,n){
        sum+=imos[i];
        ll hp=max(0ll,v[i].second-sum);
        ll times=(hp+a-1)/a;
        ans+=times;
        ll damage=times*a;
        ll reach=v[i].first+2*d;
        auto ite=lower_bound(ALL(x),reach+1);
        ite=prev(ite);
        int idx=ite-x.begin();
        if(idx==i) continue;
        sum+=damage;
        imos[idx+1]-=damage;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6528
import java.util.Scanner;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int a,b,c;
            a=sc.nextInt();
            b=sc.nextInt();
            c=sc.nextInt();
            int ans=0;
            for(int i=a;i<=b;i++){
                if(c%i==0){ans++;}
            }
            System.out.printf("%d\n",ans);
    }
}


Measured memory_bytes: 26284
n,m = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
b = gets.chomp.split(" ").map(&:to_i)
andser = a & b
orser = (a + b).uniq
puts [andser.size, orser.size].join(" ")
puts andser.join("\n") if andser != []
puts orser.sort.join("\n")




Measured memory_bytes: 37336
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int n;
V< V< V<double> > > dp;

double dfs(int c1, int c2, int c3) {
    if (dp[c1][c2][c3] >= 0) return dp[c1][c2][c3];
    if (c1 == 0 && c2 == 0 && c3 == 0) return dp[c1][c2][c3] = 0;
    double tmp = double(n - c1 - c2 - c3) / double(n);
    if (c1 > 0) tmp += double(c1) * (1 + dfs(c1 - 1, c2, c3)) / double(n);
    if (c2 > 0) tmp += double(c2) * (1 + dfs(c1 + 1, c2 - 1, c3)) / double(n);
    if (c3 > 0) tmp += double(c3) * (1 + dfs(c1, c2 + 1, c3 - 1)) / double(n);
    return dp[c1][c2][c3] = double(n) * tmp / double(c1 + c2 + c3);
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cin >> n;
    V<int> a(n);
    int cnt1 = 0, cnt2 = 0, cnt3 = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] == 1) cnt1++;
        else if (a[i] == 2) cnt2++;
        else cnt3++;
    }

    dp.resize(n + 1, V< V<double> >(n + 1, V<double>(n + 1, -1)));
    cout << dfs(cnt1, cnt2, cnt3) << '\n';
    return 0;
}


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

int main(){
  int n,a,b[100010]={},ans=0;
  cin>>n;
  fr(i,n){cin>>a;b[a]++;}
  fr(i,1e5+5) ans+=max(0,b[i]-1);
  cout<<n-2*((ans+1)/2)<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int maxn = 1e6+10;
int a[maxn];
bool cmp(int a,int b){
	return a > b;
}
int main(void){
	int n,k;
	cin >> n >> k;
 	for(int i = 0; i < n; i++){
	 	cin >> a[i];
	}
	sort(a,a+n,cmp);
	if(k>=n){
    	cout<<0<<endl;
	}else{
     	ll sum = 0;
     	for(int i = k; i < n; i++){
        	sum += a[i];
     	}
    cout<<sum;
 	}
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void) {
	string s;
	int num[26] = {};

	cin >> s;

	for (int i = 0; i < s.size(); i++)
	{
		num[s[i] - 'a']++;
	}

	/*for (int i = 0; i < 26; i++)
	{
		cout << num[i] << "\n";
	}*/

	for (int i = 0; i < 26; i++)
	{
		if (num[i] == 0) {
			cout << char('a' + i) << "\n";
			break;
		}

		if (i == 25)cout << "None\n";
	}

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> a(h,vector<char>(w));
    vector<vector<char>> a2(h,vector<char>(w));
    int i,j;
    for(i=0;i<h;i++){
        for(j=0;j<w;j++){
            cin >> a.at(i).at(j);
        }
    }
    int tate=0;
    int kie=0;
    for(i=0;i<h;i++){
        int ha=0;
        for(j=0;j<w;j++){
            if(a.at(i).at(j)!='.')
            ha++;
        }
        if(ha!=0){
            for(j=0;j<w;j++)a2.at(i-kie).at(j)=a.at(i).at(j);
            tate++;
        }
        else {
            kie++;
            }
    }
    vector<vector<char>> b(w,vector<char>(tate));
    vector<vector<char>> b2(w,vector<char>(tate));
    for(i=0;i<w;i++){
        for(j=0;j<tate;j++){
            b.at(i).at(j)=a2.at(j).at(i);
        }
    }

    int tate2=0;
    int kie2=0;
    for(i=0;i<w;i++){
        int ha=0;
        for(j=0;j<tate;j++){
            if(b.at(i).at(j)!='.')
            ha++;
        }
        if(ha!=0){
            for(j=0;j<tate;j++)b2.at(i-kie2).at(j)=b.at(i).at(j);
            tate2++;
        }
        else{
            kie2++;
        }
    }
    vector<vector<char>> ans(tate,vector<char>(tate2));
    for(i=0;i<tate;i++){
        for(j=0;j<tate2;j++){
            ans.at(i).at(j)=b2.at(j).at(i);
            cout << ans.at(i).at(j);
        }
        cout << endl;
    }
    return 0;

}

Measured memory_bytes: 384
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long int lli;

int main() {
    char alp;
    cin >> alp;
    if (alp < 'a') {
        cout << 'A' << endl;
    } else {
        cout << 'a' << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7

def main():
    n = int(ipt())
    a = [int(i) for i in ipt().split()]
    b = []
    b0 = 0
    for i,ai in enumerate(a):
        if i%2 == 1:
            b0 -= ai
        else:
            b0 += ai
    b.append(b0)
    for i in range(n-1):
        b.append((a[i]-b[-1]//2)*2)

    print(" ".join(map(str,b)))


    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 99456
#include <iostream>
#include <algorithm>
using namespace std;
int i,a[100005],b[100005],n,h,times,aMax;
int main()
{
    cin>>n>>h;
    for(i=1;i<=n;++i) cin>>a[i]>>b[i];

    for(i=1;i<=n;++i)
    if(aMax<a[i])aMax=a[i];
    sort(b+1,b+n+1);
    for(i=n;i>0;i--)
    if(aMax<b[i])
    if(h>0)
    {
        h-=b[i];
        times++;
    }

    if(h>0)
    {
        if(h%aMax>0)
        times+=h/aMax+1;
        else times+=h/aMax;
    }


    cout<<times<<'\n';

    return 0;
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int s, w, ans =0;
	cin >>s >>w;
	if(s<=w) puts("unsafe");
	else puts("safe");
	return 0;
}


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

int main(void) 
{
    ll h;
    cin >> h;
    ll cnt = 0;
    ll ans = 0;
    while(h){
        if(h > 1) h /=2;
        else h /= 2;
        ans += pow(2,cnt);
        ++cnt;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include<complex>

using namespace std;


//ユークリッドの互除法　a,bは最大公約数を求めたい２つの数
long long int gcd(long long int a, long long int b) {
             long long int tmp;
             long long int r = 1;
             if (b > a) {
                           tmp = a;
                           a = b;
                           b = tmp;
             }
             r = a % b;
             while (r != 0) {
 
 
                           a = b;
                           b = r;
                           r = a % b;
 
             }
             return b;
}

const long long int mod=1000000007;
int main(){
	long long int n=0;
	string str,str2="CODEFESTIVAL2016";
	cin>>str;
	for(int i=0;i<str.length()-8;i++){
		cout<<str[i];
	}
}


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

int main(){
  int n;
  cin>>n;
  ll ans=0;
  stack<ll> stk;
  int p[100001];
  for(int i=0;i<n;i++)cin>>p[i];

  for(int i=0;i<n;i++){
    int &a=p[i];
    a--;
    if(stk.empty())ans+=a,stk.push(1);
    else if(stk.top()<a){
      ans+=a/(stk.top()+1);
      //a%=(stk.top()+1);
      //stk.push(a);
    }
    else {
      if(stk.top()<a+1)stk.push(a+1);
      // stk.push(a);
    }
  }
  //  ans+=stk.size();
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>

int main(){
    int H,W,i,j;
    while(true){
        scanf("%d %d",&H,&W);
        if(H==0 && W==0){
            break;
        }
        else{
            for(j=0;j<W;j++)printf("#");
            printf("\n");
            for(i=1;i<H-1;i++){
                printf("#");
                for(j=1;j<W-1;j++)printf(".");
                printf("#");
                printf("\n");
            }
            for(j=0;j<W;j++)printf("#");
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2532