akhauriyash/Code-Regression huggingface dataset:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=_I()
S=input()
#print(S)

black=0
white=S.count(".")
ans=white
for idx in range(len(S)):
	if S[idx] == "#":
		black+=1
	else:
		white-=1
	ans=min(ans,black+white)


	
print(ans)
		
	


Measured memory_bytes: 66284
import java.util.*;
class Main{
  public static void main(String args[]){
    int count = 0;
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[] = new int[n];

    for(int i = 0; i<n; i++){
      a[i] = sc.nextInt();
      if(Judge_Prime(a[i])==1)count++;
    }
    System.out.println(count);
  }
  static int Judge_Prime (int n){
    int i;
    if (n < 2){
      return 0;
    }else if (n == 2){
      return 1;
    }

    if (n % 2 == 0){
      return 0;
    }

    for (i = 3; i <= n / i; i += 2){
      if (n % i == 0){
        return 0;
      }
    }
      return 1;
  }
}


Measured memory_bytes: 41884
#include <stdio.h>

int N,M,K;
bool check=false;
int main(){
  scanf("%d %d %d", &N,&M,&K);

  for(int i=0;i<=N;i++){
    for(int j=0;j<=M;j++){
      if(K==i*M+j*(N-i*2)){//iは行のボタン、jは列のボタン
        check=true;
      }
    }
  }
  if(check){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn solve(a: i64, b: i64, xs: Vec<i64>) -> i64 {
    let mut res = 0;
    let len = xs.len();
    let diff = xs[0] - 1;
    if !diff == 0 {
        if diff * a > b {
            res += b;
        } else {
            res += diff * a;
        }
    }

    for i in 1..len {
        let diff = xs[i] - xs[i-1];
        if diff * a > b {
            res += b;
        } else {
            res += diff * a;
        }
    }

    res
}

fn main() {
    input! {
        n: usize,
        a: i64,
        b: i64,
        xs: [i64; n],
    }
    println!("{}", solve(a, b, xs));
}





Measured memory_bytes: 6396
N = int(input())
A = list(map(int, input().split()))
A = sorted(A,reverse=True)
B = 1
if 0 in A:
    print(0)
    quit()
else:
    for i in A:
        B *= i
        if B> 10**18:  
            print(-1)
            quit()
print(B)

Measured memory_bytes: 21652
/*
17D8101031C 杉山　祥吾 ID:keisei334 C++
*/

#include <iostream>

using namespace std;

#define N 100000

int main(void){
  int n,count=0;
  char s[N];

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s[i];
  }

  for(int i=0;i<n;i++){
    if(s[i]=='O' && s[i+1]=='X'){
      count++;
      i++;
    }else if(s[i+1]=='O' && s[i]=='X'){
      count++;
      i++;
    }
  }

  cout<<count<<"\n";
  
  return 0;
}

/*実行結果
5
OXXOX
2

14
OXOXOXOXXOXOXO
7

10
OOOOOOOOOO
0
*/



Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
#define LL long long int

int main(){
    LL n,w;
    cin>>n>>w;
    LL weight[n];
    LL cost[n];
    for(LL i=0;i<n;i++){
        LL a,b;
        cin>>a>>b;
        weight[i]=a;
        cost[i]=b;
    }
    LL dp[n+1][w+1];
    for(LL i=0;i<=w;i++){
        dp[0][i]=0;
    }
    for(LL i=0;i<=n;i++){
        dp[i][0]=0;
    }
    
    for(LL i=1;i<=n;i++){
        for(LL j=1;j<=w;j++){
            if(weight[i-1]<=j){
                dp[i][j]=max(cost[i-1]+dp[i-1][j-weight[i-1]],dp[i-1][j]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    
    cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 79104
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n;
    cin >> n;
    cout << "Christmas";
    rep(i, 25 - n){
        cout  << " Eve";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 2050
struct edge{int t,next;}ed[N*2];
int head[N],cnt,n,mn[N],mx[N],sz[N],a,b,as=1e9;
char is[N];
void adde(int f,int t){ed[++cnt]=(edge){t,head[f]};head[f]=cnt;ed[++cnt]=(edge){f,head[t]};head[t]=cnt;}
void dfs(int u,int fa)
{
	sz[u]=(is[u]=='1');mn[u]=mx[u]=0;
	for(int i=head[u];i;i=ed[i].next)if(ed[i].t!=fa)dfs(ed[i].t,u),mx[u]+=mx[ed[i].t]+sz[ed[i].t],sz[u]+=sz[ed[i].t];
	for(int i=head[u];i;i=ed[i].next)if(ed[i].t!=fa)mn[u]=max(mn[u],mn[ed[i].t]+mx[ed[i].t]-mx[u]+sz[ed[i].t]*2);
}
int main()
{
	scanf("%d%s",&n,is+1);
	for(int i=1;i<n;i++)scanf("%d%d",&a,&b),adde(a,b);
	for(int i=1;i<=n;i++)dfs(i,0),as=min(as,(mn[i]||(mx[i]&1))?1000000000:mx[i]/2);
	printf("%d\n",as>1e8?-1:as);
}

Measured memory_bytes: 384
# dwacon5th-prelimsA - Thumbnail
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    avg = sum(A) / N
    D = [(abs(avg - a), i) for i, a in enumerate(A)]
    print(min(D)[1])


if __name__ == "__main__":
    main()

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


typedef long long ll;
typedef unsigned long long ull;

const int maxn = 2e5+1;
int n;
ll x[maxn];
ll s[maxn];
ll ss[maxn];

int main()
{
  scanf("%d", &n);
  x[0] = s[0] = 0;
  for (int i = 1; i <= n; ++i)
    scanf("%lld %lld", x+i, s+i), s[i] += s[i-1];
  for (int i = 1; i <= n; ++i)
    ss[i] = s[i]-x[i];
  ll ans = 0;
  ll mini = s[0]-x[1];
  for (int i = 1; i <= n; ++i)
    {
      ans = max(ans, ss[i]-mini);
      mini = min(mini, s[i]-x[i+1]);
    }
  printf("%lld\n", ans);
		    
}


Measured memory_bytes: 4992
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>
#define ul unsigned long long int
#define ll long long int
#define MAX 1000000+1
using namespace std;
#define F first
#define S second
#define pi 2*acos(0.0)
#define PB push_back
#define CL clear()



int main()
{

  string s;
  cin >> s;
  if(s[2]==s[3] && s[4]==s[5]) cout <<"Yes";
  else cout <<"No";


   return 0;

}




Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] total;
		while(true) {
		total = new int[10];
		total[0] = sc.nextInt()	;
		if(total[0] == 0) break ;
		for(int i = 1 ; i < 10 ;i++){
			total[i] = sc.nextInt();
		}
		for(int i = 1 ; i < total.length ; i++){
			total[0] -= total[i];
		}
		System.out.println(total[0]);
		}
		sc.close();
	}

}

Measured memory_bytes: 17196
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, groupby
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


def ns(): return stdin.readline().rstrip()


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


n = ni()
print((n + 1) // 2)


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

typedef long long ll;

ll gcd( ll x, ll y );
ll lcm( ll x, ll y );

int main()
{
    int t, n;

    for ( int i = 0; i < 4; ++i ) {
        cin >> t >> n;
        if ( t == 1 ) {
            n *= 6000;
        } else if ( t == 2 ) {
            n *= 4000;
        } else if ( t == 3 ) {
            n *= 3000;
        } else if ( t == 4 ) {
            n *= 2000;
        }
        cout << n << endl;
    }

    return 0;
}

ll gcd( ll x, ll y )
{
    if ( y == 0 ) return x;
    return gcd( y, x % y );
}

ll lcm( ll x, ll y )
{
    return x / gcd( x, y ) * y;
}




Measured memory_bytes: 3108
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;
int nums[109];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    rep(i,N) cin>>nums[i];
    sort(nums,nums+N);
    
    int cnt=1;
    rep(i,N-1) if(nums[i+1]>nums[i]) cnt++;
    cout1(cnt)
}

Measured memory_bytes: 256
from sys import stdin

class QueueNode(object):
	def __init__(self,data,next=None):
		self.data = data
		self.next = next

class LinkList(object):
	def __init__(self,head=None):
		self.head = head
		self.tail = head

	#後ろに挿入する
	def insert_q(self,data):
		node = QueueNode(data)

		if self.head is None:
			self.head = node
			self.tail = node
			return

		currentNode = self.tail

		while True:
			if currentNode.next is None:
				currentNode.next = node
				self.tail = node
				break
			currentNode = currentNode.next

	#先頭を削除する
	def delete_q(self):
		if self.head is not None:
			currentNode = self.head
			self.head = currentNode.next

	#先頭を表示する
	def print_q(self):
		if self.head is not None:
			print(self.head.data)

if __name__ == '__main__':

	qnum,loopnum = map(int,input().split(" "))

	q = [LinkList() for i in range(qnum)]

	for i in range(loopnum):
		cmd = stdin.readline().strip().split()
		t = int(cmd[1])
		if cmd[0] == "0":
			q[t].insert_q(int(cmd[2]))
		elif cmd[0] == "1":
			q[t].print_q()
		else:
			q[t].delete_q()





Measured memory_bytes: 45388
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
 
using namespace __gnu_pbds;
using namespace std;
 
 
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
long long f(long long a) {
     long long res[] = {a,1,a+1,0};
     return res[a%4];
}
 
long long getXor(long long a, long long b) {
  if(a==0)a=1;
     return f(b)^f(a-1);
}
 
  int main()
  {
ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    // ifstream fin(".in");
    // ofstream fout(".in");
i64 a,b;
cin>>a>>b;
i64 ans=0;
cout<<getXor(a,b);
 
 
    return 0;
  }

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	var i int
	if sc.Scan() {
		if num, err := strconv.Atoi(sc.Text()); err == nil {
			i = num
		}
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n, r := nextInt(), nextInt()
	var inner int
	if 10 <= n {
		inner = r
	} else {
		inner = r + 100*(10-n)
	}
	fmt.Println(inner)
}


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

int main() {
	int x;
	cin >> x;
	int s = x % 60;
	x = x / 60;
	int m = x % 60;
	x = x / 60;
	int h = x;
	cout << h << ":" << m << ":" << s << endl;

	return 0;
}

Measured memory_bytes: 3112
import itertools
import math
n=int(input())
xlist=[]
ylist=[]
ans=0
numlist=list(itertools.permutations(range(1,n+1)))
for i in range(n):
    x,y=map(int,input().split())
    xlist.append(x)
    ylist.append(y)
for i in range(len(numlist)):
    for j in range(n-1):
        a=numlist[i][j]-1
        b=numlist[i][j+1]-1
        ans+=math.sqrt((xlist[a]-xlist[b])*(xlist[a]-xlist[b])+(ylist[a]-ylist[b])*(ylist[a]-ylist[b]))
print(ans/(len(numlist)))


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

#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int;  // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9) + 7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
const double PI = acos(-1);

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    pair<ll, ll> a = make_pair(i, 0);
    while ((n % i) == 0) {
      n /= i;
      a.second += 1;
    }
    p.push_back(a);
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
  ll b = MOD, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0) {
    u += MOD;
  }
  return u;
}
// 順列
ll permutation(const ll n, const ll m) {
  ll result = 1;
  for (ll i = n; i > n - m; i--) {
    result = (result * i) % MOD;
  }
  return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
  if (x == 0) return 1;
  ll res = repeat_square(n, x / 2);
  res = res * res % MOD;
  if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ nCm
ll combination(ll n, ll m) {
  ll p = permutation(n, m);
  ll div = 1;
  for (ll i = 2; i <= m; i++) {
    div = (div * i) % MOD;
  }
  return (p * modinv(div)) % MOD;
}

// アルファベットの取得
string get_alphabet(ll n) {
  n--;
  return string(1, 'a' + (n % 26));
}

string to_str(ll n) {
  return to_string(n);
}

int main() {
  int N;
  cin >> N;
  vector<int> ans(1e7, 0);
  rep(x, 1, 101) {
    rep(y, 1, 101) {
      rep(z, 1, 101) {
        int temp = x*x + y*y + z*z + x*y + y*z + z*x;
        ans[temp]++;
      }
    }
  }

  rep(i, 1, N+1) {
    cout << ans[i] << endl;
  }
  return 0;
}


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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    int X; cin >> X;
    YES(X==7||X==5||X==3);
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		long n = Long.parseLong(str[0]);
		long a = Long.parseLong(str[1]);
		long b = Long.parseLong(str[2]);

		long c = modpow(2, n, 1000000007) - 1;
		long muri = c(n, a, 1000000007) + c(n, b, 1000000007);

		long ans = c - muri;
		while (ans < 0) {
			ans += 1000000007;
		}

		System.out.println(ans);
	}

	static long c(long n, long k, long mod) {
		long p = 1;
		long q = 1;
		for (long i = 0; i < k; i++) {
			p = p * (n - i) % mod;
			q = q * (i + 1) % mod;
		}
		return p * modpow(q, mod - 2, mod) % mod;
	}

	static long modpow(long a, long n, long mod) {
		long res = 1;
		while (n > 0) {
			if ((n & 1) == 1)
				res = res * a % mod;
			a = a * a % mod;
			n >>= 1;
		}
		return res % mod;
	}

}


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

int a[100005];

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

    int m, n;
    cin >> m >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    if (m == 2) {
        int ans1 = 0, ans2 = 0;
        for (int i = 0; i < n; i++) {
            int j = i % 2 ? 1 : 2;
            int k = 3 - j;
            if (a[i] != j)
                ans1++;
            if (a[i] != k)
                ans2++;
        }
        cout << min(ans1, ans2) << endl;
    } else {
        int cnt = 1, ans = 0;
        for (int i = 1; i < n; i++) {
            if (a[i] != a[i - 1]) {
                ans += cnt / 2;
                cnt = 1;
            } else
                cnt++;
        }
        ans += cnt / 2;
        cout << ans << endl;
    }
}


Measured memory_bytes: 3556
#include<iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<long long,int>,null_type,less<pair<long long,int>>,rb_tree_tag,tree_order_statistics_node_update>rbt;
rbt s;
int n,a,k,tot;long long tag,ans;
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>k;
	for(int i=1;i<=n;++i){
		cin>>a,a-=k;
		tag+=a;
		s.insert(make_pair(a-tag,++tot));
		ans+=i-s.order_of_key(make_pair(-tag,0));
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

const int MAX = 710000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    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;
    }
}
 
long long COM(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;
}

map<ll, ll> prime_factor(ll n){
    map<ll, ll> mp;
    for(int i = 2; i * i <= n; i++){
        while(n % i == 0){
            mp[i]++;
            n /= i;
        }
    }
    if(n != 1)mp[n]++;
    return mp;
}

int main() {
    ll n, m, ans = 1;
    cin >> n >> m;
    map<ll, ll> d = prime_factor(m);
    COMinit();
    for(auto x : d){
        ans = ans * COM(x.second + n - 1, x.second) % mod;
    }
    cout << ans << endl;
}   

Measured memory_bytes: 16896
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int n, m;
    cin >> n >> m;
    vector<pii> vs;
    set<int> st;
    if(n%2){
        for(int a=1, b= n-1; b-a>0; a++, b--){
            vs.emplace_back(a, b);
    
        }
    }else{
        bool fg = false;
          for(int a=1, b= n-1; b-a>0; a++, b--){
            if(!fg && b-a <= n/2) b--, fg = true;
            vs.emplace_back(a,b);
        }
    }

    rep(i, m){
        cout << vs[i].first << " " << vs[i].second << ln;
    }

}


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

int main() {
    char c;
    cin >> c;
    if(c == 'a'
     ||c == 'e'
     ||c == 'i'
     ||c == 'o'
     ||c == 'u'
     )cout << "vowel" << endl;
    else cout << "consonant" << endl;
}

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

const int N = 1e5 + 9;

int n, x[N], f[N], m, g[N], ans[N];
long long k;

int main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &x[i]), f[i] = ans[i] = i;
	scanf("%d%lld", &m, &k);
	for (int i = 1, a; i <= m; ++i) scanf("%d", &a), swap(f[a], f[a - 1]);
	for (; k; k >>= 1) {
		if (k & 1) {
			for (int i = 1; i < n; ++i) g[i] = ans[f[i]];
			for (int i = 1; i < n; ++i) ans[i] = g[i];
		}
		for (int i = 1; i < n; ++i) g[i] = f[f[i]];
		for (int i = 1; i < n; ++i) f[i] = g[i];
	}
	long long s = x[1];
	for (int i = 1; i <= n; ++i) {
		printf("%lld\n", s);
		s += x[ans[i] + 1] - x[ans[i]];
	}
	return  0;
}

Measured memory_bytes: 2816
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int a[100003];

int main(void){
	int n, i;
	scanf("%d", &n);
	for(i=0; i<n; i++){
		int A;
		scanf("%d", &A);
		a[A]++; a[A+1]++; a[A+2]++;
	}
	int max=0;
	for(i=2; i<=100000; i++){
		if(a[i]>max) max=a[i];
	}
	printf("%ld\n", max);
}


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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N; cin >> N;	
	vector<int> h(N);
	repp(i,0,N) cin >> h[i];
	int ans = 0;
	while(1){
		int p = 0;
		while(p < N && h[p] == 0) ++p;
		if(p == N) break;
		while(p < N && h[p] > 0){
			--h[p];
			++p;
		}
		++ans;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author /\
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DKi solver = new DKi();
        solver.solve(1, in, out);
        out.close();
    }

    static class DKi {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();
            List<Integer>[] adj = new List[n];
            for (int i = 0; i < n; i++) {
                adj[i] = new ArrayList<>();
            }
            for (int i = 0; i < n - 1; i++) {
                int a = in.nextInt();
                int b = in.nextInt();
                adj[a - 1].add(b - 1);
                adj[b - 1].add(a - 1);
            }
            long[] added = new long[n];
            while (q-- > 0) {
                int p = in.nextInt() - 1;
                int x = in.nextInt();
                added[p] += x;
            }
            long[] res = new long[n];
            res[0] = added[0];
            boolean[] vis = new boolean[n];
            vis[0] = true;
            dfs(0, res, added, adj, vis);
            StringBuilder sb = new StringBuilder();
            for (long i : res) {
                sb.append(i).append(" ");
            }
            out.print(sb);
        }

        static void dfs(int node, long[] res, long[] added, List<Integer>[] adj, boolean[] vis) {
            for (int i : adj[node]) {
                if (!vis[i]) {
                    vis[i] = true;
                    res[i] = res[node] + added[i];
                    dfs(i, res, added, adj, vis);
                }
            }
        }

    }

    static class Scanner {
        private StringTokenizer st;
        private BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

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

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

    }
}



Measured memory_bytes: 118628
n, x, y = map(int, input().split())
z = y - x
l = []
for i in range(1, n):
    for j in range(i + 1, n + 1):
        a = min(j - i, abs(x - i) + abs(y - j) + 1)
        l.append(a)

import collections

c = collections.Counter(l)
for i in range(1, n):
    print(c[i])


Measured memory_bytes: 67804
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sn = new Scanner(System.in);
		
		int k = sn.nextInt();
		int x = sn.nextInt();
		
		int min = x - (k -1);
		int max = x + (k -1);
		
		StringBuilder sb = new StringBuilder();
		for (int i = min; i <= max; i++) {
			sb.append(i);
			sb.append(" ");
		}
		
		System.out.println(sb.substring(0, sb.length() - 1));
	}
	
}


Measured memory_bytes: 21972
#include <stdio.h>

void merge_sort(int x[], int n)
{
	static int y[300001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main ()
{
	int i, N, A, count[300001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &A);
		count[A]++;
	}
	merge_sort(&(count[1]), N);
	
	int l, r, m, sum[300001] = {}, ans;
	for (i = 1, sum[0] = 0; i <= N; i++) sum[i] = sum[i-1] + count[i];
	for (i = 1; i <= N; i++) {
		l = N - i + 1;
		r = N;
		while (l < r) {
			m = (l + r) / 2;
			if ((double)sum[m] / (m - N + i) <= (double)sum[m+1] / (m - N + i + 1)) r = m;
			else l = m + 1;
		}
		printf("%d\n", sum[l] / (l - N + i));
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 5244
times = [int(input()) for _ in range(5)]
diff = [False for i in range(10)]
for time in times:
    diff[time%10]=True
res = 0
for i in range(1, 10):
    if diff[i]:
        res=i
        break
else:
    res=10

for i in range(5):
    rep = times[i]//10
    if times[i]%10!=0:
        rep+=1
    times[i] = rep*10

print(sum(times) - (10 - res))


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	//mapのkeyを降順に並べてくれる機能
	map<ll,int,greater<ll>> m;
	int n;
	cin >> n;
	ll a;
	rep(i,n){
		cin >> a;
		m[a]++;
	}
	bool flag = 0;
	ll fi=0,se=0;
	for(auto&im : m){
		//cout << im.first << " " << im.second << endl;
		if(fi==0&&im.second>=4){
			flag = 1;
			cout << im.first * im.first << endl;
			break;
		}
		if(fi==0&&(im.second==2||im.second==3)){
			fi = im.first;
		}
		else if (im.second>=2){
			se = im.first;
			flag = 1;
			cout << fi*se << endl;
			break;
		}
	}
	if (!flag){
		cout << "0" << endl;
	}
	
	return 0;
}


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

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> v(n);
  for(int i=0; i<n; i++){
    cin>>v[i];
  }
  int res = 1e9;
  for(int i=0; i<=n-k; i++){
    res = min(v[k+i-1]-v[i] + abs(v[i]), res);
    res = min(v[k+i-1]-v[i] + abs(v[k+i-1]), res);    
  }
  cout<<res<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int uchiha=1e5+5;
int arr[uchiha];
long long m=1000000007;
int main()
{
int n;
long long sum=0;
cin>>n;
sum=n*800;
int w=n/15;
cout<<sum-(w*200);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("unroll-loops, no-stack-protector")
#pragma GCC target ("avx")
#pragma GCC target ("avx2")
#pragma GCC target ("fma")
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll a[200005], sum = 0;
ll mod = 1e9 + 7;
int main(){
	fastio;
	ll n; cin >> n;
	for (ll i = 0; i < n; i++){
		cin >> a[i]; (sum += a[i]) %= mod;
		(a[i] *= a[i]) %= mod;
	}
	(sum *= sum) %= mod; 
	for (ll i = 0; i < n; i++){
		sum -= a[i]; if (sum < 0) sum += mod;
	}
	if (sum % 2) sum += mod; sum /= 2;
	cout << sum << endl;
}

Measured memory_bytes: 5216
# -*- coding: utf-8 -*-
N = int(raw_input())
a = map(int,raw_input().split())
a.sort()
a.reverse()
Bob = 0
Alice = 0
A = 0
B = 1
while A < N:
    Alice += a[A]
    A += 2
while B < N:
    Bob += a[B]
    B += 2
print Alice-Bob

Measured memory_bytes: 2568
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const MOD: i64 = (1e+9 as i64) + 7;
fn main() {
    let _n = read::<usize>();
    let s = read::<String>().chars().collect::<Vec<char>>();
    let mut cnts = vec![0i64; 255];
    for c in s.iter() {
        cnts[(*c as u8) as usize] += 1;
    }
    let mut ans = 1;
    for cnt in cnts.iter() {
        ans = ans * (1i64 + cnt) % MOD;
    }
    ans = (ans + MOD - 1) % MOD;
    println!("{}", ans);
}


Measured memory_bytes: 4352
/* ex 2_3 nknm */

#include <stdio.h>
 
int main(void){
  //引数を定義
  int N,A;
  
  //数字を入力
  scanf("%d%d", &N, &A);
  //数字を出力
  printf("%d\n", N * N - A);
  
  return 0;
}

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


int main(void){
	string s;
  cin >> s;
  vector<ll> num(3, 0);
  int n = s.size();
  rep(i, n){
    if (s.at(i) == 'a') num.at(0)++;
    else if(s.at(i) == 'b') num.at(1)++;
    else num.at(2)++;
  }
  sort(num.begin(), num.end());
  ll x = num.at(1)-num.at(0), y = num.at(2) - num.at(1), z = num.at(2) - num.at(0);
  if((x == 0 && y == 0) || (x==0 && y == 1) || (z==1 && x == 1)){
    cout << "YES";
  }
  else {
    cout << "NO";
  }

}
//全部同じ数　or 1つだけ1個多い or  2つが1つよりも１だけ数が多い　ならok

Measured memory_bytes: 3756
N = int(input())
A = list(map(int,input().split()))

for i in range(len(A)):
    V = A[i]
    j = i - 1
    while j >= 0 and A[j] > V:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = V
    print(' '.join(map(str,A)))



Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {-1,0,1,0}, dy[] = {0,-1,0,1};

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    int a, b, c;
    b = x;
    a = z;
    c = y;
    cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
using namespace std;


int main(){
	/*input*/
	int r;
	cin >> r ;


	/*calc*/
    int ans;
    ans = r*r;

    /*output*/
	cout<< ans <<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define ll long long
#define pi pair<int,int>
#define sz size()
#define er erase
#define fr first
#define sc second
using namespace std;
 
int n,m,r[100005],cnt[100005],a[100005],b[100005];
pair <pair<int,int>,int> p[100005];
 
int cif(int x)
{
    int t=0;
    while (x>0) x/=10, ++t;
    return t;
}
 
int main()
{
    cin >> n >> m;
    fort(i,m)
    {
        cin >> a[i] >> b[i];
        p[i].fr.sc=a[i], p[i].fr.fr=b[i], p[i].sc=i;
    }
    sort (p+1,p+m+1);
    fort(i,m)
        ++r[p[i].fr.sc], cnt[p[i].sc]=r[p[i].fr.sc];
    fort(i,m)
    {
        fort(j,6-cif(a[i]))
            cout << 0;
        cout << a[i];
        fort(j,6-cif(cnt[i]))
            cout << 0;
        cout << cnt[i] << '\n';
    }
}

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

int main()
{
	for(int n;cin>>n && n;){
		vector<int> a(n);
		for(int& x:a) cin>>x;

		vector<int> b=a;
		sort(begin(b),end(b));

		int res=0;
		for(int i=0;i<n;i++){
			int j=lower_bound(begin(b),end(b),a[i])-begin(b);
			res+=i&1^j&1;
		}

		cout<<res/2<<endl;
	}
}


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

using namespace std;

const int MAXN = 700;
bool adjMat[MAXN + 1][MAXN + 1];
int color[MAXN + 1];
bool dp[MAXN + 1];

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        adjMat[a][b] = adjMat[b][a] = true;
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = i + 1; j <= n; j++)
        {
            adjMat[i][j] = adjMat[j][i] = !adjMat[i][j];
        }
    }
    bool valid = true;
    vector<pair<int, int>> v;
    for (int i = 1; i <= n; i++)
    {
        if (color[i] == 0)
        {
            pair<int, int> pr = make_pair(0, 0);
            queue<int> q;
            color[i] = 1;
            q.push(i);
            while (!q.empty())
            {
                int cur = q.front();
                q.pop();
                if (color[cur] == 1)
                    pr.first++;
                else
                    pr.second++;
                for (int j = 1; j <= n; j++)
                {
                    if (j == cur)
                        continue;
                    if (adjMat[cur][j])
                    {
                        if (color[j] == 0)
                        {
                            q.push(j);
                            color[j] = color[cur] == 1 ? 2 : 1;
                        }
                        else if (color[j] == color[cur])
                        {
                            valid = false;
                        }
                    }
                }
            }
            v.push_back(pr);
        }
    }
    if (valid)
    {
        dp[0] = true;
        for (pair<int, int> pr : v)
        {
            for (int i = n; i >= 0; i--)
            {
                if (dp[i])
                {
                    dp[i] = false;
                    dp[i + pr.first] = true;
                    dp[i + pr.second] = true;
                }
            }
        }
        int target1, target2;
        target1 = target2 = n / 2;
        if (n % 2 != 0)
            target2++;
        int diff = n + 5;
        int compSize = 0;
        for (int i = 1; i <= n; i++)
        {
            if (dp[i])
            {
                int d = min(abs(i - target1), abs(i - target2));
                if (d < diff)
                {
                    diff = d;
                    compSize = i;
                }
            }
        }
        int c1 = compSize;
        int c2 = n - c1;
        cout << c1 * (c1 - 1) / 2 + c2 * (c2 - 1) / 2 << endl;
    }
    else
    {
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+8+7;
ll n,m,l;
string s,t;
int d[100],dp[100][100];

ll func(ll n){
  ll m = 0;
  while(n != 0){
    m += n%10;
    n/=10;
  }
  return m;
}

int main(){
  vi vec;
  cin >> n >> m >> l;
  lep(i,1,n){
    int a = func(i);
    if(m <= a && a <= l)vec.pb(i);
  }
  int ans = 0;
  rep(i,0,vec.sz){
    ans += vec[i];
  }
  print(ans);
  return 0;
}

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

constexpr int inf = 1e9;

int main() {
    int n; cin >> n;
    vector<string> v(n);
    bool ng = true;
    for(auto& s : v) {
        cin >> s;
        ng &= find(s.begin(), s.end(), '#') == s.end();
    }
    if(ng) {
        cout << -1 << endl;
        return 0;
    }

    int ans = inf, need = 0;
    for(int i = 0; i < n; ++i) {
        bool check = false;
        for(int j = 0; j < n; ++j) {
            check |= v[j][i] == '.';
        }
        need += check;
    }

    for(int i = 0; i < n; ++i) {
        int tans = need;
        bool found = false;
        for(int j = 0; j < n; ++j) {
            tans += v[i][j] == '.';
            found |= v[j][i] == '#';
        }
        tans += !found;

        ans = min(ans, tans);
    }

    cout << ans << endl;
}


Measured memory_bytes: 512
n, m = map(int, input().split())
apple = []
for _ in range(n):
    apple.append(list(map(int, input().split())))
apple = sorted(apple)
msum = 0
ans = 0
for i in apple:
    msum += i[1]
    if msum < m:
        ans += (i[0]*i[1])
    elif msum == m:
        ans += (i[0]*i[1])
        break
    else:
        a = m - (msum - i[1])
        ans += (i[0]*a)
        break
print(ans)

Measured memory_bytes: 28656
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
#define NUM 100005
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
int POW(int a,int n){int i;LL x=a;if(n==0)return 1;else if(n==1)return a;else FOR(i,0,n-1){x=x*a;if(x>MOD)x%=MOD;}return (int)x;}
//int cmp(const void* a,const void* b){return *(int*)a-*(int*)b;}

int main() {
  int i,n,ans=0;
  scanf("%d",&n);
  int p[n];
  FOR(i,0,n)scanf("%d",&p[i]);
  FOR(i,0,n-2){
    if(p[i]<=p[i+1]&&p[i+1]<p[i+2])ans++;
    else if(p[i]>p[i+1]&&p[i+1]>=p[i+2])ans++;
  }

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


Measured memory_bytes: 128
import java.util.*;

public class Main {
	private void doit() {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			int [] w = new int[n];
			int [] s = new int[n];
			int [] e = new int[n];
			for(int i =0; i < n;i++){
				w[i] = sc.nextInt();
				s[i] =sc.nextInt();
				e[i] = sc.nextInt();
				
			}
			boolean flg = true;
			for(int i =0; i < n;i++){
				int wei = w[i];
				for(int j =0 ;j < n; j++){
					if(i == j) continue;
					if(s[j] <= s[i] && s[i] < e[j]){
						wei += w[j];
						if(wei > 150){
							flg = false;
							break;
						}
					}
					
				}
				if(! flg){
					break;
				}
			}
			if(flg){
				System.out.println("OK");
			
			}
			else{
				System.out.println("NG");
			}
		}
		
	}

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

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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */



int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}


int main(){
  set<int> s;
  rep(i,3){
    int h;
    cin >> h;
    s.insert(h);
  }
  cout << s.size() << endl;
    
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort( a, a + 3 );
    if( a[0] + a[1] == a[2] ) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



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

using namespace std;
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V) \
    for (auto v : (V)) cout << v << ' ';
const int MOD = 1000000007;
/* cout << fixed << setprecision(10) << decimal << endl; */

int main() {
    /* code */
    int N;
    cin >> N;
    vector<int> X(N);
    REP(i, N) { cin >> X[i]; }
    sort(X.begin(), X.end());
    int ans = INT_MAX;
    FOR(i, 1, 101) {
        int tot = 0;
        for (auto x : X) {
            tot += (x - i) * (x - i);
        }
        ans = min(ans, tot);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s[0]=='A' && s[1]=='C'){
		cout<<"Yes"<<endl;
	}
	
	else if(s[1]=='A' && s[2]=='C'){
		cout<<"Yes"<<endl;
	}
	
	else if(s[2]=='A' && s[3]=='C'){
		cout<<"Yes"<<endl;
	}
	
	else if(s[3]=='A' && s[4]=='C'){
		cout<<"Yes"<<endl;
	}
	
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256