akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int, input().split()))
ans = 1
flag =0
for i  in a:
    if i == 0:
        flag=2
        break
if flag!= 2:
    for i  in a:
        ans = ans*i
        if ans > 10 ** 18:
            flag=1
            break


if flag==1:
    print(-1)
elif flag ==2:
    print(0)
else:
    print(ans)


Measured memory_bytes: 21660
N = gets.to_i
a = gets.split.map(&:to_i)

count = 1
countArray = []
a.each.with_index do |num, i|
  if num == a[i + 1]
    count += 1
  else
    countArray << count
    count = 1
  end
end

ans = countArray.map { |count| count / 2 }.inject(:+)
puts ans


Measured memory_bytes: 1788
#include <stdio.h>
#include <stdlib.h>

/* 学生一人の少なくとも1台のPCを利用していた時間の記録 */
typedef struct { int r; int t[500]; int s[500]; } Log; /* メモリが足りなかったので高々500と仮定 */

int main(void) {
	int N, M, r, q; /* PC数, 学生数, 利用記録数, 質問数 */
	int t, n, m, s; /* 時刻, PC番号, 学生番号, ログイン(1)/ログアウト(0) */
	int ts, te; /* 開始時刻, 終了時刻 */
	Log *l;
	int *u; /* 各学生が利用中のPC数 (入力用) */
	int i, j;

	/* データセット毎の処理 */
	while (scanf("%d%d", &N, &M) == 2 && N > 0 && M > 0) {
		/* 初期化 */
		l = (Log *)malloc( sizeof(Log) * (M + 1) );
		u = (Log *)malloc( sizeof(int) * (M + 1) );
		for (i = 0; i <= M; i++) l[i].r = 0;
		for (i = 0; i <= M; i++) u[i] = 0;

		/* 利用記録を読み込む */
		scanf("%d", &r);
		for (i = 0; i < r; i++) {
			scanf("%d%d%d%d", &t, &n, &m, &s);
			if (s == 1) {
				/* ログイン */
				if (u[m] == 0) {
					/* 「少なくとも1台のPCを利用していた時間」の開始を記録する */
					l[m].t[l[m].r] = t;
					l[m].s[l[m].r] = s;
					l[m].r++;
				}
				u[m]++;
			} else if (s == 0) {
				/* ログアウト */
				u[m]--;
				if (u[m] == 0) {
					/* 「少なくとも1台のPCを利用していた時間」の終了を記録する */
					l[m].t[l[m].r] = t;
					l[m].s[l[m].r] = s;
					l[m].r++;
				}
			}
		}

		/* 質問を読み込む */
		scanf("%d", &q);
		for (i = 0; i < q; i++) {
			int startTime; /* 利用開始時刻 */
			int totalTime = 0; /* 利用時間の合計 */
			int state = 0; /* 利用中か */

			scanf("%d%d%d", &ts, &te, &m);

			/* 対象学生の対象時間帯の記録を参照する */
			startTime = ts;
			j = 0;
			for (; j < l[m].r && l[m].t[j] < ts; j++) state = l[m].s[j]; /* 開始時刻前 */
			/* 対象時間帯 */
			for (; j < l[m].r && l[m].t[j] < te; j++) {
				if (l[m].s[j] == 0) {
					/* ログアウト */
					totalTime += l[m].t[j] - startTime;
					state = 0;
				} else if (l[m].s[j] == 1) {
					/* ログイン */
					startTime = l[m].t[j];
					state = 1;
				}
			}
			if (state) totalTime += te - startTime; /* 終了時刻の時点で利用中だった */


			printf("%d\n", totalTime); /* 利用時間を出力する */
		}

		/* 終了 */
		free(l);
		free(u);
	}

    return 0;
}

Measured memory_bytes: 57532
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int a = sc.nextInt();
			int b = sc.nextInt();

			int n = a + b;
			int cnt = 1;
			while (n != 0) {
				n = n / 10;
				cnt++;
			}
			System.out.println(cnt - 1);

	}
	}

}

Measured memory_bytes: 20416
import collections

n = int(input())

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

waru = 998244353

c = collections.Counter(d)

ans =1

cmax =max(c.keys())
if d[0] != 0:
    print(0)
else:
    for i in range(1,cmax+1):
        if d[i] == 0:
            ans = 0
            break
        ans *= c[i-1]** c[i]

    print(ans % waru)

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template<typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}

ll modpow(ll x, ll y) {
  ll res = 1;
  while (y > 0) {
    if (y & 1) {
      (res *= x) %= MOD;
    }
    (x *= x) %= MOD;
    y /= 2;
  }
  return res;
}

struct UnionFind {
  vi par;

  UnionFind(int n) {
    par.resize(n, -1);
  }

  int root(int x) {
    return par[x] < 0 ? x : par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);

    if(x == y) return;
    if(par[x] < par[y]) {
      swap(x, y);
    }

    par[y] += par[x];
    par[x] = y;
  }

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

  int size(int x) {
    return -par[root(x)];
  }
};

bool solve() {
  int n, m;
  cin >> n >> m;
  if(n == 0) return false;
  UnionFind uf(n);
  REP(i, m) {
    int a, b; cin >> a >> b;
    a--; b--;
    uf.unite(a, b);
  }


  map<int, int> mp;
  REP(i, n) {
    mp[uf.root(i)] = uf.size(i);
  }

  int cnt = 0;
  for(auto &e: mp) {
    if(e.second > 1) cnt++;
  }

  ll ans = 1;
  for(auto &e: mp) {
    ans *= 2;
    ans %= MOD;
  }

  if(cnt == 1) cout << (ans + 1) % MOD << endl;
  else if(cnt >= 2) cout << (ans + 1) % MOD << endl;
  else cout << ans << endl;
  return true;
}

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

  while(solve()) {}


}



Measured memory_bytes: 7808
# -*- coding:utf-8 -*-

n = int(raw_input())

lst = []

for i in xrange(n):
 name,p=map(str,raw_input().split())
 lst.append([i+1,name,int(p)])
lst.sort(key=lambda x:(x[1],-x[2]))
for i in xrange(n):
  print lst[i][0]

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

#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i, n) for (long long i = 0; i < (n); i++)
const ll INF = 1LL << 60;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
};
ll modpow(ll m, ll n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        ll t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
signed main() {
    string s;
    cin >> s;
    string t;
    REP(i, s.size()) {
        if (s[i] == '0') {
            t.push_back('0');
        }
        if (s[i] == '1') {
            t.push_back('1');
        }
        if (s[i] == 'B' && t.size() > 0) {
            t.pop_back();
        } else {
            continue;
        }
    }
    cout << t << endl;
}

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

int main() {
  char C, D; cin >> C;
  if (C=='a') D='b';
  if (C=='b') D='c';
  if (C=='c') D='d';
  if (C=='d') D='e';
  if (C=='e') D='f';
  if (C=='f') D='g';
  if (C=='g') D='h';
  if (C=='h') D='i';
  if (C=='i') D='j';
  if (C=='j') D='k';
  if (C=='k') D='l';
  if (C=='l') D='m';
  if (C=='m') D='n';
  if (C=='n') D='o';
  if (C=='o') D='p';
  if (C=='p') D='q';
  if (C=='q') D='r';
  if (C=='r') D='s';
  if (C=='s') D='t';
  if (C=='t') D='u';
  if (C=='u') D='v';
  if (C=='v') D='w';
  if (C=='w') D='x';
  if (C=='x') D='y';
  if (C=='y') D='z';
  cout << D << endl;
}

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

using namespace std;

int main(){

    int n = 0;
    cin >> n;

    bool contains7 = false;

    while(n!= 0){
        if(n%10 == 7) contains7 =true;
        n = n/10;
    }

    if(contains7){
        cout <<"Yes\n";
    }else cout <<"No\n";

	return 0;
}

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


int main() {

	int n;
	cin >> n;
	int w[100];
	int sum = 0;
	int ans = INT_MAX;
	for (int i = 0; i < n; i++) {
		int b;
		cin >> b;
		sum += b;
		w[i] = sum;
	}

	for (int i = 0; i < n; i++) {
		ans = min(ans, abs(sum - w[i] - w[i]));
	}
	cout << ans << endl;

	return 0;
}


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

int a, b, c;
long long k;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> a >> b >> c >> k;
    if(k & 1){
        cout << b - a << endl;
    }else{
        cout << a - b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>


using namespace std;


const long long size = 1000000007;


int main()
{
  long long n;

  cin >> n;
  long long x=1;
  for (long long i=1; i<n+1; i++){
    x = i*x % size;
  }
  cout << x << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
	string a;
	cin>>a;
	int tmp=a.find("ST");
	while(a.length()>0&&tmp!=string::npos)
	{
		a.erase(tmp,2);
		int x=max(tmp-1,0);
		tmp=a.find("ST",x);
	}
	cout<<a.length()<<endl;
	return 0;
} 

Measured memory_bytes: 832
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
    string number;
    while (1)
    {
        cin >> number;
        if (number == "0") break;
        int sum = 0;
        for (int i = 0; i < number.size(); i++)
        {
            sum += number[i] - '0';
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3204
from sys import stdin


def get_result(data):
    N, K = data[0]
    A = data[1:]
    sunuke = set()
    for A_val in A[1::2]:
        for val in A_val:
            sunuke.add(val)

    return N - len(sunuke)


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


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

using namespace std;

string s;
int sum;

int main() {
	cin >> s;
	int len = s.length();
	for (int i = 0; i < len; i++) sum += s[i]-'0';
	printf("%s" , sum%9 == 0 ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 3804
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main() {

	int A, B;

	cin >> A >> B;

	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;

	return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "2 3 4", "100", "600", "400", "900", "1000", "150", "2000", "899", "799" ].parse.expand.solve == "350\n1400\n301\n399" );
	assert( [ "1 1 3", "1", "10000000000", "2", "9999999999", "5000000000" ].parse.expand.solve == "10000000000\n10000000000\n14999999998" );
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abq = input.front.split.to!( long[] );
	auto ss = new long[ abq[ 0 ] ];
	foreach( ref s; ss )
	{
		input.popFront;
		s = input.front.to!( long );
	}
	auto ts = new long[ abq[ 1 ] ];
	foreach( ref t; ts )
	{
		input.popFront;
		t = input.front.to!( long );
	}
	auto xs = new long[ abq[ 2 ] ];
	foreach( ref x; xs )
	{
		input.popFront;
		x = input.front.to!( long );
	}
	
	return tuple( ss, ts, xs );
}

auto solve( long[] ss, long[] ts, long[] xs )
{
	// 後で順番を復元するためにインデックス付きXsを作成
	auto xps = new Tuple!( long, long )[ xs.length ];
	foreach( i, x; xs )
	{
		xps[ i ] = tuple( x, i );
	}
	
	ss.sort();
	ts.sort();
	xps.sort();
	
	auto anss = new long[ xs.length ];
	auto si = 0L;
	auto ti = 0L;
	foreach( xp; xps )
	{
		auto x = xp[ 0 ];
		auto xi = xp[ 1 ];
		
		auto sl = 0L;
		auto sr = 0L;
		auto tl = 0L;
		auto tr = 0L;
		
		// xから東と西で一番近い神社までの距離を計算
		solve2( ss, x, si, sl, sr );
		
		// xから東と西で一番近い寺までの距離を計算
		solve2( ts, x, ti, tl, tr );
		
		// 一番近い神社と寺に行くときの最短距離を計算
		anss[ xi ] = min(
			max( sl, tl ),					// 西の神社と寺に行く（まっすぐ行って終わり）
			max( sr, tr ),					// 東の神社と寺に行く（まっすぐ行って終わり）
			sl + tr + min( sl, tr ),		// 西の神社と東の寺に行く（近いほうに行って戻る）
			sr + tl + min( sr, tl )			// 東の神社と西の寺に行く（近いほうに行って戻る）
		);
	}
	
	return anss.map!( to!string ).join( "\n" );
}

void solve2( long[] as, long x, ref long ai, out long al, out long ar )
{
	const FAR = 10L ^^ 10 * 2;
	
	// xから東の一番近い神社or寺を検索
	foreach( a; as[ ai .. $ ] )
	{
		if( x <= a ) break;
		ai++;
	}
	
	al = FAR;
	ar = FAR;
	
	// xと神社or寺の位置が同じときは移動不要
	if( ai < as.length && as[ ai ] == x )
	{
		al = 0L;
		ar = 0L;
	}
	else
	{
		// xから東の一番近い神社or寺へ移動するときの距離を計算
		if( 0  < ai ) al = x - as[ ai - 1 ];
		
		// xから西の一番近い神社or寺へ移動するときの距離を計算
		if( ai < as.length ) ar = as[ ai ] - x;
	}
}


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

int main() {
  int N;
  cin >> N;
  
  int a[110];
  
  for(int i=0; i<N; i++){
    cin >> a[i];
  }
  
  sort(a, a+N, greater<int>());
  
  int Alice = 0;
  int Bob = 0;
  
  for(int i=0; i<N; i++){
    if(i%2 == 0){
      Alice += a[i];
    }
    else{
      Bob += a[i];
    }
  }
  
  cout << Alice - Bob <<endl;
}


Measured memory_bytes: 3628
X = int(input())
x = int(X**0.5)
num = []
if X <= 3 :
    print(1)
else :
    for b in range(2,x+1) :
        p = 2
        while b**p <= X :
            p += 1
        num.append(b**(p-1))
    print(max(num))

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

using sll = signed long long;

int main() {
	int n;
	std::cin >> n;

	std::vector<sll> tab;
	tab.resize(n);

	for (auto&e : tab)
		std::cin >> e;

	std::sort(std::begin(tab), std::end(tab));

	auto cn = tab[n - 1];

	sll dist = 1'000'000'000;
	int rpos = 0;
	for (int i{ 0 }; i < n - 1; ++i) {
		
		auto tdist = std::abs(cn - 2 * tab[i]);
		if (dist >= tdist) {
			dist = tdist;
		}
		else {
			rpos = i - 1;
			break;
		}
	}

	std::cout << cn << " " << tab[rpos] << "\n";
	return 0;
}

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

using namespace std;

int main(void) {
	string S;
	cin >> S;

	int v[3] = { 0 };
	for (int i = 0; i < 3; i++) {
		v[S[i] - 'a']++;
	}

	bool yes = (v[0] == 1 && v[1] == 1 && v[2] == 1);
	cout << (yes ? "Yes": "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

typedef long long ll;

string S, Sr;
int N;
map<string, ll> mp;
string red, blue;
ll ans;

void dfs(ll a) {
	if(a == N) {
		mp[red + '-' + blue]++;
		return ;
	}
	red += S[a];
	dfs(a + 1);
	red.pop_back();
	blue += S[a];
	dfs(a + 1);
	blue.pop_back();
}

void dfs2(ll a) {
	if(a == N) {
		ans += mp[blue + '-' + red];
		return ;
	}
	red += Sr[a];
	dfs2(a + 1);
	red.pop_back();
	blue += Sr[a];
	dfs2(a + 1);
	blue.pop_back();
}

int main()
{
	cin >> N;
	cin >> S;
	Sr = S;
	reverse(Sr.begin(), Sr.end());
	red = blue = "";
	dfs(0);
	red = blue = "";
	dfs2(0);
	cout << ans << endl;
}


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

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

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

  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];

  int ans = 1;
  int m = p[0];
  for (int i = 1; i < n; i++) {
    if (p[i] < m) ans++;
    chmin(m, p[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
n = int(input())
arr = list(map(int,input().split()))

ind = 1
ans = 0
flag = False
for i in range(n):
    if arr[i] != ind:
        ans += 1
    else:
        ind += 1
        flag = True

if flag:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 24744
#include <stdio.h>

int main ()
{	
	int r,s,t;
	
	scanf("%d %d %d", &r, &s, &t);
	
	if(r + s + t >= 22)
{
	printf("bust\n");
}	
	else
{
	printf("win\n");
}
	return 0;
}
	

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

const int mod = 998244353;

struct mint{
  ll x;
  mint(ll x = 0):x((x % mod + mod) % mod){};
  mint pow(ll y) const {
    mint res(1);
    mint a(x);
    while(y>0){
      if(y&1) res *= a;
      a *= a;
      y >>= 1;
    }
    return res;
  }
  mint inv() const{ return pow(mod-2); }
  mint& operator+= (const mint a) noexcept {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-= (const mint a) noexcept {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*= (const mint a) noexcept {
    (x *= a.x) %= mod;
    return *this;
  }
  mint& operator/= (const mint a) noexcept {
    return (*this) *= a.inv();
  }
  mint operator+ (const mint a) const noexcept {
    mint res(*this);
    return res += a;
  }
  mint operator- (const mint a) const noexcept {
    mint res(*this);
    return res -= a;
  }
  mint operator* (const mint a) const noexcept {
    mint res(*this);
    return res *= a;
  }
  mint operator/ (const mint a) const noexcept{
    mint res(*this);
    return res /= a;
  }
};

ostream& operator<<(ostream& stream, const mint& n){
  stream << n.x;
  return stream;
};

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


int main(void){
  ll n, m, k;
  cin >> n >> m >> k;
  comb c(n);
  mint ans;
  REP(i, k+1){
    ans += c(n-1, i) * m * mint(m-1).pow(n-i-1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6428
N,K = map(int,input().split())
L = list(map(int,input().split()))
ans = float('inf')
for i in range(N):
    if i+K <= N:
        if L[i] < 0:
            if L[K+i-1] > 0:
                cur = min(2*(-L[i])+L[K+i-1],2*(L[K+i-1])-L[i])
                if ans >= cur:
                    ans = cur
            else:
                cur = -L[i]
                if ans >= cur:
                    ans = cur
        else:
            cur = L[i+K-1]
            if ans >= cur:
                ans = cur
print(ans)

Measured memory_bytes: 14844
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
   input! {
      mut n: usize,
   }
   let mut k = 1;
   let mut m = 26;
   while n > m {
      m = (m + 1) * 26;
      k += 1;
   }
   n -= m / 26;

   let mut ans = vec![];
   for _ in 0..k {
      ans.push(n % 26);
      n /= 26;
   }
   ans.reverse();

   for c in ans.iter().map(|&c| b'a' + c as u8) {
      print!("{}", c as char);
   }
}


Measured memory_bytes: 2160
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int>v(4);
  for(int i = 0; i < 6; ++i){
    int x; cin >> x;--x;
    v[x]++;
  }
  sort(v.begin(),v.end());
  if(v[0] == 1 && v[1] == 1 && v[2] == 2 && v[3] == 2)
    cout << "YES" << endl;
  else 
    cout << "NO" << endl;
}

Measured memory_bytes: 3616
r1,c1,r2,c2 = map(int,input().split())
mod = 10**9+7
fact = [1]*(2*10**6+11)

for n in range(2*10**6+10):
    fact[n+1] = ((n+1)*fact[n])%mod

factinv = [1]*(2*10**6+10)
for n in range(10**6+10):
    factinv[n] = pow(fact[n],mod-2,mod)

def comb(n,k):
    return (fact[n]*factinv[n-k]*factinv[k])%mod

def fs(r,c):
    res = 0
    for i in range(1,c+1):
        res += comb(i+1+r,r)-1
    return res

ans = fs(r2,c2)-fs(r1-1,c2)-fs(r2,c1-1)+fs(r1-1,c1-1)
ans %= mod
print(ans)

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int dp[100001];
int n;


int main(){
    ios::sync_with_stdio(false);
    cin >> n;

    ll res=n;
    REP(i,n+1){
        ll ans=0;
        int t=i;
        while(t>0)ans+=t%6,t/=6;
        t=n-i;
        while(t>0)ans+=t%9,t/=9;
        res=min(ans,res);
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define print(a) cout << (a) << endl; 
typedef long long ll;
const int MOD = 1000000007; 

ll FACT(ll n, ll k) {
    ll ret = 1;
    for (int i = 0; i < k; ++i) {
        ret = ret * (n - i) % MOD;
    }
    return ret;
}

ll COM2(ll n, ll k) {
    ll x = FACT(n, k);
    ll y = FACT(k, k);
    return x / y; 
}


int main() {
    int n, m; 
    cin >> n >> m; 
    cout << COM2(n, 2) + COM2(m, 2) << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
    Scanner scanner = new Scanner(System.in);
 
    public static void main(String[] args) {
        new Main().compute();
    }
 
    void compute() {
        int N=scanner.nextInt();
        boolean Yes=N/10==9||N%10==9;
        if(Yes){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
package main

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

const (
	initialBufSize = 1024
	maxBufSize     = 1e6
)

var (
	scanner = bufio.NewScanner(os.Stdin)
	// writer  = bufio.NewWriterSize(os.Stdout, 1000000)
)

func main() {
	scanner.Split(bufio.ScanWords)
	// scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	// defer writer.Flush()
	a, b, c, d := scanInt(), scanInt(), scanInt(), scanInt()

	ta := true
	for {
		if ta {
			c = c - b
			if c <= 0 {
				fmt.Println("Yes")
				return
			}
			ta = !ta
		} else {
			a = a - d
			if a <= 0 {
				fmt.Println("No")
				return
			}
			ta = !ta
		}
	}

}

func scanInt() int {
	i, _ := strconv.Atoi(scanString())
	return i
}

func scanInts(size int) []int {
	ints := make([]int, size)
	for i := 0; i < size; i++ {
		ints[i] = scanInt()
	}
	return ints
}

func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanString(), 64)
	return f
}

func scanFloat64s(size int) []float64 {
	f := make([]float64, size)
	for i := 0; i < size; i++ {
		f[i] = scanFloat64()
	}
	return f
}

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

func scanStrings(size int) []string {
	s := make([]string, size)
	for i := 0; i < size; i++ {
		s[i] = scanString()
	}
	return s
}


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

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

Measured memory_bytes: 3640
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
    int n;
    cin >> n;

    string s;
    cin >> s;

    int count=0;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] l = new int[N];
		for(int i=0; i<N; i++){
			l[i] = sc.nextInt();
		}
		for(int i=0;i<N;i++){
			for(int j=N-1;j>i;j--){
				if(l[i] < l[j] ){
					int swap = l[i];
					l[i] = l[j];
					l[j] = swap;
				}
			}
		}
		int ans = 0;
		for(int i=0;i<K;i++){
			ans += l[i];
		}
		System.out.println(ans);
	}

}



Measured memory_bytes: 22228
N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]
ans = 0
count1 = 0
count2 = 0
for i in range(N):
  for j in range(N):
    if S[i] == S[j]:
      count1 += 1
  for k in range(M):
    if S[i] == T[k]:
      count2 += 1
  ans = max(ans,count1-count2)
  count1 = 0
  count2 = 0
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w;cin >> h >> w;
	vector<string> s(h+2);
	rep(i,h) cin >> s.at(i+1);
	rep(i,w+2){
		s.at(0)+=' ';
		s.at(h+1)+=' ';
	}
	for(int i=1;i<=h;++i){
		s.at(i)=' '+s.at(i)+' ';
	}
	for(int i=1;i<=h;++i){
		for(int j=1;j<=w;++j){
			if(s[i][j]=='.'){
				int cnt=0;
				for(int k=-1;k<=1;++k){
					for(int l=-1;l<=1;++l){
						if(s[i+k][j+l]=='#') cnt++;
					}
				}
				char c='0'+cnt;
				s[i][j]=c;
			}
		}
	}
	for(int i=1;i<=h;++i){
		cout << s.at(i).substr(1,w) << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#define rep(i, n) for(ll i=0; i<n; i++)
using namespace std;
typedef long long ll;

const ll INF = ll(1e18)+1;

int main(){
    int n; cin>>n;
    ll m=1000;
    int a[n];
    rep(i,n) cin>>a[i];
    int mins=a[0], up=0;
    for(int i=1; i<n; i++){
        if(up && a[i] < a[i-1]){ m += (m/mins)*(a[i-1]-mins); up=0; mins=a[i];}
        if(a[i] > a[i-1]) up = 1;
        if(a[i] < mins) mins = a[i];
        //cout << "m : " << m << endl;
    }
    if(up) m += (m/mins)*(a[n-1]-mins);
    cout << m << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,x[200001],y[200001];
int xx1=1e9,my1=1e9,xx2=1,my2=1,xx3=1e9,my3=1,xx4=1,my4=1e9;
int dis(int x1,int y1,int x2,int y2)
{
	return abs(x1-x2)+abs(y1-y2);
}
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) 
		scanf("%lld %lld",&x[i],&y[i]);
	for(int i=1;i<=n;i++)
	{
		if(dis(x[i],y[i],1,1)<dis(xx1,my1,1,1))
		{
			xx1=x[i];
			my1=y[i];
		} 
		if(dis(x[i],y[i],1e9,1e9)<dis(xx2,my2,1e9,1e9))
		{
			xx2=x[i];
			my2=y[i];	
		} 
		if(dis(x[i],y[i],1,1e9)<dis(xx3,my3,1,1e9))
		{
			xx3=x[i];
			my3=y[i];
		}
		if(dis(x[i],y[i],1e9,1)<dis(xx4,my4,1e9,1))
		{
			xx4=x[i];
			my4=y[i];
		}
	}
	int ans=dis(xx1,my1,xx2,my2);
	ans=max(ans,dis(xx1,my1,xx3,my3));
	ans=max(ans,dis(xx1,my1,xx4,my4));
	ans=max(ans,dis(xx2,my2,xx3,my3));
	ans=max(ans,dis(xx2,my2,xx4,my4));
	ans=max(ans,dis(xx3,my3,xx4,my4));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6780
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define INF INT_MAX/2

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

int main()
{
	while (1)
	{
		int n; cin >> n;
		if (n == 0) return 0;

		set<string> str;
		rep(i, 0, n) { string s; cin >> s; str.insert(s); }

		set<string> delstr;
		for (string a : str) for (string b : str)
		{
			if (a == b) continue;
			if (a.find(b) != string::npos) delstr.insert(b);
		}

		for (string a : delstr) str.erase(a);

		vector<string> s(str.begin(), str.end());
		n = s.size();

		vvi dist(n, vi(n, 0));
		rep(i, 0, n) rep(j, 0, n)
		{
			string a = s[i];
			string b = s[j];

			rrep(len, min(a.length(), b.length()), 1)
			{
				bool ok = true;
				rep(i, 0, len)
				{
					if (a[a.length() - 1 - len + 1 + i] != b[i]) ok = false;
				}
				if (ok)
				{
					dist[i][j] = len;
					break;
				}
			}
		}

		vvi dp(1 << n, vi(n+1, INF));
		dp[0][n] = 0;
		rep(mask, 0, (1 << n) - 1) rep(i, 0, n + 1)
		{
			if (dp[mask][i] == INF) continue;
			rep(j, 0, n) if ((mask & (1 << j)) == 0)
			{
				int ni = mask + (1 << j);
				if (i == n)
					dp[ni][j] = min(dp[ni][j], (int)s[j].length());
				else
					dp[ni][j] = min(dp[ni][j], dp[mask][i] + (int)s[j].length() - dist[i][j]);
			}
		}

		int ans = INF;
		rep(i, 0, n) ans = min(ans, dp[(1 << n) - 1][i]);
		cout << ans << endl;
	}
}

Measured memory_bytes: 4756
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        String t = scanner.next();
        int sn = s.length();
        int tn = t.length();
        int max = 0;
        int count = 0;
        for(int i = 0; i < sn-tn+1; i++){
            for(int j = 0; j < tn; j++){
                if(s.charAt(i+j) == t.charAt(j)){
                    count++;
                }
            }
            max = Math.max(max, count);
            count = 0;
        }
        System.out.println(tn-max);
    }
}

Measured memory_bytes: 35576
import sys

# import re
import math
import collections
# import decimal
# import bisect
# import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, m = ns()
    a = [-int(i) for i in input().split()]
    heapq.heapify(a)

    cnt = 0
    while cnt < m:
        cnt += 1

        item = heapq.heappop(a)
        item = (item + 1) // 2
        heapq.heappush(a, item)

    ans = 0
    while len(a) > 0:
        ans += - heapq.heappop(a)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 16844
# 加算と減算なので順番を入れ替えることができる
# ある数がmaxになるパターン数 * ある数 分のプラス
# ある数がminになるパターン数 * ある数 分のマイナス
# を別に考える

# 自分が小さい方からx番目(1-indexed)の時、
# maxになるパターン数は、(x-1)C(K-1)

# 自分が大きい方からy番目(1-indexed)の時、
# minになるパターンは、(y-1)C(K-1)

MOD = 10**9+7

n = 10**5
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル
for i in range(2, n+1):
    g1.append((g1[-1] * i) % MOD)
    inverse.append((-inverse[MOD % i] * (MOD//i)) % MOD)
    g2.append((g2[-1] * inverse[-1]) % MOD)

def combi(n, r):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % MOD

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

A.sort()

result = 0
for i, a in enumerate(A):
    s = combi(i, K-1)*a
    result = (result + s) % MOD

for i, a in enumerate(A[::-1]):
    s = combi(i, K-1)*a
    result = (result - s) % MOD

print(result)

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    unsigned long ans{N};
    for(unsigned long i = 1; i * i <= N; ++i){
        if(N % i == 0)ans = min(ans, i + N / i - 2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF 1e9+7
#define rep(i,n) for(ll i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
const int maxn = 100000;
ll mod = INF;

int n,k,q;
int point[maxn];

int main(){
    cin >> n>>k>>q;
    fill(point,point+n,q-k);
    rep(i,q){
        int a;
        cin >> a;
        a--;
        point[a]--;
    }
    rep(i,n){
        point[i]=-point[i];
        if(point[i]<=0)cout << "No"<<endl;
        else cout << "Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3980
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int count = 0;
		for(int i = 0; i < N; i++){
			if(sc.nextInt() >= K)count++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 47428
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    while(1)
    {
        
        int k={};
        int a,b={};//aまでの足し算で合計がbになる
        cin>>a>>b;
        if(a==0&&b==0)break;
        for(int i=1;i<=a;i++)
        {
            for(int u=i+1;u<=a;u++)
            {
                int c={};
                c=b-u-i;
                if(c>u&&c<=a)k++;
            }
        }
        cout<<k<<endl;
        
    }
}



Measured memory_bytes: 3060
import java.util.*;

public class Main {
	//0114 cording start
	int n,m,goal,d;
	StringBuilder []s;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			n = sc.nextInt();
			if(n == 0) break;
			m = sc.nextInt();
			goal = sc.nextInt();
			d = sc.nextInt();
			s = new StringBuilder[d];
			for(int i = 0 ; i< d; i++){
				s[i] = new StringBuilder(sc.next());
			}
			
			if(solve()){
				System.out.println("0");
			}
			else{
				boolean flg = false;
				for(int i = 0 ; i < d; i++){
					for(int j =0; j < n-1; j++){
						if(s[i].charAt(j) == '0'){
							if((j == 0 || s[i].charAt(j-1) == '0') && (j == n-2 || s[i].charAt(j+1) == '0')){
								s[i].setCharAt(j, '1');
								if(solve()){
									System.out.println((i +1) + " " + (j + 1));
									flg = true;
									break;
								}
								else{
									
								}
								s[i].setCharAt(j, '0');
							}
						}
					}
					if(flg){
						break;
					}
				}
				if(! flg){
					System.out.println("1");
				}
			}
		}
	}

	private boolean solve() {
		int now = m-1;
		for(int i = 0 ; i < d; i++){
			if(now- 1 >= 0 && s[i].charAt(now-1) == '1'){
				now = now - 1;
			}
			else if(now < n - 1 && s[i].charAt(now) == '1'){
				now = now + 1;
			}
			else{
				
			}
		}
		if(now == goal - 1){
			return true;
		}
		return false;
	}

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

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const ll INF = 1ll << 60;

// O(N^3)
// return value: whether the graph has negative loop
bool warshall_floyd(vector<vector<ll>> &adj) {
    int n = adj.size();
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (adj[i][k] == INF || adj[k][j] == INF) continue;
                adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
            }
        }
    }
    for (int i = 0; i < n; i++) {
        if (adj[i][i] < 0) return false;
    }
    return true;
}

// verified
//   http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_C&lang=jp
void AOJ_GRL_1_C() {
    int V, E;
    cin >> V >> E;
    vector<vector<ll>> adj(V, vector<ll>(V, INF));
    for (int i = 0; i < V; i++) adj[i][i] = 0;
    for (int i = 0; i < E; i++) {
        int s, t; ll d;
        cin >> s >> t >> d;
        adj[s][t] = d;
    }
    bool negative_loop = warshall_floyd(adj);
    if (!negative_loop) {
        cout << "NEGATIVE CYCLE" << '\n';
        return;
    }
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < V; j++) {
            if (j) cout << ' ';
            if (adj[i][j] == INF) cout << "INF";
            else cout << adj[i][j];
        }
        cout << '\n';
    }
}

int main() {
    AOJ_GRL_1_C();
    return 0;
}


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

#define min(a,b) a<b?a:b
#define ll long long

int main()
{
	int n;
	cin>>n;
	ll arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	
	ll dp[n];
	dp[0] = 0;
	dp[1] = abs(arr[1]-arr[0]);
	
	for(int i=2;i<n;i++)
	{
		dp[i] = min((dp[i-2]+abs(arr[i-2]-arr[i])),(dp[i-1]+abs(arr[i-1]-arr[i])));
	}
	
	cout<<dp[n-1];
	
	return 0;	
}


Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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

left = max(A)
center = left // 2

right = 0
diff = INF
for i in range(N):
    if A[i] == left:
        continue

    x = abs(center-A[i])
    if diff > x:
        diff = x
        right = A[i]

print(left, right)


Measured memory_bytes: 14424
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		// ?????????????????°?????\???
		int gameCount = in.nextInt();
		// ??????????????????????????°????????\???
		int[] cardNum = new int[9];
		// ????????????????????????????????\???
		String[] cardColor = new String[9];
		// ??????????????????????´????????????????
		ArrayList<Integer> resultList = new ArrayList<>();

		for(int setCount = 0; setCount < gameCount; setCount++) {

			for(int cardCount = 0; cardCount < 9; cardCount++) {

				cardNum[cardCount] = in.nextInt();

			}

			for(int cardCount = 0; cardCount < 9; cardCount++) {

				cardColor[cardCount] = in.next();

			}


			Rummy rummy = new Rummy(cardNum, cardColor);

			int[][] hadCard = rummy.hasCardSet(cardNum, cardColor);

			int point = 0;

			point += rummy.sameNumberCheck(hadCard);

			point += rummy.continuousNumberCheck(hadCard);

			if(point == 3) {

				resultList.add(1);

			} else {

				resultList.add(0);

			}
		}

		for(int result: resultList) {

			System.out.println(result);

		}

	}
}

class Rummy{

	// ?????£?????????
	int[] cardNum;
	String[] cardColor;

	// ?????????????????????
	Rummy(int[] cardNum, String[] cardColor){

		this.cardNum = cardNum;
		this.cardColor = cardColor;

	}

	// ???????????????????????????????????£??????????????´?????????????????????
	int[][] hasCardSet(int[] cardNum, String[] cardColor) {

		int[][] hasCard = new int[3][9];

		for(int i = 0; i < 9; i++) {

			for(int j = 1; j <= 9; j++) {

				if(cardNum[i] == j) {

					switch(cardColor[i]) {

					case "R":

						hasCard[0][j-1] += 1;

						break;

					case "G":

						hasCard[1][j-1] += 1;

						break;

					case "B":

						hasCard[2][j-1] += 1;

						break;

					}
				}
			}
		}

		return hasCard;

	}

	int sameNumberCheck(int[][] hasCard) {

		int point = 0;

		hasCardSet(cardNum, cardColor);

		for(int i = 0; i < 3; i++) {

			for(int j = 0; j < 9; j++) {

				if(hasCard[i][j] >= 3) {

					point++;
					hasCard[i][j] -= 3;

				}
			}
		}

		return point;

	}

	int continuousNumberCheck(int[][] hasCard) {

		int point = 0;
		int continuousCount = 0;

		hasCardSet(cardNum, cardColor);

		for(int i = 0; i < 3; i++) {

			for(int j = 0; j < 9; j++) {

				if(hasCard[i][j] != 0) {

					continuousCount++;

					if(continuousCount == 3) {

						point++;
						hasCard[i][j] -= 1;
						hasCard[i][j-1] -= 1;
						hasCard[i][j-2] -= 1;
						j = 0;
						continuousCount = 0;

					}

				} else {

					continuousCount = 0;

				}
			}
		}

		return point;

	}
}

Measured memory_bytes: 29052
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int inf2=0x3f3f3f3f;
const long long inf=0x3f3f3f3f3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
namespace fastio{
	char in[100000];
	int itr=0,llen=0;
	char get(){
		if(itr==llen)llen=fread(in,1,100000,stdin),itr=0;
		if(llen==0)return EOF;
		return in[itr++];
	}
	char out[100000];
	int itr2=0;
	void put(char c){
		out[itr2++]=c;
		if(itr2==100000){
			fwrite(out,1,100000,stdout);
			itr2=0;
		}
	}
	int clear(){
		fwrite(out,1,itr2,stdout);
		itr2=0;
		return 0;
	}
	int getint(){
    	int r=0; bool ng=0; char c; c=get();
    	while (c!='-'&&(c<'0'||c>'9')) c=get();
   		if (c=='-') ng=1, c=get();
    	while (c>='0'&&c<='9') r=r*10+c-'0', c=get();
    	return ng?-r:r;
	}
	string getstr(){
		string ret="";
		char ch=get();
		while(ch==' '||ch=='\n')ch=get();
		while(ch!=' '&&ch!='\n')ret.push_back(ch),ch=get();
		return ret;
	}
	void putstr(string s){
		for(int i=0;i<s.size();i++)put(s[i]);
	}
	void putint(int x){
		if(x<0){
			put('-');
			x=-x;
		}
		if(x==0){
			put('0');
			return;
		}
		char c[20];int pos=0;
		while(x){
			c[pos++]='0'+x%10;
			x/=10;
		}
		for(int i=pos-1;i>=0;i--)put(c[i]);
	}
	void getarr(int arrname[],int size){
		 for(int i=0;i<size;i++)arrname[i]=getint();
	}
}
using namespace fastio;
#define fastio
struct UFS{
	int par[200005];
	void init(int n){
		for(int i=0;i<=n;i++)par[i]=i;
	}
	int find(int x){
		return x==par[x]?x:par[x]=find(par[x]);
	}
	void unite(int x,int y){
		par[find(x)]=find(y);
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
}uf;
int n,d;
int a[200005];
struct Edge{
	ll val;int x,y;
};
bool operator<(Edge a,Edge b){
	return a.val<b.val;
}
vector<Edge>edge;
void solve(int l,int r){
	if(l==r)return; 
	int mid=l+r>>1;
	solve(l,mid);solve(mid+1,r);
	ll mn=inf,pl=-1;
	for(int i=l;i<=mid;i++){
		ll vl=a[i]-d*i;
		if(mn>vl){
			mn=vl;
			pl=i;
		}
	}
	mn=inf;ll pr=-1;
	for(int i=mid+1;i<=r;i++){
		ll vr=a[i]+d*i;
		if(mn>vr){
			mn=vr;
			pr=i;
		}
	}
	for(int i=l;i<=mid;i++){
		int vl=a[i]-d*i;
		int vr=a[pr]+d*pr;
		edge.push_back((Edge){vl+vr,i,pr});
	}
	for(int i=mid+1;i<=r;i++){
		int vl=a[pl]-d*pl;
		int vr=a[i]+d*i;
		edge.push_back((Edge){vl+vr,pl,i});
	}
}
signed main(){
	n=getint();d=getint();
	for(int i=0;i<n;i++)a[i]=getint();
	solve(0,n-1);
	sort(edge.begin(),edge.end());
	uf.init(n+2);
	ll ans=0;
	for(int i=0;i<edge.size();i++)
		if(!uf.same(edge[i].x,edge[i].y)){
			uf.unite(edge[i].x,edge[i].y);
			ans+=edge[i].val;
		}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 102368
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		Map<String, Integer> map = new HashMap<>();
		for(int i = 0; i < n; i++) {
			String s = sc.next();
			if(map.containsKey(s)) {
				map.put(s, map.get(s)+1);
			}else {
				map.put(s, 1);
			}
		}
		List<Entry<String, Integer>> list_entries = new ArrayList<Entry<String, Integer>>(map.entrySet());
		Collections.sort(list_entries, new Comparator<Entry<String, Integer>>() {
			public int compare(Entry<String, Integer> obj1, Entry<String, Integer> obj2)
			{
				return obj2.getValue().compareTo(obj1.getValue());
				}
        });
		ArrayList<String> list = new ArrayList<>();
		int check = 0;
		for(Entry<String, Integer> entry : list_entries) {
			if(entry.getValue() != check && check != 0 ) {
				break;
			}else {
				list.add(entry.getKey());
				check = entry.getValue();
			}
		}
		String[] a = list.toArray(new String[list.size()]);
		Arrays.sort(a);
		for(String l : a) {
			System.out.println(l);
		}
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

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

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

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

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 75136
H,W,D=map(int,input().split())
L=[0 for i in range(H*W+1)]
A=[]
for i in range(H):
    a=list(map(int,input().split()))
    A.append(a)
    
for i in range(H):
    for j in range(W):
        L[A[i][j]]=[i+1,j+1]
L[0]=[0,0]
#print(L)
l=[0 for i in range(H*W+1)]
for i in range(D):
    for j in range(H*W+1):
        if (i+j*D)>(H*W):
            break
        elif j==0:
            l[i+j*D]=0
        else:
            l[i+j*D]=l[i+(j-1)*D]+abs(L[i+j*D][0]-L[i+(j-1)*D][0])+abs(L[i+j*D][1]-L[i+(j-1)*D][1])
#print(l)
Q=int(input())
for i in range(Q):
    a,b=map(int,input().split())
    print(l[b]-l[a])


Measured memory_bytes: 21252
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(" ").map { it.toInt() }
    val add = a + b
    val min = a - b
    val mul = a * b
    if (b <= 0) println(Math.max(min, mul))
    else println(Math.max(add, mul))
}


Measured memory_bytes: 37872
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;
import java.util.function.BiPredicate;

public class Main {

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] A = new int[N];

            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }

            System.out.println(solve(0, A.length - 1, new RangeMinimumQuery(A, (integer, integer2) -> integer.compareTo(integer2) < 0)));
        }
    }

    private static long solve(int l, int r, RangeMinimumQuery rmq){
        if (l > r)
            return 0;

        if (l == r)
            return rmq.queryKey(l, r);

        int p = rmq.queryPosition(l, r);
        int key = rmq.queryKey(l, r);

        return (long)key * (p - l + 1) * (r - p + 1) + solve(l, p - 1, rmq) + solve(p + 1, r, rmq);
    }

    public static class RangeMinimumQuery {
        private final int[][] rmqPos;
        private final int[] keys, log2;
        private final int N, LG;
        private final BiPredicate<Integer, Integer> f;

        public RangeMinimumQuery(int[] A, BiPredicate<Integer, Integer> op){
            this.N = A.length;
            this.LG = LOG2(A.length);

            this.rmqPos = new int[this.LG + 1][this.N + 1];
            this.keys = Arrays.copyOf(A, A.length);
            this.log2 = new int[this.N + 1];

            this.f = op;

            build();
        }

        public int queryPosition(int x, int y){
            int k = log2[y - x + 1];
            int p = y - (1 << k) + 1;

            if (f.test(keys[rmqPos[k][x]], keys[rmqPos[k][p]]))
                return rmqPos[k][x];
            else
                return rmqPos[k][p];
        }

        public int queryKey(int x, int y){
            int k = log2[y - x + 1];
            int p = y - (1 << k) + 1;

            if (f.test(keys[rmqPos[k][x]], keys[rmqPos[k][p]]))
                return keys[rmqPos[k][x]];
            else
                return keys[rmqPos[k][p]];
        }

        private static int LOG2(int x){
            int c = 0;

            while (x >= 1){
                x >>= 1;
                c++;
            }

            return c;
        }

        private void build(){
            for (int i = 0; i < N; i++) {
                rmqPos[0][i] = i;
            }

            log2[1] = 0;

            for (int i = 2; i <= N; i++) {
                log2[i] = log2[i >> 1] + 1;
            }

            for (int i = 1; i <= LG; i++) {
                for (int j = 0; j + (1 << i) - 1 < N; j++) {
                    int p = 1 << (i - 1);

                    if (f.test(keys[rmqPos[i - 1][j]], keys[rmqPos[i - 1][j + p]]))
                        rmqPos[i][j] = rmqPos[i - 1][j];
                    else
                        rmqPos[i][j] = rmqPos[i - 1][j + p];
                }
            }
        }
    }
}


Measured memory_bytes: 120260