akhauriyash/Code-Regression huggingface dataset:
use List::Util qw(max min sum);
my ($n) = split(/\s+/, <>);
my ($s) = split(/\s+/, <>);

my $white = 0;
for (my $i=0; $i<$n; $i++) {
    $white++ if substr($s, $i, 1) eq '.';
}
my $black = $n - $white;

my @e = ($black);
my $w = 0;
for (my $i=0; $i<$n; $i++) {
    push @e, ($white-$w)+($i-$w);
    $w++ if substr($s, $i, 1) eq '.';
}

print min(@e), "\n";


Measured memory_bytes: 9088
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#pragma warning( disable : 26451)
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef vector<ll> vl;
typedef vector<vector<long long>> vvl;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const int INF = 1e9;

ll get_k1(string n)
{
	if (sz(n) <= 0)
		return 0;
	return (sz(n) - 1) * 9 + (n[0] - '0');
}

ll get_k2(string n)
{
	if (sz(n) < 2)
		return 0;
	ll tn = sz(n) - 1;
	ll res = 0;
	if (tn >= 2)
		res = (tn * (tn - 1)) / 2LL * 81;
	for (int i = 1; i <= n[0] - '0'; i++)
	{
		string ts = string(sz(n) - 1, '9');
		if (i == n[0] - '0')
			ts = n.substr(1);
		while (ts[0] == '0')
			ts.erase(0, 1);
		res += get_k1(ts);
	}
	return res;
}

ll get_k3(string n)
{
	if (sz(n) < 3)
		return 0;
	ll tn = sz(n) - 1;
	ll res = 0;
	if (tn >= 3)
	{
		res = (tn - 2) * (tn - 1) * (tn) / 6LL * 729LL;
	}
	for (int i = 1; i <= n[0] - '0'; i++)
	{
		string ts = string(sz(n) - 1, '9');
		if (i == n[0] - '0')
			ts = n.substr(1);
		while (ts[0] == '0')
			ts.erase(0, 1);
		res += get_k2(ts);
	}
	return res;
}

ll solve(string n, int k)
{
	if (k == 1)
	{
		return get_k1(n);
	}
	else if (k == 2)
	{
		return get_k2(n);
	}
	else if (k == 3)
	{
		return get_k3(n);
	}
	return 0;
}
ll brute(string n, int k)
{
	stringstream ss;
	ss << n;
	int nn;
	ss >> nn;
	ll res = 0;
	for (int i = 1; i <= nn; i++)
	{
		int tk = 0;
		int ti = i;
		while (ti)
		{
			if (ti % 10 > 0)
				tk++;
			ti /= 10;
		}
		if (tk == k)
			res++;

	}
	return res;
	
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	string s;
	int k;
	cin >> s >> k;
	cout << solve(s, k);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <string>
using namespace std;
#define min(x, y) ((x < y) ? x : y)
#define rep(x, n) for (int x = 1; x <= n; ++x)
const int inf = 214748364;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int k = a * 100 + b * 10 + c;
	if (k % 4 == 0)
		puts("YES");
	else puts("NO");
	return 0;
}


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

using namespace std;

#define ll long long int
#define MoD 1e9 + 7
//#define ar array

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

int d, t, s;

void solve(){
	cin >> d >> t >> s;

	string ans= ((d*1.0/s)>t)?"No":"Yes";
	cout << ans << "\n";
}

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

	int t=1;
	for(int i=1; i<=t; ++i) {
		solve();
	}

}


Measured memory_bytes: 3592
#include<stdio.h>
#include <string.h>
int main(){

char n[201],s[101],t[101];
char *p;
scanf("%s %s",n,s);

strcpy(t,n);
strcat(n,t);
p=strstr(n,s);
if(p==NULL)printf("No\n");
else printf("Yes\n");
return 0;
}

Measured memory_bytes: 972
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
/*int n,w;
int wt[105];
int val[105];
int dp[105][100005];
int go(int i,int cost,int ww)
{
    if(i==n && ww<w){
        return 1000000000;
    }
    if(i==n && ww>=w) return 0;
    if(dp[i][cost]!=-1) return dp[i][cost];
    int a = min(go(i+1,cost+val[i],ww+wt[i])+wt[i],go(i+1,cost,ww));

    dp[i][cost] = a;
    return dp[i][cost];
}
int main()
{
    cin>>n>>w;
    for(int i=0;i<n;i++){
        cin>>wt[i]>>val[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<go(0,0,0);
    int ans;
    for(int i=0;i<=100;i++){
        if(dp[0][i]<w)
            ans = i;
    }
    cout<<endl;
    cout<<ans<<endl;
}*/
ll wt[105];
ll val[105];
ll dp[105][100001];
int main()
{
    int n,w;
    cin>>n>>w;
    for(int i=0;i<n;i++)
    {
        cin>>wt[i]>>val[i];

    }
    for(int i=0;i<=100;i++){
    for(int j=0;j<=100000;j++){

            dp[i][j] = 1000000000001;
        }

    }

    for(int i=0;i<=n;i++)
    dp[i][0] = 0;

    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=100000;j++)
        {
            dp[i][j] = dp[i-1][j];
            if(j>=val[i-1])
            {
                dp[i][j] = min(dp[i][j],dp[i-1][j-val[i-1]]+wt[i-1]);
            }
        }
    }
    ll mx = 0;
    for(int i=100000;i>=0;i--)
    {
        if(dp[n][i]<=w && dp[n][i]!=0)
        {
            cout<<i<<endl;return 0;
        }
        //cout<<dp[n][i]<<endl;
    }
    cout<<mx<<endl;
}



Measured memory_bytes: 80256
#include<stdio.h>

#define MAX 200000
#define SENTINEL 2000000000
long merge(int A[],int n,int left,int mid,int right);
long mergeSort(int A[],int n,int left,int right);

int L[MAX/2+2],R[MAX/2+2];


int main(void){
  int A[MAX],n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  long int a = mergeSort(A,n,0,n);

  // for(i=0;i<n-1;i++){
  //   printf("%d ",A[i]);
  // }
  // printf("%d\n",A[n-1]);

  printf("%ld\n",a);
  return 0;
}




long int merge(int A[],int n,int left,int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  long int count=0;
  int i,j,k;

  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=R[n2]=SENTINEL;
  i=0,j=0;

  for(k=left;k<right;k++){
    // count++;
    if(L[i]<=R[j]){

      A[k]=L[i++];
    }
    else{
      A[k]=R[j++];
      count+=n1-i;
    }
  }
  return count;
}

long int mergeSort(int A[],int n,int left,int right){
  int mid;
  long int v1,v2,v3;
  if(left+1<right){
    mid = (left+right)/2;
    v1=mergeSort(A,n,left,mid);
    v2=mergeSort(A,n,mid,right);
    v3=merge(A,n,left,mid,right);
    return v1+v2+v3;
  }else return 0;
}



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

typedef long long ll;

template<typename H> void print(H head) { std::cout << head << std::endl; }

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

  ll A, B;
  std::cin >> A >> B;

  ll ans = (B - 1 + A - 2) / (A-1);
  print(ans);
  return 0;
}


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

int main() {
  int K,A,B;
  cin>>K>>A>>B;
  string a;
  for(int i=A; i<B+1; i++){
    if (i%K == 0){
      a = "OK";
      break;
    }
    else
      a="NG";
  }
  if (a=="OK")
    cout<<"OK"<<endl;
  else
    cout<<"NG"<<endl;
}



Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

string S, T;
int dp[3001][3001];

int main() {
	cin >> S >> T;
	for (int i = 0; i <= S.size(); i++) {
		for (int j = 0; j <= T.size(); j++) {
			if (i - 1 >= 0)
				dp[i][j] = max(dp[i - 1][j], dp[i][j]);
			if (j - 1 >= 0)
				dp[i][j] = max(dp[i][j - 1], dp[i][j]);
			if (i - 1 >= 0 && j - 1 >= 0 && S[i - 1] == T[j - 1])
				dp[i][j] = max(dp[i - 1][j - 1] + 1, dp[i][j]);

		}
	}
	
	string out;
	int i = S.size(), j = T.size();
	while (i > 0 && j > 0) {
		if (i >= 1 && j >= 1 && dp[i][j] == dp[i - 1][j - 1] + 1 && S[i - 1] == T[j - 1]) {
			out += S[i - 1];
			i--, j--;
		}
		else if(i >= 1 && dp[i][j] == dp[i - 1][j]){
			i--;
		}
		else if(j >= 1 && dp[i][j] == dp[i][j - 1]){
			j--;
		}
	}
	reverse(out.begin(), out.end());
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 35456
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	a := nextInts(n + 1)

	l, r := make([]int, n+1), make([]int, n+1)
	l[n], r[n] = a[n], a[n]
	for i := n - 1; i >= 0; i-- {
		l[i] = a[i] + (l[i+1]+1)/2
		r[i] = a[i] + r[i+1]
	}
	if l[0] > 1 {
		puts(-1)
		return
	}

	ans, cur := 0, 1
	for i := 0; i <= n; i++ {
		ans += cur
		if i < n {
			cur = min((cur-a[i])*2, r[i+1])
		}
	}
	puts(ans)
}


Measured memory_bytes: 5136
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

int main()
{
	IO_OP;
	int a, b, c;
	cin >> a >> b >> c;
	cout << a+b+c- max(a, max(b, c)) << endl;	
	
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <climits>
#include <algorithm>
#include <functional>
#include <string.h>

#define LOP(N) for(int i=0; i<N; i++)
#define LOOP(i, N) for(int i=0; i<N; i++)
#define LOOP_s(i, start, end) for(int i=start; i<end; i++)

typedef long long ll;

using namespace std;


int main() {
    ll a, b, x;
    cin >> a >> b >> x;

    ll min, max;
    min = a/x;
    if (a%x != 0) ++min;
    max = b/x;
    cout << max - min + 1;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int N;
int A[100];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int ans = -1;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            ans = max(ans, abs(A[i] - A[j]));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
sp = list([input().split() for i in range(n)])
sp2 =[[i] + sp[i] for i in range(n)]

ans = sorted(sp2, key= lambda x:int(x[2]), reverse=True)

ans2 = sorted(ans, key =lambda x:x[1])
for i in range(n):
  
  print(ans2[i][0] +1)

Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define DEKAI 1000000007
/* ┗(^o^)┛ｗｗｗｗｗ┏(^o^)┓ﾄﾞｺﾄﾞｺﾄﾞｺﾄﾞｺｗｗｗｗｗ */

int main(){
	int h,w;
	cin>>h>>w;
	char a[100][100];
	lp(i,h){
		lp(j,w){
			cin>>a[i][j];
		}
	}
	int x[100],y[100];
	lp(i,100){
		x[i]=0;
		y[i]=0;
	}
	lp(i,h){
		int stat=0;
		lp(j,w){
			if(a[i][j]=='#'){
				stat=1;
				break;
			}
		}
		if(stat==0){
			y[i]=1;
		}
	}
	lp(i,w){
		int stat=0;
		lp(j,h){
			if(a[j][i]=='#'){
				stat=1;
				break;
			}
		}
		if(stat==0){
			x[i]=1;
		}
	}
	lp(i,h){
		if(y[i]==1) continue;
		lp(j,w){
			if(x[j]==1) continue;
			cout<<a[i][j];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

class UnionFind {
    int n;
    vector<int> uni;
    int forest_size;
public:
    explicit UnionFind(int n) : n(n), uni(static_cast<u32>(n), -1), forest_size(n) {};

    int root(int a){
        if (uni[a] < 0) return a;
        else return (uni[a] = root(uni[a]));
    }

    bool unite(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] += uni[b];
        uni[b] = a;
        forest_size--;
        return true;
    }
    int size(){ return forest_size; }
    int size(int i){ return -uni[root(i)]; }
    bool same(int a, int b) { return root(a) == root(b); }
};

void solve(int n, int m){
    vector<int> deg(n);
    UnionFind uf(n);
    int ok = 1;
    for (int i = 0; i < m; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        if(!uf.unite(a, b)) ok = 0;

        deg[a]++; deg[b]++;
    }
    for (int i = 0; i < n; ++i) {
        if(deg[i] > 2) ok = 0;
    }
    puts(ok ? "yes" : "no");
};

int main() {
    int n, m;
    while(cin >> n >> m, n) solve(n, m);
    return 0;
}


Measured memory_bytes: 3636
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
 
 
using namespace std;
 
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
 
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}
#define int long long
#define left left228
#define right right228
#define prev prev228
#define mp make_pair
#define all(v) v.begin(), v.end()
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define firn(i, n) for (int i = 1; i < (int)n; ++i)
#define x first
#define y second

const int N = 200 * 1000 + 228;

int n;
int a[N], l[N], r[N];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        l[i] = 0, r[i] = n + 1;
    }
    vector<int> st;
    for (int i = 1; i <= n; ++i) {
        while (!st.empty() && a[i] < a[st.back()]) {
            r[st.back()] = i;
            st.pop_back();
        }
        st.push_back(i);
    }
    st.clear();
    for (int i = n; i; --i) {
        while (!st.empty() && a[i] < a[st.back()]) {
            l[st.back()] = i;
            st.pop_back();
        }
        st.push_back(i);
    }
    int res = 0;
    for (int i = 1; i <= n; ++i) {
        res += a[i] * (i - l[i]) * (r[i] - i);
    }
    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 7156
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	Int len = s.size();

	vector<vector<mint>> dp(len + 1, vector<mint>(13, 0));
	dp[0][0] = 1;

	for (Int i = 0; i < len; i++) {
		for (Int j = 0; j < 13; j++) {
			if (s[i] != '?') {
				dp[i + 1][(j * 10 + (s[i] - '0')) % 13] += dp[i][j];
			}
			else {
				for (Int k = 0; k < 10; k++) {
					dp[i + 1][(j * 10 + k) % 13] += dp[i][j];
				}
			}
		}
	}

	cout << dp[len][5] << "\n";

}

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

using namespace std;

template <typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
    o << "[";
    for(size_t i = 0; i < v.size(); i++) {
        o << v[i];
        if(i != v.size() - 1) {
            o << ", ";
        }
    }
    o << "]";
    return o;
}

int main() {
    string s;
    cin >> s;
    if(s.size() % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }
    for(size_t i = 0; i < s.size(); i += 2) {
        if(s[i] != 'h' || s[i + 1] != 'i') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return EXIT_SUCCESS;
}


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

typedef long long  Weight;
struct Edge {
	int src, dest;
	int cap, rev;
	Weight weight;
	bool operator < (const Edge &rhs) const { return weight > rhs.weight; }
};

const int V = 4000;
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
Weight h[V];                //??????????????£???
Weight dist[V];             //???????????¢
int prevv[V], preve[V];  //??´???????????¨??????

void add_edge(Graph &g, int src, int dest, int cap, Weight weight) {
	g[src].push_back(Edge{ src, dest, cap, (int)g[dest].size(), weight });
	g[dest].push_back(Edge{ dest, src, 0, (int)g[src].size() - 1, -weight });
}
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const Weight INF = 2147483647;
const Weight ZERO=0;
//????????????double?????????eps?????????
Weight min_cost_flow(Graph &g, int s, int t, int f) {
	Weight res = ZERO;
	memset(h, ZERO, sizeof(h));
	typedef pair<Weight, int> P;
	while (f > 0) {
		priority_queue<P, vector<P>, greater<P> > que;
		fill(dist, dist + V, INF);
		dist[s] = 0;
		que.push(P(ZERO, s));
		while (!que.empty()) {
			P p = que.top(); que.pop();
			const int v = p.second;
			if (dist[v] < p.first) continue;
			REP(i, g[v].size()) {
				Edge &e = g[v][i];
				if (e.cap > 0 && dist[e.dest] > dist[v] + e.weight + h[v] - h[e.dest]) {
					dist[e.dest] = dist[v] + e.weight + h[v] - h[e.dest];
					prevv[e.dest] = v;
					preve[e.dest] = i;
					que.push(P(dist[e.dest], e.dest));
				}
			}
		}
		if (dist[t] == INF) return -1;
		REP(v, V) h[v] = h[v] + dist[v];

		int d = f;
		for (int v = t; v != s; v = prevv[v]) d = min(d, g[prevv[v]][preve[v]].cap);
		f -= d;
		res = res + d * h[t];
		for (int v = t; v != s; v = prevv[v]) {
			Edge &e = g[prevv[v]][preve[v]];
			e.cap -= d;
			g[v][e.rev].cap += d;
		}
	}
	return res;
}

int N, M;
int norma ;
int amari ;
bool check(const int dis, const vector<vector<int>>&diss) {
	const int start=0;
	const int tukai0=start+1;
	const int tukai1=tukai0+N;
	const int akuma=tukai1+N;
	const int goal=akuma+M;
	Graph g(goal+1);
	for (int i = 0; i < N; ++i) {

		add_edge(g, start, tukai0 + i, 108, 0);
	}
	for (int i = 0; i < N; ++i) {
		add_edge(g,tukai0+i,tukai1+i,norma,0);
		add_edge(g,tukai0+i,tukai1+i,1,1);
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < M; ++j) {
			if (diss[i][j] <= dis) {
				add_edge(g,tukai1+i,akuma+j,1,0);
			}
		}
	}
	for (int j = 0; j < M; ++j) {
		add_edge(g,akuma+j,goal,1,0);
	}
	auto p(min_cost_flow(g,start,goal,M));
	if(p==-1)return false;
	return p<=amari;
}
int main() { cin >> N >> M;
	vector<vector<int>>diss(N,vector<int>(M));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < M; ++j) {
			cin>>diss[i][j];
		}
	}
	norma=M/N;
	amari = M-(M/N)*N;
	int al=0;
	int ar=1e9;
	while (al + 1 != ar) {
		int am((al+ar+1)/2);
		if (check(am, diss)) {
			ar=am;
		}else{
			al=am;
		}
	}
	if(amari==0)cout<<0<<endl;
	else cout<<1<<endl;
	cout<<ar<<endl;
	
	return 0;
}

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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("999");
            //ABC
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("1000");
            //ABD
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("1481");
            //ABD
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int N = int.Parse(InputList[0]);

        if (1 <= N && N <= 999) Console.WriteLine("ABC");
        else Console.WriteLine("ABD");
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
#define task "tet"
using namespace std;
const ll N = 1e6 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;

ll k;
string s;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>k>>s;
    ll n = s.size();
    if (n <= k) cout<<s;
    else{
        for (ll i = 0;i < k;i++) cout<<s[i];
        cout<<"...";
    }
}


Measured memory_bytes: 3672
from itertools import accumulate
input()
*s, = accumulate(map(int, input().split()))
l,r,t = 0,2,s[-1]
c = t
for m in s[1:-2]:
    while t+m > s[r]+s[r+1]:
        r += 1
    while m > s[l]+s[l+1]:
        l += 1
    x = sorted([s[l],m-s[l],s[r]-m,t-s[r]])
    c = min(c,x[-1]-x[0])
print(c)

Measured memory_bytes: 25972
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const ll INF = ll(1e18) + 1LL;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

// keyの値であるとき、key以下となる個数を求める。
bool isOK(const vector<ll> &A, const ll &key, const ll &k)
{
    ll cnt = 0;
    for(int i = 0; i < A.size(); i++)
    {
        if(A[i] >= 0)
        {
            ll left = -1, right = (int)A.size();
            while(right - left > 1)
            {
                ll mid = (left + right) / 2;
                if(A[i] * A[mid] < key) left = mid;
                else right = mid;
            }
            cnt += right;
        }
        else
        {
            ll left = -1, right = (int)A.size();
            while(right - left > 1)
            {
                ll mid = (left + right) / 2;
                if(A[i] * A[mid] < key) right = mid;
                else left = mid;
            }
            cnt += (int)A.size() - right;
        }
        if (A[i] * A[i] < key) cnt--;
    }
    cnt /= 2;
    if(cnt < k) return true;
    return false;
}

//ｘ以下となる個数がｋ個あるようなｘを求める
ll search(const vector<ll> &A, const ll &k)
{
    ll left = -INF, right = INF;
    while(right - left > 1)
    {
        ll key = (left + right) / 2;
        if(isOK(A, key, k)) left = key;
        else right = key;
    }
    return left;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    vector<ll> A(n);
    for(int i = 0; i < n; i++) cin >> A[i];
    sort(A.begin(), A.end());
    ll ans = search(A, k);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(void){
    int N,temp=1000;

    scanf("%d",&N);

    if(N>=100){
        temp = N%100;
        if(temp>=10){
            temp = temp%10;
        }
    }
    if(temp==1000 && N>=10){
        temp = N%10;
    }
    if(temp==1000 && N>=0){
        temp = N;
    }

    if(temp==2||temp==4||temp==5||temp==7||temp==9)
        printf("hon");
    if(temp==0||temp==1||temp==6||temp==8)
        printf("pon");
    if(temp==3)
        printf("bon");

    return 0;
}

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

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

    int ans = 0;
    vector<int> m(N);
    for(int i=0;i<N;i++){
        cin >> m[i];
        ans++;
        X -= m[i];
    }

    sort(m.begin(), m.end());

    ans += X/m[0];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#define mid ((l + r) / 2)
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1.0);

const int maxn = 2e5 + 5;
struct node {
    int t, e;
} a[maxn];
int n;

bool cmp(node x, node y) {
    return x.e < y.e;
}

int main() {
    ios_base :: sync_with_stdio(false);
    cin >> n;
    for(int i = 0; i < n; i ++) {
        cin >> a[i].t >> a[i].e;
    }
    sort(a, a + n, cmp);
    ll sum = 0;
    bool flag = true;
    for(int i = 0; i < n; i ++) {
        sum += a[i].t;
        if(sum > a[i].e) {
            flag = false;
            break;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main(){
	int k, t, ans = 0;
	scanf("%d %d", &k, &t);
	for(int i=0; i<t; i++){
		int a;
		scanf("%d", &a);
		ans = std::max(ans, (a-(k+1)/2)*2-1);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int op[N];
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    int y;
    int mx=0,c=0;
    for (int i=0;i<x;i++){
        cin>>y;
        c=0;
        while (y%2==0)
            y/=2,c++;
        mx+=c;
    }
    cout<<mx;
    return 0;
}


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

int main(void) {
	char str[1200];
	int i;
	
	gets(str);
	
	i = 0;
	while (str[i] != '\0') {
		if (islower(str[i])) putchar(toupper(str[i]));
		else if (isupper(str[i])) putchar(tolower(str[i]));
		else putchar(str[i]);
		i++;
	}
	puts("");
	
	return 0;
}

Measured memory_bytes: 524
n=int(input())
h=list(map(int,input().split()))
ans=0
kari=0
for i in range(n-1):
        if h[i+1]<=h[i]:
            kari+=1
        else:
            if ans<kari:
                ans=kari
            kari=0
        
       
print(max(ans,kari))

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

using namespace std;

namespace {
    int N;
    vector<int> A;
    void input() {
        cin >> N;
        A.resize(N);
        for (int i = 0; i < N; i++) {
            cin >> A[i];
        }
    }

    void solve() {
        map<int, int> M;
        for (auto a : A) {
            M[a]++;
        }
        int ans = 0;
        for (auto it = M.begin(); it != M.end(); it++) {
            auto a = it->first;
            auto count = it->second;
            if (a > count) {
                ans += count;
            } else {
                ans += count - a;
            }
        }
        cout << ans << endl;
    }
}

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



Measured memory_bytes: 5120
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	N := readInt64()
	K := readInt64()

	var ans int64
	for b := int64(1); b <= N; b++ {
		ans += N / b * max(0, b-K)
		ans += max(0, N%b+1-K)
	}

	if K == 0 {
		ans -= N
	}

	println(ans)
}

func max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <list>
#include <cmath>
using namespace std;
#define rep(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define rep1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
long long int Max(long long int a,long long int b){
    if(a>=b)return a;
    else return b;
}
long long int comb(long long int n,long long int r){
    vector<vector<long long int> > v(n+1,vector<long long int>(n+1,0));
    long long int i,j;
    rep(i,0,n+1){
        v.at(i).at(0)=1;
        v.at(i).at(i)=1;
    }
    rep(i,0,n+1){
        rep(j,0,i)v.at(i).at(j)=v.at(i-1).at(j-1)+v.at(i-1).at(j);
    }
    return v.at(n).at(r);
}
int main(void){
    int a,b,c=0,d=0,i;
    cin>>a>>b;
    rep(i,0,a)c+=b*pow(10,i);   
    rep(i,0,b)d+=a*pow(10,i);
    if(c>=d)cout<<c<<endl;
    else cout<<d<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int H, W, N;
        H = cin.nextInt();
        W = cin.nextInt();
        N = cin.nextInt();
        int[] Y = new int[N];
        int[] X = new int[N];

        long[] XY = new long[N];

        int[] p = new int[W];
        p[0] = 1;

        for (int i = 0; i < N; i++)
        {
            Y[i] = cin.nextInt() - 1;
            X[i] = cin.nextInt() - 1;
            XY[i] = ((long)X[i] << 32) + Y[i];
        }

        Array.Sort(XY);

        int ans = H;

        int nowx = 0;
        for (int i = 0; i < N; i++)
        {
            int x = (int)(XY[i] >> 32);
            int y = (int)(XY[i] & 0xFFFFFFFF);

            //Console.WriteLine(y + " " + x);
            while(x >= nowx + 2)
            {
                nowx++;
                p[nowx] = p[nowx - 1] + 1;
            }
            if (x == nowx + 1 && y == p[nowx]) p[nowx]++;
        }

        for (int i = 1; i < W; i++)
        {
            p[i] = Math.Max(p[i - 1] + 1, p[i]);
        }

        for (int i = 0; i < N; i++)
        {
            if (Y[i] >= p[X[i]]) ans = Math.Min(ans, Y[i]);

            //Console.WriteLine(X[i] + " " + Y[i] + " " + p[X[i]]);
        }

        Console.WriteLine(ans);
    }
    
}




class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}



Measured memory_bytes: 19120
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
R,C,K=map(int, sys.stdin.readline().split())

value=defaultdict(lambda: 0)
value=[ [0 for _ in range(C+1)] for __ in range(R+1) ]
for _ in range(K):
    r,c,v=map(int, sys.stdin.readline().split())
    value[r][c]=v

dp0=[0]*(C+1)
dp1=[0]*(C+1)
dp2=[0]*(C+1)
dp3=[0]*(C+1)

#dp1[1]=value[1][1]

for r in range(1,R+1):
    for c in range(1,C+1):
        dp0[c]=max( dp0[c-1], dp0[c] )
        dp1[c]=max( dp1[c-1], dp1[c] )
        dp2[c]=max( dp2[c-1], dp2[c] )
        dp3[c]=max( dp3[c-1], dp3[c] )
        #今のマスにアイテムがある場合
        if 0<value[r][c]:
            dp3[c]=max( dp3[c-1], dp2[c]+value[r][c] )
            dp2[c]=max( dp2[c-1], dp1[c]+value[r][c] )
            dp1[c]=max( dp1[c-1], dp0[c]+value[r][c] )

    #上の行にアイテムをコピー
    for c in range(1,C+1):
        dp0[c]=max( dp0[c], dp1[c], dp2[c], dp3[c] )
    dp1=[0]*(C+1)
    dp2=[0]*(C+1)
    dp3=[0]*(C+1)

print dp0[C]


Measured memory_bytes: 152336
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int a, b, c, x, y;
    
    cin >> a >> b >> c >> x >> y;
    
    int smallest = 1e9;
    
    for(int i = 0; i <= 200000; i += 2){
        int sum;
        int tmp1 = x - i / 2;
        int tmp2 = y - i / 2;
        int lackOfA = 0;
        int lackOfB = 0;
        if(i / 2 < x){
            lackOfA = x - i / 2;
        }
        if(i / 2 < y){
            lackOfB = y - i / 2;
        }
        
        sum = i * c + lackOfA * a + lackOfB * b;
        
        smallest = min(smallest, sum);
    }
    cout << smallest << endl;
}


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

int main(){
  int a;
  cin>>a;
  vector<long long>c(a),ans(a);
  for(int i=0;i<a;i++){
    cin>>c[i];
  }
  if(a%2==1){
    for(int i=0;i<a;i++){
      if(i%2==1){
        ans[(a+i)/2]=c[i];
      }
      else{
        ans[(a-i-1)/2]=c[i];
      }
    }
  }
  else{
        for(int i=0;i<a;i++){
      if(i%2==0){
        ans[(a+i)/2]=c[i];
      }
      else{
        ans[(a-i-1)/2]=c[i];
      }
    }
  }
      for(int i=0;i<a;i++){
cout<<ans[i];
        if(i!=a-1){
          cout<<" ";
        }
        else{
          cout<<endl;
        }
    }
  }


Measured memory_bytes: 5248
#include <cstdio>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 
//__int128
const int maxn = 2e5;
int a[maxn];

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	//freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	int n;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	LL res = 0;
	int c = 0;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		if(a[i] < 0){
			++c;
			a[i] = -a[i];
		}
		res += a[i];
	}
	if(c & 1){
		sort(a, a + n);
		res -= 2 * a[0];
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<queue>
#include<algorithm>
const int N = 1e5+5;
struct Element{
    int v,d;
    bool operator < (const Element &u)const{
        return v>u.v;
    }
};
Element a[N];
std::priority_queue<Element>Q;

int cmp(Element a,Element b){
    if(a.d!=b.d) return a.d<b.d;
    else return a.v>b.v;
}

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    //a[i].d表示a[i]必须在第d天(包括)之内完成
    for(int i = 0; i < n; i++){ 
        scanf("%d%d",&a[i].d,&a[i].v);
        a[i].d = m+1-a[i].d;
        if(a[i].d<=0){
            a[i].d = 1;
            a[i].v = 0;
        }
    }
    std::sort(a,a+n,cmp);
    for(int i = 0; i < n; i++){
        int size = Q.size();
        if(size>=a[i].d){
            int v = Q.top().v;
            if(v<a[i].v){
                Q.pop();
                Q.push(a[i]);
            }
        }
        else Q.push(a[i]);
    }
    long long ans = 0;
    while(Q.size()){
        ans += (long long)Q.top().v;
        Q.pop();
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 2168
#include<stdio.h>
#define N 1000000
#define MAXM 100
#define SPAN 4
int insertionSort(int[],int,int);
void shellSort(int[],int);
void printArray(int[],int);
int main(void)
{
  int i,n;//counter
  int arr[N];//array
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&arr[i]);
  shellSort(arr,n);
  return 0;
}
int insertionSort(int A[],int n,int g)
{
  int i,j;//counter
  int v;
  int cnt=0;
  for(i=g;i<n;i++)
    {
      v=A[i];
      j=i-g;
      while(j>=0&&A[j]>v)
        {
          A[j+g]=A[j];
          j=j-g;
          cnt++;
        }
      A[j+g]=v;
    }
  return cnt;
}
void shellSort(int A[],int n)
{
  int i;//counter
  int pow4=1;
  int cnt=0;
  int m;
  int G[MAXM];
  for(m=1;;m++)
    {
      pow4*=SPAN;
      if(pow4>n) break;
    }
  for(i=0;i<m;i++)
    {
      pow4/=SPAN;
      G[i]=pow4;
    }
  for(i=0;i<m;i++) cnt+=insertionSort(A,n,G[i]);
  //output is from here
  printf("%d\n",m);
  printArray(G,m);
  printf("%d\n",cnt);
  for(i=0;i<n;i++) printf("%d\n",A[i]);
}
void printArray(int arr[],int n)
{
  int i;
  for(i=0;i<n;i++)
    {
      if(i>0) printf(" ");
      printf("%d",arr[i]);
    }
  printf("\n");
}


Measured memory_bytes: 5604
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)

	a1 := make([]int, N+1)
	a2 := make([]int, N+1)

	for i := 1; i < N+1; i++ {
		var a int
		fmt.Scan(&a)
		a1[i] = a1[i-1] + a
	}
	for i := 1; i < N+1; i++ {
		var a int
		fmt.Scan(&a)
		a2[i] = a2[i-1] + a
	}

	ans := 0
	for i := 1; i < N+1; i++ {
		ans = max(ans, a1[i]+a2[N]-a2[i-1])
	}
	fmt.Println(ans)
}

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

bool sieve[100001]; // 1 = composite 0=prime

void sievealgo(void){
    sieve[1]=1;
    sieve[0]=1;
    for(int i=4;i<=100000;i+=2){
        sieve[i]=1;
    }
    for(int i=3;i<=100000;i+=2){
        if(sieve[i]==0){
            for(int j=2*i;j<=100000;j+=i){
                sieve[j]=1;
            }
        }
    }
}



int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int arr[100001];
    arr[0]=0;
    sievealgo();
    for(int i=1;i<=100000;i++){
        arr[i]=arr[i-1];
        if((i&1)==0){
            continue;
        }
        else{
            if(sieve[i]==0 && sieve[(i+1)/2]==0){
                arr[i]+=1;
            }
        }
    }
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int l,r;
        cin>>l>>r;
        cout<<arr[r]-arr[l-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 1152
matrix = [list(map(int, input().split(' '))) for _ in range(3)]

temps = []
for i in range(3):
    temp = []
    temp.append(matrix[i][1] - matrix[i][0])
    temp.append(matrix[i][2] - matrix[i][1])
    temp.append(matrix[i][2] - matrix[i][0])
    temps.append(temp)
    
if temps[0] == temps[1] and temps[0] == temps[2]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
#define MAX_N 14
#define INF 1000000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll dp[1<<MAX_N];
bool dc[1<<MAX_N]={};
vector<ll> c[2000];
ll n,m,tmp,ts,ans=INF;
signed main(){
  dc[0]=true;
  cin >> n >> m;
  ll a[m],b[m];
  fill(dp,dp+(1<<MAX_N),INF);
  for(int i=0;i<m;i++){
    ts=0;
    cin >> a[i]>>b[i];
    for(int j=0;j<b[i];j++){
      cin >>tmp;
      tmp--;
      c[i].push_back(tmp); 
      ts|=(1<<tmp);
    }
    for(ll j=0;;j=(j-ts)&ts){
      dp[j] = min(dp[j],a[i]);
      if(j==ts) break;
    }
  }
  dp[0]=0;
  ll TS;
  for(int i=1;i<1<<n;i++){
    for(ll y=0;;y=(y-i)&i){
      if(y==0) continue;
      if(y==i) break;
      TS = i^y;
      dp[i] = min(dp[i],dp[y]+dp[TS]);
    }
  }
  if(dp[(1<<n)-1]==INF){
    cout << "-1\n";
  }else{
    cout  << dp[(1<<n)-1]<<endl;
  }
}



Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
ans=1
flag=True
if 0 in a:
  ans=0
  flag=False
if flag:
  for i in a:
    #print(ans)
    ans*=i
    if ans>10**18:
      ans=-1
      break
print(ans)

Measured memory_bytes: 21656
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;

bool is_prime(int x)
{
    if(x == 2) return true;
    if(x % 2 == 0) return false;
    
    for(int i=2; i*i<=x; i++)
    {
        if(x % i == 0) return false;
    }
    
    
    return true;
}

int main(int argc, const char * argv[]) {
    
    int x;
    cin >> x;
    int ans = x;

    while(!is_prime(ans))
    {
        ans++;
    }
    
    cout << ans << endl;
    
    return 0;
}


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

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int sunuke[n] = {0};
    for (int i =0; i < k; i++) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int a;
            cin >> a;
            sunuke[a-1] = 1;
        }
    }
    int count =0;
    for (int sunu : sunuke) count += sunu;
    cout << (n-count) << endl;

    return 0;
}



Measured memory_bytes: 3500
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<set>
typedef long long int ll;
using namespace std;

ll string_to_ll(string str){
    ll sz = str.size();
    ll ret=0;
    ll ke=1;
    for(int i=sz-1;i>=0;i--){
        ll s=str[i]-'0';
        ret += ke*s;
        ke*=10;
    }
    return ret;
}

int main(){
    string str;
    cin >> str;
    int sz=str.size();
    int loop=1<<(sz-1);
    ll ans=0;
    for(int i=0;i<loop;i++){
        int cut[10];
        string substr[10];
        int tmp=i;
        int cut_num=0;
        for(int j=0;j<sz-1;j++){
            if(tmp%2==1){
                cut[cut_num]=j;
                cut_num++;
            }
            tmp=tmp/2;
        }
        if(cut_num==0){
            substr[0]=str;
        }else{
            for(int j=0;j<=cut_num;j++){
                if(j==0){
                    substr[j]=str.substr(0,cut[j]+1);
                }else if(j==cut_num){
                    substr[j]=str.substr(cut[j-1]+1,sz-1-cut[j-1]);
                }else{
                    substr[j]=str.substr(cut[j-1]+1,cut[j]-cut[j-1]);
                }
            }
        }
        for(int j=0;j<=cut_num;j++){
            ans += string_to_ll(substr[j]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
char Map[305][305];
char Mapp[305*2][305*2];
int main(){
    int n;
    scanf("%d",&n);
    getchar();
    for(int i=0;i<n;i++){
        scanf("%s",Map[i]);
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            Mapp[i][j]=Map[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=n;j<2*n;j++){
            Mapp[i][j]=Map[i][j-n];
        }
    }
    int ans=0;

   


    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                if(Mapp[j][k+i]!=Mapp[k][j+i]){
                    goto l1;
                }
            }
        }
        ans+=n;
        l1:;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 512