akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>

using namespace std;
//typedef long long ll;
typedef unsigned long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;


int main() {

    int min_x = 0;
    int max_x;
    int min_y = 0;
    int max_y;

    cin >> max_x >> max_y;

    int n;
    cin >> n;
    rep(i, n) {
        int x, y, a;
        cin >> x >> y >> a;

        if (a == 1) {
            cmax(min_x, x);
        } else if (a == 2) {
            cmin(max_x, x);
        } else if (a == 3) {
            cmax(min_y, y);
        } else if (a == 4) {
            cmin(max_y, y);
        }
    }

    int w = max_x - min_x;
    cmax(w, 0);
    int h = max_y - min_y;
    cmax(h, 0);
    cout << w * h << endl;

}


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

int main() {
    int n;  cin >> n;
    int h = n / 100;
    int tmp = h * 100 + h * 10 + h;

    if (tmp >= n) {
        cout << tmp << endl;
    } else {
        cout << (h+1) * 100 + (h+1) * 10 + (h+1) << endl;
    }
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,a,b = inpl()
h = [inp() for _ in range(n)]
ok = 10**12
ng = 0
c = a-b
def chk(x):
    cnt = 0
    for t in h:
        t -= b*x
        if t <= 0: continue
        cnt += (t+c-1)//c
    if cnt <= x:
        return True
    return False
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if chk(mid):
        ok = mid
    else:
        ng = mid
print(ok)

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

const int N = 1005;

int q, n, a[4 * N][4 * N], r;

int main(){
    scanf("%d%d", &q, &n);
    for(; q--; ){
        int x, y; char c[3];
        scanf("%d%d%s", &x, &y, c);
        if(c[0] == 'W') x += n;
        x = (x % (2 * n) + 2 * n) % (2 * n) + 1;
        y = (y % (2 * n) + 2 * n) % (2 * n) + 1;
        a[x][y]++;
        a[x][y + 2 * n]++;
        a[x + 2 * n][y]++;
        a[x + 2 * n][y + 2 * n]++;
    }
    for(int i = 1; i <= 4 * n; i++){
        for(int j = 1; j <= 4 * n; j++){
            a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
        }
    }
    for(int i = 0; i < 2 * n; i++){
        for(int j = 0; j < 2 * n; j++){
            int x = a[i + n][j + n] - a[i][j + n] - a[i + n][j] + a[i][j];
            int y = a[i + 2 * n][j + 2 * n] - a[i + n][j + 2 * n] -
                    a[i + 2 * n][j + n] + a[i + n][j + n];
            r = max(r, x + y);
        }
    }
    printf("%d\n", r);
}

Measured memory_bytes: 63104
n = gets.to_i
ans = n.to_s.size
hi = 10 ** ans
(1..((n**0.5).ceil)).each do |d|
    break if(d >= hi)
    if(n % d == 0)
        ans = (n/d).ceil.to_s.size
        hi = 10**ans
    end
end
p ans

Measured memory_bytes: 2044
<?php

fscanf(STDIN,"%d %d",$num, $sum);

if($sum / $num < 1000 || $sum / $num > 10000){
    echo "-1 -1 -1";
    exit;
}

for($one = 0; $one<= $num; $one++){
    for($five = 0; ($five+$one) <= $num; $five++){
        $ten = $num - $one - $five;
        if($ten * 10000 + $five * 5000 + $one * 1000 == $sum){
            printf("%d %d %d", $ten, $five, $one);
            exit;
        }
    }


}
echo "-1 -1 -1";

Measured memory_bytes: 4604
import random
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]

t=[random.randint(1,26) for i in range(D)]
#print(t) 
    
M=22*10000
day=[random.randint(1,365) for i in range(M)]
q=[random.randint(1,26) for i in range(M)]
    
m=[0]*D
 
a=[[0 for i in range(26)] for j in range(D)]
R=[[0 for i in range(26)] for j in range(D)]
for u in range(D):
    i=t[u]
    for y in range(u,D):
        a[y][i-1]=u+1
    if u==0:
        m[u]=s[u][i-1]
    else:
        m[u]=m[u-1]+s[u][i-1]
mm=[0]*D
for d  in range(D):
    for i in range(26):
        mm[d]+=c[i]*(d+1-a[d][i])
    if not d==0:
        mm[d]+=mm[d-1]
for d in range(D):
    m[d]-=mm[d]
mmm=m[D-1]

#for i in range(D):
 #   print(a[i])
 
 
for p in range(M):
    new_type=q[p]
    old_type=t[day[p]-1]
    #print(new_type,old_type)
    A=0
    B=0
    C=0
    C=s[day[p]-1][old_type-1]-s[day[p]-1][new_type-1]
    for d in range(D):
        A+=c[new_type-1]*(d+1-a[d][new_type-1])+c[old_type-1]*(d+1-a[d][old_type-1])
    xday=day[p]
    R=a
    if xday>1:
        before_new=a[xday-2][new_type-1]
        before_old=a[xday-2][old_type-1]
        now_new=a[day[p]-1][new_type-1]
        now_old=a[day[p]-1][old_type-1]
        for d in range(day[p]-1,D):
            if a[d][new_type-1]==now_new:
                a[d][new_type-1]=xday
            if a[d][old_type-1]==now_old:
                a[d][old_type-1]=before_old
    else:
        for d in range(day[p]-1,D):
            if a[d][old_type-1]==1:
                a[d][old_type-1]=0
            if a[d][new_type-1]==0:
                a[d][new_type-1]=1   
    t[day[p]-1]=new_type
    for d in range(D):
        B+=c[new_type-1]*(d+1-a[d][new_type-1])+c[old_type-1]*(d+1-a[d][old_type-1])
    T=mmm-(B-A+C)
    if T>mmm:
        mmm=T
        #for i in range(D):
         #   print(a[i])
        #print(mmm)
    else:
        a=R
    #print(mmm)
for i in range(len(t)):
    print(t[i])

Measured memory_bytes: 102572
n, k, q = map(int, input().split())
ans_cnt = []

for i in range(n): ans_cnt.append(0)

for i in range(q):
    answer = int(input())
    ans_cnt[answer-1] += 1

for i in range(n):
    had_point = k - (q-ans_cnt[i])
    if had_point > 0: print('Yes')
    else: print('No')
    

Measured memory_bytes: 4672
from math import ceil
N, P = map(int,input().split())
if N >= 40: print(1)
elif N == 1: print(P)  
else:
  ans = 1
  for i in range(1,ceil(P ** (1 / N))):
    if P % ((i + 1) ** N) == 0:
      ans = i + 1
  print(ans)      
                 

Measured memory_bytes: 63788
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,a,n) for(int i=a;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;

const int INF=1000000;
char fi[101][101];
int d[21][21];
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
double EPS = 1e-10;
int N,M;
int sx,sy;
int gx,gy;
int w,h;
int ans;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int MAX_V=100;
const int MAX_N=100;
char o[3]={'+','-','*'};
#define md 1000003


int dp[353][353]={0};
int bow[353][353]={0};
double add(double a,double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b)))
	return 0;
	return a+b;
}

struct P{
	double x,y;
	P(){}
		P(double x,double y):x(x),y(y){
		}
		P operator + (P p){
			return P(add(x,p.x),add(y,p.y));
		}
		P operator - (P p){
			return P(add(x,-p.x),add(y,-p.y));
		}
		P operator *(double d){
			return P(x*d,y*d);
		}
		double dot(P p){
			return add(x*p.x,y*p.y);
		}
		double det(P p){
			return add(x*p.y,-y*p.x);
		}
};

bool cmp_x(const P& p,const P& q){
	if(p.x!=q.x) return p.x<q.x;
	return p.y<q.y;
}

vector<P> convex_hull(P* ps, int n){
	sort(ps,ps+n,cmp_x);
	int k=0;
	vector<P> 	qs(n*2);
	
	rep(i,n){
		while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
			k--;
		qs[k++]=ps[i];
	}
	for(int i=n-2,t=k;i>=0;i--){
		while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
		k--;
		qs[k++]=ps[i];
	}
	qs.resize(k-1);
	return qs;
}

int n;
P ps[101];

int main(){
	
	int a,b;
	char c;
	while(cin>>a>>c>>b,c!='?'){
		ll ans=0;
		if(c=='+')
		 ans=a+b;
		else if(c=='-')
		ans=a-b;
		else if(c=='*')
		ans=a*b;
		else if(c=='/')
		ans=a/b;
		cout<<ans<<endl;
	}
	
	
	
	
	
	
	

	
}

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

using ll=long long; 

void solve(){
	string s,t;
	cin>>s>>t;
	sort(s.begin(), s.end());
	sort(t.rbegin(), t.rend());
	if(s<t){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>

using namespace std;

int main()
{
  string S;

  cin >> S;

  if (S == "AAA") {
    cout << "No";
  }
  else if (S == "BBB") {
    cout << "No";
  }
  else {
    cout << "Yes";
  }

  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

a.sort()
left = a.pop()
yoi = left/2
for i in range(n-1):
    if a[i] >= yoi:
        a[i] = (abs(a[i]-yoi), 1)
    else:
        a[i] = (abs(a[i]-yoi), -1)
a.sort()
right = abs(int(a[0][0]+a[0][1]*yoi))
print(left, right)

Measured memory_bytes: 64108
#include<stdio.h>

int A[1000000],n;

int binarySearch(int key){
	int left=0;
	int right = n;
	int mid;
	while(left < right){
		mid = (left + right) / 2;
		if(key == A[mid]) return 1;
		if(key > A[mid]) left = mid + 1;
		else if(key<A[mid]) right = mid;
	}
	return 0;
}

int main(){
	int i, q, k, sum = 0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}

	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&k);
		if (binarySearch(k)) sum++;
	}
	printf("%d\n",sum);

	return 0;
}

Measured memory_bytes: 3000
#include <stdio.h>

int main(void) {
	int a[3];
	int i, j, temp;

	scanf("%d", &a[0]);
	scanf("%d", &a[1]);
	scanf("%d", &a[2]);

	for (i = 0; i < 2; i++) {
		if (a[0] <= a[1] && a[1] <= a[2]) {
			break;
		}
		for (j = 0; j < 2; j++) {
			if (a[j] > a[j + 1]) {
				temp = a[j];
				a[j] = a[j + 1];
				a[j + 1] = temp;
			}
		}
	}
	printf("%d %d %d\n", a[0], a[1], a[2]);

	return 0;
}



Measured memory_bytes: 2140
H,W,N = map(int,input().split())
ab = [list(map(int,input().split())) for _ in [0]*N]

d = {}
for a,b in ab:
    for da in (-1,0,1):
        for db in (-1,0,1):
            if not ( 2<=a+da<=H-1 and 2<=b+db<=W-1):continue
            d[(a+da,b+db)] = d.get((a+da,b+db),0)+1

ans = [0]*10
for v in d.values():
    ans[v] += 1
ans[0] = (H-2)*(W-2) - sum(ans[1:])
print(*ans,sep="\n")

Measured memory_bytes: 190952
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	abc := make(map[byte]*Variable)
	abc['A'] = &Variable{'A', sc.ReadInt()}
	abc['B'] = &Variable{'B', sc.ReadInt()}
	abc['C'] = &Variable{'C', sc.ReadInt()}

	s := make([]string, n+1)
	for i := 0; i < n; i++ {
		s[i] = sc.ReadString()
	}
	s[n] = "AB" // sentinel

	choosed := make([]byte, n)
	cur := ""
	next := s[0]
	for i := 1; i <= n; i++ {
		cur = next
		next = s[i]

		left := abc[cur[0]]
		right := abc[cur[1]]

		if left.Value == 0 && right.Value == 0 {
			fmt.Println("No")
			return
		} else if left.Value == 1 && right.Value == 1 {
			union := UnionString(cur, next)
			if len(union) >= 2 || cur[0] == union[0] {
				choosed[i-1] = left.Name
				left.Value++
				right.Value--
			} else {
				choosed[i-1] = right.Name
				right.Value++
				left.Value--
			}
		} else if left.Value >= right.Value {
			choosed[i-1] = right.Name
			right.Value++
			left.Value--
		} else {
			choosed[i-1] = left.Name
			left.Value++
			right.Value--
		}
	}

	fmt.Println("Yes")
	for _, c := range choosed {
		fmt.Printf("%c\n", c)
	}
}

type Variable struct {
	Name  byte
	Value int
}

func UnionString(left string, right string) []byte {
	union := make([]byte, 0, 2)
	m := make(map[byte]bool)
	for i := 0; i < len(left); i++ {
		m[left[i]] = true
	}
	for i := 0; i < len(right); i++ {
		b := right[i]
		if m[b] {
			union = append(union, b)
		}
	}
	return union
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 3796
#include<stdio.h>

int main(){
  int g[101][101];
  int i,j,n,a,b,k;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++) g[i][j]=0;
  }

  for(i=1;i<=n;i++){
    scanf("%d %d ",&a,&k);
    for(j=1;j<=k;j++){
      scanf("%d",&b);
      g[a][b]=1;
    }
  }
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      printf("%d",g[i][j]);
      if(j!=n) printf(" ");
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2108
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

LL f(int N,LL C,vector<LL>& x,vector<LL>& v){
	vector<LL> dp(N+1,0);
	LL sum = 0;
	for(int i=0;i<N;++i){
		sum += v[i];
		dp[i+1] = max(dp[i],sum-2*x[i]);
	}
	LL ret = 0;
	sum = 0;
	for(int i=N-1;i>=0;--i){
		sum += v[i];
		LL res = sum-(C-x[i]) + dp[i];
		ret = max(ret,res);
	}
	return ret;
}
void solve(){
	int N;
	LL C;
	cin>>N>>C;

	vector<LL> X(N),V(N);
	vector<LL> Xr(N),Vr(N);
	for(int i=0;i<N;++i){
		cin>> X[i] >> V[i];
		Vr[N-1-i] = V[i];
		Xr[N-1-i] = C-X[i];
	}
	LL ans1 = f(N,C,X,V);
	LL ans2 = f(N,C,Xr,Vr);
	LL ans = max(ans1,ans2);
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 4224
//
//*****************
//Created by corol
//*****************
//

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define wv(a, n) for (int i=0;i<(n);i++) {cin >> (a)[i];}
#define w(t) while (t--)
#define vi vector <int>
#define vs vector <string>
#define vll vector <long long>
#define vii vector <pair <int,int>>
#define MM <<
#define all(x) sort((x).begin(), (x).end());
#define rall(x) sort((x).rbegin(), (x).rend());
#define it int64_t
int dp[1000][1000];

template<class A>
void read(vector<A> &v);

template<class A, size_t S>
void read(array<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class T>
void print(T &x) {
    cout << x;
}

struct graph {
    int first, second;
};

bool cmputd(pair<int, int> a, pair<int, int> b) {
    return a.first > b.first;
}

bool cmpdtu(pair<int, int> a, pair<int, int> b) {
    return a.first < b.first;
}

bool cmpdtu_struct(graph a, graph b) {
    return a.first < b.first;
}

void test_cases();

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

    test_cases();
    //cout << "Time elapsed: " << 1.000 * clock() / CLOCKS_PER_SEC << " ms. \n";
    return 0;
}

int d_min(vector<int> &a, int p) {
    int l = -1;
    int r = (int) a.size();
    while (r > l + 1) {
        int m = (l + r) / 2;
        if (a[m] <= p) l = m;
        else r = m;
    }
    return l;
}

int d_max(vector<int> &a, int p) {
    int l = -1;
    int r = (int) a.size();
    while (r > l + 1) {
        int m = (l + r) / 2;
        if (a[m] < p) l = m;
        else r = m;
    }
    return r;
}

void test_cases()
{
    int n;
    cin >> n;
    cout << (n%2==0 ? "1": "0");
}

Measured memory_bytes: 3628
import sys
import collections
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    a_list = list(input().split())
    int_freq = dict(collections.Counter(a_list))
    sorted_freqs = sorted(int_freq.values(), reverse=True)
    print(sum(sorted_freqs[K:]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 43628
#include <iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[100];
    for(int i = 0;i<n;i++){
       cin>>a[n-1-i];
    }
    for(int j = 0;j<n;j++){
        
        if(j == n-1){
            cout<<a[j]<<endl;
        }else{
           cout<<a[j]<<" "; 
        }
    }
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

const int MAX_INT = 1000100;
// const int MAX_INT = 100;

int main() {
	int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    bool zero = false;
    rep(i, n) {
        if (!zero && a[i]==1) {
            zero = true;
        } else if (zero && a[i]==1) {
            cout << 0 << endl;
            return 0;
        }
    }
    if (zero) {
        cout << 1 << endl;
        return 0;
    }
    vector<int> isp(MAX_INT+1, 0);
    sort(all(a));
    isp[0] = isp[1] = 0;
    for(const auto& num: a) {
        for(int i=1; num*i<=MAX_INT; i++) {
            isp[num*i]++;
        }
        // debug(isp);
    }
    int ans = 0;
    for(const auto& num: a) {
        if (isp[num]==1) ans++;
    }
    cout << ans << endl;
}


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

ll n;
ll ans;
ll a[1<<18],b[1<<18];

int pre(int i) {
    return (i + n - 1) % n;
}

int nxt(int i) {
    return (i + 1) % n;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) cin >> a[i];
    priority_queue<pair<ll,ll>> pq;
    for (int i = 0; i < n; i++) {
        pq.push({a[i],i});
    }
    while (!pq.empty()) {
        ll num = pq.top().first;
        ll id = pq.top().second;
        pq.pop();
        ll k = (num - b[id]) / (a[pre(id)] + a[nxt(id)]);
        ans += k;
        a[id] -= k * (a[pre(id)] + a[nxt(id)]);
        if (a[id] == b[id]) continue;
        if (k == 0 && a[id] != b[id]) {
            cout << -1 << endl;
            return 0;
        }
        pq.push({a[id], id});
    }

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


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

int sumOfDigits(int n) {
	int sum = 0;
	while (n) {
		sum += (n % 10);
		n /= 10;
	}
	return sum;
}

int main() {
	int N, A, B, res = 0;
	cin >> N >> A >> B;
	for (int i = 1; i <= N; ++i) {
		int sum = sumOfDigits(i);
		if (sum >= A && sum <= B) {
			res += i;
		}
	}
	cout << res;
	return 0;
}

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

int main(int argc, char **argv)
{
	ll N, K; cin >> N >> K;
	vector<ll> x(N); for (ll i = 0; i < N; ++i) cin >> x[i];

	ll res{1<<29};
	for (ll i = 0; i < N-K+1; ++i)
	{
		ll left = x[i], right = x[i+K-1];
		res = min(res, right-left+min(abs(left), abs(right)));
	}
	
	std::cout << res << std::endl;
}


Measured memory_bytes: 1024
import java.io.*;
import java.util.*;
import java.util.Arrays;
import java.util.Collections;
// import java.io.BufferedReader;
// import java.io.IOException;
// import java.io.InputStreamReader;
// import java.util.ArrayList;
// import java.util.Arrays;
// import java.util.Collections;
// import java.util.List;
// import java.util.HashSet;
// import java.util.Set;
// import java.util.Map;
// import java.util.HashMap;

import java.math.*;

public class Main {
    private static Scanner sc;
    private static final long mod = 1000000007;

    public static void main(final String[] args) {
        final Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private static String getUpperAlpha(int i) {
        return String.valueOf((char) (i + 64));
    }

    /* i=1 return a */
    private static String getLowerAlpha(int i) {
        return String.valueOf((char) (i + 96));
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null)
                br.close();
        }

        public String next() throws IOException {
            if (i < s.length)
                return s[i++];
            String st = br.readLine();
            while (st == "")
                st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }

        public long[] nextLongArray(int n) throws NumberFormatException, IOException {
            long[] ret = new long[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextLong();
            }
            return ret;
        }

        public int[] nextIntArray(int n) throws NumberFormatException, IOException {
            int[] ret = new int[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextInt();
            }
            return ret;
        }
    }

    private void solve() {
        try {
            int n = sc.nextInt();
            int[] a = sc.nextIntArray(n);
            int count = 0;
            for (int i = 0; i < a.length; i++) {
                if (i % 2 == 0 && a[i] % 2 != 0)
                    count++;
            }
            System.out.println(count);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}


Measured memory_bytes: 32532
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
using namespace std;

int dp[1000 + 1][100000 + 1];

void solve() {
  int N, W;
  cin >> N >> W;

  for (int i = 0; i < N; i++) {
    int w, v;
    cin >> w >> v;
    for (int x = 0; x <= W; x++) {
      dp[i + 1][x] = max(dp[i + 1][x], dp[i][x]);
      if (x + w <= W) {
        dp[i + 1][x + w] = max(dp[i + 1][x + w], dp[i][x] + v);
      }
    }
  }
  cout << dp[N][W] << endl;
}

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


Measured memory_bytes: 79360
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const int INF = 0x3fffffff;


int main(){
	int N, ans=INF;
	int a[105];

	cin >> N;
	rep(i,N) cin >> a[i];

	for(int k=-100; k<=100; k++){
		int sum = 0;
		rep(i,N){
			int t = k - a[i];
			sum += t*t;
		}
		chmin(ans, sum);
	}

	cout << ans << endl;

	return 0;
}


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

int keisan(int k){
    int sum = 1;
  int buf = 1;
    for (int i = 1; i <= k; ++i)
    {
      buf *= 3;
      sum += buf;
    }
    return sum;
}
    
int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  deque<tuple<int, int, int>> dq;
  dq.push_back(make_tuple(a, b, c));
  
  int m=keisan(k-1);
  //cout << m << endl;
  while(m!=0){
    int x, y, z;
    tie(x, y, z) = dq.front();
    dq.pop_front();
    dq.push_back(make_tuple(x*2, y, z));
    dq.push_back(make_tuple(x, y*2, z));
    dq.push_back(make_tuple(x, y, z*2));
    m--;
  }
    
  int ans = 0;
  while(!dq.empty()){
    int x, y, z;
    //x = get<1>(dq.front());
    //y = get<2>(dq.front());
    //z = get<3>(dq.front());
    
    tie(x, y, z) = dq.front();
    //cout << x << " " << y << " " << z << endl;
    dq.pop_front();
    if(x < y && y < z){
      ans = 1;
    }
  }
  
  
  if(ans == 0){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}



Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define in (void)scanf
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
//#define Rep(i,a,n)for(LL i=(LL)(a);i<(LL)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Repp(i,l,r,k)for(int i=(int)(l);i<(int)(r);i+=(int)(k))
//#define Repp(i,l,r,k)for(LL i=(LL)(l);i<(LL)(r);i+=(LL)(k))
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007//998244353,1000000007,1000000009,4999999999999997
int upi(const void* a, const void* b) { return*(int*)a<*(int*)b ? -1 : *(int*)a> * (int*)b ? 1 : 0; }
int downi(const void* a, const void* b) { return*(int*)a<*(int*)b ? 1 : *(int*)a> * (int*)b ? -1 : 0; }
void sortupi(int* a, int n) { qsort(a, n, sizeof(int), upi); } //1,2,3,4,...
void sortdowni(int* a, int n) { qsort(a, n, sizeof(int), downi); }
int upLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? -1 : *(LL*)a> * (LL*)b ? 1 : 0; }
int downLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? 1 : *(LL*)a> * (LL*)b ? -1 : 0; }
void sortupLL(LL* a, int n) { qsort(a, n, sizeof(LL), upLL); }
void sortdownLL(LL* a, int n) { qsort(a, n, sizeof(LL), downLL); }
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } // a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } // aaa,aab
LL gcd(LL p, LL q) { while (q) { LL t = p % q; p = q; q = t; }return p; }
LL modpow(LL a,LL n,LL m){LL x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invmodpow(b,p)modpow(b,p-2,p)// a/b≡a*b^{-1}(mod p)...return b^{-1}(mod p)
//typedef struct fac { LL n, exp; }F;
//LL fact(LL n,F*a){LL x=n,i,j,c=0;for(i=2;i*i<=x;i++){for(j=1;x%i==0;j++)x/=i;if(j>1){a[c].n=i;a[c++].exp=j-1;}}if(x-1){a[c].n=x;a[c++].exp=1;}return c;}
LL nibtan(LL* a,LL n,LL x){LL p=0,q=n/2,r=n-1;while(r-p>1){if(x>=a[q])p=q;if(x<=a[q])r=q;q=(p+r)/2;}return a[p]==x?p:r;}
//snippet

#define N 200009
typedef struct xy { LL x, y; }F;

void run(void) {
	int n;
	F f[N];
	LL M0 = -1e18, m0 = 1e18, M1 = -1e18, m1 = 1e18;
	in("%d\n", &n);
	rep(i, n)in("%lld%lld", &f[i].x, &f[i].y);
	rep(i, n) {
		M0 = Ma(M0, f[i].x - f[i].y);
		m0 = mi(m0, f[i].x - f[i].y);
		M1 = Ma(M1, f[i].x + f[i].y);
		m1 = mi(m1, f[i].x + f[i].y);
	}
	printf("%lld\n", Ma(M0 - m0, M1 - m1));
}

int main(void) {
	int test = 1;
//	in("%d", &test);
	while (test--) {
		run();
		fflush(stdout);
	}
	return 0;
}

Measured memory_bytes: 4852
H, W, K = map(int, input().split())
c = [list(input()) for _ in range(H)]

ans = 0
for case_h in range(1 << H):
    tmp = case_h
    flag_y = []
    for _ in range(H):
        flag_y.append(tmp % 2)
        tmp >>= 1
    #
    for case_w in range(1 << W):
        tmp = case_w
        flag_x = []
        for _ in range(W):
            flag_x.append(tmp % 2)
            tmp >>= 1
        #
        cnt = 0
        for y in range(H):
            for x in range(W):
                if flag_y[y] == 0 and flag_x[x] == 0 and c[y][x] == '#':
                    cnt += 1
        #
        if cnt == K:
            ans += 1

print(ans)

Measured memory_bytes: 9220
{-# LANGUAGE BangPatterns #-}

import Data.Array (Array, listArray, accumArray, (!))
import Data.List (sortOn, sortBy)
import qualified Data.ByteString.Char8 as B
import Control.Monad (forM_)
import qualified Data.Vector.Unboxed as V
import Data.Char (isSpace)

lowerBound x xs = go xs (-1) (V.length xs) where
  go !xs !l !r
    | l==r-1 = r
    | x==(xs V.! m) = m
    | x<=(xs V.! m) = go xs l m
    | otherwise = go xs m r
    where !m = (l+r) `div` 2
{-# INLINE lowerBound #-}

inf = 10^11

a # b = abs (a-b)
{-# INLINE (#) #-}

near q xs
  | q < V.head xs = (-inf, V.head xs)
  | q > V.last xs = (V.last xs, inf)
  | otherwise = (V.unsafeIndex xs (i-1), V.unsafeIndex xs i)
  where i = lowerBound q xs

solv ss ts qs = map calc (V.toList qs) where
  calc q =
    let !(sl, sr) = near q ss
        !(tl, tr) = near q ts
    in minimum [ min (q#sr + sr#tr) (q#tr + tr#sr)
               , min (q#sr + sr#tl) (q#tl + tl#sr)
               , min (q#sl + sl#tr) (q#tr + tr#sl)
               , min (q#sl + sl#tl) (q#tl + tl#sl)
               ]

main = do
  [a,b,q] <- map read . words <$> getLine :: IO [Int]
  ys <- V.unfoldrN (a+b+q) (B.readInt.B.dropWhile isSpace) <$> B.getContents :: IO (V.Vector Int)
  let ss = V.slice 0 a ys
      ts = V.slice a b ys
      qs = V.slice (a+b) q ys
  putStr . unlines . map show $ solv ss ts qs


Measured memory_bytes: 9724
N=int(input())
A=[]
B=[]
for i in range(N):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
A.sort()
B.sort()
ans=0
if(N%2==1):
  print(B[N//2]-A[N//2]+1)
else:
  ans+=(B[N//2]+B[N//2-1])-(A[N//2]+A[N//2-1])+1
  print(ans)

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

signed main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (auto& s : S) cin >> s;

    vector<vector<int>> r(H, vector<int> (W));
    vector<vector<int>> c(H, vector<int> (W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            r[i][j] = c[i][j] = S[i][j] == '.';
            if (r[i][j] && j - 1 >= 0) r[i][j] += r[i][j - 1];
            if (c[i][j] && i - 1 >= 0) c[i][j] += c[i - 1][j];
        }
    }

    for (int i = 0; i < H; i++) {
        int t = 0;
        for (int j = W - 1; j >= 0; j--) {
            if (!t || !r[i][j]) t = r[i][j];
            r[i][j] = t;
        }
    }
    for (int j = 0; j < W; j++) {
        int t = 0;
        for (int i = H - 1; i >= 0; i--) {
            if (!t || !c[i][j]) t = c[i][j];
            c[i][j] = t;
        }
    }

    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            ans = max(ans, r[i][j] + c[i][j] - 1);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 67072
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

#define x first
#define y second

signed main(){
	cout<<fixed<<setprecision(10);
	
	long double ans = 0;
	int N;
	vector<pair<int,int>> in;
	vector<int> P;
	
	cin>>N;
	
	in.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>in[i].first>>in[i].second;
		P.push_back(i);
	}
	
	do{
		long double sum = 0;
		for(int i = 1; i < N; i++){
			sum += sqrt((in[P[i]].x - in[P[i-1]].x)*(in[P[i]].x - in[P[i-1]].x) + (in[P[i]].y - in[P[i-1]].y)*(in[P[i]].y - in[P[i-1]].y));
		}
		ans += sum;
		
	} while(next_permutation(P.begin(), P.end()));
	
	for(int i = 0; i < N; i++){
		ans /= i+1;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
f = false
a.select{|aa| aa % 2 == 0}.each do |aa|
    if aa % 3 != 0 && aa % 5 != 0
        f = true
    end
end
if f
    puts "DENIED"
else
    puts "APPROVED"
end

Measured memory_bytes: 1788
def main():
    A, B = map(int, input().split())

    cnt = 0
    for i in range(A,B+1):
        str_i = str(i)
        if str_i[0] == str_i[4] and str_i[1] == str_i[3]:
            cnt += 1

    print(cnt)
    
main()

Measured memory_bytes: 39024
#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;
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; }
ll MOD = 1000000007;

int main(void){
  string s; cin >> s;
  if(s == "SSS") cout << 0 << endl;
  else if(s == "RSS") cout << 1 << endl;
  else if(s == "SRS") cout << 1 << endl;
  else if(s == "SSR") cout << 1 << endl;
  else if(s == "RRS") cout << 2 << endl;
  else if(s == "SRR") cout << 2 << endl;
  else if(s== "RSR") cout << 1 << endl;
  else cout << 3 << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
using namespace std;
long long f(long long x){
    long long res = 0;
    if(x % 2 == 0){
        if(x / 2 % 2 == 1) res++;
        res ^= x;
    }
    else{
        if((x + 1) / 2 % 2 == 1) res++;
    }
    return res;
}
int main(){
    long long A, B;
    cin >> A >> B;
    if(A == 0){
        cout << f(B) << endl;
        return 0;
    }
    long long ans = f(B)^f(A - 1);
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    int N, K;
    cin >> N >> K;

    long double ans = 0;
    for(int s = 1; s <= N; s++){
        int k = 0;
        while(s * (1<<k) < K){
            k++;
        }
        //cout << k << endl;
        ans += pow((long double)0.5, k);
    }

    ans /= (long double)N;

    printf("%.30Lf\n", ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

public class Main {

	private static final int NUM = 3;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			Set<Integer> set = new HashSet<>();
			IntStream.range(0, NUM).forEach(i -> set.add(scanner.nextInt()));
			System.out.println(set.size());
		}
	}
}


Measured memory_bytes: 26068
#include <iostream>
#include<algorithm>

using namespace std;

int main()
{
	long long  a, b, x,i,res=0;
	cin >> a >> b >> x;
	if(a != 0)
		res = (b / x + 1) - ((a - 1) / x + 1);
	else
		res = (b / x + 1);

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
if n==0 and a[0]!=1:
  print(-1)
  exit()
b=[a[0]==0]
for i in a[1:]:
  b+=[2*b[-1]-i]
  if b[-1]<0:
    print(-1)
    exit()
b.pop()
ans=root=a[-1]
a=a[::-1]
b=b[::-1]
for i,j in zip(a[1:],b):
  root=min(root,j)+i
  ans+=root
print(ans)

Measured memory_bytes: 709540
fun main() {
    agc023a()
}

fun agc023a() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toLong() }
    val table = Array<Long>(n + 1) { 0L }
    for (i in 0 until n) {
        table[i + 1] = table[i] + a[i]
    }
    val counts = table.groupingBy { it }.eachCount()
    var count = 0L
    for (v in counts.values) {
        if (v > 1) {
            count += (v - 1) * v.toLong() / 2L
        }
    }
    println(count)
}

Measured memory_bytes: 89308
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {
			String f = sc.next();
			if (f.equals("#")) {
				break;
			}

			char[][][] dice = new char[6][3][];
			dice[0][0] = f.toCharArray();
			dice[0][1] = sc.next().toCharArray();
			dice[0][2] = sc.next().toCharArray();

			int[] z = { 0, 1, 3, 4, 2, 5 };

			for (int i = 0; i < 6; i++) {
				// z[zinv[i]]= i;
			}
			for (int i = 1; i < 6; i++) {
				for (int j = 0; j < 3; j++) {
					if (i == 5) {
						dice[z[i]][2 - j] = sc.next().toCharArray();
					} else if (i == 2 || i == 3) {
						char temp;
						dice[z[i]][j] = sc.next().toCharArray();
						temp = dice[z[i]][j][0];
						dice[z[i]][j][0] = dice[z[i]][j][2];
						dice[z[i]][j][2] = temp;
					} else {
						dice[z[i]][j] = sc.next().toCharArray();
					}
				}
			}

			boolean ok[][] = new boolean[3][4];

			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					if (dice[i][0][j] == '*') {
						ok[i][0] = true;
					}
				}
				if (ok[i][0]) {
					ok[i][0] = false;
					for (int j = 0; j < 3; j++) {
						if (dice[i + 3][0][j] == '*') {
							ok[i][0] = true;
						}
					}
				} else {
					ok[i][0] = false;
				}
				//
				for (int j = 0; j < 3; j++) {
					if (dice[i][2][j] == '*') {
						ok[i][3] = true;
					}
				}
				if (ok[i][3]) {
					ok[i][3] = false;
					for (int j = 0; j < 3; j++) {
						if (dice[i + 3][2][j] == '*') {
							// System.out.println((i+3)+" "+j);
							ok[i][3] = true;
						}
					}
				} else {
					ok[i][3] = false;
				}
				//
				for (int j = 0; j < 3; j++) {
					if (dice[i][j][0] == '*') {
						ok[i][1] = true;
					}
				}
				if (ok[i][1]) {
					ok[i][1] = false;
					for (int j = 0; j < 3; j++) {
						if (dice[i + 3][j][0] == '*') {
							ok[i][1] = true;
						}
					}
				} else {
					ok[i][1] = false;
				}

				//
				for (int j = 0; j < 3; j++) {
					if (dice[i][j][2] == '*') {
						ok[i][2] = true;
					}
				}
				if (ok[i][2]) {
					ok[i][2] = false;
					for (int j = 0; j < 3; j++) {
						if (dice[i + 3][j][2] == '*') {
							ok[i][2] = true;
						}
					}
				} else {
					ok[i][2] = false;
				}
			}

			int ans[][] = { { 2, 1, 1, 0 }, { 3, 2, 2, 3 }, { 1, 2, 2, 1 } };
			int min = Integer.MAX_VALUE;
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 4; j++) {
					if (ok[i][j]) {
						// System.out.println(i+" "+j);
						min = Math.min(ans[i][j], min);
					}
				}
			}
			System.out.println(min);
		}

	}

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

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;
 
// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
// 
 
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 
 
#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return 
 
 
#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)
 
#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>
 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
 
#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5
#define N (1ll<<10)

void solve(){
    ll s, w;
    cin>>s>>w;
    if(w >= s){
        print("unsafe");
        ret;
    }
    else print("safe");
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
 
    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }

}


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

const int MaxN = 300;
int n, m;
char s[MaxN + 5];
int cnt[MaxN + 5];

int main()
{
	while (~scanf("%d%d", &n, &m)) {
		memset(cnt, 0, sizeof(cnt));
		for (int i = 1; i <= n; i++) {
			scanf("%s", s);
			for (int j = 0; j < m; j++) cnt[s[j]]++;
		}
		int cnt_4 = 0, cnt_2 = 0, cnt_1 = 0;
		for (int ch = 'a'; ch <= 'z'; ch++)
			if (cnt[ch] % 4 == 0) cnt_4++;
				else if (cnt[ch] % 4 == 2) cnt_2++;
					else if (cnt[ch] % 2 == 1) cnt_1++;
		if ((n & 1) && (m & 1)) {
			if ((cnt_2 <= n / 2 + m / 2) && (cnt_1 == 1)) printf("Yes\n");
			else printf("No\n");
		}
		else if ((n & 1) && (!(m & 1))) {
			if ((cnt_2 <= m / 2) && (cnt_1 == 0)) printf("Yes\n");
			else printf("No\n");
		}
		else if ((!(n & 1)) && (m & 1)) {
			if ((cnt_2 <= n / 2) && (cnt_1 == 0)) printf("Yes\n");
			else printf("No\n");
		}
		else {
			if (cnt_2 == 0 && cnt_1 == 0) printf("Yes\n");
			else printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
using namespace std;
char a[100005],b[100005];
map<long long,char>vis;
long long gcd(long long x,long long y){
	while(y){
		x%=y;
		swap(x,y);
	}
	return x;
}
int main(){
    long long n,m;
    long long orz;
    cin>>n>>m;
    scanf("%s%s",a+1,b+1);
    orz=n*m/gcd(n,m);
    for(long long i=1;i<=n;i++){
    	vis[(i-1)*orz/n+1]=a[i];
    	//cout<<(i-1)*(orz/n)+1<<" ";
	}
	//cout<<endl;
	//cout<<orz/m<<endl;
	for(long long i=1;i<=m;i++){
		//cout<<(i-1)*(orz/m)+1<<" ";
		if(vis[(i-1)*orz/m+1]){
			if(vis[(i-1)*orz/m+1]!=b[i]){
				printf("-1");
				return 0;
			}
		}
	}
	cout<<orz<<endl;
    return 0;
}


Measured memory_bytes: 10880
# ####################################################################
# import io
# import sys

# _INPUT = """\
# 100 12 9
# """
# sys.stdin = io.StringIO(_INPUT)
####################################################################
####################################################################
import sys
def _p(*_a):
  #return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################
def _pa(_aa):
  #return
  for _a in _aa: _p(_a)
####################################################################
X,K,D = map(int, input().split())

X = abs(X)

# K回移動しても、0に届かない場合
if K * D < X:
  ans = X - (K*D)
  print(ans)
  exit()


# 0に届く場合
a = X // D
k = K - a
x = X - (a * D)
# _p(a,k,x)
if k % 2 == 0:
  ans = x
else:
  ans = x - D

print(abs(ans))









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

using namespace std;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vector<int> v(n);
	vector<int>vv(n);
	for (int i = 0; i<n; i++) {
		cin >> v[i];
	}
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		vv[i] = v[i];
	}
	sort(vv.begin(), vv.end());

	
	for (int i = 0; i < n; i++) {
		if (v[i] != vv[i]) {
			cnt++;
		}
	}

	string s = (cnt==2 || cnt==0) ? "YES" : "NO";

		cout << s << endl;
	return 0;

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int>g[100005];
int vis[100005];
typedef pair<int,int>p;
const int mod=1e9+7;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int n,k;
	cin>>n>>k;
	int u,v;
	memset(vis,0,sizeof(vis));
	for(int i=0;i<n-1;i++){
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	queue<p>q;
	long long ans=k;
	q.push({1,0});
	while(!q.empty()){
		int fa=q.front().first,dep=q.front().second+1;
		q.pop();
		vis[fa]=1;
		int cnt=0;
		for(int i=0;i<g[fa].size();i++){
			int v=g[fa][i];
			if(vis[v])
				continue;
			if(dep==1)
				ans=ans*(k-(cnt++)-1)%mod;
			else ans=ans*(k-(cnt++)-2)%mod;
			q.push({v,dep});
		}
	}
	cout<<ans<<"\n";
	return 0;
} 

Measured memory_bytes: 7288
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;

int main()
{
    ll n;
    cin >> n;
    if(n%2==0){
        cout << (n / 2) * (n-1) << endl;
    }else{
        cout << ((n-1) / 2) * n << endl; 
    }
}

Measured memory_bytes: 256
from itertools import groupby
n = int(input())
A = list(map(int, input().split()))

A = groupby(A)
G = []
for i, _ in A:
    G.append(i)

p = 1000
for i in range(len(G)-1):
    if G[i] < G[i+1]:
        tmp1 = p // G[i]
        tmp2 = p % G[i]
        p = tmp1 * G[i+1] + tmp2

print(p)

Measured memory_bytes: 9124
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
int nxt[65][200010] = {};

void solve(){
    ll N,K;
    cin >> N >> K;
    ll A[200010];
    rep(i,0,N){
        cin >> A[i];
        A[i]--;
        nxt[0][i] = A[i];
    }

    rep(k,0,62){
        rep(i,0,N){
            nxt[k+1][i] = nxt[k][nxt[k][i]];
        }
    }
    ll ans = 0;
    rrep(i,62,0){
        if((K>>i) & 1){
            ans = nxt[i][ans];
        }
    }
    print(ans+1);
}

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


Measured memory_bytes: 54428