akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll d, g;
  cin >> d >> g;
  g /= 100;
  vll p(d), c(d);
  for (ll i = 0; i < d; i++) {
    cin >> p[i] >> c[i];
    c[i] /= 100;
  }

  vector<vll> dp(d, vll(g + 1, inf));
  dp[0][0] = 0;
  for (ll i = 1; i <= g; i++) {
    if (i > p[0] + c[0]) break;
    dp[0][i] = min(i, p[0]);
  }
  for (ll i = 1; i < d; i++) {
    dp[i] = dp[i - 1];
    for (ll j = 1; j <= g; j++) {
      for (ll k = 1; k <= p[i]; k++) {
        ll pts = (i + 1) * k;
        if (k == p[i]) pts += c[i];
        if (dp[i - 1][max(0ll, j - pts)] < inf) {
          dp[i][j] = min(dp[i][j], dp[i - 1][max(0ll, j - pts)] + k);
        }
      }
    }
  }
  /*for (ll i = 0; i < d; i++) {
    for (ll j = 0; j < g; j++) {
      cout << dp[i][j] << " ";
    }
    cout << dp[i][g] << endl;
  }*/
  cout << dp[d - 1][g] << endl;
}

Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
const int N=101000;
const int K=20;
double EPS=1e-7;
typedef long long ll;
#define lef(x) (x<<1)
#define rig(x) (lef(x)+1)
pair<int,int> tree[4*N];
int best[N];

void update(int p,int tl,int tr,int k,int c)
{
	if(tl==tr)
	{
		tree[p]={c,tl-1};
	}else
	{
		int mid=(tl+tr)/2;
		if(k<=mid)
			update(lef(p),tl,mid,k,c);
		else
			update(rig(p),mid+1,tr,k,c);
		tree[p]=min(tree[lef(p)],tree[rig(p)]);
	}
}

pair<int,int> query(int p,int tl,int tr,int l,int r)
{
	if(l>r)
		return {1e9,1e9};
	if(tl==l && tr==r)
	{
		return tree[p];
	}else
	{
		int mid=(tl+tr)/2;
		return min(query(lef(p),tl,mid,l,min(r,mid)),
					query(rig(p),mid+1,tr,max(l,mid+1),r));
	}
}



int32_t main()	
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    for (int i = 0; i < 4*N; ++i)
    {
    	tree[i]={1e9,1e9};
    }
	int n,m;
	string s;
	cin>>n>>m;
	cin>>s;
	if(s[n]!='1')
	{
		update(1,1,n+1,n+1,0);
	}
		pair<int,int> at;
	for (int i = n-1;i>=0; --i)
	{
		if(s[i]=='1')
		{
			best[i]=1e9;
			continue;
		}
		at=query(1,1,n+1,i+2,min(i+m+1,n+1));
		if(at.first==1e9)
		{
			best[i]=1e9;
			continue;	
		}
		best[i]=at.second;
		update(1,1,n+1,i+1,at.first+1);
		// cout<<i<<" "<<at.first+1<<"\n";
	}
	int t=0;
	if(best[0]==1e9)
	{
		cout<<-1<<"\n";
		return 0;
	}
	while(best[t]!=n)
	{
		cout<<best[t]-t<<" ";
		t=best[t];
	}
	cout<<best[t]-t<<"\n";

    return 0;
}

Measured memory_bytes: 4176
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        s: chars
    }

    let mut ret = 1i64 << 60;
    for i in 0..s.len()-2 {
        let mask = (1 << i) + (1 << (i+1)) + (1 << (i+2));
        let v = bit_filter(mask, &s);
        let k = num(v[0]) * 100 + num(v[1]) * 10 + num(v[2]);
        ret = std::cmp::min(ret, (753 - k).abs());
    }
    println!("{}", ret);
}

fn num(c: char) -> i64 {
    c as i64 - '0' as i64
}

#[allow(dead_code)]
pub fn bit_filter<T: Clone>(mask: usize, v: &[T]) -> Vec<T> {
    let mut ret = vec![];
    for i in 0..v.len() {
        if (mask >> i) & 1 == 1 {
            ret.push(v[i].clone());
        }
    }
    ret
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define int int64_t
#define rep(i, N) for(int i=0; i<N; i++)
#define repr(i, N) for(int i=N-1; i>=0; --i)
using namespace std;
//using pair = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;

//プロトタイプ宣言
//int myfunc(int, vvec);

//グローバル変数
//int N, M;
//vvec data(N, vec(M));

//関数：
int gcd(int mx, int mn) {
	if(mn == 0) return(mx);
	else gcd(mn, mx%mn);
}

bool has_divisor(int n, int i) {
	//base case 1:
	if (i == n) return false;
	//base case 2:
	if (n % i == 0) return true;
	return has_divisor(n, i+1);
}

bool is_prime(int n) {
	if (n == 1) return false;
	else if (n == 2) return true;
	else {
		return !has_divisor(n, 2);
	}
}

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

	int N; cin >> N;
	string S; cin >> S;
	vec d(N);

	d[0] = 0;
	for(int i=1; i<N; i++) {
		if(S[i-1] == S[i]) d[i] = d[i-1] + 1;
		else d[i] = 0;
	}

	int ct = 0;
	rep(i, N) {
		if(d[i] == 0) ct++;
	}

	cout << ct << endl;
	return 0;
}
//std::string str;
//str = std::to_string(int i);
//bitset<3> s(N);
//int ans = (char)grid - '0';

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

int main() {
  string s,t;
  cin >> s >> t;
  int maxt=0;
  bool ti=false;
  for(int i=0;i<t.size();i++) {
    maxt=max(maxt,(int)t.at(i));
  }
  for(int j=0;j<min(t.size(),s.size());j++) {
    if(s[j]<maxt) ti=true;
  }

  for(int j=0;j<min(t.size(),s.size());j++) {
    if(s[j]!=maxt) break;
    if(j==min(t.size(),s.size())-1 && t.size()>s.size()) ti=true;
  }
  if(ti) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using lond = long double;
lond pi(void) {
 return atan(1.0) * 4.0;
}
#define PI 3.14159265358979323846264338327950L


int main(){
	int a,b,h,m;
	cin >> a >> b >> h >> m;
	double th = double(h *60 + m)/720 * 2 * PI;
	double tm = double(m)/60 * 2 * PI;
	//座標
	double xh = a * cos(th),yh = a*sin(th);
	double xm = b * cos(tm),ym = b*sin(tm);
	double dx = xh-xm,dy = yh-ym;
	double ans = sqrt(dx*dx + dy*dy);
	printf("%.10f\n",ans);
	return 0;
}

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

#define ll long long
#define ld long double
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<int> l(n);

    rep(i, n)
    {
        cin >> l[i];
    }
    //a1,b2,c3,null0

    vector<int> flag(n);
    int mn = INF;
    rep(i, (int)pow(4, n))
    {
        int temp = i;
        int temp_a = 0;
        int temp_b = 0;
        int temp_c = 0;
        int counter = 0;
        int flag;
        for (int j = n - 1; j >= 0; j--)
        {

            flag = temp / (int)pow(4, j);
            temp -= flag * (int)pow(4, j);
            if (flag == 3)
            {
                if (temp_c != 0)
                {
                    counter++;
                }
                temp_c += l[j];
            }
            else if (flag == 2)
            {
                if (temp_b != 0)
                {
                    counter++;
                }
                temp_b += l[j];
            }
            else if (flag == 1)
            {
                if (temp_a != 0)
                {
                    counter++;
                }
                temp_a += l[j];
            }
        }
        if (temp_a == 0 || temp_b == 0 || temp_c == 0)
        {
            continue;
        }
        int hypo = counter * 10 + abs(a - temp_a) + abs(b - temp_b) + abs(c - temp_c);
        //cout << hypo << endl;
        mn = min(hypo, mn);
    }

    cout << mn << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int out;
        if (399 < x && x < 600) {
            out = 8;
        }else if (x < 800) {
            out = 7;
        }else if (x < 1000) {
            out = 6;
        }else if (x < 1200) {
            out = 5;
        }else if (x < 1400) {
            out = 4;
        }else if (x < 1600) {
            out = 3;
        }else if (x < 1800) {
            out = 2;
        }else {
            out = 1;
        }
        System.out.println(out);
    }


    private static int nextInt(Scanner scanner) {
        return Integer.parseInt(scanner.next());
    }

    private static long nextLong(Scanner scanner) {
        return Long.parseLong(scanner.next());
    }

    private static float nextFloat(Scanner scanner) {
        return Float.parseFloat(scanner.next());
    }

    private static double nextDouble(Scanner scanner) {
        return Double.parseDouble(scanner.next());
    }


}









Measured memory_bytes: 35668
"""
重さと価値がそれぞれw_i,v_iであるようなn個の品物がある.
これらの品物の中から, 重さの総和がWを超えないように選んだ時の,
価値の総和の最大値を求めよ.
1<=n<=100, 1<=w_i,v_i<=100, 1<=W<=10000
"""
#-------------------------------------------------------------------------------
n ,W = map(int, input().split())
w=[0]*n
v=[0]*n
for i in range(n):
    x,y = map(int, input().split())
    w[i] = x
    v[i] = y
dp = [[0 for i in range(W+1)] for j in range(n+1)]
for i in range(n):
    for j in range(W+1):
        if j < w[i]:
            dp[i + 1][j] = dp[i][j]
        else:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i])
#print(dp)
print(dp[n][W])


Measured memory_bytes: 171528
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

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

  int cnt[100005] = {0};
  int ac = 0, pena = 0;

  while (m--) {
    int p;
    string s;
    cin >> p >> s;
    if (cnt[p] == -1) {
      ;
    } else if (s == "WA") {
      cnt[p]++;
    } else {
      pena += cnt[p];
      ac++;
      cnt[p] = -1;
    }
  }
  cout << ac << " " << pena << endl;

  return 0;
}

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

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

    int e = 0;
    int o = 0;

    if(n >= 2) e = n * (n-1) / 2;
    if(m >= 2) o = m * (m-1) / 2;
 
    cout << e+o << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	x := readInt()
	if is753(x) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func is753(x int) bool {
	switch {
	case x == 3:
		return true
	case x == 5:
		return true
	case x == 7:
		return true
	default:
		return false
	}
}

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

func readInt() int {
	i, e := strconv.Atoi(read())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 640
S=input()
T=input()
count=0
ans1=len(S)+1
ans=0
for i in range(len(S)-len(T)+1):
    count=count+i
    for j in range(len(T)):
        if S[count]!=T[j]:
            ans+=1
        count+=1
    if ans<ans1:
        ans1=ans
    ans=0
    count=0
print(ans1)

Measured memory_bytes: 9044
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif
const int N = 3005;
int dp[N][N][2];
int n;
int a[N];
int solve(int i,int j,int cur){
    if(i > j) return 0;

    int &ans = dp[i][j][cur];
    if(ans != -1) return ans;

    if(!cur){
        int res = -1e18;
        res = max(res,a[i] + solve(i+1,j,1));
        res = max(res,a[j] + solve(i,j-1,1));
        return ans = res;
    }else{
        int res = 1e18;
        res = min(res,-a[i] + solve(i+1,j,0));
        res = min(res,-a[j] + solve(i,j-1,0));
        return ans = res;
    }
    return -1;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<solve(0,n-1,0)<<endl;
    return 0;
    
}



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

typedef long long ll;

int gcds(int a, int b){
    if(a<b){
        swap(a,b);
    }
    int r=0;
    while(a%b>0){
        r=a%b;
        a=b;
        b=r;
    }
    return b;
}

int lcms(int a,int b){
    int c=0;
    c=gcds(a,b);
    int d=0;
    d=a*b/c;
    return d;
}

int main(){
    int N;
    cin>>N;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin>>a.at(i);
    }

    //sort(a.begin(),a.end());
    //reverse(a.begin(),a.end());
    //for(int i=1;i<N;i++){
    //    a.at(i)=lcms(a.at(i-1),a.at(i));
    //}

    int cnt=0;
    for(int i=0;i<N;i++){
        cnt+=a.at(i);
    }
    cnt-=N;

    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Relocate freopen("./in.txt","r",stdin);freopen("./out.txt","w",stdout)
#define up(mi,a,b) for(mi=a;mi<=b;++mi)
#define down(mi,b,a) for(mi=b;mi>=a;--mi)
#define fill(a,v) memset(a,v,sizeof(a))
#define INF 0x3f3f3f3f
#define MAX 500
#define LL long long
using namespace std;
int main(void)
{
	int i, j, k;
	FAST_IO;
	//Relocate;
	LL A, B, C;
	cin >> A >> B >> C;
	LL ans = min(A + B, C);
	if (C - ans > 0)
		ans++;

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

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

int main() {
	string s; cin >> s;
	bool f(0); 
	for(int i=0; i<s.size() && !f; i++) {
		if(s[i] != 'C') continue;
		for(int j=i+1; j<s.size() && !f; j++)
			if(s[j] == 'F') f = true;
	}
	cout << (f ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    vector<int> a(3),b(3);
    rep(i,3){
        cin>>a[i];
        b[i]=i;
    }
    int ans=100000;
    do{
        int cnt=0;
        rep(i,2) cnt+=abs(a[b[i]]-a[b[i+1]]);
        chmin(ans,cnt);
    }while(next_permutation(all(b)));
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#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 ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=200005;
int x[N],y[N],p[N],a[N],b[N],w[N],ind[N];
ii x1[N],y2[N];
map<int,vi> mx,my;
int finda(int x)
{
  return ((p[x]==x)?x:p[x]=finda(p[x]));
}
int combine(int x,int y)
{
  int x1=finda(x),y1=finda(y);
  if(x1==y1) return 0;
  p[y1]=x1;
  return 1;
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n,c1=0,c2=0;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>x[i]>>y[i],p[i]=i;
      mx[x[i]].pb(i);
      my[y[i]].pb(i);
    }
  for(auto it:mx)
    {
      vi tmp=it.se;
      x1[++c1]=mp(it.fi,tmp[0]);
      rep(i,1,sz(tmp))
	combine(tmp[i],tmp[0]);
    }
  for(auto it:my)
    {
      vi tmp=it.se;
      y2[++c2]=mp(it.fi,tmp[0]);
      rep(i,1,sz(tmp))
	combine(tmp[i],tmp[0]);
    }
  rep(i,1,c1)
    {
      a[i]=x1[i].se; b[i]=x1[i+1].se;
      w[i]=x1[i+1].fi-x1[i].fi; ind[i]=i;
    }
  rep(i,1,c2)
    {
      a[c1+i-1]=y2[i].se; b[c1+i-1]=y2[i+1].se;
      w[c1+i-1]=y2[i+1].fi-y2[i].fi; ind[c1+i-1]=c1+i-1;
    }
  sort(ind+1,ind+c1+c2-1,[](int i,int j){return w[i]<w[j];});
  ll ans=0;
  rep(i,1,c1+c2-1)
    if(combine(a[ind[i]],b[ind[i]]))
      ans+=w[ind[i]];
  cout<<ans<<endl;
  return 0 ;
}


Measured memory_bytes: 29568
#include <cstdio>
#include <cmath>
#include <climits>
#include <vector>
#include <algorithm>

int main() {
  int n, k;
  while (scanf("%d %d", &n, &k) == 2) {
    std::vector<int> cans(n);

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

    int total = INT_MAX;
    for (int i = 0; i+k <= n; ++i) {
      int j = i + k - 1;
      total = std::min(total,
                       std::min(std::abs(cans[i]), std::abs(cans[j])) +
                       std::abs(cans[j] - cans[i]));
    }

    printf("%d\n", total);
  }
  return 0;
}


Measured memory_bytes: 640
n = int(input())
s = ""
listW = []
flag = True
for i in range(n):
    if i == 0:
        w = input()
        listW.append(w)
        s = w[-1]
        continue
    else:
        w = input()
        if w in listW:
            print("No")
            flag = False
            break
        listW.append(w)
        if w[0] == s:
            s = w[-1]
            continue
        else:
            print("No")
            flag = False
            break
if flag:
    print("Yes")

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<utility>
#include<algorithm>
using namespace std;
#define INF (1<<29)

int dx[]={0,0,1,-1};
int dy[]={-1,1,0,0};
struct P{
	int xsum;
	int m;
	bool stable;
};
int w,h;
char p[62][12];

P dfs(int y,int x){
	int xl=INF,xr=-1;
	P up={-1},res={0,0,true};
	stack<pair<int,int> > q;
	pair<int,int>  a,b;
	q.push(make_pair(y,x));
	char id = p[y][x];
	if(p[y+1][x]!='.')xl=xr=x;
	while(!q.empty()){
		a = q.top();q.pop();//cout<<a.first<<' '<<a.second<<endl;
		if(p[a.first][a.second]=='.')continue;
		res.m++;
		res.xsum+=a.second;
		for(int i=0;i<4;i++){
			b = make_pair(a.first+dy[i],a.second+dx[i]);
			if(i==0 && p[b.first][b.second]!=id && p[b.first][b.second]!='.'){
				up = dfs(b.first,b.second);
				if(!up.stable){
					res.stable=false;
					break;
				}
				res.xsum += up.xsum;
				res.m += up.m;
			}else if(i==1 && p[b.first][b.second]!=id && p[b.first][b.second]!='.'){
				xl = min(xl,b.second);
				xr = max(xr,b.second);
			}
			if(p[b.first][b.second]==id){
				q.push(b);	
			}
		}
		p[a.first][a.second]='.';
	}
	int m = res.m;
	//printf("%d,%d,%c %d,%d,%d,%d\n",y,x,id,xl,xr,res.xsum,m);
	//printf(" %d %d %d\n",xl*m*2,res.xsum*2+m,(xr+1)*m*2);
	if(xl!=INF && !(xl*m*2<res.xsum*2+m && res.xsum*2+m<(xr+1)*m*2))res.stable=false;
	return res;
}
int main(){
	while(cin>>w>>h,w||h){
		memset(p,'.',sizeof(p));
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++)cin>>p[i][j];
		}
		bool ok=true;
		for(int x=1;x<=w;x++){
			p[h+1][x]='0';
		}
		for(int x=1;x<=w;x++){
			if(p[h][x]!='.' && !dfs(h,x).stable)ok=false;
		}
		cout<<(ok?"STABLE":"UNSTABLE")<<endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
char s[3];
int main()
{
        for(int i = 0; i< 3; i++)
        {
                cin >> s[i];
        }
        if(s[0] == s[1]&&s[0]== s[2]&&s[1] == s[2])
        {
                cout<< "No" << endl;
        }
        else{

          cout << "Yes"<< endl;
        }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define float long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define endl '\n'
#define pii pair<int, int>
#define min3(a,b,c) min(a, min(b, c))
#define max3(a,b,c) max(a, max(b, c))
#define all(x) x.begin(), x.end()
#define fill(a,b) memset(a, b, sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

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

}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

int index(int numToFind, std::vector<int> vectorToFindIn) {int len = vectorToFindIn.size();for (int i = 0; i < len; i++){if (vectorToFindIn[i] == numToFind){return i;}}return -1;}

ll gcd(ll a,ll b)
{
	if (b==0) return a;
	return gcd(b,a%b);
}
string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}
 
string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,cur=0,ans=0;
	cin>>n;
	int a[n];
	cin>>a[0];
	for (int i=1;i<n;++i)
	{
		cin>>a[i];
		if (a[i]>a[i-1])
		{
			ans=max(cur,ans);
			cur=0;
		}
		else
		{
			++cur;
		}
	}
	ans=max(cur,ans);
	cout<<ans;
	return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

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

const int undef=998244344;
const int N= 212345;
ll n;
 
struct MTree {
  ll st[4*N], ls[4*N];
   
  MTree() {
    rep(i,0,4*N) st[i] = n;
    rep(i,0,4*N) ls[i] = undef;
  }

  void push(int tl, int tr, int id) {
    if (ls[id] != undef) {
      st[id*2] = min(st[id*2], ls[id]);
      st[id*2+1] = min(st[id*2+1], ls[id]);
      ckmin(ls[id*2], ls[id]);
      ckmin(ls[id*2+1], ls[id]);
      ls[id] = undef;
    }
  }
   
  ll qsum(int l, int r, int tl=0, int tr=n-1, int id=1) {
    if (l > tr or r < tl) return 0;
    if (l <= tl and r >= tr) {
      return st[id];
    } else {
      push(tl, tr, id);
      int tm = (tl+tr)/2;
      return qsum(l, r, tl, tm, id*2) + qsum(l, r, tm+1, tr, id*2+1);
    }
  }
   
  void put(int l, int r, ll x, int tl=0, int tr=n-1, int id=1) {
    if (l > tr or r < tl) return;
    if (l <= tl and r >= tr) {
      ckmin(st[id], x);
      ckmin(ls[id], x);
    } else {
      push(tl, tr, id);
      int tm = (tl+tr)/2;
      put(l, r, x, tl, tm, id*2);
      put(l, r, x, tm+1, tr, id*2+1);
      ckmin(st[id], min(st[id*2], st[id*2+1]));
    }
  }

  ll qmin(int x) {
    return qsum(x, x);
  }
};
 

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int q;
  cin >> n >> q;

  ll ans = (n-2) * (n-2);

  MTree h, v;

  rep(i,0,q) {
    int a, b;
    cin >> a >> b;

    if (a==1) {
      int stop = v.qmin(b);
      h.put(2, stop, b);
      ans -= max(0,stop-2);
    } else {
      int stop = h.qmin(b);
      v.put(2, stop, b);
      ans -= max(0,stop-2);
    }
  }

  cout << ans << '\n';

}

Measured memory_bytes: 30108
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N, K; cin >> N >> K;
  int ans = 0;
  REP(i, N) {
    int h; cin >> h;
    ans += (h >= K ? 1 : 0);
  }
  cout << ans << endl;
}


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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n;
        cin>>n;
        n -= 400;
        n /= 200;
        cout<<8-n<<endl;
    }
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
int main(){
    char a[1010];
    for(int i=0;i<1010;i++)a[i]='0';
    scanf("%s",a);
    int w;
    scanf("%d",&w);
    for(int i=0;i<1010;i++){
        if(a[i]-'a'>=0&&a[i]-'a'<=25&&i%w==0){
            printf("%c",a[i]);
        }
    }
    printf("\n");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};

int main(){
  ll k,a,b;
  cin >> k >> a >> b;
  for(ll i=a;i<=b;i++){
    if(i%k==0){
      cout << "OK";
      return 0;
    }
  }
  cout << "NG";
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

string S;
int p = 0;

void a() {
  for(; p >= 1 && S[p-1] != '\n'; --p);
}

void e() {
  for(; p < S.size() && S[p] != '\n'; ++p);
}

int main() {
  string line;
  S = "\n";
  while(getline(cin,line) && line != "END_OF_TEXT") {
    S += line;
    S += '\n';
  }
  if(S.size() == 1) S += '\n';

  char c;
  string buffer = "";
  p = 1;
  while(cin >> c && c != '-') {
    switch(c) {
    case 'a':
      a();
      break;
    case 'e':
      e();
      break;
    case 'p':
      a();
      if(p != 1) {
	--p;
	a();
      }
      break;
    case 'n':
      e();
      if(p+1 != S.size()) ++p;
      a();
      break;
    case 'f':
      p = min(p+1,(int)S.size()-1);
      break;
    case 'b':
      p = max(p-1, 1);
      break;
    case 'd':
      if(p+1 != S.size()) S.erase(p,1);
      break;
    case 'k':
      if(S[p] == '\n') {
	if(p+1 != S.size()) {
	  S.erase(p,1);
	  buffer = "\n";
	}
      } else {
	for(int i = 1; ; ++i) {
	  if(S[p+i] == '\n'){
	    buffer = S.substr(p,i);
	    S.erase(p,i);
	    break;
	  }
	}
      }
      break;
    case 'y':
      S.insert(p,buffer);
      p += buffer.size();
      break;
    }
  }
  cout << S.substr(1);
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(){
  char s[2];
  int i,count,j;
  scanf("%s",&s);
  for(i=0;i<=2;i++){
  if(s[i]=='a' || s[i]=='b' || s[i]=='c'){
    for(j=i-1;j>=0;j--){
      if(s[j]!=s[i])
  count++;
    }} }
  if(count==3)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define Yes()           printf("Yes\n")
#define No()            printf("No\n")
#define YES()           printf("YES\n")
#define NO()            printf("NO\n")
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  string s; cin >> s;
  if (s.size() == 3) reverse(s);
  outl(s);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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




int main() {
  int n,y;
  cin >> n >> y;
  
  int r10000 = -1, r5000 = -1, r1000 = -1; 
  for(int i = 0; i <= n; i++){//10000
      for(int j = 0; i + j <= n; j++){//5000
        int c = n-i-j;//1000円札の枚数
        int ans = 10000*i + 5000*j + 1000*c;
        if(ans == y){
            r10000 = i;
            r5000 = j;
            r1000 = c;
        }
      }
  }
  cout << r10000 << " " << r5000 << " " << r1000 << endl;

}



Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
#define MX 100005
set<ii> T,o;
vi g[MX];
int N,M,a,b,C[MX];
bool dfs(int u,int p){
    if(C[u]++)return 0;
    int t=0;
    for(auto&h:g[u])if(!T.count(minmax(h,u))){
        T.insert(minmax(h,u));
        if(!dfs(h,u)){
            ++t;
            o.insert({u,h});
        }
    }
    if(t&1)return o.insert({u,p}),1;
    return 0;
}
int main(void){
    scanf("%d%d",&N,&M);
    if(M&1)return puts("-1"),0;
    F(M)scanf("%d%d",&a,&b),g[--a].PB(--b),g[b].PB(a);
    assert(!dfs(0,0));
    for(auto&h:o)printf("%d %d\n",h.aa+1,1+h.bb);
    return 0;
}


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

void Main() {
  int n;
  string s;
  cin >> n;
  cin >> s;

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

  cout << s << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
static const int N = 100;

int main() {
    int M[N][N];
    int n, u, k, v;
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }
    
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j) cout << " ";
            cout << M[i][j];
        }
        
        cout << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3132
/**
  *  Worg
  */
#include <vector>
#include <iostream>

int main() {
	int n, w; std::cin >> n >> w;
	std::vector<long long> dp(w + 1, -1);
	dp[0] = 0;

	for (int i = 0; i < n; i++) {
		int weight, value; std::cin >> weight >> value;

		for (int j = w - weight; j >= 0; j--) {
			if (dp[j] != -1) {
				dp[j + weight] = std::max(dp[j + weight], dp[j] + value);
			}
		}
	}

	long long answer = 0;
	for (auto& value: dp) {
		answer = std::max(answer, value);
	}
	std::cout << answer << '\n';

	return 0;
}

Measured memory_bytes: 1024
use std::vec::Vec;
use std::collections::BinaryHeap;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (n, m) = {
      let v: Vec<usize> = read_vec();
      (v[0], v[1])
    };

    // (b_i, a_i)
    let mut v: Vec<(u64, u64)> = Vec::new();
    for _ in 0..n {
      let t: Vec<u64> = read_vec();
      v.push((t[0], t[1]));
    }
    v.sort_by(|a, b| b.0.cmp(&a.0));
    //println!("{:?}", v);
    let mut heap = BinaryHeap::new();
    let mut now = v.pop().unwrap();
    let mut ans = 0;
    for i in 1..m + 1 {
      while now.0 <= i as u64 {
        heap.push(now.1);
        now = match v.pop() {
          None => (1_000_000, 0),
          Some(e) => e,
        };
      }
      ans += match heap.pop() {
        None => 0,
        Some(x) => x,
      };
    }

    //println!("{:?}", heap);
    println!("{}", ans);

}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int h, w, G[25][25], sy, sx, gy, gx;

int dfs(int ry, int rx, int depth) {
  if (depth == 10) return inf;

  int res = inf;
  rep(k, 4) {
    int ny = ry + dy[k];
    int nx = rx + dx[k];
    if (ny < 0 || ny >= h || nx < 0 || nx >= w || G[ny][nx]) continue;
    while (0 <= ny && ny < h && 0 <= nx && nx < w) {
      if (ny == gy && nx == gx) return depth + 1;
      if (G[ny][nx]) {
        G[ny][nx] = 0;
        chmin(res, dfs(ny - dy[k], nx - dx[k], depth + 1));
        G[ny][nx] = 1;
        break;
      }
      ny += dy[k];
      nx += dx[k];
    }
  }
  return res;
}

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

  while (cin >> w >> h, w && h) {
    memset(G, 0, sizeof(G));
    rep(i, h) {
      rep(j, w) {
        cin >> G[i][j];
        if (G[i][j] == 2) {
          sy = i, sx = j, G[i][j] = 0;
        }
        if (G[i][j] == 3) {
          gy = i, gx = j, G[i][j] = 0;
        }
      }
    }

    int ans = dfs(sy, sx, 0);
    cout << (ans == inf ? -1 : ans) << '\n';
  }

  




  
  return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int a, b, c, d;
    cin >> a >> b;
    cin >> c >> d;
    if (d == 1) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

int get_int3(int *a1, int *a2, char *a3) {
  scanf("%d %d %c", a1, a2, a3);
  return 0;
}

struct point2d {
    int x;
    int y;
};

#define NUM_MAX 100000
#define K_MAX 1000

enum color {
    ENUM_WHITE = 'W',
    ENUM_BLACK = 'B'
};

int main(void) {
    int num, pat;
    get_int2(&num, &pat);

    int i;
    static int cnt[K_MAX*2][K_MAX*2];
    for(i = 0; i < num; i++) {
        int x, y;
        char color;
        get_int3(&x, &y, &color);
        x = x % (pat*2);
        y = y % (pat*2);
        struct point2d np1 = {x%(pat*2), (y+pat)%(pat*2)};
        struct point2d np2 = {(x+pat)%(pat*2), y%(pat*2)};
        struct point2d np3 = {(x+pat)%(pat*2), (y+pat)%(pat*2)};
        if(color == ENUM_WHITE) {
            cnt[x][y]++;
            cnt[np3.x][np3.y]++;
        } else {
            cnt[np1.x][np1.y]++;
            cnt[np2.x][np2.y]++;
        }
    }

    int row, col;
#ifdef DEBUG
    for(row = 0; row < pat*2; row++) {
        for(col = 0; col < pat*2; col++) {
            printf(" %d", cnt[row][col]);
        }
        putchar('\n');
    }
#endif

    // calc cumulative sum of 2d
    static int cum_row[K_MAX*2+1][K_MAX*2+1];
    static int cum_col[K_MAX*2+1][K_MAX*2+1];
    static int cum[K_MAX*2+1][K_MAX*2+1];
    for(row = 1; row <= pat*2; row++) {
        for(col = 1; col <= pat*2; col++) {
            cum_row[row][col] = cum_row[row][col-1] + cnt[row-1][col-1];
        }
    }

    for(col = 1; col <= pat*2; col++) {
        for(row = 1; row <= pat*2; row++) {
            cum_col[row][col] = cum_col[row-1][col] + cnt[row-1][col-1];
        }
    }

    for(row = 1; row <= pat*2; row++) {
        for(col = 1; col <= pat*2; col++) {
            cum[row][col] = cum[row-1][col-1] + cum_col[row][col] + cum_row[row][col] - cnt[row-1][col-1];
        }
    }
#ifdef DEBUG
    printf("cum\n");
    for(row = 1; row <= pat*2; row++) {
        for(col = 1; col <= pat*2; col++) {
            printf(" %d", cum[row][col]);
        }
        putchar('\n');
    }
#endif

    int ans = 0;
    for(row = 0; row < pat; row++) {
        for(col = 0; col < pat; col++) {
            int res = cum[row+pat][col+pat] - cum[row][col+pat] - cum[row+pat][col] + cum[row][col];
            ans = max(ans, res);
            ans = max(ans, num-res);
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 62720
#include<stdio.h>
#include<stdlib.h>
#define INF 2140000000
#define N 102
#define white 0
#define gray 1
#define black 2

int color[N],p[N],d[N];      //ｐは親、ｄは距離

void prim(int a[][N],int n){
  int i,mincost,u;

  for(i=0;i<n;i++){
    color[i]=white;
    d[i]=INF;
  }

  d[0]=0;
  p[0]=-1;

  while(1){
    mincost=INF;

    for(i=0;i<n;i++){
      if(color[i]!=black && d[i]<mincost){
        mincost=d[i];
        u=i;
      }
    }

    if(mincost==INF) break;

    color[u]=black;

    for(i=0;i<n;i++){
      if(color[i]!=black && a[u][i]!=-1 && d[i]>a[u][i]){
        d[i]=a[u][i];
        p[i]=u;
        color[i]=gray;
      }
    }
  }
}

void print(int a[][N], int n){
  int sum=0,i;
  for(i=1;i<n;i++){
    sum+=d[i];
  }
  printf("%d\n",sum);
}

int main(){
  int a[N][N],n,i,j,result;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&a[i][j]);
    }
  }

  prim(a,n);
  print(a,n);

  return 0;
}


Measured memory_bytes: 2052
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	FastScanner in;
	PrintWriter out;

	void solve() {
		int n = in.nextInt();

		double answer = 0;
		if (n % 2 == 1) {
			answer = (n / 2 + 1) / (n * 1.0);
		} else {
			answer = (n / 2) / (n * 1.0);
		}

		out.println(answer);
	}

	void run() {
		try {
			in = new FastScanner(new File("Main.in"));
			out = new PrintWriter(new File("Main.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new Main().runIO();
	}
}


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

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi > 
const int N = 100010;
int main()
{
    ll a,b;
    cin>>a>>b;
    if(a+b==15) cout<<"+";
    else if(a*b ==15) cout<<"*";
    else cout<<"x";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST ll t;cin>>t;while(t--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
ll sizes[100001];
ll arr[100001];
ll root(ll i){
    while(i!=arr[i]) i=arr[i];
    return(i);
}
void Union(ll i,ll j){
    ll root_i=root(i),root_j=root(j);
    if(root_i==root_j) return;
    if(sizes[root_i]>sizes[root_j]) swap(root_i,root_j);
    sizes[root_j]+=sizes[root_i];
    arr[root_i]=arr[root_j];
    return;
}
bool prime[10000];
void era(){
    memset(prime,true,sizeof prime);
    for(ll p=2;p*p<=10000;p++){
        if(prime[p]){
            for(ll q=p*p;q<=10000;q+=p){
                prime[q]=false;
            }
        }
    }

    return;
}
bool D[10];
bool ok(int N){

    while(N){
        if(D[N%10]) return(false);
        N/=10;
    }
    return(true);

}
int main(){
    IO

    int N,K;
    cin>>N>>K;
    int d;
    mset0(D)
    for(int i=0;i<K;i++){
        cin>>d;
        D[d]=true;
    }
    int ans=N;
    while(!ok(ans)) ans++;
    cout<<ans;
    return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}


int main (){
    ll n,m;
    cin >> n >> m;
    ll sum=0;
    rep(i,m){
        ll a;
        cin >> a;
        sum+=a;
    }
    if(sum>n){
        cout << -1 <<endl;
    }
    else{
        cout << n-sum <<endl;
    }


    return 0;
}


Measured memory_bytes: 3620
n,k = map(int,input().split())
l = []
for _ in range(n):
    a = int(input())
    l.append(a)

ans = 10**9
l.sort()

for i in range(n-k+1):
    tmp = l[k+i-1] - l[i]
    if tmp < ans:
        ans = tmp

print(ans)

Measured memory_bytes: 80880
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a,long long int b){
	if(a<b){
    	int tmp = a;
    	a = b;
    	b = tmp;
  	}
  	int r = a % b;
  	while(r!=0){
    	a = b;
    	b = r;
    	r = a % b;
  	}
	return b;  
}

int main(){
	long long int n,k,max,ans;
  cin >> n >> k;
  long long int a[n];
  for(int i=0;i<n;i++)cin >> a[i];
  sort(a,a+n);
  reverse(a,a+n);
  max=a[0];
  ans=a[0];
  for(int i=0;i<n;i++)ans=gcd(ans,a[i]);
  if (k%ans==0 && k<=max)cout << "POSSIBLE" <<endl;
  else cout << "IMPOSSIBLE" <<endl;
  
}

Measured memory_bytes: 1024
#include <stdio.h>

int main() {
  int H, W, N, size, npainting;
  scanf("%d", &H);
  scanf("%d", &W);
  scanf("%d", &N);
  size = (H < W) ? W: H;
  npainting = (N + size - 1) / size;
  printf("%d\n", npainting);
}


Measured memory_bytes: 128
// cities to vapori-
// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz // math is your friend
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define REP(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){
	
	fastio;
	int n,p;
	string cad;
	cin >> n >> p >> cad;
	ll ans = 0;
	if(p == 2){
		for(int i = 0; i < n; ++i)
			ans += (i+1) * ((cad[i]-'0')%2 == 0);
	}else if(p == 5){
		for(int i = 0; i < n; ++i)
			ans += (i+1) * ((cad[i]-'0')%5 == 0);
	}else{
		map<int,int> mp;
		mp[0]++;
		int sum = 0, pot = 1;
		for(int i = n-1; i >= 0; --i){
			sum = (sum + (cad[i]-'0')*pot) % p;
			ans += mp[sum];
			mp[sum]++;
			pot = pot*10 % p;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 916