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

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solution(String[] args) throws Exception{
		long L = nextLong();
		long R = nextLong();
		HashMap<Integer,Integer> map = new HashMap<>();
		for(int i=0;i<=2019;i++){
			map.put(i, i);
		}
		long ans =2019;
		for(long i=L;i<R;i++){
			HashMap<Integer,Integer> tmp = new HashMap<>();
			for(long k=i+1;k<=R;k++){
				int x = (int)((i%2019)*(k%2019))%2019;
				ans = Math.min(ans, x);
				if(tmp.containsKey(x)){
					break;
				}
				tmp.put(x, x);
			}
			for(int x:tmp.keySet()){
				map.remove(x);
			}
			if(ans==0||map.size()==0){
				break;
			}
		}
		pw.println(ans);

	}

	public static void dfs(int n,int cnt,ArrayList<Integer>[] tree,int parent,int[] set){
		if(n!=parent&&tree[n].size()==1){
			set[n]=cnt;
			return;
		}
		for(int x:tree[n]){
			if(x==parent){
				continue;
			}
			dfs(x,cnt+1,tree,n,set);
		}
	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



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

int main() {
  long long n;
  cin >> n;
  vector<long long> h(n);
  long long downfrom;
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
    if (i == 0) downfrom = h.at(i);
    else if (h.at(i) > h.at(i - 1)) downfrom = h.at(i);
    if (i > 0 && h.at(i) < downfrom - 1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

typedef long long LL;

const int N = 100005;
const LL inf = (LL)1e18;;

int n;
LL a[N], ans;

LL dfs(int d, LL v)
{
	v = min(v, inf);
	if (v < a[d]) return -1;
	if (d == n) return ans += a[d], a[d];
	LL w = dfs(d + 1, (v - a[d]) * 2);
	if (w == -1) return -1;
	ans += min(w, v - a[d]) + a[d];
	return a[d] + min(w, v - a[d]);
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i <= n; i++) scanf("%lld", &a[i]);
	if (dfs(0, 1) == -1) puts("-1");
	else printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 7712
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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; }

int main () {
  int n;
  cin >> n;
  vll a(n);
  rep(i,n) cin >> a[i];
  
  vector<ll> csum(a.size()+1);
  rep(i,a.size()) {
    csum[i+1] = csum[i] + a[i];
  }
  ll ans = INFLL;
  for (int i = 1; i <= n-1; ++i) {
    ll x = csum[i] - csum[0];
    ll y = csum[n] - csum[i];
    ans = min(ans, abs(x-y));
  }

  cout << ans << endl;
  return 0;
}

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

#define reg register
#define pr std::pair<int, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;

namespace modular {
    const int MOD = 998244353;
    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
    inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
    inline int mul(int x, int y) { return 1LL * x * y % MOD; }
    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1) ans = mul(ans, x);
        return ans;
    }
};  // namespace modular
using namespace modular;

namespace Base {
    template <typename Tp>
    inline Tp input() {
        Tp x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return 0;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x *= y;
    }
    template <typename Tp>
    inline void read(Tp &x) {
        x = input<Tp>();
    }
    template <typename Tp>
    inline void chmax(Tp &x, Tp y) {
        x < y ? x = y : 0;
    }
    template <typename Tp>
    inline void chmin(Tp &x, Tp y) {
        x > y ? x = y : 0;
    }
};  // namespace Base
using namespace Base;
/*----------------------------------------------------------------------------*/

#define MAX_N 407

int N, sa, sb;
int a[MAX_N], b[MAX_N];
int coe[MAX_N][MAX_N], tmp[MAX_N][MAX_N];
int inv[MAX_N * 2], fac[MAX_N * 2];

void init() {
    inv[0] = fac[0] = 1;
    Rep(i, 807) inv[i] = qpow(i, MOD - 2), fac[i] = mul(fac[i - 1], i);
    coe[0][0] = 1;
    Rep(i, N) {
        rep(j, 0, sa) rep(k, 0, sb) tmp[j][k] = coe[j][k], coe[j][k] = 0;
        int bs = MOD - 1, p = mul(a[i], inv[sa]);
        lep(j, 0, b[i]) {
            rep(k, 0, sa) rep(t, j, sb) inc(coe[k][t], mul(tmp[k][t - j], bs));
            bs = mul(bs, mul(p, inv[j + 1]));
        }
        rep(j, a[i], sa) rep(k, 0, sb) inc(coe[j][k], tmp[j - a[i]][k]);
    }
    rep(i, 0, sa) rep(j, 0, sb) coe[i][j] = MOD - coe[i][j];
    inc(coe[sa][0], 1);
}

void solve() {
    int res = 0;
    rep(i, 0, sa) {
        int bs = qpow(add(1, MOD - mul(i, inv[sa])), MOD - 2), cur = bs;
        rep(j, 0, sb) {
            inc(res, mul(mul(fac[j], cur), coe[i][j]));
            cur = mul(cur, bs);
        }
    }
    printf("%d\n", res);
}

int main() {
    read(N);
    Rep(i, N) {
        read(a[i]), sa += a[i];
        read(b[i]), sb += b[i];
    }
    init();
    solve();
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const long long inf2=0x3f3f3f3f3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(a,b)<<" "<<max(0,a+b-n)<<endl;
	return 0;
}

Measured memory_bytes: 764
/**
 *    author:  math2do
 *    created: 04.05.2020 03:25:00 IST
**/

#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(const char &ch) {
  return "'" + string(1, ch) + "'";
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  reverse(res.begin(), res.end());
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

long long power(int x, int b) {
  long long a = x;
  long long res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a;
    }
    b >>= 1;
    a = a * a;
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long x;
  cin >> x;
  pair <int, int> ans;
  bool found = false;
  for (int a = -1000; a <= 1000; a++) {
    long long A = power(a, 5);
    long long rem = A - x;
    int l = -1000, h = 1000;
    while (l <= h) {
      int m = (l + h) / 2;
      long long B = power(m, 5);
      if (B == rem) {
        found = true;
        ans.first = a;
        ans.second = m;
        goto end;
      } else if (B > rem) {
        h = m - 1;
      } else {
        l = m + 1;
      }             
    } 
  } 
  end : {
    assert(found);
    cout << ans.first << " " << ans.second << endl;
  } 
  return 0;
}


Measured memory_bytes: 3604
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int N=0;
    cin >> N;
    int num=0;
    int A[N];
    for(int i=0;i<N;++i){
        cin >> A[i];
    }
    int flag=1;
    while(flag){
        flag=0;
        for(int j=N-1;j>0;--j){
            if(A[j] < A[j-1]){
                swap(A[j],A[j-1]);
                flag=1;
                ++num;
                }
            }
        }
    for(int i=0;i<N;++i){
        if(i > 0) printf(" ");

        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d", num);
    printf("\n");
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

 
int main(){
  int a,b;
  cin >> a >> b;
  int ans = max(a+a-1,b+b-1);
  ans = max(ans,a+b);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
object Main {
    def step(s: String, x: Int, y: Int, cmd: Array[String]) = cmd(0) match {
        case "print" => {println(s.slice(x, y+1)); s}
        case "reverse" => s.take(x) + s.slice(x, y+1).reverse +s.drop(y+1)
        case "replace" => s.patch(x, cmd(3), y-x+1)
    }
    def main(args: Array[String]): Unit = {
        val in = io.Source.stdin.getLines
        val s = in.next
        in.next
        in.map(_.split(" ")).foldLeft(s)((t, u) => step(t, u(1).toInt, u(2).toInt, u))
    }
}

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

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  int N, M;
  cin >> N >> M;
  float p = pow(0.5, M);
  int ans = ((N - M) * 100 + M * 1900) / p;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <stdio.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long INF = 1LL<<60;
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; }
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

struct P {
    int num;
    int bonus;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int d, g; cin >> d >> g;
    vector<P> v(d);
    rep(i,d) cin >> v[i].num >> v[i].bonus;
    int ans = 10000;
    for(int bit = 0; bit<(1<<d); bit++) {
        int point = g;
        int cnt = 0;
        vector<int> ch(d,0);
        for(int n = 0; n < d; n++) {
            if(bit&(1<<n)) {
                rep(i,v[n].num) {
                    if(point<=0) break;
                    cnt++;
                    point -= (n+1)*100;
                }
                if(point>0) point -= v[n].bonus;
                ch[n]++;
            }
        }
        if(point<=0) chmin(ans,cnt);
        else {
            rrep(i,d) {
                if(ch[i]==0 && point>0) {
                    rep(j,v[i].num) {
                        if(point<=0) break;
                        cnt++;
                        point -= (i+1)*100;
                    } 
                }
            }
            chmin(ans,cnt);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int K, N, ans=0, maxD=0;
    cin >> K >>N;
    vector<int> a(N+1);

    for(int i=0; i<N; i++){
	cin >> a[i];	
    }
    a[N] = a[N-1]+a[0]+ (K-a[N-1]);

    for(int i=0; i<N; i++){
	maxD=max(maxD, a[i+1]-a[i]);
    }



    cout << K-maxD << endl;
} 




Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
using namespace std;

double d,tx[100][3],ty[100][3],bx[100][4],by[100][4];
int n,f[100],f2[100],mc;

struct gr {
	int t,f;
	int to[100],fr[100];
};


gr g[100];

void makebox() {
	int i,j,j1,j2,a,a1,a2;
	double vx1,vy1,vx2,vy2,b;
	for (i=0;i<n;i++) {
		for (j=0;j<3;j++) {
			j1=(j+1) % 3; j2=(j+2) % 3;
			if (((tx[i][j]-tx[i][j1])*(tx[i][j]-tx[i][j1])+(ty[i][j]-ty[i][j1])*(ty[i][j]-ty[i][j1]))-((tx[i][j]-tx[i][j2])*(tx[i][j]-tx[i][j2])+(ty[i][j]-ty[i][j2])*(ty[i][j]-ty[i][j2]))==0) a=j;
		}
		a1=(a+1) % 3; a2=(a+2) % 3;
		vx1=tx[i][a]-(tx[i][a1]+tx[i][a2])/2;
		vy1=ty[i][a]-(ty[i][a1]+ty[i][a2])/2;
		b=sqrt(vx1*vx1+vy1*vy1);
		bx[i][0]=tx[i][a1]; by[i][0]=ty[i][a1];
		bx[i][1]=tx[i][a2]; by[i][1]=ty[i][a2];
		vx2=d*vx1/b; vy2=d*vy1/b;
		bx[i][2]=bx[i][1]+vx2; by[i][2]=by[i][1]+vy2;
		bx[i][3]=bx[i][0]+vx2; by[i][3]=by[i][0]+vy2;
	}
}
int hit(int n1,int n2) {
	int i,j,k;
	double a,b,mtb,mt,mb,vx1,vy1,vx2,vy2,vx[5],vy[5];
	for (i=0;i<2;i++) { vx[i]=bx[n1][i+1]-bx[n1][i]; vy[i]=by[n1][i+1]-by[n1][i];}
	for (i=0;i<3;i++) { vx[2+i]=tx[n2][(i+1) % 3]-tx[n2][i]; vy[2+i]=ty[n2][(i+1) % 3]-ty[n2][i];}
	for (i=0;i<5;i++) {
		 vx2=-vy[i]; vy2=vx[i];
		 vx1=vx2/sqrt(vx2*vx2+vy2*vy2); vy1=vy2/sqrt(vx2*vx2+vy2*vy2);
		 mtb=0;
		for (j=0;j<3;j++) for (k=0;k<4;k++) {
		 vx2=bx[n1][k]-tx[n2][j]; vy2=by[n1][k]-ty[n2][j];
		 a=vx2*vx1+vy2*vy1; if (a<0) a=-a;
		 if (a>mtb) mtb=a;
	     }
	     a=vx[0]*vx1+vy[0]*vy1; if (a<0) a=-a;
	     b=vx[1]*vx1+vy[1]*vy1; if (b<0) b=-b;
	     mb=a+b;
	     mt=0;
	     for (j=0;j<3;j++) { a=(vx[2+j]*vx1+vy[2+j]*vy1)/2; if (a<0) a=-a;  mt+=a;  }
	     if (mtb-mt-mb>0.01) return 0;   
		      }
		 return 1;     
         }
         
void  search(int s) {
	int i;
	mc++; f2[s]=1;
	for (i=0;i<g[s].t;i++) if (f[g[s].to[i]]==0 && f2[g[s].to[i]]==0) search(g[s].to[i]);
 }
  
int main() {
	int i,j,ans,mn,mi,t;
	while (true) {
	cin >> n >> d;
	if (n==0) break;
    for (i=0;i<n;i++) {
		for (j=0;j<3;j++) cin >> tx[i][j] >> ty[i][j];
		g[i].t=g[i].f=0;
	    }
    makebox(); t=n;
    for (i=0;i<n;i++) for (j=0;j<n;j++) if (i!=j) {if (hit(i,j)==1) { g[i].to[g[i].t]=j; g[i].t++; g[j].fr[g[j].f]=i; g[j].f++;}}
	for (i=0;i<n;i++) f[i]=0; ans=0;
	while (t>0) {
		   mn=0;
	       for (i=0;i<n;i++) {
		   if (f[i]==0) {
			   for (j=0;j<n;j++) f2[j]=0;
			   mc=0; search(i);
			   if (mc>mn) { mi=i; mn=mc;}
			   }
		   }
		   for (j=0;j<n;j++) f2[j]=0;
		   mc=0; search(mi);
		   for (j=0;j<n;j++) if (f2[j]==1) f[j]=1;
		   t-=mc;
		   ans++;	    
           }
           cout << ans << endl; 
      }
     return 0;
}  	 

Measured memory_bytes: 1320
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
					  cerr << "\n\n" << "Time elapsed: " << \
					  (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
					  return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define inf 100000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'

ll cnt[31];

int main()
{
	fastio;
	#ifdef APNA_IO
		start_routine();
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif
 	
 	ll n,m;cin>>n>>m;
 	for(ll i=1;i<=n;i++)
 	{
 		ll k;cin>>k;
 		for(ll j=0;j<k;j++)
 		{
 			ll x;cin>>x;
 			cnt[x]++;
 		}
 	}
 	ll ans=0;
 	for(ll i=1;i<=m;i++)
 		if(cnt[i]==n)
 			ans++;
 		cout<<ans;
 	


		
	#ifdef APNA_IO
		end_routine();
    #endif
}



Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
 
int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  

long long int a, b, c, d;
cin>>a>>b>>c>>d;
long long int w, x, y, z;
w = a * c;
x = a * d;
y = b * c;
z = b * d;

if(w > x && w > y && w > z) cout<<w;
else if(x > w && x > y && x > z) cout<<x;
else if(y > w && y > x && y > z) cout<<y;
else cout<<z;
 
return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll Q=1000000007;

int main(){
  int N;
  string S;
  cin >> N >> S;
  int sum=0;
  int i=0;
  while(true){
    sum ++;
    char cur=S[i];
    for(int j=1;j<2*N;j++){
      if(i+j==N){
        cout << sum << endl;
        return 0;
      }else if(S[i+j]!=cur){
        i=i+j;
        break;
      }
    }
  }
}

Measured memory_bytes: 512
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#define M 1000000007
typedef long long int ll;
ll dp[105][100005];
int main()
{
    int n,i;
    ll W;
    cin>>n>>W;
    ll w[n],v[n];
    ll S=0;
    int j;
    for(i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
        S+=v[i];
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=S;j++)
        {
          dp[i][j]=1e12;
        }
    }
    if(w[0]<=W)
    {
        dp[1][v[0]]=w[0];
    }
    for(i=2;i<=n;i++)
    {
        for(j=1;j<=S;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(j>=v[i-1])
            {dp[i][j]=min(dp[i][j],dp[i-1][j-v[i-1]]+w[i-1]);}
        }

    }
    int ans=-1;
    for(i=1;i<=S;i++)
    {
        if(dp[n][i]<=W)
        {
            ans=i;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 79360
#include <iostream>
#include <math.h>
#include <stdio.h>
#define inf 1e9
#define eps 1e-9
using namespace std;

struct vec2d{
	double x, y;
	vec2d(){}
	vec2d(double x, double y){
		this->x = x, this->y = y;
	}
	double add(double a, double b){
		if(fabs(a+b) < eps * (fabs(a) + fabs(b))) return 0.0;
		return a+b;
	}
	vec2d operator+(vec2d ope){
		return vec2d(add(x, ope.x), add(y, ope.y));
	}
	vec2d operator-(vec2d ope){
		return vec2d(add(x, -ope.x), add(y, -ope.y));
	}
	vec2d operator*(double t){
		return vec2d(x*t, y*t);
	}
	vec2d operator/(double t){
		return vec2d(x/t, y/t);
	}
	double dot(vec2d ope){
		return add(x*ope.x, y*ope.y);
	}
	double cross(vec2d ope){
		return add(x*ope.y, -y*ope.x);
	}
	double norm(){
		double d2 = dot(*this);
		if(d2 > 0) return sqrt(d2);
		return 0.0;
	}
};

double distPP(vec2d p, vec2d q){
	return (p-q).norm();
}

double distSP(vec2d p, vec2d q, vec2d x)
{
	if((x-p).dot(q-p) <= 0) return distPP(p, x);
	if((x-q).dot(p-q) <= 0) return distPP(q, x);
	return fabs( (x-p).cross(q-p) / distPP(p, q) );
}

bool isOnS(vec2d p, vec2d q, vec2d x)
{
	return (p-x).cross(q-x) == 0 && (p-x).dot(q-x) <= 0;
}

bool isCross(vec2d p, vec2d q, vec2d r, vec2d s)
{
	if((q-p).cross(s-r) == 0){
		return isOnS(p, q, r) || isOnS(p, q, s) || isOnS(r, s, p) || isOnS(r, s, q);
	}
	double t = (r-p).cross(s-r) / (q-p).cross(s-r);
	vec2d x = p + (q-p)*t;
	return isOnS(p, q, x) && isOnS(r, s, x);
}

double distSS(vec2d p, vec2d q, vec2d r, vec2d s)
{
	if(isCross(p, q, r, s)) return 0;
	double ret = distSP(p, q, r);
	ret = min(ret, distSP(p, q, s));
	ret = min(ret, distSP(r, s, p));
	ret = min(ret, distSP(r, s, q));
	return ret;
}

int n1, n2;
vec2d p[55], q[55];

int main(void)
{
  cin >> n1;
  for(int i = 1; i <= n1; i++){
    cin >> p[i].x >> p[i].y;
  }
  cin >> n2;
  for(int i = 1; i <= n2; i++){
    cin >> q[i].x >> q[i].y;
  }
  p[0] = vec2d(0, 0);
  q[0] = vec2d(0, 1000);
  p[n1+1] = vec2d(1000, 0);
  q[n2+1] = vec2d(1000, 1000);

  double ans = inf;
  for(int i = 1; i <= n1+1; i++){
    for(int j = 1; j <= n2+1; j++){
      ans = min(ans, distSS(p[i-1], p[i], q[j-1], q[j]));
    }
  }
  printf("%.11f\n", ans);

  return 0;
}



Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x, a, b, c;
  cin >> x;
  a = x / 100;
  b = (x - a * 100) / 10;
  c = (x - a * 100 - b * 10);
  
  cout << a + b + c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int)(n).size())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

long long MOD = 1e9+7;
typedef vector<vector<int> > Matrix;

Matrix ones(int n){
  Matrix r(n, vector<int>(n));
  fore(x,0,n){
    r[x][x]=1;
  }
  return r;
}

Matrix operator*(Matrix &a, Matrix &b){
  int n = a.size(), m = b[0].size(), z = a[0].size(), i, j, k;
  Matrix r(n, vector<int>(m));
  for(i = 0; i < n; i++){
    for(j = 0; j < m; j++){
      for(k = 0; k < z; k++){
        r[i][j] = (r[i][j]%MOD+((a[i][k]%MOD)*(b[k][j]%MOD))%MOD)%MOD;
      }
    }
  }
  return r;
}

Matrix fpow(Matrix a, long long b){
  Matrix r = ones(a.size());
  while(b){
    if(b%2){
      r = r*a;
      b--;
    }
    else{
      a = a*a;
      b /= 2;
    }
  }
  return r;
}
int main(){FIN;
  ll n,k,x,ans=0; cin >> n >> k;
  Matrix m;
  m.resize(n);
  fore(i,0,n) fore(j,0,n) cin >> x, m[i].pb(x);
  Matrix tt = fpow(m,k);
  fore(i,0,n) fore(j,0,n) ans = (ans+tt[i][j])%MOD;
  cout << ans << "\n";
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; 
		//order_of_key (k) : Number of items strictly smaller than k .
		//find_by_order(k) : K-th element in a set (counting from zero) (returns an iterator)           


void inp_out()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
	#endif
}

int32_t main()
{
	fastIO
	inp_out();

	string s; 
	cin >> s;

	int n = s.size(); 

	int ans = 0; 

	for(int i = 0; i < n; ++ i)
	{
		int cnt = 0; 
		while(s[i]  != 'S'  && i < n)
		{
			++ cnt; 
			++ i; 
		}

		ans = max(ans, cnt); 
	}

	cout << ans; 

	return 0;
}

Measured memory_bytes: 3668
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.LinkedList;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        O_Matching solver = new O_Matching();
        solver.solve(1, in, out);
        out.close();
    }

    static class O_Matching {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            long mod = (int) 1e9 + 7;
            int n = in.ni();
            int[][] g = new int[n][n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    g[i][j] = in.ni();
                }
            }

            long[] dp = new long[1 << n];
            dp[0] = 1;
            LinkedList<Integer>[] masks = new LinkedList[n + 1];
            for (int i = 0; i < n + 1; i++) {
                masks[i] = new LinkedList<>();
            }
            for (int i = 0; i < 1 << n; i++) {
                masks[Integer.bitCount(i)].add(i);
            }
            for (int i = 0; i < n; i++) {
                for (int mask : masks[i]) {
                    for (int j = 0; j < n; j++) {
                        if (g[i][j] == 1 && (mask & (1 << j)) == 0) {
                            dp[mask | (1 << j)] = (dp[mask | (1 << j)] + dp[mask]) % mod;
                        }
                    }
                }

            }

            out.println(dp[(1 << n) - 1]);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

    }
}



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


int main(){
  int l,r,d;
  cin >> l >> r >> d;
  int ans=0;
  for(int i=l;i<=r;++i){
    if(i%d==0) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

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

    cout << 24 + (24 - N) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define int long long
typedef vector<int> VI;
typedef vector<VI> VVI;
//参考回答
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n; 
    cin >> n;
	VVI abc(3, VI(n)), dp(n + 1, VI(3));
	rep(i,n) cin >> abc[0][i] >> abc[1][i] >> abc[2][i];
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 3; j++) dp[i][j] = max(dp[i-1][(j + 1) % 3], dp[i-1][(j + 2) % 3]) + abc[j][i-1];
	}
	cout << *max_element(dp[n].begin(), dp[n].end()) << endl;
 
 
	return 0;
}

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

int main(){
	string S;
	cin >> S;
	int N = S.size() - 2;
	while(true){
		if(S.substr(0, N / 2) == S.substr(N / 2, N / 2)){
			cout << N << endl;
			break;
		} else {
			N -= 2;
		}
	}
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int a,b,c;
    cin>>a>>b>>c;
    int t=c-a-b;
    Yes(t>0&&4*a*b<t*t);
}

Measured memory_bytes: 256
import Data.Maybe
import Data.List

main :: IO ()
main = do
  input <- getContents
  putStrLn $ trim (solve (trim input))

--処理
solve :: String -> String
solve s | x > y     = "Alice"
        | y > x     = "Bob"
        | otherwise = "Draw"
 where
  [a, b] = fmap read (words s) :: [Int]
  x      = if a == 1 then 100 else a
  y      = if b == 1 then 100 else b

trimHead :: String -> String
trimHead = dropWhile (\s -> isJust (elemIndex s [' ', '\t', '\n', '\r']))

trim :: String -> String
trim = reverse . trimHead . reverse . trimHead

Measured memory_bytes: 508
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 1000000007
#define MAX 1e17
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll par[300000], depth[300000];
void init(ll n) {
  REP(i, n) {
    par[i] = i;
    depth[i] = 0;
  }
  return;
}
ll find(ll x) {
  if (par[x] == x)
    return x;
  else
    return par[x] = find(par[x]);
}

void merge(ll x, ll y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return;

  if (depth[x] > depth[y]) {
    par[y] = x;
  } else {
    par[x] = y;
    if (depth[x] == depth[y])
      depth[y]++;
  }
}

bool same(ll x, ll y) { return (find(x) == find(y)); }
P itrTree[123456];
int main() {
    ll n,m;
    init(123456);
    cin>>n>>m;
    vector<ll> a;
    REP(i,n){ll h;cin>>h;a.pb(h);}
    REP(i,m){
        ll s,t;
        cin>>s>>t;
        merge(s,t);
    }
    REP(i,n){
        itrTree[i]=P(MAX,i);
    }
    set<ll> p;
    REP(i,n){
        ll parent=find(i);
        p.insert(parent);
        if(itrTree[parent].first>a[i]){
            itrTree[parent].first=a[i];
            itrTree[parent].second=i;
        }
    }
    if(p.size()==1)return !printf("0\n");
    if(p.size()*2-2>n){
        cout<<"Impossible"<<endl;return 0;
    }
    ll ret=0;
    for(auto &i:p){
        ret+=itrTree[i].first;
        a[itrTree[i].second]=MAX;
    }
    sort(a.begin(),a.end());
    REP(i,(signed)p.size()-2){
        ret+=a[i];
    }
    cout<<ret<<endl;
    
}


Measured memory_bytes: 11508
import           Control.Monad
import           Control.Applicative

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  rs     <- replicateM m $ map read . words <$> getLine

  forM_ (ans n rs) $ \i -> print i
  where ans n rs = map (\i -> length (filter (== i) (concat rs))) [1 .. n]

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
//#define int ll
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back

int r, c, m;

int r_cnt[333'333];
int c_cnt[333'333];
set<pair<int,int>> st;
void solve()
{
    cin>>r>>c>>m;

    forn(i, m)
    {
        int x, y; cin>>x>>y;
        --x, --y;
        r_cnt[x]++;
        c_cnt[y]++;
        st.insert(mp(x, y));
    }
    int rmx = *max_element(r_cnt, r_cnt+r);
    int cmx = *max_element(c_cnt, c_cnt+c);
    vector<int> rdx, cdx;
    forn(i, r) if (r_cnt[i] == rmx) rdx.pb(i);
    forn(i, c) if (c_cnt[i] == cmx) cdx.pb(i);
    forn(i, sz(rdx)) forn(j, sz(cdx))
    {
        if (st.count(mp(rdx[i], cdx[j]  ) ) == 0)
        {
            cout << (rmx+cmx)<<'\n';
            return;
        }
    }   
    cout << rmx+cmx-1<<'\n';
}

signed main(void)
{
    int T = 1;
    // cout << fixed;
    // cout.precision(44);
    ios_base::sync_with_stdio(0); cin.tie(0);
    //cin >> T;
    while (T--) solve();
    return 0;
}

Measured memory_bytes: 23756
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 2e7 + 9, M = 1e7, OO = 0x3f3f3f3f;
int main()
{
int n;
	string s;

	cin >> n >> s;

	for (int i = 0; i < s.size(); i++) {
		int ch = (s[i] -'A') + n;
		char ch2 = (ch % 26) + 'A';

		cout << (char)ch2 ;

	}
	cout << endl;

    return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

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

ll N;
ll ans = (ll) 1e9;

ll calc(ll n) {
    ll ret = 0;
    while (n) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

void solve() {
    cin >> N;
    REP(i,1,N) {
        ans = min(ans, calc(i) + calc(N-i));
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;
int main()
{
	int n;
	string in;
	cin >> in;
	n = in.size() - 1;
	if (in.compare(n, 1, "s")) {
		cout << in << "s";
	}
	else{
		cout << in << "es";
	}
	return 0;
}

Measured memory_bytes: 3632
n = int(input())
nums = list(map(int, input().split()))

for i in range(n):
    v = nums[i]
    j = i - 1
    while j >= 0 and nums[j] > v:
        nums[j+1] = nums[j]
        j -= 1
    nums[j+1] = v
    print(' '.join(map(str, nums)))


Measured memory_bytes: 5596
n = int(input())
a = list(map(int,input().split()))
a_max = max(a)

ans = 0
for i in range(1, n):
  if a[i - 1] > a[i]:
    ans += a[i - 1] - a[i]
    a[i] = a[i - 1]

print(ans)

Measured memory_bytes: 32172
#include <bits/stdc++.h>
using namespace std;
long long n,a,b,c;
string x[100005];
vector <char> s;
bool ok=1;
int main()
{ cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin>>n>>a>>b>>c;
  for(int i=1;i<=n;i++)
    cin>>x[i];
  x[n+1]=x[n];
  for(int i=1;i<=n;i++)
  { if(x[i]=="AB")
    { if(a==b)
      { if(a==0)
        { ok=0;
          break;
        }
        else if(a==1 && c==0)
        { if(x[i+1]=="AB")
          { a--,b++,s.push_back('B');
            continue;
          }
          if(x[i+1]=="AC")
             a++,b--,s.push_back('A');
          else
             a--,b++,s.push_back('B');
          continue;
        }
      }
      if(a>b)
         a--,b++,s.push_back('B');
      else
         a++,b--,s.push_back('A');
    }
    if(x[i]=="AC")
    { if(a==c)
      { if(a==0)
        { ok=0;
          break;
        }
        else if(a==1 && b==0)
        { if(x[i+1]=="AC")
          { a--,c++,s.push_back('C');
            continue;
          }
          if(x[i+1]=="AB")
             a++,c--,s.push_back('A');
          else
             a--,c++,s.push_back('C');
          continue;
        }
      }
      if(a>c)
         a--,c++,s.push_back('C');
      else
         a++,c--,s.push_back('A');
    }
    if(x[i]=="BC")
    { if(b==c)
      { if(b==0)
        { ok=0;
          break;
        }
        else if(b==1 && a==0)
        { if(x[i+1]=="BC")
          { b--,c++,s.push_back('C');
            continue;
          }
          if(x[i+1]=="AB")
             b++,c--,s.push_back('B');
          else
             b--,c++,s.push_back('C');
          continue;
        }
      }
      if(b>c)
         b--,c++,s.push_back('C');
      else
         b++,c--,s.push_back('B');
    }
  }
  if(!ok)
  { cout<<"No\n";
    return 0;
  }
  cout<<"Yes\n";
  for(auto it:s)
    cout<<it<<'\n';
  return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    string S;
    ll K;
    cin >> S >> K;
    for(int i = 0; i < K; i++){
        if(S.at(i) != '1'){
            cout << S[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
// Last Change: 03/22/2019 21:12:03.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

/*
AB全てABで
AはABで、BはBで
AはAで、BはABで
AはAで、BはBで、
*/

int main() {
  ll A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  ll ans, tmp;

  // AはABで
  tmp = C * max(X, Y) * 2;
  ans = tmp;

  // AはABで,BはBで
  tmp = C * X * 2;
  if (X < Y) {
    tmp += B * (Y - X);
  }
  ans = min(ans, tmp);

  // AはAで,BはABで
  tmp = C * Y * 2;
  if (X > Y) {
    tmp += A * (X - Y);
  }
  ans = min(ans, tmp);

  // AはAで,BはBで
  tmp = A * X + B * Y;
  ans = min(ans, tmp);

  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,w,h) rep(j,h)rep(i,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> a(n);rep(i,n)std::cin >> a[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int a,b,c;
    std::cin >> a>>b>>c;
    if(a-b<=c){
        std::cout << c+b-a << std::endl;
    }else {
        std::cout << 0 << std::endl;
    }
}

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

const int MAXN = 1e2 + 5;

int N, M;
int a[MAXN][MAXN], b[MAXN][MAXN];
vector <int> gp[MAXN][MAXN];
vector <int> adj[MAXN];
bool bio[MAXN];
int conn[MAXN];

void load() {
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; i++)
		for (int j = 0; j < M; j++) {
			scanf("%d", a[i] + j);
			a[i][j]--;
		}
}

bool dfs(int x) {
	bio[x] = true;
	for (auto it : adj[x])
		if (conn[it] == -1 || (!bio[conn[it]] && dfs(conn[it]))) {
			conn[it] = x;
			return true;
		}
	return false;
}

void matching(int col) {
	for (int i = 0; i < N; i++) {
		adj[i].clear();
		for (int j = 0; j < N; j++)
			if (!gp[i][j].empty())
				adj[i].push_back(j);
	}
	
	memset(conn, -1, sizeof conn);
	for (int i = 0; i < N; i++) {
		memset(bio, false, sizeof bio);
		dfs(i);
	}
	
	for (int i = 0; i < N; i++) {
		b[conn[i]][col] = gp[conn[i]][i].back();
		gp[conn[i]][i].pop_back();
	}
}

void output(int mat[MAXN][MAXN]) {
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			printf("%d ", mat[i][j] + 1);
		puts("");
	}
}

void solve() {
	for (int i = 0; i < N; i++)
		for (int j = 0; j < M; j++)
			gp[i][a[i][j] / M].push_back(a[i][j]);
			
	for (int j = 0; j < M; j++)
		matching(j);
	
	output(b);
	
	for (int j = 0; j < M; j++) {
		vector <int> col;
		for (int i = 0; i < N; i++)
			col.push_back(b[i][j]);
		sort(col.begin(), col.end());
		for (int i = 0; i < N; i++)
			b[i][j] = col[i];
	}
	
	output(b);
}

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

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

int x[110];

int main(){
  int n, m, c;
  cin >> n >> m >> c;
  for (int i = 0; i < m; i++){
    int k;
    cin >> k;
    x[k]++;
  }
  for (int i = 0; i < c; i++){
    x[i+1] += x[i];
  }
  cout << min(m - x[c], x[c]) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  if(s=="AAA" || s=="BBB") cout<<"No"<<endl;
  else cout<<"Yes"<<endl;

  return 0;
}


Measured memory_bytes: 256