akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    int k, n;
    cin>>k>>n;
    int prev, first; cin>>prev; first = prev;
    int biggest=-1, sum=0;
    for(int i=0; i<n; i++){
        int temp;
        if(i == n-1){
            temp = first+k;
        }
        else cin>>temp;
        sum+=temp-prev;
        biggest = max(biggest, temp-prev);
        prev = temp;
    }
    cout<<sum-biggest;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t H,W,D;
  cin>>H>>W>>D;
  map<int64_t,pair<int64_t,int64_t>>M;
  for(int64_t i=0;i<H;i++)
    for(int64_t j=0;j<W;j++){
    int64_t a;cin>>a;
      pair<int64_t,int64_t>p(i,j);
      M[a]=p;
     }map<int64_t,int64_t>m;
  for(int64_t i=1;i<=D;i++)
    m[i]=0;
  for(int64_t i=D+1;i<=H*W;i++){
  int64_t I1=M.at(i).first;int64_t J1=M.at(i).second;
    int64_t I2=M.at(i-D).first;int64_t J2=M.at(i-D).second;
    m[i]=m[i-D]+abs(I1-I2)+abs(J1-J2);
  }int Q; cin>>Q;
  for(int i=0;i<Q;i++){
  int64_t L,R; cin>>L>>R;
    cout<<m.at(R)-m.at(L)<<endl;
  }
  return 0;
}

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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const int INF = 1e9;

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n, 0);

    for (int i = 0; i < k; i++){
      int d;
      cin >> d;
      int x;
      for (int j = 0; j < d; j++){
        cin >> x;
        x--;
        a[x]++;
      }
    }

    int ans = 0;
    for (auto i : a) if (i == 0) ans++;


    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {

	private final static int[] dp = new int[100010];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] h = new int[N];
		for(int i = 0;i < N;i++){
			h[i] = sc.nextInt();
		}
		sc.close();

		dp[0] = 0;
		dp[1] = Math.abs(h[0]-h[1]);
		for(int i = 2;i < N;i++){
			dp[i] += Math.min(dp[i-2]+Math.abs(h[i-2]-h[i]),dp[i-1]+Math.abs(h[i-1]-h[i]));
		}
		System.out.println(dp[N-1]);
	}
}

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

int main() {
 string s;
 cin >> s;
 int dpn = (s[0] - '0') * 10 + (s[1] - '0');
 int blkg = (s[2] - '0') * 10 + (s[3] - '0');
 if (dpn > 12 || dpn == 0) {
  if (blkg > 12 || blkg == 0) {
   printf("NA\n");
  } else printf("YYMM\n");
 } else {
  if (blkg > 12 || blkg == 0) {
   printf("MMYY\n");
  } else printf("AMBIGUOUS\n");
 }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " [" << x.fi << " " << x.se << "]"<<endl;
#define debug_v(x) {cerr << #x << " "; for (auto ioi : x) cerr << ioi << " "; cerr << endl;}
#define debug_vp(x) {cerr << #x << " "; for (auto ioi : x) cerr << '[' << ioi.fi << " " << ioi.se << ']'; cerr << endl;}
#define debug_v_v(x) {cerr << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cerr << ioi2 << " "; cerr << '\n';} cerr << "*/" << #x << endl;}
#define gen_clock(x) ll x = clock(); cerr << "Clock " << #x << " created" << endl;
#define check_clock(x) cerr << "Time spent in " << #x << ": " << (double)(clock() - x)/CLOCKS_PER_SEC << endl; x = clock();
#define reset_clock(x) x = clock()

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

int c[13],a[13][13];

void solve()
{
	int n,m,x,i,j,k;
	cin>>n>>m>>x;
	for(i=0;i<n;i++)
	{
		cin>>c[i];
	for(j=0;j<m;j++)
	{
		cin>>a[i][j];
	}
	}
	int ans=infi,cost;
	for(i=0;i<(1<<n);i++)
	{
		vi algo(m,0);
		cost=0;
		for(j=0;j<n;j++)
		if(i&(1<<j))
		{
			cost+=c[j];
			for(k=0;k<m;k++)
			algo[k]+=a[j][k];
		}
		for(j=0;j<m;j++)
		if(algo[j]<x) break;
		if(j==m)
		ans=min(ans,cost);
	}
	if(ans==infi) cout<<-1;
	else cout<<ans;
}

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


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int i;
    cin >> i;
    int j=i/100;
    if(i%10==7)cout << "Yes" << endl;
    else if(i/100==7)cout << "Yes" << endl;
    else if((i-100*j)/10==7)cout << "Yes" << endl;
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL INF=1e18;
const int MAXN=2e5+5;
const double eps=1e-10;
int tot;
int head[MAXN];
int n,m;
struct Edge
{
    int from,to,nxt;
}e[MAXN];
void addedge(int u,int v)
{
    e[tot].from=u;
    e[tot].to=v;
    e[tot].nxt=head[u];
    head[u]=tot++;
}
bool dfs(int s,int t,int k)
{
    if(s==n&&k==2) return true;
    for(int i=head[s];i!=-1;i=e[i].nxt){
        int to=e[i].to;
        if(dfs(to,n,k+1)) return true;
    }
    return false;
}
int main()
{
    int d,k;
    while(scanf("%d%d",&n,&m)!=EOF){
        memset(head,-1,sizeof(head));
        int u,v;
        for(int i=1;i<=m;i++){
            scanf("%d%d",&u,&v);
            addedge(u,v);
        }
        if(dfs(1,n,0))
            printf("POSSIBLE\n");
        else printf("IMPOSSIBLE\n");
    }
    return 0;
}


Measured memory_bytes: 3328
n = int(input())
l = list(map(int,input().split()))
count = 0
for i in range(1,n-1):
  temp = []
  temp.append(l[i-1])
  temp.append(l[i])
  temp.append(l[i+1])
  temp.sort()
  if temp[1] == l[i]:
    count +=1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    ll l,r;
    cin>>l>>r;

    ll r1=r/2019;
    ll l1=0;
    if(l>0){l1=(l-1)/ll(2019);}
    ll c=r1-l1;
    if(c>=1){

        cout<<0<<endl;

    }else{
        vector<ll> v;
        ll ans=INF;
        for(ll i=l;i<r;i++){
           for(ll j=i+1;j<=r;j++){
               ll a=(i*j)%2019;
               ans=min(a,ans);
           }
        }


        cout<<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define IN(p, a, b) a <= p && p <= b
using namespace std;

const int INF = 1001001001;

int main(void){
  int w, a, b;
  cin >> w >> a >> b;
  if(IN(b, a, a+w) || IN(b+w, a, a+w)){
    cout << 0 << endl;
    return 0;
  }
  cout << min(abs(a+w-b), abs(b+w-a)) << endl;
  return 0;
}

Measured memory_bytes: 256
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

N,M,C = ints_raw()
Bs = ints_raw()
ans = 0
for n_i in xrange(N):
    As = ints_raw()
    val = sum(map(lambda i: As[i]*Bs[i],range(M)))+C
    #print val
    if val > 0:
        ans = ans +1
print ans


Measured memory_bytes: 2568
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
        int n[3];
        for(int i=0; i<3; ++i)cin>>n[i];
        sort(n,n+3);
        int ans = abs(n[0]-n[1])+abs(n[1]-n[2]);
        cout<<ans<<endl;
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define mm(arr) memset(arr, 0, sizeof(arr))
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define pb push_back
#define PI 3.141592653589793
#define MOD 1000000007

using namespace std;
int main(){
    FAST
    string s; cin >> s;
    ll sum=700;
    for(int i=0;i<s.size(); i++){
        if(s[i] == 'o'){
            sum+=100;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3592
#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn=55;
int a[maxn];

bool cmp(const int a,const int b){
	return a>b;
}

int main(){
	int x,y;
	int ans=0;
	scanf("%d%d",&x,&y);
	for(int i=0;i<x;i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+x,&cmp);
	for(int i=0;i<y;i++){
		ans+=a[i];
	}
	printf("%d\n",ans); 
	return 0;
} 

Measured memory_bytes: 128
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
//    int x=sc.nextInt();
//    int a=sc.nextInt();
//    int b=sc.nextInt();
    System.out.println(((s.indexOf('a')!=-1)&&(s.indexOf('b')!=-1)&&(s.indexOf('c')!=-1))?"Yes":"No");
  }
}

Measured memory_bytes: 21844
N = int(input())
L = [list(map(int,input().split())) for _ in range(N)]

dp = [[0]*3 for _ in range(N+1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i+1][k] = max(dp[i+1][k], dp[i][j]+L[i][k])

print(max(dp[N][0], dp[N][1], dp[N][2]))


Measured memory_bytes: 48380
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int main()
{
    ll n, k;
    cin >> n >> k;

    cout << min(n % k, k - n % k) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t i64;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())

bool hasSuffix(string s, string suffix) {
  if (s.size() < suffix.size()) return false;
  for (int i = 0; i < suffix.size(); i++) {
    if (suffix.at(suffix.size() - 1 - i) != s.at(s.size() - 1 - i)) {
      return false;
    }
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  vector<string> list = {"dream", "dreamer", "erase", "eraser"};
  while (s.size() > 0) {
    bool replaced = false;
    for (int i = 0; i < list.size(); i++) {
      string suffix = list.at(i);
      if (hasSuffix(s, suffix)) {
        s = s.substr(0, s.size() - suffix.size());
        replaced = true;
      }
    }
    if (!replaced) {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;
}


Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    int n; cin >> n;
    map<int, int> m;
    rep(i, n) {
        int a; cin >> a;
        m[a]++;
    }

    priority_queue<int> pq;
    for (auto kv: m) pq.push(kv.second);

    if (pq.size() == 1) {
        cout << 1 << endl;
        return 0;
    }

    while (pq.top() != 1) {
        int first = pq.top(); pq.pop();
        int second = pq.top(); pq.pop();
        first--; second--;
        if (first > 0) pq.push(first);
        if (second > 0) pq.push(second);
    }

    cout << pq.size() << endl;
}


Measured memory_bytes: 5628
#include <bits/stdc++.h>
#define ll long long
using namespace std;
template <typename T> void chkmax(T &x, T y) {x = x > y ? x : y;}
template <typename T> void chkmin(T &x, T y) {x = x > y ? y : x;}
template <typename T> void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	while (!isdigit(c)) {if (c == '-') f = -1; c = getchar();}
	while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); x *= f;
}
const int N = 200010;
int n, a[N], s[N], val[N];
struct SegmentTree {
	const static int M = N * 4;
	#define lc k << 1
	#define rc k << 1 | 1
	int mx[M];
	void modify(int k, int l, int r, int x, int v) {
		if (l == r) return mx[k] = v, void();
		int mid = (l + r) >> 1;
		if (x <= mid) modify(lc, l, mid, x, v);
			else modify(rc, mid + 1, r, x, v);
		mx[k] = max(mx[lc], mx[rc]);
	}
	int query(int k, int l, int r, int L, int R) {
		if (L <= l && r <= R) return mx[k];
		int mid = (l + r) >> 1, ret = -1e9;
		if (L <= mid) chkmax(ret, query(lc, l, mid, L, R));
		if (R > mid) chkmax(ret, query(rc, mid + 1, r, L, R));
		return ret;
	}
} T0, T1;
bool check(int mx, int s) {
	if (s < 0) return false;
	if (s & 1) return T1.query(1, 1, n, mx, n) >= s;
	return T0.query(1, 1, n, mx, n) >= s;
}
int main() {
	read(n);
	for (int i = 1, mx = 0; i <= n; i++) {
		read(a[i]), val[i] = 1 + (a[i] > mx);
		chkmax(mx, a[i]);
	}
	memset(T1.mx, -0x3f, sizeof(T1.mx));
	for (int i = n; i; i--) {
		int v0 = T0.query(1, 1, n, a[i], n), v1 = T1.query(1, 1, n, a[i], n);
		if (val[i] & 1) T0.modify(1, 1, n, a[i], v1 + val[i]), T1.modify(1, 1, n, a[i], v0 + val[i]);
			else T0.modify(1, 1, n, a[i], v0 + val[i]), T1.modify(1, 1, n, a[i], v1 + val[i]);
	}
	for (int i = n; i; i--) s[i] = s[i + 1] + val[i] - 1;
	int cntx = 0, cnty = 0, mxx = 0, mxy = 0; string st = "";
	for (int i = 1; i <= n; i++) {
		T0.modify(1, 1, n, a[i], 0), T1.modify(1, 1, n, a[i], 1 - 1e9);
		if (check(mxy, cntx + s[i + 1] - cnty + (a[i] > mxx))) st = st + '0', cntx += a[i] > mxx, chkmax(mxx, a[i]);
			else if (check(max(mxx, a[i]), cnty + s[i + 1] - cntx - (a[i] > mxx))) st = st + '0', cntx += a[i] > mxx, chkmax(mxx, a[i]);
				else st = st + '1', cnty += a[i] > mxy, chkmax(mxy, a[i]);
	}
	if (cntx != cnty) cout << "-1\n"; else cout << st << '\n';
	return 0;
}

Measured memory_bytes: 9816
<?php
list($a, $v) = ints();
list($b, $w) = ints();
list($t) = ints();
$D = abs($a - $b);
$V = $v - $w;
if ($D === 0) exit('YES');
if ($V <= 0) exit('NO');
echo $D / $V <= $t ? 'YES' : 'NO';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16212
import java.util.*;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] d = new int[N];
    for (int i=0;i<d.length;i++){
      d[i] = sc.nextInt();
    }
    Arrays.sort(d);
    int ans = 1;
    for (int i=1;i<d.length;i++){
      if (d[i-1] < d[i]){
        ans = ans + 1;
      }
    }
    System.out.println(ans);
  }
}

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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define MOD 998244353

uint add(uint a, uint b) { return a+b < MOD ? a+b : a+b-MOD; }
uint sub(uint a, uint b) { return a < b ? a+MOD-b : a-b; }
uint mul(uint a, uint b) { return (ull)a*b%MOD; }
uint sqr(uint a) { return mul(a, a); }

uint modpow(uint b, uint e)
{
    uint r = 1;
    for (; e; e >>= 1) {
        if (e&1) r = mul(r, b);
        b = mul(b, b);
    }
    return r;
}

uint modinv(uint n) { return modpow(n, MOD-2); }
uint moddiv(uint n, uint d) { return mul(n, modinv(d)); }

#define N 100016

int d[N], f[N];

int main()
{
    canhazfast();

    int n, dmx = 0;
    uint ans = 1;

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
        dmx = max(dmx, d[i]);
        ++f[d[i]];
    }
    retif(d[0] != 0 || f[0] != 1) cout << "0\n", 0;
    for (int i = 1; i <= dmx; ++i) {
        retif(!f[i]) cout << "0\n", 0;
        uint t = modpow(f[i-1], f[i]);
        ans = mul(ans, t);
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import deque
def resolve():
    n,m=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(m):
        u,v=map(int,input().split())
        u-=1; v-=1
        E[u].append(v)
        E[v].append(u)

    q=int(input())
    VDC=[None]*q
    for i in range(q):
        v,d,c=map(int,input().split())
        v-=1
        VDC[i]=(v,d,c)
    VDC.reverse()

    dp=[[0]*11 for _ in range(n)]
    ans=[0]*n

    for v,d,c in VDC:
        Q=deque([(v,d)])
        dp[v][d]=1
        while(Q):
            v,d=Q.popleft()
            if(d>0):
                Q.append((v,d-1))
                for nv in E[v]:
                    if(dp[nv][d-1]): continue
                    dp[nv][d-1]=1
                    Q.append((nv,d-1))
            if(ans[v]==0):
                ans[v]=c

    print(*ans,sep='\n')
resolve()

Measured memory_bytes: 170972
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int height = sc.nextInt();
		int width = sc.nextInt();		
		List<List<Integer>> listHeight = new ArrayList<>();

		for(int cntHeight = 0 ; cntHeight < height ; cntHeight++){
			String str = sc.next();
			List<Integer> listWidth = new ArrayList<>();
			for(int cntWidth = 0 ; cntWidth < width ; cntWidth++){				
				listWidth.add((str.charAt(cntWidth) == '#') ? 1 : 0);
			}
			listHeight.add(listWidth);
		}
		sc.close();

		for(int cntHeight = height-1 ; cntHeight > -1 ; cntHeight--){
			int sum = 0;
			for(int cntWidth = 0 ; cntWidth < width ; cntWidth++){				
				sum = sum + listHeight.get(cntHeight).get(cntWidth);			
			}
			if(sum == 0){
				listHeight.remove(cntHeight);
				height--;
			}
		}

		for(int cntWidth = width-1 ; cntWidth > -1 ; cntWidth--){
			int sum = 0;
			for(List<Integer> list :listHeight){
				sum = sum + list.get(cntWidth);
			}			
			if(sum == 0){
				for(List<Integer> list :listHeight){
					list.remove(cntWidth);					
				}
				width--;
			}
		}
		
		for(List<Integer> list : listHeight){
			for(int cntWidth = 0 ; cntWidth < width ; cntWidth++){	
				System.out.print(list.get(cntWidth)==1 ? "#" : ".");
			}
			System.out.println("\n");
		}
	}
}

Measured memory_bytes: 25176
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef pair<pl, ll> ppl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll w, h, n;
  cin >> w >> h >> n;
  
  ll xmin=0, xmax=w, ymin=0, ymax=h;
  
  ll x, y, a;
  rep(_, n) {
    cin >> x >> y >> a;
    
    if(a==1) chmax(xmin, x);
    if(a==2) chmin(xmax, x);
    if(a==3) chmax(ymin, y);
    if(a==4) chmin(ymax, y);
  }
  
  cout << max(xmax-xmin, 0LL) * max(ymax-ymin, 0LL) << newl;
  return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll S;
    cin >> S;

    ll A = 1000000000LL;
    ll B = (S + A - 1) / A;
    cout << 0 << " " << 0 << " " << A << " " << 1 << " " << A*B-S << " " << B << endl;

    return 0;
}

/*



*/

Measured memory_bytes: 3592
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
 
const int MAX = 110;
 
int main(){
    int X,N;
    bool p[MAX] = {false};
 
    cin >> X >> N;
    if(N == 0){
        cout << X << endl;
        return 0;
    }
    for(int i = 0;i < N;i++){
        int n;
        cin >> n;
        p[n] = true;
    }
 
    if(p[X] == false){
        cout << X << endl;
        return 0;
    }
 
    int l = X - 1;
    int r = X + 1;
    while(true){
        if(p[l] == false){
            cout << l << endl;
            return 0;
        }
        if(p[r] == false){
            cout << r << endl;
            return 0;
        }
        l--;
        r++;
    }
 
    return 0;
}

Measured memory_bytes: 3140
#include <climits>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <cassert>

using namespace std;

int _gcd(int larger, int smaller) {
    if (smaller == 0) {
        return larger;
    }
    return _gcd(smaller, larger % smaller);
}

int gcd(int m, int n) {
    int larger, smaller;
    if (m < n) {
        larger = m;
        smaller = n;
    } else {
        larger = n;
        smaller = m;
    }
    return _gcd(larger, smaller);
}

int solve(int n, vector<int>& as) {
    int ans = as[0];
    for (int i = 1; i < as.size(); i++) {
        ans = gcd(ans, as[i]);
    }
    return ans;
}

void utest() {
    assert(gcd(1, 1) == 1);
    assert(gcd(1, 3) == 1);
    assert(gcd(2, 2) == 2);
    assert(gcd(4, 6) == 2);
    assert(gcd(4, 8) == 4);
    assert(gcd(4, 11) == 1);
    assert(gcd(35, 30) == 5);
    assert(gcd(13, 17) == 1);
    assert(gcd(1, 1) == 1);
    assert(gcd(3, 1) == 1);
    assert(gcd(2, 2) == 2);
    assert(gcd(6, 4) == 2);
    assert(gcd(8, 4) == 4);
    assert(gcd(11, 4) == 1);
    assert(gcd(30, 35) == 5);
    assert(gcd(17, 13) == 1);
}

int main() {
    int n;
    vector<int> as;
    scanf(" %d", &n);
    for (int i = 0; i < n; i++) {
        int ai;
        scanf(" %d", &ai);
        as.push_back(ai);
    }
    printf("%d\n", solve(n, as));
    return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
int main(int argc, char const *argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int n,k,s;
    cin>>n>>k>>s;
    vector<int>v(n,1);
    for(int i=0;i<n;i++) {
        if(i<k) v[i]=s;
        else {
            s==1e9?v[i]=s-1:v[i]+=s;
        }
    }
    for(int x:v) cout<<x<<" ";
}

Measured memory_bytes: 1664
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int k, n;
int a[200010];

int solve() {
    map<int, int> m;
    for (int i = 0; i < n; i++) m[a[i]]++;
    vector<int> v;
    for (auto u : m) {
        v.push_back(u.second);
    }
    
    sort(ALL(v));
    int res = 0;
    for (int i = 0; i < (int)v.size()-k; i++) res += v[i];
    return res;
}

void input() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 11640
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N, R = rl()

ans = R
if N < 10:
	ans += 100 * (10-N)
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1001001001;
constexpr long long INFL = (1LL<<60);
constexpr double eps = (1e-9);

// a の長さをすべてt以下にする操作を，k回以内に実現可能か？
bool is_ok(const vector<ll>& a, const ll& k, const ll& t) {
  ll count = 0;
  for (auto& x : a) {
    if (x == t) continue;
    count += x / t;
    if (count > k) {
      return false;
    }
  }
  if (count > k) return false;
  else return true;
}

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

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

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

  ll ub = a[n-1];
  ll lb = 0;

  while (ub - lb > 1) {
    ll mid = lb + (ub - lb) / 2;
    if (is_ok(a, k, mid)) ub = mid;
    else lb = mid;
  }

  cout << ub << endl;

  return 0;
}


Measured memory_bytes: 4744
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)

ll t[200001] = {};
int main() {
	ll n, T; cin >> n >> T;
	ll ans = 0;
	rep(i, 0, n)cin >> t[i];
	rep(i, 1, n) {
		if (t[i] - t[i - 1] > T) {
			ans += T;
		}
		else {
			ans += t[i] - t[i - 1];
		}
	}
	ans += T;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
//Rainy Season
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;
const int INF = 1 << 29;
int main ()
{
    string S;
    cin >> S;
    int max = 0;
    int count = 0;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] == 'R') {
            count++;
        }
        else {
            count = 0;
        }
        max = max < count ? count : max;
    }
    cout << max << endl;
    return 0;
}

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

class Radix {
private:
  const char* s;
  int a[128];
public:
  Radix(const char* s = "0123456789ABCDEF") : s(s) {
    int i;
    for(i = 0; s[i]; ++i)
      a[(int)s[i]] = i;
  }
  std::string to(long long p, int q) {
    int i;
    if(!p)
      return "0";
    char t[64] = { };
    for(i = 62; p; --i) {
      t[i] = s[p % q];
      p /= q;
    }
    return std::string(t + i + 1);
  }
  std::string to(const std::string& t, int p, int q) {
    return to(to(t, p), q);
  }
  long long to(const std::string& t, int p) {
    int i;
    long long sm = a[(int)t[0]];
    for(i = 1; i < (int)t.length(); ++i)
      sm = sm * p + a[(int)t[i]];
    return sm;
  }
};
int main() {
  Radix r;
  int a, b;
  string c;
  cin >> a >> b;
  c = r.to(a, b);
  
  cout << c.length() << endl;
  
}

Measured memory_bytes: 256
//Think simple yet elegant.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define REP(i,n) for(int i=0;i<n;i++)
const ll maxn=500005;
const ll mod=1e9+7;


int main(){
	fast;
	string s,t;
	cin>>s>>t;
	int ans=1e9,i,j,k;
	for(i=0;i<s.length()-t.length()+1;++i){
		int cnt=0;
		string temp=s.substr(i,t.length());
		for(j=0;j<t.length();++j){
			if(temp[j]!=t[j])
				++cnt;
		}
		ans=min(ans,cnt);
	}
	cout<<ans;
	
}




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


int main()
{
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R), A(M), B(M), C(M);
    for( int i = 0; i < R; ++i ) cin >> r[i];
    for( int i = 0; i < M; ++i ) cin >> A[i] >> B[i] >> C[i];


    int length[201][201] = {INT_MAX};
    for( int i = 1; i <= N; ++i ){
        for( int j = 1; j <= N; ++j ){
            length[i][j] = (i == j)? 0: 1e+7;
        }
    }
    
    for( int i = 0; i < M; ++i ){
        length[A[i]][B[i]] = C[i];
        length[B[i]][A[i]] = C[i];
    }

    for( int k = 1; k <= N; ++k ){
        for( int i = 1; i <= N; ++i ){
            for( int j = 1; j <= N; ++j ){
                length[i][j] = min( length[i][j], length[i][k] + length[k][j] );
            }
        }
    }

    int ans = INT_MAX;
    sort( r.begin(), r.end() );
    do{
        int total_length = 0;
        for( int i = 0; i < R-1; ++i ) total_length += length[r[i]][r[i+1]];
        ans = min( ans, total_length );
    }while( next_permutation( r.begin(), r.end() ) );

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <deque>
#include <vector>
#include <unordered_map>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <climits>
#include <bitset>
#include <random>

void show_all(std::string& str, int rest, int used = 0) {
	if (rest == 0) {
		std::cout << str << '\n';
		return;
	}
	for (auto i = 0; i <= used + 1; ++i) {
		str.push_back('a' + i);
		show_all(str, rest - 1, std::max(used, i));
		str.pop_back();
	}
}

int main() {
	std::cin.tie(nullptr); std::cin.sync_with_stdio(false);
	int n; std::cin >> n;
	std::string str = "a";
	show_all(str, n - 1);
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=305;
const int mod=1e9+7;
vc<pi> q[maxn];
int dp[maxn][maxn][maxn];
int n,m;
int dfs(int r,int g,int b)
{
    //dbg(r,g,b);
    if(r==n||g==n||b==n) return 1;
    int &ret=dp[r][g][b];
    if(ret!=-1) return ret;
    ret=0;
    int p=max({r,g,b})+1;
    bool okr=1,okg=1,okb=1;
    for(auto u:q[p])
    {
        int l=u.first,t=u.second;
        okr&=(((g>=l)+(b>=l)+1)==t);
        okb&=(((r>=l)+(g>=l)+1)==t);
        okg&=(((r>=l)+(b>=l)+1)==t);
    }
    if(okr) ret=(ret+dfs(p,g,b))%mod;
    if(okg) ret=(ret+dfs(r,p,b))%mod;
    if(okb) ret=(ret+dfs(r,g,p))%mod;
    //dbg(r,g,b,ret);
    return ret;
}
int main()
{
    memset(dp,-1,sizeof(dp));
    cin>>n>>m;
    for(int i=0,l,r,x;i<m;i++)
    {
        cin>>l>>r>>x;
        q[r].push_back(make_pair(l,x));
    }
    cout<<dfs(0,0,0)<<'\n';
}

Measured memory_bytes: 111232
#include<iostream> 
#include<algorithm>
#include<map>
#include <cstdlib>
using namespace std;

int main(){
    int n;
    cin>>n;
    long long r=1,a[100005];
    for(int i=0;i<n;i++){
    	cin>>a[i];
	}
	sort(a,a+n);
	if(a[0]==0){
		cout<<0;
		return 0;
	}
	for(int i=n-1;i>=0;i--){
		if(1000000000000000000/a[i]>=r) r*=a[i];
		else{
			cout<<-1;
			return 0;
		}
	}
	cout<<r;
    return 0;
}

Measured memory_bytes: 3928
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int main(){
  int N,A,B,C,D;  cin>>N>>A>>B>>C>>D;
  --A;  --B;  --C;  --D;
  string s; cin>>s;
  bool ok=true;
  char str='#';
  if(C<D){
    rep(i,B,D-1) if(s[i]==str && s[i+1]==str) ok=false;
    rep(i,A,C-1) if(s[i]==str && s[i+1]==str) ok=false;
  }else{
      rep(i,A,C-1) if(s[i]==str && s[i+1]==str) ok=false;
      rep(i,B,D-1) if(s[i]==str && s[i+1]==str) ok=false;
      if(ok){
        bool isok=false;
        rep(i,B,D+1) if(i-1>=0 && s[i-1]=='.' && s[i]=='.' && s[i+1]=='.' && i+1<=N-1){
          isok=true;
          break;
        }
        if(!isok) ok=false;
      }
  }
  if(ok){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[][] A = new int[n][m];
		int[] b = new int[m];
		int[] sum = new int[n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				A[i][j] = scan.nextInt();
			}
		}
		for (int i = 0; i < m; i++) {
			b[i] = scan.nextInt();
		}
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				sum[i] += A[i][j] * b[j];
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.println(sum[i]);
		}
	}

}

Measured memory_bytes: 40524
/**
 *      ABC 57 B
 *      author  : kyomukyomupurin
 *      created : 2018-09-06 02:26:06
**/

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, M; cin >> N >> M;
    int a[N + 10] = {}; int b[N + 10] = {}; int c[M + 10] = {}; int d[M + 10];

    for (int i = 0; i < N; ++i) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < M; ++i) {
        cin >> c[i] >> d[i];
    }
    int answer[N + 10] = {};

    for (int i = 0; i < N; ++i) {
        int point = 0;
        int min = abs(a[i] - c[0]) + abs(b[i] - d[0]);
        for (int j = 0; j < M; ++j) {
            int x = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if (x < min){
                min = x;
                point = j;
            }
        }
        answer[i] = point;
    }

    for (int i = 0; i < N; ++i) {
        cout << answer[i] + 1 << endl;
    }

    return 0;

}

Measured memory_bytes: 256
Scanf.scanf "%d %d" (fun n k ->
    let p = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a - 1)) in
    let c = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in

    let par = Array.init n (fun i -> i) in
    
    let rec root x =
        if x = par.(x) then x else
            let r = root par.(x) in
            let () = par.(x) <- r in
            r
    in

    let merge a b =
        if root a <> root b then
            par.(par.(b)) <- par.(a)
    in
    Array.iteri merge p;

    let cluster = Array.init n root in
    let size = Array.make n 0 in
    Array.iter (fun v -> size.(v) <- size.(v) + 1) cluster;

    let sum = Array.make n 0 in

    let calc_loop_score start len =
        let rec loop cur len acc =
            if len = 0 then acc else
                let cur = p.(cur) in
                let acc = acc + c.(cur) in
                loop cur (len - 1) acc
        in
        loop start len 0
    in
    Array.iteri (fun i sz -> if sz > 0 then sum.(i) <- calc_loop_score i sz) size;

    let calc_best start len =
        let rec loop cur len acc mx =
            if len = 0 then mx else
                let cur = p.(cur) in
                let acc = acc + c.(cur) in
                let mx = max mx acc in
                loop cur (len - 1) acc mx
        in
        if len = 0 then 0 else loop start len 0 (-100000000000000)
    in

    let score = Array.init n (fun i ->
        let cl = cluster.(i) in
        let sz = size.(cl) in
        if k >= sz then (
            let kr = (k - sz) / sz in
            let base = if sum.(cl) > 0 then kr * sum.(cl) else 0 in
            let len = sz + (k mod sz) in
            base + calc_best i len
        ) else (
            calc_best i k
        )
    ) in
    (*
    Array.iter (Printf.printf "%d ") cluster;
    print_newline ();
    Array.iter (Printf.printf "%d ") size;
    print_newline ();
    Array.iter (Printf.printf "%d ") sum;
    print_newline ();
    Array.iter (Printf.printf "%d ") score;
    print_newline ();
    *)
    Array.fold_left max (-10000000000000) score |> Printf.printf "%d\n"
)

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

using namespace std;

int main (void) {

  string s, t;
  int cnt = 0, cnt2 = 0;

  cin >> s >> t;

  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < s.size()-1-i; j++) {
      if (s[j] > s[j+1])
	swap (s[j], s[j+1]);
    }
  }
  for (int i = 0; i < t.size(); i++) {
    for (int j = 0; j < t.size()-1-i; j++) {
      if (t[j] < t[j+1])
	swap (t[j], t[j+1]);
    }
  }

  for (int i = 0; i < s.size(); i++) {
    if (s[i] > t[i]) {
      cnt = 1;
      break;
    }
    else if (s[i] < t[i])
      break;
    
    if (s[i] == t[i])
      cnt2++;
  }
  if (cnt2 == s.size() && s.size() >= t.size())
    cnt = 1;

  if (!cnt)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;  

  return 0;
  
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());

        if(n >= 30)
        {
            Console.WriteLine("Yes");
        }
        else {
            Console.WriteLine("No");
        }


        Console.ReadLine();
    }


}



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

using namespace std;

vector<int> graph[100005];
int dist[100005];
int ans = 0;

void dfs(int n){
    if(dist[n]){
        return;
    }
    dist[n] = 1;
    for(int e : graph[n]){
        dfs(e);
        dist[n] = max(dist[e] + 1, dist[n]);
    }
    ans = max(ans, dist[n]);
}

int main(){
    int N, M;
    cin >> N >> M;
    for(int i = 1; i<=M; i++){
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
    }
    for(int i = 1; i<=N; i++){
        if(!dist[i]){
            dfs(i);
        }
    }
    cout << ans-1 << endl;
}


Measured memory_bytes: 8192
#include <stdlib.h>
#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 count=0;
    rep(i,3){
        if(s.at(i)=='1')
            count++;
    }
    cout<<count<<endl;

    
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  long long a, b, k;
  cin >> a >> b >> k;
  if (a > k) {
    a -= k;
    k = 0;
  } else {
    k -= a;
    a = 0;
  }
  if (b > k) {
    b -= k;
  } else {
    b = 0;
  }
  cout << a << ' ' << b << endl;
  return 0;
}


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

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  int k, n;
  string s;
  cin >> k >> s;
  n = s.size();
  combination c(n + k);
  mint ans = 0;
  for (int i = 0; i <= k; i++) {
    mint now = mint(26).pow(k - i);
    now *= mint(25).pow(i);
    now *= c(i + n - 1, n - 1);
    ans += now;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 35648
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <assert.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
using namespace std;

// #define __DEBUG__

#ifdef __DEBUG__
bool debug_disabled = false;
#else
bool debug_disabled = true;
#endif

#define dbg if (debug_disabled) {} else cerr

int C[15];
int A[15][15];

void solve() {
    int N, M, X;
    cin >> N >> M >> X;
    for (int i = 0; i < N; ++i) {
        cin >> C[i];
        for (int j = 0; j < M; ++j) {
            cin >> A[i][j];
        }
    }
    int best = -1;
    for (int i = 0; i < (1 << N); ++i) {
        vector<int> cur(M, 0);
        int cost = 0;
        for (int j = 0; j < N; ++j) {
            if ((i & (1 << j)) == 0) continue;
            cost += C[j];
            for (int k = 0; k < M; ++k) {
                cur[k] += A[j][k];
            }
        }
        bool can = true;
        for (int j = 0; j < M; ++j) {
            if (cur[j] < X) can = false;
        }
        if (can) {
            if (best == -1 || cost < best) best = cost;
        }
    }
    cout << best << endl;
}

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout.precision(12);
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; ++i) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3660
#include <iostream>
using namespace std;
long long x;
int main(void){
    // Your code here!
    cin >> x;
    long long res = x / 11 * 2;
    if (x % 11 == 0) cout << res << endl;
    else if (x % 11 <= 6) cout << res + 1 << endl;
    else cout << res + 2 << endl;
}


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

using namespace std;

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a) for (int i = (int) (a); i < (int) (b); i++)
#define RS resize

int main()
{
	int n;
	cin >> n;
	int res = 0;
	int cnt = 0;
	rep(i, n) {
		int t;
		cin >> t;
		if (t) {
			cnt++;
			res = max(res, cnt);
		} else {
			cnt = 0;
		}
	}
	cout << ++res << endl;
}



Measured memory_bytes: 3100