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

public class Main{

	public static int w;
	public static int h;
	public static boolean c[][];
	public static boolean flag[][];

	public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		int island;

		while (true){
			island = 0;
			w = sc.nextInt();
			h = sc.nextInt();
			if (w == 0 && h == 0){
				break;
			}
			c = new boolean[h][w];
			flag = new boolean[h][w];

			for (int y = 0; y < h; y++){
				for (int x = 0; x < w; x++){
					c[y][x] = (sc.nextInt() == 1);
					flag[y][x] = true;
				}
			}

			for (int y = 0; y < h; y++){
				for (int x = 0; x < w; x++){
					if (fill(x, y)){
						island++;
					}
				}
			}

			System.out.println("" + island);
		}
	}

	public static boolean fill(int x, int y){
		if (x < 0 || x >= w || y < 0 || y >= h){
			return false;
		}

		if (c[y][x] && flag[y][x]){
			c[y][x] = false;
			fill(x - 1, y - 1);
			fill(x    , y - 1);
			fill(x + 1, y - 1);
			fill(x - 1, y    );
			fill(x + 1, y    );
			fill(x - 1, y + 1);
			fill(x    , y + 1);
			fill(x + 1, y + 1);
			return true;
		}

		return false;
	}
}

Measured memory_bytes: 53204
package main

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

// thanks! http://kujira16.hateblo.jp/entry/2017/04/09/223843

type Io struct {
    reader    *bufio.Reader
    writer    *bufio.Writer
    tokens    []string
    nextToken int
}

func NewIo() *Io {
    return &Io{
        reader: bufio.NewReader(os.Stdin),
        writer: bufio.NewWriter(os.Stdout),
    }
}

func (io *Io) Flush() {
    err := io.writer.Flush()
    if err != nil {
        panic(err)
    }
}

func (io *Io) NextLine() string {
    var buffer []byte
    for {
        line, isPrefix, err := io.reader.ReadLine()
        if err != nil {
            panic(err)
        }
        buffer = append(buffer, line...)
        if !isPrefix {
            break
        }
    }
    return string(buffer)
}

func (io *Io) Next() string {
    for io.nextToken >= len(io.tokens) {
        line := io.NextLine()
        io.tokens = strings.Fields(line)
        io.nextToken = 0
    }
    r := io.tokens[io.nextToken]
    io.nextToken++
    return r
}

func (io *Io) NextInt() int {
    i, err := strconv.Atoi(io.Next())
    if err != nil {
        panic(err)
    }
    return i
}

func (io *Io) NextFloat() float64 {
    i, err := strconv.ParseFloat(io.Next(), 64)
    if err != nil {
        panic(err)
    }
    return i
}

func (io *Io) PrintLn(a ...interface{}) {
    fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
    fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntLn(a []int) {
    b := []interface{}{}
    for _, x := range a {
        b = append(b, x)
    }
    io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
    b := []interface{}{}
    for _, x := range a {
        b = append(b, x)
    }
    io.PrintLn(b...)
}

func Log(name string, value interface{}) {
    fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func intMin(a, b int) int {
    if a < b {
        return a
    }
    return b
}

func intMax(a, b int) int {
    if a > b {
        return a
    }
    return b
}
func main() {
    io := NewIo()
    defer io.Flush()
    a := io.NextInt()
    b := io.NextInt()
    c := io.NextInt()
    if (b - a == c - b) {
        io.PrintLn("YES")
    } else {
        io.PrintLn("NO")
    }
}


Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  cin >> s;
  int d = s.back() - '0';
  switch (d) {
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon" << endl;
      break;
    case 3:
      cout << "bon" << endl;
      break;
    default:
      cout << "hon" << endl;
  }
  return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int b[100009],k1=0,ans[100009];
    char a[100009];
    scanf("%s",a);
    memset(ans,0,sizeof(ans));
    for(int i=1; a[i]!='\0'; i++)
        if(a[i]=='L'&&a[i-1]=='R')
            b[k1++]=i-1;
    for(int i=0; i<k1; i++)
    {
        int num=0,num1=0,tmp=i==k1-1?strlen(a)-1:b[i+1]-1;
        //printf("%d\n",b[i]);
        for(int j=!i?0:b[i-1]+2; j<=b[i]; j++)
            if(a[j]=='R')
                num++;
        //printf("%d %d %d\n",b[i+1]-1,i,k1-1);
        for(int k=b[i]+1; k<=tmp; k++)
        {
            if(a[k]=='L')
                num1++;
        }
        ans[b[i]]+=(num-1)/2;
        ans[b[i]+1]+=num-(num-1)/2;
        ans[b[i]+1]+=(num1-1)/2;
        ans[b[i]]+=num1-(num1-1)/2;
    }
    for(int i=0; i<strlen(a); i++)
        printf("%d ",ans[i]);
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui32;
using namespace std;

void no() {
    cout << "No\n";
    exit(0);
}

void yes() {
    cout << "Yes\n";
    exit(0);
}

int main() {
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, m, k;
    cin >> n >> m >> k;
    if (k == 0) {
        yes();
    }
    if (k > n * m)
        no();
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if (i * j + (n - i) * (m - j) == k)
                yes();
        }
    }
    no();
    return 0;
}

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

#define ll long long
// #define endl '\n'

// void max_self(int &a, int b){a = max(a, b);}
// void min_self(int &a, int b){a = min(a, b);}

void solve(){
	int n; cin>>n;
	vector< int > v(n);
	for(int &i : v) cin>>i;
	unordered_map< int, int > m;
	int gcd = v[0], cnt = 0;
	for(int i = 1; i<n; i++) gcd = __gcd(gcd, v[i]);
	for(int i = 1; i<n; i++){
		bool ok = 1;
		int a = v[i];
		for(int j = 2; j * j <= a; j++){
			if((a%j) == 0){
				if(m[j]){
					ok = 0;
					break;
				}
				m[j]++;
			}
			while((a%j) == 0){
				a = a / j;
			}
		}
		if(a > 1){
			if(m[a]){
				ok = 0;
			}
			m[a]++;
		}
		cnt += ok;
	}
	// cout<<cnt<<endl;
	if(((cnt + 1) != n) && (gcd == 1)){
		cout<<"setwise coprime"<<endl;
	}else if((cnt + 1) == n){
		cout<<"pairwise coprime"<<endl;
	}else{
		cout<<"not coprime"<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1;// cin>>t;
	for(int i = 1; i<=t; i++){
		solve();
	}
	return 0;
}


Measured memory_bytes: 46492
#include<stdio.h>

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a<b){
        printf("a < b\n");
    }else if(a>b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }
   
    return 0;
}


Measured memory_bytes: 2084
def gcd(a,b):
    while b:
        a,b=b,a%b
        
    return a
    
ans=0
    
K=int(input())
for i in range(1,K+1):
    for j in range(1,K+1):
        gcd_=gcd(i,j)
        
    
        for k in range(1,K+1):
            ans+=gcd(k,gcd_)
            
print(ans)

Measured memory_bytes: 9224
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */

/** Problem2424 : Kakezan **/
ll toInt(string N) {
	ll res;
	stringstream ss(N);
	ss >> res;
	return res;
}

string toStr(ll N) {
	string res;
	stringstream ss;
	ss << N;
	ss >> res;
	return res;
}

int main()
{
	int Q;
	string N;
	cin>>Q;
	rep(i, Q) {
		cin>>N;
		int cnt=0;
		
		bool used[1000001]={0};
		
		while (1) {
			if (!used[toInt(N)]) {
				used[toInt(N)] = true;
			} else {
				cout << -1 << endl;
				break;
			}
			
			if (N.size()==1) {
				cout << cnt << endl;
				break;
			}
			
			ll tmp = 0;
			for (int j=1; j<=N.size()-1; j++){
				ll a = toInt(N.substr(0, j));
				ll b = toInt(N.substr(j));
				tmp = max(tmp, a*b);
			}
			
			N = toStr(tmp);
			cnt++;
		}
	}
}

Measured memory_bytes: 2224
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static public final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static public final int getPair1(long v) {return (int)(v >> 32);}
	static public final int getPari2(long v) {return (int)(v & 0xFFFFFFFF);}

	static public final long quad(long a, long b, long c, long d) {
		return ((a&0xFFFF)<< 48) + ((b&0xFFFF)<< 32) + ((c&0xFFFF)<< 16) +(d&0xFFFF);}
	static public final int getQuad1(long v) {return (int)( v >> 48          );}
	static public final int getQuad2(long v) {return (int)((v >> 32) & 0xFFFF);}
	static public final int getQuad3(long v) {return (int)((v >> 16) & 0xFFFF);}
	static public final int getQuad4(long v) {return (int)( v        & 0xFFFF);}

	static public final long record(int e, int m, int i) {
		return quad(-1, e, m, i);
	}
	static public final int re(long record) {
		return getQuad2(record);
	}
	static public final int rm(long record) {
		return getQuad3(record);
	}
	static public final int ri(long record) {
		return getQuad4(record);
	}

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

	private int p;
	private int[] inv;
	private int[] fact;
	private int[] finv;
	public final int mod(long v) {
		v %= p;
		return (int)(v < 0 ? v+p : v);
	}
	public final int mul(long a, long b) {
		return mod(a*b);
	}
	public final void initFact(double limit, double p) {
		initFact((int)limit, (int)p);
	}
	public final void initFact(int limit, int p) {
		this.p = p;
		this.inv = new int[limit+1];
		this.fact = new int[limit+1];
		this.finv = new int[limit+1];
		fact[1] = finv[1] = inv[0] = inv[1] = 1;
		for(int i=2;i<=limit;i++) {
			int a = p / i;
			int b = p % i;
			inv[i]  = mul(-a, inv[b]);
			fact[i] = mul(fact[i-1], i);
			finv[i] = mul(finv[i-1], inv[i]);
		}
	}
	public final int comb(int m, int n) {
		return mul(mul(fact[m], finv[n]), finv[m-n]);
	}

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

	public void exec() throws Exception{
		final int M1 = sc.nextInt();
		final int D1 = sc.nextInt();
		final int M2 = sc.nextInt();
		final int D2 = sc.nextInt();
		if(M1!=M2) {
			out.println(1);
		}else {
			out.println(0);
		}
	}
}


Measured memory_bytes: 23124
import sys

N=int(input())

A=list(map(int,input().split()))

ans=0
now=1
old=0

if not 1 in A:
    print(-1)
    sys.exit()

for i in range(N):
    if A[i]==now:
        now+=1
        ans=ans+i-old
        old=i+1
ans=ans+N-old

print(ans)
        

Measured memory_bytes: 24744
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

#############################################

H, W = map(int, input().split())
f = []
for _ in range(H):
    S = input()
    f.append(S)

flag = True

for y in range(H):
    for x in range(W):
        if f[y][x] == ".":
            continue
        tmp = False
        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if inside(ny, nx, H, W) and f[ny][nx] == "#":
                tmp = True
                break
        if not tmp:
            flag = False
            break

if flag:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
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; }

int main() {
    ll A; cin >> A;
    ld B; cin >> B;
    ll ans = A * B + 0.001;
    cout << ans << endl;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 2147483647;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

template <typename T>
class SegmentTree {
    public:
        int n;
        vector<T> data;
        T e;
        function<T(T, T)> operation;
        function<T(T, T)> process;

        SegmentTree() {}
        SegmentTree(int n_, T e_, function<T(T, T)> operation_, 
            function<T(T, T)> process_) : e(e_), operation(operation_), process(process_) {
            n = 1;
            while (n < n_) n <<= 1;
            data.assign(2 * n, e);
        }

        T query(int a, int b) {
            return query(a, b + 1, 1, 0, n);
        }

        T query(int a, int b, int k, int l, int r) {
            if (a >= r || b <= l) return e;
            if (a <= l && b >= r) return data[k];
            T c = query(a, b, 2 * k + 0, l, (l + r) / 2);
            T d = query(a, b, 2 * k + 1, (l + r) / 2, r);
            return operation(c, d);
        }

        void update(int idx, T v) {
            idx += n;
            data[idx] = process(data[idx], v);
            while (idx >>= 1) {
                data[idx] = operation(data[2 * idx + 0], data[2 * idx + 1]);
            }
        }

        T operator[](int idx) {
            return data[idx + n];
        }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    SegmentTree<int> seg = SegmentTree<int>(n, Inf, 
            [](int a, int b) { return min(a, b); }, [](int a, int b) { return b; });
    rep (i, q) {
        int c, x, y;
        cin >> c >> x >> y;
        if (c == 0) {
            seg.update(x, y);
        } else {
            cout << seg.query(x, y) << endl;
        }
    } 

    return 0;
}




Measured memory_bytes: 3912
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n,root=0;
struct ti
{
    int par,lef,rig,dep,hei;
}nodes[30];
void setdepth(int node,int depth)
{
    if(node==-1)return;
    nodes[node].dep=depth;
    setdepth(nodes[node].lef,depth+1);
    setdepth(nodes[node].rig,depth+1);
}
int setheight(int node)
{
    int h1=0,h2=0;
    if(nodes[node].lef!=-1)h1=setheight(nodes[node].lef)+1;
    if(nodes[node].rig!=-1)h2=setheight(nodes[node].rig)+1;
    nodes[node].hei=max(h1,h2);
    return max(h1,h2);
}
int sibling(int node)
{
    if(nodes[node].par==-1)return -1;
    if(nodes[nodes[node].par].lef!=-1&&nodes[nodes[node].par].lef!=node)return nodes[nodes[node].par].lef;
    if(nodes[nodes[node].par].rig!=-1&&nodes[nodes[node].par].rig!=node)return nodes[nodes[node].par].rig;
    return -1;
}
void print(int node)
{
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",node,nodes[node].par,sibling(node),(nodes[node].lef==-1?0:1)+(nodes[node].rig==-1?0:1),nodes[node].dep,nodes[node].hei,nodes[node].par==-1?"root":(nodes[node].lef!=-1||nodes[node].rig!=-1?"internal node":"leaf"));
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)nodes[i].par=nodes[i].lef=nodes[i].rig=-1;
    for(int i=0;i<n;i++)
    {
        int iid,ilef,irig;
        cin>>iid>>ilef>>irig;
        if(ilef!=-1)
        {
            nodes[ilef].par=iid;
            nodes[iid].lef=ilef;
        }
        if(irig!=-1)
        {
            nodes[irig].par=iid;
            nodes[iid].rig=irig;
        }
    }
    for(int i=0;i<n;i++)if(nodes[i].par==-1)root=i;
    setdepth(root,0);
    setheight(root);
    for(int i=0;i<n;i++)print(i);
	return 0;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int cntMemo[100009];
    rep(i,100009) cntMemo[i] = 0;
    int n;
    cin >> n;
    ll sum = 0;
    rep(i,n){
        int a;
        cin >> a;
        cntMemo[a]++;
        sum += (ll)a;
    }
    int q;
    cin >> q;
    rep(i,q){
        int b,c;
        cin >> b >> c;
        sum += (ll)cntMemo[b] * (c - b);
        cntMemo[c] += cntMemo[b];
        cntMemo[b] = 0;
        cout << sum << endl;
    }
}


Measured memory_bytes: 3980
s = gets.to_s
s1 = s[0..1]
s2 = s[2..3]

def yymmdetect(s)
    if s.to_i > 12
        return "YY"
    elsif s.to_i == 0
        return "YY"
    else
        return "MM"
    end
end

result = yymmdetect(s1) + yymmdetect(s2)
hantei = ""
if result == "MMMM"
    hantei = "AMBIGUOUS"
elsif result == "YYYY"
    hantei = "NA"
else
    hantei = result
end

puts hantei

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define        sqr(a)       ((a)*(a))

int main()
{
    ll i,j,k,n;

    cin >> n;

    for(i=1;i<=9;i++)
    {
        if(n%i == 0&& (n/i)<=9)
        {
            return cout << "Yes" << endl,0;
        }
    }

    cout << "No" << endl;
}


Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;
const int INF = 1001001001;

int main() {
	int n, m, x;
	cin >> n >> m >> x;
	vector<int> c(n);
	vector<vector<int>> a(n, vector<int>(m));
	rep(i, n) {
		cin >> c[i];
		for (int k = 0; k < m; k++) {
			cin >> a[i][k];
		}
	}
	int ans = INF;
	for (int b = 0; b < 1 << n; b++) {

		int cost = 0;
		vector<int> u(m);
		rep(i, n) {
			if (b >> i & 1) {
				cost += c[i];
				rep(k, m) u[k] += a[i][k];
			}
		}
		bool over_x = true;
		rep(k, m) if (u[k] < x) over_x = false;
		if (over_x)  ans = min(ans, cost);
	}
	if (ans == INF) cout << -1 << endl;
	else cout << ans << endl;


	return 0;
}

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

using namespace std;


int n, ans = 0;
string s;
int main() {
	cin >> n;
	cin >> s;
	for (int i = 0; i < n - 1; i++) {
		if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') {
			ans++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
pub 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()
}

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

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

use std::collections::BTreeMap;

fn main() {
    let _n: usize = read();
    let av: Vec<i64> = read_vec();

    let mut btm: BTreeMap<i64, u64> = BTreeMap::new();

    let mut sum = 0;
    btm.insert(sum, 1);
    let mut ans = 0;

    for a in av {
        sum += a;
        let tmp = *btm.get_mut(&sum).unwrap_or(&mut 0);
        ans += tmp;
        btm.insert(sum, tmp + 1);
    }

    println!("{}", ans);
}


Measured memory_bytes: 10492
#include <stdio.h>

typedef struct {
	int key, id, rest, flag;
} data;

typedef struct {
	data obj[200001];
	int size;
} max_heap;

void push(data x, max_heap* h)
{
	int i = ++(h->size), j = i >> 1;
	data tmp;
	h->obj[i] = x;
	while (j > 0) {
		if (h->obj[i].key > h->obj[j].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j >>= 1;
		} else break;
	}
}

data pop(max_heap* h)
{
	int i = 1, j = 2;
	data output = h->obj[1], tmp;
	h->obj[1] = h->obj[(h->size)--];
	while (j <= h->size) {
		if (j < h->size && h->obj[j^1].key > h->obj[j].key) j ^= 1;
		if (h->obj[j].key > h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j <<= 1;
		} else break;
	}
	return output;
}

int main()
{
	int i, N, A[200001], B[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	for (i = 1; i <= N; i++) scanf("%d", &(B[i]));
	
	int count[3][200001] = {};
	for (i = 1; i <= N; i++) {
		count[0][A[i]]++;
		count[1][B[i]]++;
	}
	
	int C[200001];
	data d, e;
	max_heap h;
	h.size = 0;
	for (i = 1; i <= N; i++) {
		if (count[1][i] > 0) {
			d.key = count[0][i] + count[1][i];
			d.id = i;
			d.rest = count[1][i];
			d.flag = 0;
			push(d, &h);
		}
	}
	for (i = 1; i <= N; i++) {
		if (h.size == 0) break;
		while (1) {
			d = pop(&h);
			if (d.flag == 0 && A[i] > d.id) {
				d.flag = 1;
				d.key -= count[0][d.id];
				push(d, &h);
			} else break;
		}
		if (A[i] != d.id) {
			C[i] = d.id;
			d.key--;
			d.rest--;
			if (d.rest > 0) push(d, &h);
		} else {
			if (h.size == 0) break;
			e = pop(&h);
			C[i] = e.id;
			e.key--;
			e.rest--;
			if (e.rest > 0) push(e, &h);
			push(d, &h);
		}
	}
	if (i <= N) {
		printf("No\n");
		fflush(stdout);
		return 0;
	}
	
	for (i = 1; i <= N; i++) count[2][C[i]]++;
	for (i = 1; i <= N; i++) if (count[1][i] != count[2][i]) break;
	if (i <= N) {
		printf("No\n");
		fflush(stdout);
		return 0;
	} else printf("Yes\n");
	for (i = 1; i < N; i++) printf("%d ", C[i]);
	printf("%d\n", C[N]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 9448
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> vec;
typedef vector<vec> mat;
#define N 3
int po[N*N+10];
int m2i(mat m){
  int res=0;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      res+=m[i][j]*po[i*N+j];
  return res;
}
mat i2m(int x){
  mat res(N,vec(N));;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      res[i][j]=(x%po[i*N+j+1])/po[i*N+j];
  return res;
}

signed main(){
  po[0]=1;
  for(int i=0;i<N*N;i++) po[i+1]=po[i]*10;
  mat p(N,vec(N));
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      cin>>p[i][j];
  mat e(p);
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      e[i][j]=i*N+j+1;
  e[N-1][N-1]=0;
  int ans=m2i(e);
  //cout<<ans<<endl;
  queue<int> q;
  map<int,int> m;
  q.push(m2i(p));
  m[m2i(p)]=0;
  int ax[]={1,0,-1,0};
  int ay[]={0,1,0,-1};
  while(!q.empty()){
    int x=q.front();q.pop();
    if(x==ans) break;
    //cout<<x<<endl;
    p=i2m(x);
    int zy,zx;
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
	if(p[i][j]==0) zy=i,zx=j;
    //cout<<zy<<" "<<zx<<endl;
    for(int k=0;k<4;k++){
      int ny=zy+ay[k],nx=zx+ax[k];
      if(ny<0||N<=ny||nx<0||N<=nx) continue;
      swap(p[zy][zx],p[ny][nx]);
      int t=m2i(p);
      //cout<<t<<endl;
      if(!m.count(t)){
	m[t]=m[x]+1;
	q.push(t);
      }
      swap(p[zy][zx],p[ny][nx]);
    }
  }
  cout<<m[ans]<<endl;
  return 0;
}

Measured memory_bytes: 14468
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));
 
ll gcd(ll x, ll y){
	if(x<y) swap(x,y);
	if(y==0) return x;
	return gcd(y,x%y);
}
 
ll lcm(ll x, ll y){
	return (x*y/gcd(x,y));
}
int add(int x){
	return ((x+9)/10)*10;
}

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////
	int n;
	cin >> n;
	int l[n];
	int ans=0;
	int maxt=0;
	REP(i,n){
		cin >> l[i];
		ans+=l[i];
		maxt=max(maxt,l[i]);
	}
	cout << (ans-maxt>maxt ? "Yes" : "No");
/////////////////////////////////////////////
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
map<int,int> M[2];
vector<pair<int,int>> V[2];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>x;
		M[i%2][x]++;
	}
	FOR(i,2) {
		V[i].push_back({0,-1-i});
		V[i].push_back({0,-3-i});
		FORR(m,M[i]) V[i].push_back({m.second,m.first});
		sort(ALL(V[i]));
		reverse(ALL(V[i]));
		V[i].resize(2);
	}
	
	int ret=1<<30;
	FOR(x,2) FOR(y,2) if(V[0][x].second !=V[1][y].second) ret=min(ret,N-V[0][x].first-V[1][y].first);
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

void solve(){
    int n,k;
    cin >> n >> k;
    int h[n];

    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    int dp[n] = {0};
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    for(int i=2;i<n;i++){
        for(int j=1;j<=k && j<=i;j++){
            if(j==1){
                dp[i] = abs(h[i] - h[i-j]) + dp[i-j];
            }
            else{
                if(dp[i] > (abs(h[i] - h[i-j]) + dp[i-j]))
                    dp[i] = abs(h[i] - h[i-j]) + dp[i-j];
            }
        }
    }
    cout << dp[n-1] << endl;

}

int main (){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 4376
for i in range(int(input())):
	b1 = b2 = b3 = out = score = 0
	while 1:
		n = input()
		if n == "HIT":
			if b3 > 0 : 
				score += 1;
			b3 = b2;
			b2 = b1;
			b1 = 1;
		elif n == "HOMERUN":
			score += b1 + b2 + b3 + 1;
			b1 = b2 = b3 = 0
		elif n == "OUT":
			out += 1;
			if out >=3: break
	print(score)


Measured memory_bytes: 5584
//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

typedef long long ll;
const int INF=1<<30;

const int MOD=1e9+7;

const int maxn=1000000+10;

ll fac[maxn*3];
ll Pow(ll x,ll p){
	x%=MOD;ll ret=1;
	for(;p;p>>=1,x=x*x%MOD) if(p&1) ret=ret*x%MOD;
	return ret;
}

ll inv(ll x){return Pow(x,MOD-2);}
ll fix(ll x){return (x%MOD+MOD)%MOD;}

ll C(int n,int m){
	if(n<0||m<0||n<m) return 0;
	return fac[n]*inv(fac[n-m]*fac[m]%MOD)%MOD;	
}

ll S(int r,int c)
{
	if(r<=0||c<=0) return 0;
//	ll ret=0;
//	rep(i,1,r) 	ret+=C(i+c+1,c)-1;
//	return ret%MOD;
	return C(r+c+2,c+1)-(c+2)-r;
}

int main()
{
//	freopen("std.in","r",stdin);
	fac[0]=1; rep(i,1,2001000) fac[i]=fac[i-1]*i%MOD;
	
	int r1,r2,c1,c2;
	cin>>r1>>c1>>r2>>c2;
	cout<<fix(S(r2,c2)-S(r1-1,c2)-S(r2,c1-1)+S(r1-1,c1-1))<<endl;
	return 0;
}


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

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;

    cout << Z << " " << X << " " << Y << endl;
}

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

int N, C, A[6], bc[1 << 5];
int P[333], Q[333], M[1 << 5][1 << 5], V;
long long D[333][333];

int main()
{
	scanf("%d %d", &N, &C);
	int L = N * C;
	for (int i = 0; i < N; i++) scanf("%d", &A[i]);
	sort(A, A + N);

	int b = (1 << (N - 1));
	D[0][A[N - 1] * N] = 1;
	for (int i = 1; i < b; i++) bc[i] = bc[i - (i&(-i))] + 1;
	for (int i = 0; i < b; i++) for (int j = 0; j < b; j++) if (bc[i] == bc[j]) {
		P[V] = i; Q[V] = j;
		M[i][j] = V++;
	}
	for (int t = 0; t < L; t++) {
		int d = t % N - 1;
		if (d >= 0) for (int i = V - 1; i >= 0; i--) {
			int p = P[i], q = Q[i];
			if (q & (1 << d)) continue;
			for (int j = 0; j < N - 1; j++) if (~p & (1 << j)) {
				int l = t + A[j] * N;
				long long *v = D[M[p + (1 << j)][q + (1 << d)]];
				for (int k = t; k <= L; k++) if (D[i][k]) {
					int x = min(L, max(k, l));
					v[x] += D[i][k];
				}
			}
		}
	}

	double ans = D[V - 1][L];
	for (int i = 1; i < N; i++) {
		ans /= i;
		ans /= C;
	}

	printf("%.16lf\n", ans);

	return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;

const int MaxN = 1e5, MaxM = 2e5;
int n, all;
int pre[MaxM + 5], last[MaxN + 5], other[MaxM + 5];
int father[MaxN + 5], size[MaxN + 5], D[MaxN + 5];

void Build(int x, int y)
{
	pre[++all] = last[x];
	last[x] = all;
	other[all] = y;
}

void Init()
{
	all = -1; memset(last, -1, sizeof(last));
	for (int i = 1; i <= n - 1; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		Build(u, v); Build(v, u);
	}
}

void Dfs(int x, int fa, int dep)
{
	father[x] = fa;
	int ed = last[x], dr;
	size[x] = 1; D[x] = dep;
	while (ed != -1) {
		dr = other[ed];
		if (dr != fa) {
			Dfs(dr, x, dep + 1);
			size[x] += size[dr];
		}
		ed = pre[ed];
	}
}

void Solve()
{
	Dfs(1, 0, 0);
	int cnt = (D[n] - 1) / 2;	
	//printf("cnt : %d\n", cnt);
	int p = n;
	for (int i = 1; i <= cnt; i++) p = father[p];
	//printf("size : %d\n", size[p]);
	if (size[p] >= n - size[p]) printf("Snuke\n");
		else printf("Fennec\n");
}

int main()
{
	while (~scanf("%d", &n)) {
		Init();
		Solve();
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  if(N % K == 0) {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
using namespace std;


int main(){
    int h,w;
    cin>>h>>w;
    char a[50][50]={};
    int b[50][50]={};
    
    for(int i=0;i<h;i++){
        for(int t=0;t<w;t++){
            cin>>a[i][t];
            b[i][t]=a[i][t]-'0';
        }}
    
    for(int t=1;t<w;t++){b[0][t]+=b[0][t-1];}
    
    for(int i=1;i<h;i++){b[i][0]+=b[i-1][0];}
    
    for(int i=1;i<h;i++){
        for(int t=1;t<w;t++){
            b[i][t]+=min(b[i][t-1],b[i-1][t]);
        }}
    
    cout<<b[h-1][w-1]<<endl;
    
    return 0;
}


Measured memory_bytes: 3104
//21
#include<cstdio>
#include<algorithm>
using namespace std;

const int maxn = 302;

int n, k, lbt;
int dp[maxn][maxn], sdp[maxn][maxn];
int c[maxn][maxn];
int ans[maxn];

int main() {
	scanf("%d%d%d", &n, &k, &lbt);
	for (int i = 0; i <= n; i++) {
		c[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % lbt;
		}
	}
	for (int j = 1; j <= k; j++) {
		dp[1][j] = 1;
		sdp[1][j] = j % lbt;
	}
	for (int len = 2; len <= n; len++) {
		for (int j = 1; j <= k; j++) {
			for (int i = 1; i < len; i++) {
				dp[len][j] = (dp[len][j] + (long long)c[len - 2][i - 1] * sdp[i][j - 1] % lbt * dp[len - i][j]) % lbt;
			}
			sdp[len][j] = (sdp[len][j - 1] + dp[len][j]) % lbt;
		}
	}
	ans[0] = 1;
	for (int len = 1; len <= n; len++) {
		for (int i = 1; i <= len; i++) {
			ans[len] = (ans[len] + (long long)c[len - 1][i - 1] * sdp[i][k] % lbt * ans[len - i]) % lbt;
		}
	}
	printf("%d", ans[n]);
	return 0;
}

Measured memory_bytes: 1280
n, t = map(int, input().split())
ts = map(int, input().split())
x = 0
out = False
t_sw = 0
t_last = 0
for ti in ts:
    if out and t_sw > ti:
        t_sw = ti + t
    elif out and t_sw <= ti:
        x += t_sw - t_last
        out = False
    if not out:
        t_last = ti
        t_sw = t_last + t
        out = True
if out:
    x += t_sw - t_last
print(x)


Measured memory_bytes: 19216
#include <iostream>
#include <cstdlib>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <numeric>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define loopi(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define loop(i, n) for (int i = 0; i < (int)n; i++)
#define loopeq(i, n) for (int i = 0; i <= (int)n; i++)
#define loopll(i, n) for (ll i = 0; i < (ll)n; i++)
#define looplleq(i, n) for (ll i = 0; i <= (ll)n; i++)

int main() {
    int a,b,c,d; cin >> a >> b >> c >> d;
    while (a > 0 && c > 0) {
        c -=b;
        if (c <= 0) { cout << "Yes" << endl; return 0;}
        a -= d;
        if (a <= 0) { cout << "No" << endl; return 0;}
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <climits>
#include <math.h>
#include <utility>
#include <ctime>
#include <cstdlib>
using namespace std;

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) a.begin(),a.end()

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin >> n;
    int t, a;
    cin >> t >> a;
    t *= 1000, a *= 1000;

    int tm = 1e6, ti;
    for (int i = 0; i < n; i++) {
        int h;
        cin >> h;
        if (abs(t - h * 6 - a) < tm) {
            tm = abs(t - h * 6 - a);
            ti = i;
        }
    }

    cout << ti + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#define L long long int
m[31][50];main(n,p,d,x){L a[50],b;for(;scanf("%d",&n),n;){memset(m,0,6200);for(p=0;p<n;a[p]=(L)1<<p,p++)for(scanf("%d",&x);x;x--)scanf("%d",&d),m[d][p]=1;for(d=1;d<31;d++){for(b=p=0;p<n;p++)if(m[d][p])b|=a[p];for(p=0;p<n;p++)if(m[d][p]&&(a[p]=b)==((L)1<<n)-1){printf("%d\n",d);goto s;}}puts("-1");s:;}return 0;}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		if(n>=2) {
			System.out.println(n*(n-1)/2);
		}else {
		System.out.println(0);
		}

	}

}


Measured memory_bytes: 23124
//(UNCOMMENT WHEN SUBMITTING)
//#pragma GCC optimize("O3")
 
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
// #pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN NEEDED)
// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>

// clang-format off
#define range(i) for (int _ = 0; _ < i; _++)
#define vprnt(v) for (auto vi : v) cout << vi << " "; cout << endl;
#define fastio() ios::sync_with_stdio(false); cin.tie(0)
#define ll long long
#define all(x) (x).begin(), (x).end()
using namespace ::std;
int nxt() {int x;cin >> x;return x;}
ll nxtll() {ll x;cin >> x;return x;}
// clang-format on
 
int main() {
    fastio();

    int N = nxt();
    vector<int> A(N);
    generate(all(A), nxt);


    vector<set<int>> AP(N);
    for (int i = 0 ; i < N ; i++) {
        for(int j=2 ; j * j <= A[i] ; j++) {
            while(A[i]%j == 0) {
                AP[i].emplace(j);
                while(A[i]%j == 0)
                    A[i]/=j;
            }
        }

        if(A[i] != 1) {
            AP[i].emplace(A[i]);
        }   
    }

    set<int> myset;
    set<int> otset;
    bool pairwise = true;
    bool setwise = true;
    for (int i = 0 ; i < N ; i++) {
        bool noneinsert = true;
        for (int a : AP[i]) {
            if (pairwise && !myset.emplace(a).second) {
                pairwise = false;
            }
        }
    }

    if (pairwise) {
        cout << "pairwise coprime" << endl;
        return 0;
    }

    for (int a : AP[0]) {
        otset.emplace(a);
    }

    for (int i = 1 ; i < N ; i++) {
        set<int> nset = otset;
        for (int a : otset) {
            if (AP[i].find(a) == AP[i].end()) {
                nset.erase(a);
            }
        }
        otset = nset;
    }

    setwise = otset.empty();

    if (setwise) {
        cout << "setwise coprime" << endl;
        return 0;
    }

    cout << "not coprime" << endl;
    
    return 0;
}

Measured memory_bytes: 290172
// AOJ 3116 Range Count Query
// 2020.1.14 bal4u

#include <stdio.h>

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void out(int n) { // 非負整数の表示（出力）
	int i; char b[30];

	if (!n) pc('0');
	else {
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

void Qsort(int *a, int l, int r) {
	int i, j, m, t;
	
	i = l, j = r, m = a[(l+r) >> 1];
	while (1) {
		while (a[i] < m) i++;
		while (m < a[j]) j--;
		if (i >= j)	break;
		t = a[i], a[i] = a[j], a[j] = t;
		i++, j--;
	}
	if (l+1 < i) Qsort(a, l, i-1);
	if (j+1 < r) Qsort(a, j+1, r);
}

int a[100005]; int N;

// 見つからなければ、一つ小さい要素を返す
int bsLE(int x) {
	int m, l = 0, r = N;

    while (l < r) {
        m = (l+r) >> 1;
        if (a[m] <= x) l = m + 1; else r = m;
    }
	return l-1;
}

// 見つからなければ、一つ大きい要素を返す。
int bsGE(int x) {
	int m, l = 0, r = N;

    while (l < r) {
        m = (l+r) >> 1;
        if (a[m] < x) l = m + 1; else r = m;
    }
	return l;
}

int main()
{
	int i, l, r, Q;
	
	N = in(), Q = in();
	for (i = 0; i < N; ++i) a[i] = in();
	Qsort(a, 0, N-1);
	while (Q--) {
		l = in(), r = in();
		out(bsLE(r) - bsGE(l) + 1);
	}
	return 0;
}



Measured memory_bytes: 2108
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>                                                
#include<cstdio>                                                   
#include<cstdlib>
#include<algorithm>
#include<set>
#include<map>
#include<cctype>
#include<sstream>
#include<queue>
using namespace std;

int main()
{
	int n;
	cin >> n;
	int temp;
	
	
		int a, b, c;
		a = n / 100;
		b = (n / 10) % 10;
		c = n % 10;
		for (int i = a;i <= 9;i++)
		{
			temp = 100 * i + 10 * i + i;
			if ( temp>= n)
			{
				cout<<temp<< endl;
				break;
			}
		}
	
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rrep(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr ll INF = (ll)1e9;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N, x; cin >> N >> x;
	vector<int>a(N);
	rep(i, 0, N)cin >> a[i];
	sort(all(a));
	int ans = 0;
	rep(i, 0, N) {
		if (x >= a[i]) {
			if (i != N - 1) {
				++ans;
				x -= a[i];
			}
			else if (x == a[i])++ans;

		}
	}
	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 3616
import java.util.*;
public class Main {
    public static long mod(long x, long y){
    return x%y<0?x%y+(y<0?-y:y):x%y;
    }
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = 1000000007;
        long b = 1;
        long c = 1;
        long d = 1;
        for(int i=0;i<n;i++){b*=10;
                             c*=9;
                             d*=8;
                             b=mod(b,a);
                             c=mod(c,a);
                             d=mod(d,a);
                            }       
		System.out.println(mod(b-2*c+d,a));
	}
}

Measured memory_bytes: 35736
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
using ui64 = uint_fast64_t;
#define REP(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int f(int h1, int h2, int x, int y) {
    int xb = x * h2;
    int ya = y * h1;
    int g = gcd(xb, ya);
    int alpha = ya / g;
    int beta = xb / g;
    return x * alpha + y * beta;
}

void solve(int N) {

    vector<pair<int, int>> hi(N, make_pair(-1, -1));
    vector<pair<int, int>> graph(N, make_pair(-1, -1));
    
    REP(i, N) {
        int p, q, r, b;
        cin >> p >> q >> r >> b;
        --r, --b;
        graph[i] = make_pair(r, b);
        hi[i] = make_pair(p, q);
    }

    vector<int> dp(N, -1);
    function<int(int)> dfs = [&](int cur) {
        if (dp[cur] != -1) return dp[cur];
        int l_wei = graph[cur].first;
        int r_wei = graph[cur].second;
        if (l_wei == -1 and r_wei == -1) {
            return dp[cur] = (hi[cur].first + hi[cur].second) / gcd(hi[cur].first, hi[cur].second);
        } else if (l_wei == -1) {
            int r = dfs(r_wei);
            int y = hi[cur].first;
            int x = hi[cur].second;
            return dp[cur] = f(x, y, 1, r);
        } else if (r_wei == -1) {
            int l = dfs(l_wei);
            int y = hi[cur].first;
            int x = hi[cur].second;
            return dp[cur] = f(x, y, l, 1);
        } else {
            int y = dfs(l_wei);
            int x = dfs(r_wei);
            return dp[cur] = f(hi[cur].first, hi[cur].second, x, y);
        }
    };

    REP(i, N) dfs(i);
    cout << *max_element(dp.begin(), dp.end()) << endl;
}

signed main() {

    int N;
    while (cin >> N, N) solve(N);

}


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

/* debugging */
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << ": " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<"| ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


#define boost ios::sync_with_stdio(0); cin.tie(0);
#define int long long

const int N = 1e5 + 10;
const int mod = 1e9 + 7;

int32_t main(){
    boost;

    
    //code
    int n,k;
    cin >> n >> k;

    if(k == 1){
    	cout << 0;
    	return 0;
    }
    cout << (n-k);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <vector>
#include <queue>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 2e5+5;
int n, m, p[N], q[N], lg[N], ans[N];
vector<int> to[N]; pair<int, int> s[N];
priority_queue<pair<int, int> > h;
struct ST
{
    int _[18][N];
    void build(int k)
    {
        for(int i = 2-k; i <= n; i += 2) _[0][i] = p[i];
        for(int i = 2-(k^1); i <= n; i += 2) _[0][i] = n+1;
        for(int i = 1, m = lg[n]; i <= m; ++i)
            for(int j = 1; j+(1<<i)-1 <= n; ++j)
                _[i][j] = min(_[i-1][j], _[i-1][j+(1<<(i-1))]);
    }
    int ask(int l, int r)
    {
        int i = lg[r-l+1];
        return min(_[i][l], _[i][r-(1<<i)+1]);
    }
}f[2];
int solve(int l, int r)
{
    int a = f[l&1].ask(l, r), b = f[(l&1)^1].ask(q[a]+1, r), c = ++m; s[c] = make_pair(a, b);
    if(l != q[a]) to[c].push_back(solve(l, q[a]-1));
    if(q[a]+1 != q[b]) to[c].push_back(solve(q[a]+1, q[b]-1));
    if(q[b] != r) to[c].push_back(solve(q[b]+1, r));
    return c;
}
int main()
{
    n = read();
    for(int i = 1; i <= n; ++i) p[i] = read(), q[p[i]] = i;
    for(int i = 2; i <= n; ++i) lg[i] = lg[i>>1]+1;
    f[0].build(0), f[1].build(1), solve(1, n), m = 0, h.push(make_pair(-s[1].first, 1));
    while(h.size())
    {
        int x = h.top().second; h.pop(); ans[++m] = s[x].first, ans[++m] = s[x].second;
        for(int i = 0; i < to[x].size(); ++i) h.push(make_pair(-s[to[x][i]].first, to[x][i]));
    }
    for(int i = 1; i <= n; ++i) printf("%d ", ans[i]); puts("");
    return 0;
}

Measured memory_bytes: 48384
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int  main(){
    long long int  n;
    cin>>n;
    vector<long long int >v(n);
    for(long long int  i=0;i<n;i++){
        cin>>v[i];
    }
    long long int  result=0;
    for(long long int  i=0;i<n;i++)
    {
        v[i]=v[i]-i-1;
    }
    sort(v.begin(),v.end());
    long long int f=v[n/2];
    if(n%2==0){
        f=(v[n/2]+v[n/2-1])/2;
    }
    long long int finalresult=0;
    for(long long int  i=0;i<n;i++)
    {
        finalresult+=abs(v[i]-f);
    }
    cout<<finalresult;
}

Measured memory_bytes: 4792