akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int card[100010];

int main(void)
{
    int n, k;
    int c;
    int i, j;
    int zero;
    int max;
    
    while (1){
        scanf("%d%d", &n, &k);
        if (n == 0 && k == 0){
            break;
        }
        
        memset(card, 0, sizeof(card));
        
        zero = 0;
        for (i = 1; i <= k; i++){
            scanf("%d", &c);
            if (c == 0){
                zero = 1;
            }
            else {
                card[c] = 1;
            }
        }

        max = 0;
        for (i = 1; i <= n + 1; i++){
            if (card[i] != 0){
                card[i] += card[i - 1];
            }
            if (card[i] == 0 && card[i - 1] != 0){
                if (max < card[i - 1]){
                    max = card[i - 1];
                }
                j = i - 2;
                while (card[j] != 0){
                    card[j] = card[j + 1];
                    j--;
                }
            }
        }

        if (zero == 1){
            for (i = 1; i <= n + 1; i++){
                if (card[i] == 0 && card[i - 1] != 0 && card[i + 1] != 0){
                    if (max < card[i - 1] + card[i + 1] + 1){
                        max = card[i - 1] + card[i + 1] + 1;
                    }
                }
            }
        }
        
//        
//        for (i = 1; i <= n; i++){
//            printf("[%d]", card[i]);
//        }

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

Measured memory_bytes: 996
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
/*int find(int a){
     if(a==par[a])return a;
     return par[a]=find(par[a]);
}
void unite(int a,int b){
     a=find(a),b=find(b);
     if(a==b)return ;
     par[b]=a;
}
ll modexpo(ll a,ll b)
{
     int ans=1LL;
     while(b>0)
     {
          if(b&1)ans=(ans*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return ans;
}
*/















bool compare(pair<int,int> p1,pair<int,int> p2){
     if(p1.fi<p2.fi)return true;
     else if(p1.fi==p2.fi&&p1.se<p2.fi)return true;
     return false;

}

int main(){
     vector<string> t;
     t.pb("AC");t.pb("WA");t.pb("TLE");t.pb("RE");
     int n;
     cin>>n;
     int res[4]={0};
     for(int i=0;i<n;i++){
          string s;cin>>s;
          for(int j=0;j<4;j++){
               if(s==t[j]){
                    res[j]++;break;
               }
          }
     }
    for(int i=0;i<4;i++){
         cout<<t[i]<<" x "<<res[i]<<endl;
    }
}



















































Measured memory_bytes: 3600
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#define FasterIO     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define all(a) a.begin(),a.end()
#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<n;i++)
#define f1n(i,n) for(i=1;i<=n;i++)
#define szf sizeof()
#define sz size()
#define ln length()
using namespace std;
using ll=long long;
int cnt,element;
//long long int arr[100000001];
vector<ll>vec;
int main()
{
    ll a,b,c,k,flag=0,rafi,ans,sum=0;
    cin>>a>>b>>c>>k;
    if(a>=k)
    {
        cout<<k<<endl;
    }
    else{
        k=k-a;
      //  cout<<k<<endl;
        sum=a;
        if(b>=k)
        {
            cout<<a<<endl;
         //   return 0;
        }
        else
        {
            k=k-b;
           //   cout<<k<<endl;
            sum=sum-(1*k);
           /* if(sum<0)
            {
                sum=0;
            }*/
            cout<<sum<<endl;
            // return 0;
        }
    }
    return 0;
}


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

int main(){
  int i,n;
  string s;
  i=n=0;
  cin >> s;
  
  while(i<s.size()){
  	if(s.at(i) == '+') n++;
    else n--;
    i++;
  }
  cout << n << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

struct SHOP_INFO {
	int price;
	int count;
	bool operator<(const SHOP_INFO& another) const {
		return price < another.price;
	}
};
int main() {
	vector<SHOP_INFO> energy_price_map;
	int N, M;
	scanf("%d %d", &N, &M);

	SHOP_INFO input;
	while ((int)energy_price_map.size() < N) {
		scanf("%d %d", &input.price, &input.count);
		energy_price_map.push_back(input);
	}

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

	unsigned long long needed_money = 0;
	unsigned long long price = 0;
	unsigned int count = 0;
	for (auto shop_info : energy_price_map) {
		price = shop_info.price;
		count = shop_info.count;
		needed_money += M > count ? price*count : price*M;
		if ((M -= count) <= 0) break;

	}

	printf("%llu", needed_money);
	return 0;
}

Measured memory_bytes: 1400
#include<stdio.h>
 #include<stdlib.h>
 #include<string.h>
 
 
 int pop(void);
 void push(int insert);
 
 
int top = 1;
int matrix[2000];

int main(){

  int a,b,x;
  char pre_date;
  while((x = scanf("%s",&pre_date)) != -1){
    if(pre_date == '+') {
      a = pop();
      b = pop();
      push(b+a);

    }
    else if(pre_date == '-'){
     a = pop();
      b = pop();
      push(b-a);

    }
    else if(pre_date == '*'){
      a = pop();
      b = pop();
      push(b*a);

    }


    else push(atoi(&pre_date));

  }

  printf("%d\n",pop());

  return 0;

}


int pop(void){
  top--;
  //fprintf(stderr,"top %d : return matrix %d\n",top,matrix[top]);
  return matrix[top];

}


void push(int insert){
  //fprintf(stderr,"insert %d\n",insert);
  matrix[top] = insert;
  top++;
}

Measured memory_bytes: 548
#include<iostream>
using namespace std;
string s;
int main()
{
	int ans=0;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		ans+=s[i]-'0';
		ans%=9;
	}
	cout<<(ans==0?"Yes":"No");
	return 0;
} 

Measured memory_bytes: 3372
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val H = scanner.nextInt()
    val W = scanner.nextInt()
    val N = scanner.nextInt()

    val c = IntArray(H*W)
    var curIndex = 0
    for (i in 1..N) {
        val noc = scanner.nextInt()
        for (j in 1..noc) {
            c[curIndex] = i
            curIndex++
        }
    }

    val builder = StringBuilder()
    for (i in 0 until H) {
        builder.append(if (i%2==0) intArraytoStringWithSpace(c.copyOfRange(i*W,(i+1)*W)) else intArraytoStringWithSpace(c.copyOfRange(i*W,(i+1)*W).reversedArray())).append("\n")
    }
    print(builder.toString())
}

fun intArraytoStringWithSpace(array:IntArray): String {
    val builder = StringBuilder()
    array.forEach { builder.append(it).append(" ") }
    return builder.removeSuffix(" ").toString()
}

Measured memory_bytes: 39740
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[100010][4],dp[100010][4];
int main(){
    cin>>n;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=3;j++)
            cin>>a[i][j];
    for (int i=1;i<=3;i++)
        dp[1][i]=a[1][i];
    for (int i=2;i<=n;i++)
        for (int j=1;j<=3;j++)
            dp[i][j]=a[i][j]+max(dp[i-1][j+1<=3?j+1:(j+1)%3],dp[i-1][j+2<=3?j+2:(j+2)%3]);
    int res=0;
    for (int i=1;i<=3;i++)
        res=max(res,dp[n][i]);
    cout<<res;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

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

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

// ---------------------
#define INF 922337203685477580
#define IINF (1<<21)
typedef long long ll;

vector<pair<int, pair<int, int> > > G;
int V, E;

vector<int> par;
vector<int> rnk; // ??±???
void init(int n) {
  par = vector<int>(n);
  rnk = vector<int>(n);
  REP(i, n) {
    par[i] = i;
    rnk[i] = 0;
  }
}
int root(int key) {
  if (par[key] == key) return key;
  return root(par[key]);
}
int same(int a, int b) {
  return root(a) == root(b);
}
void unite(int a, int b) {
  int x = root(a);
  int y = root(b);
  if (x == y) return;

  if (rnk[x] < rnk[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rnk[x] == rnk[y]) rnk[x]++;
  }
}

int main() {
  cin >> V >> E;


  REP(i, E) {
    int s, t, w;
    cin >> s >> t >> w;

    G.push_back(make_pair(w, make_pair(s, t)));
  }
  init(V);
  sort(G.begin(), G.end());

  // for (auto g: G) {
  //   cerr << g.first << " (" << g.second.first << ", " << g.second.second << ")" << endl;
  // }

  ll sum = 0;
  for (auto g: G) {
    int s, t, w;
    w = g.first;
    s = g.second.first;
    t = g.second.second;

    if (!same(s, t)) {
      unite(s, t);
      sum += w;
    }
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 4500
if __name__ == "__main__":
    s = input()

    p = set(s)

    if len(p) % 2 == 1:
        print('No')
        exit()

    if 'S' in p and 'N' in p:
        print('Yes')
    elif 'W' in p and 'E' in p:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 2940
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( [ $ t : ty ] ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( [ $ t : ty ] ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( [ $ t ] ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let mut xs = get!([u64]);
    let k = get!(usize);

    for _ in 0..k {
        let i = (0..xs.len()).max_by_key(|&i| xs[i]).unwrap();
        xs[i] *= 2;
    }

    println!("{}", xs.iter().sum::<u64>());
}


Measured memory_bytes: 8572
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX_E 100005
#define MAX_V 10005

struct edge{int u, v, cost;};

bool comp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}
int V, E;
edge es[MAX_E];
int par[MAX_V];
int _rank[MAX_V];

void init(int x){
	for(int i = 0; i < x; i++){
		par[i] = i;
		_rank[i] = 0;
	}
}

int find(int x){
	return par[x] == x ? x : par[x] = find(par[x]);
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	
	if(_rank[x] < _rank[y]){
		par[x] = y;
	} else{
		par[y] = x;
		if(_rank[x] == _rank[y]) _rank[x]++;
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

int kruskal(){
	sort(es, es + E, comp);
	init(V);
	int res = 0, count = 0;
	for(int i = 0; i < E; i++){
		edge e = es[i];
		if(!same(e.u, e.v)){
			unite(e.u,e.v);
			res += e.cost;
			count++;
		}
	}
	return res;
}

int main(){
	int s, t, w, x, y = 0;
	
	cin>>V;
	
	for(int i = 1; i <= V; i++){
		for(int j = 1; j <= V; j++){
			cin>>x;
			if(x != -1 && i <= j){
				es[y].u = i;
				es[y].v = j;
				es[y++].cost = x;
			}
		}
	}
	
	E = y;
	
	cout<<kruskal()<<endl;
	
	return 0;
	
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
ll ans[100000]={};
ll fun(ll a[],ll pos,ll n,ll k)
{
	if(pos>=n-1)
		return 0;
	if(ans[pos]!=LLONG_MAX&&pos!=0)
		return ans[pos];
	for(int i=1;i<=k&&pos+i<n;i++)
	{
		ans[pos]=min(abs(a[pos]-a[pos+i])+fun(a,pos+i,n,k),ans[pos]);
		//cout<<ans[pos]<<" ";
	}
	//cout<<pos<<" "<<ans[pos]<<endl;
	return ans[pos];
}
int main()
{
	rep(i,0,100000)
	ans[i]=LLONG_MAX;
    cin.sync_with_stdio(0);
    cin.tie(0); cin.exceptions(cin.failbit);
	ans[0]=INT_MAX;
    ll n,k;
    cin>>n>>k;
    ll a[n];
    rep(i,0,n)
    cin>>a[i];
    cout<<fun(a,0,n,k);
    return 0;
}


Measured memory_bytes: 9600
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)
	n, _ := nextInt()

	nCoins := 0
	nCoins += n / 25
	n = n % 25
	nCoins += n / 10
	n = n % 10
	nCoins += n / 5
	n = n % 5
	nCoins += n

	fmt.Println(nCoins)
}



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

int main(){
  int n;
  cin >> n;
  int zero = 0;
  int H[n];
  for(int i = 0;i<n;i++){
    cin >> H[i];
  }
  if(n==1){
    cout << zero <<endl;
    exit(0);
  }
  int count = 0;
  int result = 0;
  for(int i = n-1;i>=1;i--){
    if(H[i]<=H[i-1]){
      count++;
    }else{
      count = 0;
    }
    if(result<=count){
      result = count;
    }
  }
  cout << result <<endl;
  return 0;
}

Measured memory_bytes: 640
fn chmax<T: PartialOrd>(x: &mut T, a: T) {
    if *x < a {
        *x = a;
    }
}

fn main() {
    proconio::input! {
        n: usize,
        p: [[i32; 3]; n],
    }
    let mut dp = vec![0; 3];
    for p in p {
        let mut next = vec![0; 3];
        for (i, (next, a)) in next.iter_mut().zip(p.iter()).enumerate() {
            for (j, v) in dp.iter().enumerate() {
                if i != j {
                    chmax(next, *a + *v);
                }
            }
        }
        dp = next;
    }
    let ans = dp.into_iter().max().unwrap();
    println!("{}", ans);
}

Measured memory_bytes: 9144
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

key = []
for i, v in enumerate(A):
    for k, j in enumerate(v):
        if (j in B):
            key.append([i, k])

ans = [[[0, 0], [1, 0], [2, 0]], [[0, 1], [1, 1], [2, 1]], [[0, 2], [1, 2], [2, 2]], [[0, 0], [1, 1], [2, 2]], [
    [0, 2], [1, 1], [2, 0]], [[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]], [[2, 0], [2, 1], [2, 2]]]

for i in ans:
    count = 0
    for j in i:
        if (j in key):
            count += 1
    if (count == 3):
        print('Yes')
        exit()

print('No')

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, L, A;
  cin >> N >> L;
  A = (L-1)*N+N*(N+1)/2;
  if (L<=0&&0<=L+N-1) {
    cout << A;
  }
  else{
    if (0<L) {
      cout << A-L;
    }
    else {
      cout << A-L-N+1;
    }
  }
}

Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <stdio.h>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

struct UnionFind{
    int size;
    std::vector<int> par;
    std::vector<int> rank;
    UnionFind(int x){
        size=x;
        par=std::vector<int> (x);
        rank=std::vector<int> (x,1);
        for (int i=0;i<x;i++) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        else return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        x=root(x);y=root(y);
        if(x==y) return;
        if(rank[x]<rank[y]) par[x]=y;
        else par[y]=x;
        if(rank[x]==rank[y]) rank[x]++;
    }
    bool check(int x,int y){
        return root(x)==root(y);
    }
    void initialize(){
        for (int i=0;i<size;i++){
            par[i]=i;rank[i]=1;
        }
    }
};

using namespace std;

int main(){
	int h,w;
	cin >> h >> w;
	vector<string> da(h);
	rip(i,h,0) cin >> da[i];
	UnionFind uf(h*w);
	rip(i,h,0){
		rip(j,w,0){
			if(i < h-1){
				if(da[i][j] != da[i+1][j]) uf.unite(i*w+j, i*w+w+j);
			}
			if(j < w-1){
				if(da[i][j] != da[i][j+1]) uf.unite(i*w+j, i*w+j+1);
			}
		}
	}
	vector<ll> bl(h*w), wh(h*w);
	rip(i,h,0){
		rip(j,w,0){
			if(da[i][j] == '.') wh[uf.root(i*w+j)]++;
			else bl[uf.root(i*w+j)]++;
		}
	}
	ll ans = 0;
	rip(i,h*w,0) ans += bl[i]*wh[i];
	cout << ans << endl;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
#define inrep(x) int x;scanf("%d",&x);while(x--)
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
int h,w,a,b;
int grid[1200][1200];
int row[1200][2],col[1200][2];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>h>>w>>a>>b;
	swap(a,b);
	memset(grid,-1,sizeof(grid));
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			grid[i][j]=1;
		}
	}
	for(int i=a+1;i<=2*a;i++){
		for(int j=1;j<=b;j++){
			grid[i][j]=0;
		}
	}
	for(int i=1;i<=a;i++){
		for(int j=b+1;j<=2*b;j++){
			grid[i][j]=0;
		}
	}
	for(int i=a+1;i<=2*a;i++){
		for(int j=b+1;j<=2*b;j++){
			grid[i][j]=1;
		}
	}
	for(int i=2*a+1;i<=h;i++){
		for(int j=1;j<=b;j++){
			grid[i][j]=1;
		}
	}
	for(int i=2*a+1;i<=h;i++){
		for(int j=b+1;j<=2*b;j++){
			grid[i][j]=0;
		}
	}
	for(int i=1;i<=a;i++){
		for(int j=2*b+1;j<=w;j++){
			grid[i][j]=1;
		}
	}
	for(int i=a+1;i<=2*a;i++){
		for(int j=2*b+1;j<=w;j++){
			grid[i][j]=0;
		}
	}
	for(int i=2*a+1;i<=h;i++){
		for(int j=2*b+1;j<=w;j++)
			grid[i][j]=0;
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++)
			cout<<grid[i][j];
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;



int main()
{
	vector<lint> v(3);
  cin >> v;
  sort(v.begin(), v.end());
  cout << v[0] * v[1] / 2 << endl;
}


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

#define rep(i, n) for (ll i=0;i<(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(x) (x).begin(),(x).end()
#define Sort(a) sort(ALL(a))
#define Rev(a) reverse(ALL(a))


using namespace std;
//using ll=long long;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pi;
const long double PI=3.14159265358979323846;


template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}


int main(){

  string s;
  cin>>s;

  ll n= s.size();
  
  vector<ll> v(s.size(), 0);
  
  ll tmp = 0;
  rep(i, n-1){
    if(s[i]=='R' and s[i+1]=='L'){
      v[i] += (i-tmp+2)/2;
      v[i+1] += (i-tmp+1)/2;
      tmp = i;
    }
    if(s[i]=='L' and s[i+1]=='R'){
      v[tmp] += (i-tmp)/2;
      v[tmp+1] += (i-tmp+1)/2;
      tmp = i+1;
    }
  }
  v[tmp] += (n-1-tmp)/2;
  v[tmp+1] += (n-1-tmp+1)/2;

  //cout << (n-1-tmp-1)/2 << " "<< (n-1-tmp)/2<<endl;
  
  rep(i, n){
    cout <<v[i]<< " ";
  }
  cout <<endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL LINF=1LL<<62;
const LL mod=1e9+7;


int main(){
    int N;
    string s;
    cin >> N >> s;
    LL ec[N+1],wc[N+1];
    memset(ec,0,sizeof(ec));
    memset(wc,0,sizeof(wc));
    for(int i=0;i<N;i++){
        ec[i+1]=ec[i]+(s[i]=='E');
        wc[i+1]=wc[i]+(s[i]=='W');
    }
    LL ans=LINF;
    for(int i=0;i<N;i++){
        ans=min(ans,wc[i]+ec[N]-ec[i+1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5380
#include<stdio.h>
#include<iostream>
#include<vector>
#include<bitset>

using namespace std;

#define MAX_BIN 17

unsigned long long int crop(unsigned long long int num, int a){
    return (num&((1<<a)-1))+((num&(((1<<MAX_BIN)-1)^((1<<(a+1))-1)))>>1);
}
unsigned long long int insert(unsigned long long int num, bool bit,int a){
    return (num&((1<<a)-1))+((num&(((1<<MAX_BIN)-1)^((1<<a)-1)))<<1)+(bit<<a);
}

vector<unsigned long long int> GrayCodeGenerator(unsigned long long int a,unsigned long long int b,int binary_digit){
    std::bitset<17> dif(a^b);
    if(dif.count()%2==0){
        vector<unsigned long long int> emp={};
        return emp;
    }
    if(binary_digit==1){
        vector<unsigned long long int> ans;
        ans.push_back(a);
        ans.push_back(b);
        return ans;
    }
    int dig;
    for(int i=binary_digit-1;i>=0;i--){
        if((a&(1<<i))!=(b&(1<<i)))dig=i;
    }
    unsigned long long int adash=crop(a,dig);
    unsigned long long int bdash=crop(b,dig);
    unsigned long long int c=adash;
    c=c^(1<<(binary_digit-2));
    vector<unsigned long long int> p=GrayCodeGenerator(adash,c,binary_digit-1);
    vector<unsigned long long int> q=GrayCodeGenerator(c,bdash,binary_digit-1);
    for(unsigned long long int i=0;i<p.size();i++)p[i]=insert(p[i],(a&(1<<dig))>>dig,dig);
    for(unsigned long long int i=0;i<q.size();i++)q[i]=insert(q[i],(b&(1<<dig))>>dig,dig);
    std::copy(q.begin(),q.end(),std::back_inserter(p));
    return p;
}

int main()
{
    int n,a,b;
    scanf("%d %d %d",&n,&a,&b);
    vector<unsigned long long int> ans=GrayCodeGenerator(a,b,n);
    if(ans.empty())printf("NO\n");
    else{
        printf("YES\n");
        for(unsigned long long int i : ans){
            printf("%lld\n",i);
        }
    }
    return 0;
}

Measured memory_bytes: 2288
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#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;
using P = pair<int, int>;

int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  rep(i, N) {
    cin >> A[i];
    B[i] = A[i];
  }

  sort(B.begin(), B.end());
  rep(i, N) {
    if (A[i] != B[B.size() - 1]) {
      cout << B[B.size() - 1] << endl;
    } else {
      cout << B[B.size() - 2] << endl;
    }
  }

  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, cnt;
int a[N];

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; ++i) {
        if (i < n && a[i] == i && a[i + 1] == i + 1) {
            swap(a[i], a[i + 1]);
            ++cnt;
            continue;
        }
        if (i == a[i]) {
            ++cnt;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 4004
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
  //int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  ll h,w;
  cin>>h>>w;
    if(h==1 or w==1)
        cout<<"1\n";
    else
  cout<<((h*w)+1)/2<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
int i,n,sum=0,s[1001];
double ave,a=0;
while(1){
scanf("%d",&n);
if(n==0) break;
for(i=0;i<n;i++){
scanf("%d",&s[i]);
sum+=s[i];

}
ave=(double)sum/n;

  for(i=0;i<n;i++){
    a+=((s[i]-ave)*(s[i]-ave));
  }
  printf("%f\n",sqrt((double)a/n));
  sum=0;
  a=0;
  }

return 0;

}


Measured memory_bytes: 2128
// #include <iostream>
#include<bits/stdc++.h>
#include<vector>

using namespace std;

int main() {
    long int n;
    int k;
    cin>>n>>k;
    int b[n];
    vector<int>a;
    for(auto i = 0 ; i< n ; i++){
        int t;
        cin>>t;
        a.push_back(t);
    }
    b[n-1] = 0;
    for(auto i = n-2 ; i >=0 ; i--){
        int j = i+2;
        b[i] = abs(a[i]-a[i+1]) + b[i+1];
        while(j<n && j<=i+k){
            b[i] = min(abs(a[i]-a[j]) + b[j] , b[i]);
            j++;
        }
        
    }
    cout<<b[0];

    
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  int i;
  int sum = 0;
  for(i = 0; i < n; i++)
  {
    cin >> a.at(i);
    sum += a.at(i);
    a.at(i) *= n;
  }
  int min = 10000;
  int check;
  for(i = 0; i < n; i++)
  {
    if(abs(a.at(i)-sum) < min)
    {
      check = i;
      min = abs(a.at(i)-sum);
    }
  }
  cout << check << endl;
}

Measured memory_bytes: 256
n = gets.to_i

works = []
n.times do
  works.push(gets.split.map(&:to_i))
end

def main(works)
  works.sort! {|a, b| a[1] <=> b[1] }

  total = 0
  works.each do |work|
    total += work[0]
    if total > work[1]
      return 'No'
    end
  end
  return 'Yes'
end

print main(works)

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

int main(){
  int R;
  cin >> R;
  if(R<1200){
    cout << "ABC" << endl;
  }else if(R<2800){
    cout << "ARC" << endl;
  }else{
    cout << "AGC" << endl;
  }
  return 0;
}


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

using namespace std;

int dp[100005],h[10005];
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;++i)
	scanf("%d",h+i);
	for(int i=n;i>=1;--i)
	{
		if(i == n)
		dp[i] = 0;
		else
		{
			dp[i] = INT_MAX;
			for(int j=i+1;j<=i+k;++j)
			{
				if(j <= n)
				dp[i] = min(dp[i],dp[j]+abs(h[j-1]-h[i-1]));
			}
		}
	}
	printf("%d\n",dp[1]);
	return 0;
}


Measured memory_bytes: 640
($n,$m)=glob<>;
for(1..$n){
    my($x,$y)=glob<>;
    $s{$_}->{x}=$x;
    $s{$_}->{y}=$y;
}
for(1..$m){
    my($x,$y)=glob<>;
    $c{$_}->{x}=$x;
    $c{$_}->{y}=$y;
}
for my$i(1..$n){
    $min=1e9;$o=0;
    for my$j(1..$m){
        $d= abs($s{$i}->{x}-$c{$j}->{x})+
            abs($s{$i}->{y}-$c{$j}->{y});
        if($d<$min){
            $min=$d;
            $o=$j;
        }
    }
    print$o,"\n";
}



Measured memory_bytes: 768
import java.util.*;

public class Main{
	public static void main(String[] args){
		int i,j;
		int pre,max;
		Scanner sc = new Scanner(System.in);

		while(true){
			int n=sc.nextInt(), k=sc.nextInt();
			if(n==0 && k==0) break;
			int[] x = new int[n];

			for(i=0;i<n;i++) x[i]=sc.nextInt();
			for(i=0,pre=0;i<k;i++) pre+=x[i];
			max = pre;
			for(j=1;j<n-k;j++){
				pre = pre - x[j-1] + x[k+j-1];
				if(max < pre) max = pre;
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 13000
#include<iostream>

using namespace std;

const int MAX = 500000;
const int inf = 1000000001;
long long counter = 0;
int L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(int a[], int left, int mid, int right)
{
	int n1 = mid - left;
	int n2 = right - mid;
	int i, j, k;
	for (i = 0; i < n1; i++)L[i] = a[left + i];
	for (i = 0; i < n2; i++)R[i] = a[mid + i];
	L[n1] = R[n2] = inf;
	i = j = 0;
	for (k = left; k < right; k++)
	{
		if (L[i] <= R[j])
		{
			a[k] = L[i];
			i++;
		}
		else
		{
			a[k] = R[j];
			j++;
		}
		counter++;
	}
}

void mergesort(int a[], int left, int right)
{
	if (left + 1 < right)
	{
		int mid = (left + right) / 2;
		mergesort(a, left, mid);
		mergesort(a, mid, right);
		merge(a, left, mid, right);
	}
}

int main()
{
	int n, i;
	cin >> n;
	int* s = new int[n];
	for (i = 0; i < n; i++)cin >> s[i];
	mergesort(s, 0, n);
	for (i = 0; i < n; i++)
	{
		if (i)cout << " ";
		cout << s[i];
	}
	cout << endl << counter << endl;
    return 0;
}

Measured memory_bytes: 5084
#include<cstdio>

#define gec     getchar
#define FILE(F) freopen(F".in","r",stdin),freopen(F".out","w",stdout)

typedef long long ll;
template<typename T>
inline void read(T &x)
{
	x=0;bool f=0; char c=gec();
	for(;c<'0'||c>'9';c=gec())f=(c=='-');
	for(;c>='0'&&c<='9';c=gec())x=x*10+c-'0';
	x=f?-x:x;
}
namespace IO
{
inline void fpr(char *c){fprintf(stderr,"%s\n",c);}
inline void fpr(int           x,char *c){fprintf(stderr,"[ %s ] : = %d   \n",c,x);}
inline void fpr(ll            x,char *c){fprintf(stderr,"[ %s ] : = %lld \n",c,x);}
inline void fpr(double        x,char *c){fprintf(stderr,"[ %s ] : = %.5lf\n",c,x);}
inline void fpr(long double   x,char *c){fprintf(stderr,"[ %s ] : = %.5Lf\n",c,x);} 
}using namespace IO;

const int MAXN(100010);
int n;
struct Node
{
	int nd,nx;
}bot[MAXN<<1];int tot,first[MAXN],val[MAXN];
void add(int a,int b)
{bot[++tot]=(Node){b,first[a]};first[a]=tot;
 bot[++tot]=(Node){a,first[b]};first[b]=tot;}

void DFS(int x,int f)
{
	for(int y,v=first[x];v;v=bot[v].nx)
	if((y=bot[v].nd)!=f)
	{
		DFS(y,x);
		val[x]^=val[y]+1;
	}
}

int main()
{
	read(n);
	for(int i=1,a,b;i<n;i++)
	{
		read(a);read(b);
		add(a,b);
	}
	DFS(1,0);
	puts(val[1]?"Alice":"Bob");
	return 0;
}	

Measured memory_bytes: 7168
N = int(input())
As = list(map(int, input().split()))
ct = [0] * N
     
for a in As: #ここがキモ．リスト「As」にはそれぞれの上司が入っていて，その中からaを取り出すので，a=上司になっている．これにより，ctの上司を正確に呼び出すことができる．
    ct[a-1] += 1
     
for c in ct:
    print(c)

#別解
#print(*c,sep='\n')

Measured memory_bytes: 32372
int D[4][2]={/*{-1,-1},{-1,0},{-1,1},{0,-1},*/{0,1},{1,-1},{1,0},{1,1}};
char m[10][10];
int grid(){
	int i=1,j,k,l;
	for(;i<9;i++)for(j=1;j<9;j++)if(m[i][j]=='Q')for(k=0;k<4;k++)for(l=1;m[i+D[k][0]*l][j+D[k][1]*l];l++)if(m[i+D[k][0]*l][j+D[k][1]*l]=='Q')return 0;
	return 1;
}
void dfs(int depth){
	if(!grid())return;
	int i=1,j;
	if(depth==8){for(;i<9;i++)puts(m[i]+1);exit(0);}
	for(;i<9;i++)for(j=1;j<9;j++)if(m[i][j]!='Q'){
		m[i][j]='Q';
		dfs(depth+1);
		m[i][j]='.';
	}
}
main(){
	int N,i,j,x,y;
	for(i=1;i<=8;i++)for(j=1;j<=8;j++)m[i][j]='.';
	scanf("%d",&N);
	for(i=0;i<N;i++)scanf("%d%d",&y,&x),m[y+1][x+1]='Q';
	dfs(N);
	puts("No Answer");
	exit(0);
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    int n, x, y, a; sc(n);
    vector<vector<P> > A(n);
    rep(i, 0, n){
        sc(a);
        rep(j, 0, a){
            sc(x), sc(y);
            A[i].push_back(P(x-1, y));
        }
    }
    int cnt, ans = 0;
    bool check;
    rep(i, 1, 1<<n){
        cnt = 0, check = true;
        rep(j, 0, n){
            if (!(i & (1<<j))) continue;
            for (const auto &k : A[j]){
                if (((i & (1<<k.first))>0) != k.second) check = false;
            }
            if (!check) break;
            else cnt += 1;
        }
        if (check) ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// AOJ 1245: Gap
// 2017.10.18 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct { char r, c; } T;
#define QMAX 100000
typedef struct { char tbl[4][8]; int s; } Q;
Q q[QMAX+3]; int top, end;
char tbl[4][8];

#define HASHSIZ 99991
unsigned hash[HASHSIZ+2], *hashend = hash + HASHSIZ;

int insert(unsigned x)
{
	unsigned *p = hash + x % HASHSIZ;
	while (*p) {
		if (*p == x) return 1;
		if (++p == hashend) p = hash;
	}
	*p = x;
	return 0;
}

unsigned check(char tbl[4][8])
{
	int i, j, k, f;
	unsigned x;

	for (x = 0, f = 0, k = 11, i = 0; i < 4; i++, k += 10) {
		for (j = 1; j < 7; j++) {
			x <<= 1, x += tbl[i][j];
			if (tbl[i][j] != k+j) f = 1;
		}
		x <<= 1, x += tbl[i][7];
	}
	if (f) return x;
	return 0;
}

int main()
{
	int t, i, j, r, c, r2, c2, v, s, ans;
	char tmp[4][8];
	unsigned x;

	scanf("%d", &t);
	while (t-- > 0) {
		for (r = 0; r < 4; r++) for (c = 1; c < 8; c++) scanf("%d", &v), tbl[r][c] = v;
		// initial layout
		for (r = 0; r < 4; r++) {
			tbl[r][0] = 10*r + 11;
			for (c = 1; c < 8; c++)	if (tbl[r][c] % 10 == 1) tbl[r][c] = 0;
		}

		memset(hash, 0, sizeof(hash));
		if ((x = check(tbl)) == 0) { puts("0"); continue; }
		insert(x);
		ans = -1, top = 0, end = 1;
		memcpy(q[0].tbl, tbl, sizeof(tbl)), q[0].s = 0;

		while (top != end) {
			for (i = 0; i < 4; i++) {
				memcpy(tmp, q[top].tbl, sizeof(tbl)), s = q[top].s + 1;
				for (j = 0, r = 0; r < 4; r++) for (c = 1; c < 8; c++) {
					if (tmp[r][c] == 0) { if (j++ == i) goto next1; }
				}
		next1:
				v = tmp[r][c-1];
				if (v == 0 || v % 10 == 7) continue;
				v++;
				for (r2 = 0; r2 < 4; r2++) for (c2 = 1; c2 < 8; c2++) {
					if (tmp[r2][c2] == v) {
						tmp[r2][c2] = 0, tmp[r][c] = v;
						goto next2;
					}
				}
		next2:
				if ((x = check(tmp)) == 0) { ans = s; goto done; }
				if (insert(x)) continue;
				memcpy(q[end].tbl, tmp, sizeof(tbl)), q[end].s = s;
				if (++end == QMAX) end = 0;
			}
			if (++top == QMAX) top = 0;
		}
done:	printf("%d\n", ans);
	}
 	return 0;
}

Measured memory_bytes: 4388
let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let vs = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun v -> v in
  Printf.printf "%d\n" @@
  Array.fold_left (Array.fold_left max) min_int @@
  Array.init (min n k + 1) @@ fun i ->
    Array.init (min n k + 1 - i) @@ fun j ->
      let a = Array.make (i + j) 0 in
      for k = 0 to i - 1 do
        a.(k) <- vs.(k)
      done;
      for k = 0 to j - 1 do
        a.(k + i) <- vs.(n - 1 - k)
      done;
      Array.sort compare a;
      fst @@
      Array.fold_left (fun (acc, n) v ->
        if v < 0 && 0 < n then (acc, n - 1) else (acc + v, n)) (0, k - i - j) a


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> have(n);
  rep(i, k) {
    int d;
    cin >> d;
    rep(j, d) {
      int a;
      cin >> a;
      --a;
      have[a]++;
    }
  }
  int ans = 0;
  rep(i, n) {
    if (have[i] == 0) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
def sol(inp=input):
    n=int(inp())
    curs=list(map(int,inp().split()))
    tgts=list(map(int,inp().split()))
    if sum(curs)<sum(tgts):
        return -1
    diffs=[c-t for c,t in zip(curs,tgts)]
    shorts=[-d for d in diffs if d<0]
    if len(shorts)==0:
        return 0
    sum_shorts=sum(shorts)
    overs_decending=sorted(d for d in diffs if d>0)[::-1]
    tmp_sum_overs=0
    for i,over in enumerate(overs_decending):
        tmp_sum_overs+=over
        if tmp_sum_overs>=sum_shorts:
            return i+len(shorts)+1
print(sol())

Measured memory_bytes: 18708
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') ch=getchar(),o=-1;
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n,A,B,s;
    cin>>n>>A>>B;
    s=abs(A-B);
    puts(s%2==0?"Alice":"Borys");
    return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};

vector<int>graph[MAX];
ll ans,n,k;
void dfs(int src,int par)
{
    ll rem=k-1;
    if(par)
        rem--;
    for(auto i:graph[src])
    {
        if(i==par)
            continue;
        if(rem==0)
        {
            cout<<"0"<<endl;
            exit(0);
        }
        ans=(ans*rem)%MOD;
        dfs(i,src);
        rem--;
    }
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    cin>>n>>k;
    for(int i=1; i<n; i++)
    {
        int u,v;
        cin>>u>>v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    ans=k;
    dfs(1,0);

    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 34820
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
  
  int n; cin>>n;
  ll ans{};
  for(int i=1; i<=n; i++){
    ans += n/i;
    if(n%i==0) ans--;
  }
  cout<<ans <<endl;
  
  
  
}


Measured memory_bytes: 3600
#include <queue>
#include <iostream>
#include <string>

int main(){
	std::priority_queue<int> que;
	std::string s;
	while(std::cin>>s){
		if(s=="end")break;
		if(s=="insert"){
			int n;
			std::cin>>n;
			que.push(n);
		}else {
			std::cout<<que.top()<<std::endl;
			que.pop();
		}
	}
}

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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int A,B,C; cin >> A >> B >> C;
    int K; cin >> K;
    
    while(A>=B){
        B *= 2;
        K--;
    }
    while(B>=C){
        C *= 2;
        K--;
    }
    if(K>=0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
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 long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 

vll dp(100100);

ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  st s;	
  	ci(s);
  ll n=s.sz;
  bl b=true;
  FOR(i,0,n){
    if(i%2==0&&s[i]=='L'){
      co("No")
        b=false;
      break;
    }
    else if(i%2==1&&s[i]=='R'){
      co("No")
        b=false;
      break;
    }
  }
  if(b){
    co("Yes")
  }
}

Measured memory_bytes: 1024