akhauriyash/Code-Regression huggingface dataset:
import java.util.*;import java.awt.geom.*;class Main{public static void main(String[]g){Scanner S=new Scanner(System.in);double x,d[]=new double[6];for(int i,r,n=S.nextInt();n-->0;System.out.println(r)){for(r=i=0;i<6;)d[i++]=S.nextDouble();x=Math.hypot(d[0]-d[3],d[1]-d[4]);if(x<=d[2]+d[5])r=1;if(x+d[2]<d[5])r=-2;if(x+d[5]<d[2])r=2;}}}


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

struct node {
	int key;
	struct node *car;
	struct node * cdr;
};

void
record(struct node *r, struct node *p)
{
	if (p->key == r->key)
		return;
	else if (p->key < r->key) {
		if (r->car == NULL)
			r->car = p;
		else
			record(r->car, p);
	} else {
		if (r->cdr == NULL)
			r->cdr = p;
		else
			record(r->cdr, p);
	}
}

void
preorder(struct node *a)
{
	if (a == NULL)
		return;

	printf(" %d", a->key);
	preorder(a->car);
	preorder(a->cdr);
}

void
inorder(struct node *a)
{
	if (a == NULL)
		return;

	inorder(a->car);
	printf(" %d", a->key);
	inorder(a->cdr);
}

int
main(void)
{
	int i, n, p;
	struct node *a;

	scanf("%d", &n);

	a = (struct node *)malloc(sizeof(struct node) * n);
	if (a == NULL)
		return 1;

	for (i = p = 0; i < n; i++) {
		char cmd[16];
		int key;

		scanf("%s", cmd);
		if (cmd[0] == 'i') {
			scanf("%d", &key);
			a[p].key = key;
			a[p].car = NULL;
			a[p].cdr = NULL;
			record(a, a + p++);
		} else if (cmd[0] == 'p') {
			inorder(a);
			printf("\n");
			preorder(a);
			printf("\n");
		}
	}

	return 0;
}



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

int main() {
  
  int l,n;
  cin >> n >> l;
  vector<string> s(n);
  string m;
  
  for (int i = 0;i < n;i++){
    cin >> s.at(i);
  }
  
  sort(s.begin(),s.end());
  
  for (int i = 0 ;i <n;i++){
m = m + s.at(i);
  }
  cout << m << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
   int w,h,x,y,r;
   scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
   if(w-r>=x&&r<=x&&h-r>=y&&r<=y){
   	printf("Yes\n");
   }else{
   	printf("No\n");
    }
}


Measured memory_bytes: 2092
import bisect
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()

ans = 0
i = 0
j = 0
for b in B:
    while i < N and A[i] < b:
        i += 1
    while j < N and C[j] <= b:
        j += 1
    ans += i * (N-j)

print(ans)

Measured memory_bytes: 23328
#!/usr/bin/env python3
import sys

def WarshallFloyd(V: int, cost: "List[List[int]]"):
    """
    全ての頂点対の間の最短距離を求めます。
    ==============
    V: 頂点数
    cost: 隣接行列(辺が存在しない部分はINF)
    --------------
    cost: 最短距離の行列
    """
    INF = 1e18
    for k in range(V):
        for i in range(V):
            for j in range(V):
                if cost[i][k] != INF and cost[k][j] != INF:
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
    return cost

def solve(H: int, W: int, c: "List[List[int]]", A: "List[List[int]]"):
    cost = WarshallFloyd(len(c), c)
    C = [0] * 10
    for a in A:
        for aa in a:
            if aa != -1:
                C[aa] += 1
    c = 0
    for i in range(10):
        c += cost[i][1] * C[i]
    print(c)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    c = [[int(next(tokens)) for _ in range(9 - 0 + 1)] for _ in range(9 - 0 + 1)]  # type: "List[List[int]]"
    A = [[int(next(tokens)) for _ in range(W)] for _ in range(H)]  # type: "List[List[int]]"
    solve(H, W, c, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
/*==============================================*\
Codeforces ID:    mdshihab
                                                  |
Name:     Md. Shihabul Minhaz                     |
Study:      CSE, JKKNIU                           |
Address:  Trishal, Mymensingh, Bangladesh         |
                                                  |
 mail:   mdshihabul20171@gmail.com                |
 FB  :   fb.com/mdshihabul.minhaz.7               |
 github: Shihabulminhaz                           |
stopstalk :  mdshihab                             |
                                                  |
@uthor   Md. Shihabul Minhaz (shihab)             |
\*===============================================*/


#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int shihab;
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
    //  FI(); /// skip this line for compile
    ll n,m,a,b,cost=0;
    map<ll, ll>mp;
    map<ll, ll>::iterator it;
    cin >> n >> m;
    for(int i=0; i<n; i++)
    {
        cin >> a >> b;
        mp[a]+=b;
    }
    for(it=mp.begin(); it!=mp.end(); it++)
    {
        if(m>=it->second)
        {
            cost+= it->second * it->first;
            m-= it->second;
        }
        else
        {
            cost+= m * it->first;
            m-= m;
        }
        if(m<=0)
            break;
    }
    cout << cost << endl;
    return 0;
    //code end
}
//okbye


Measured memory_bytes: 9916
import java.util.Scanner;
import java.util.Arrays;


class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();

    int i = 0;
    for(i = 1;H > 1;i++){

      H = H/2;
    }


  /*  double N = 0;
    for(int n = 1;n <= i;n++){
      N += Math.pow(2, i-1)-1;
    }*/

  
  //  System.out.println(N);
    System.out.println((long)(Math.pow(2, i-1)+Math.pow(2, i-1)-1));
  }

}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
const int Maxn=3005;
int n,mod,s[Maxn][Maxn],C[Maxn][Maxn];
int ksm(int x,int k,int m=mod){
    int ret=1,tmp=x;
    while(k){
        if(k&1)ret=1ll*ret*tmp%m;
        tmp=1ll*tmp*tmp%m;k>>=1;
    }
    return ret;
}
int main(){
    cin>>n>>mod;
    s[0][0]=1;
    for(int i=1;i<=n+1;i++)
        for(int j=1;j<=i;j++)
            s[i][j]=(s[i-1][j-1]+1ll*s[i-1][j]*j)%mod;
    for(int i=0;i<=n;C[i++][0]=1)
        for(int j=1;j<=i;j++)
            C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
    int ans=0;
    for(int i=0;i<=n;i++){
        int sum=0,w=ksm(2,ksm(2,n-i,mod-1)),base=ksm(2,n-i);
        for(int j=0,coef=1;j<=i;j++,coef=1ll*coef*base%mod)
            sum=(sum+1ll*s[i+1][j+1]*w%mod*coef)%mod;
        ans=(ans+(i&1?-1ll:1)*C[n][i]*sum)%mod;
    }
    cout<<(ans+mod)%mod<<"\n";
    return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    ll x, y;
    cin >> x >> y;
    ll a = x; int ans = 0;
    while (a <= y) {
        ++ans;
        a *= 2;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    string S;
    cin>>S;
    vector<int> W(n+1),R(n+1);
    int red=0;
    for(int i=0; i<n; ++i){
        if(S[i]=='W'){
            W[i+1]=W[i]+1;
            R[i+1]=R[i];
        }
        else{
            W[i+1]=W[i];
            R[i+1]=R[i]+1;
            ++red;
        }
    }

    int mn=INT_MAX;
    for(int i=0; i<=n; ++i){
        mn = min(mn, W[i]+red-R[i]- min(W[i],red-R[i]));
    }
    cout<<mn<<"\n";
}

Measured memory_bytes: 5116
package main

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

var scanner = bufio.NewScanner(os.Stdin)

const (
	initialBufSize = bufio.MaxScanTokenSize //65536
	maxBufSize     = 10000000000
)

const inf = 1000000000

func main() {
	scanner.Split(bufio.ScanWords)
	buf := make([]byte, initialBufSize)
	scanner.Buffer(buf, maxBufSize)

	l, r := nextInt(), nextInt()

	min := inf
LABEL:
	for i := l; i < r; i++ {
		for j := l + 1; j <= r; j++ {
			mod := i * j % 2019
			if mod < min {
				min = mod
			}
			if min == 0 {
				break LABEL
			}
		}
	}
	fmt.Println(min)
}

func next() string {
	scanner.Scan()
	return scanner.Text()
}
func nextInt() int {
	i, err := strconv.Atoi(next())
	if err != nil {
		fmt.Println(err)
	}
	return i
}


Measured memory_bytes: 640
import sys

roman = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}


def check(i, y):
  if i == y:
    return True
  elif i == 'I' and y == 'V':
    return True
  elif i == 'V' and (y == 'I' or y == 'X'):
    return True
  elif i == 'X' and (y == 'V' or y == 'L'):
    return True
  elif i == 'L' and (y == 'X' or y == 'C'):
    return True
  elif i == 'C' and (y == 'L' or y == 'D'):
    return True
  elif i == 'D' and (y == 'C' or y == 'M'):
    return True
  elif i == 'M' and y == 'D':
    return True
  else:
    return False


def solve(r):
  if len(r) == 1:
    return roman[r[0]]
  else:
    maxRoman = 0
    for i in range(len(r) - 1):
      if roman[r[i]] < roman[r[i + 1]]:
        maxRoman = i + 1
      else:
        break
    ans = roman[r[maxRoman]]
    for sub in range(maxRoman - 1, -1, -1):
      ans -= roman[r[sub]]
    for add in range(maxRoman + 1, len(r)):
      if add < len(r) - 1 and not check(r[add - 1], r[add]):
        r = r[add:]
        return ans + solve(r)
      ans += roman[r[add]]
  return ans


for line in sys.stdin:
  try:
    line = line.replace('\n', '')
    print(solve(line))
  except:
    break

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

#define MAX 101
int A[MAX];

void print(int A[], int n){
  int i;
  for(i = 0; i < n; i++){
    if (i > 0) cout << " ";
    cout << A[i];
  }
  cout << "\n";
}

void InsertionSort(int A[], int n){
  int i, j, v, x;
  for (i = 1; i < n; i++){
    v = A[i];
    j = i - 1;
    while (j >= 0 && A[j] > v){
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    print(A, n);
  }
}

int main(){
  int i, n;
  cin >> n;
  for (i = 0; i < n; i++){
    cin >> A[i];
  }
  print(A, n);
  InsertionSort(A, n);
  return 0;
}



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

using namespace std;
#define int long long
int MOD = 1000000007;

signed main(){
    int N;
    cin >> N;
    
    int power = 1;
    for(int i=1;i<=N;i++){
        power = (power%MOD)*(i%MOD);
    }
    
    cout << power%MOD << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
signed main() {
  int n, d;
  set<int> se;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> d;
    se.insert(d);
  }
  cout << se.size() << "\n";
  return (0);
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for(ll i = 0; i < (n); i++)
#define fori(i, b, e) for(ll i = (b); i < (e); i++)
#define forr(i, b, e) for(ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    cout << (n - k + 1) << endl;
    return 0;
}

Measured memory_bytes: 256
s=input()
if len(s)<26:
    al=[chr(ord('a') + i) for i in range(26)]
    for i in al:
        if not(i in s):
            print(s+i)
            exit()
if s=="zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()
for i in range(25):
    if s[i]<s[i+1]:
        k=i
a="z"
for i in range(k+1,26):
    if s[k]<s[i]:
        a=min(a,s[i])
print(s[:k]+a)

Measured memory_bytes: 9032
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int p[] = new int[n];
        int max = 0;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            if (p[i] > max) {
                max = p[i];
            }
            sum += p[i];
        }
        int gen = max / 2;
        sum -= gen;
        System.out.println(sum);
    }
}

Measured memory_bytes: 21844
N, M = map(int, input().split())
AB = []
for i in range(M):
    AB.append(list(map(int, input().split())))

AB.sort(key=lambda x: x[1])

removed = []

for a,b in AB:
    if len(removed) == 0:
        removed.append(b - 1)
    elif max(removed) < a:
        removed.append(b - 1)

print(len(removed))


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

#define ii(i,start,end,inc) for(int i = start; i < end; i += inc)
#define dd(i,start,end,inc) for(int i = start; i > end; i -= inc)
#define zz(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define BHAAG ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef pair<ll, ll> pll; 
typedef pair<int, int> pii; 
typedef pair<ull, ull> pull; 

const int  MAX = 1e6 + 3;
template <typename T> istream &operator>>(istream &os, vector<T> &v) { for (auto &e : v) os >> e; return os; }
template <typename T> void print(vector<T> &v, string sep = " ", string end = "\n") { for (auto it = v.begin(); it != v.end() - 1; ++it) { cout << *it << sep ; } cout << v.back() << end; }

// PRIMES 
vi my_primes;
void computePrimes(int mx) { my_primes.assign(mx + 1, 0); ii(i, 2, mx, 1) if (my_primes[i] == 0) ii(j, i + i, mx, i) if (my_primes[j] == 0) my_primes[j] = i; my_primes[0] = my_primes[1] = -1; }
inline bool isPrime(int x){ return my_primes[x] == 0; }

#define divs(a,b) ( b % a == 0 )

int main(int argc, char const *argv[])
{
    #ifdef JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int n, k;
    cin >> n >> k;

    vi a(n); cin >> a;

    for(int i = k ; i < n; ++i){
        if( a[i] > a[i - k])
            cout << "Yes";
        else
            cout << "No";
        cout << '\n';
    }

    return 0;
}


Measured memory_bytes: 4052
var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
var n = +input.shift();
var nums = input.shift().split(' ').map(Number);

function insertion_sort(numbers) {
  for (var i = 0; i < numbers.length; i++) {
    var key = numbers[i];
    var j = i - 1;
    while (j >= 0 && numbers[j] > key) {
      numbers[j + 1] = numbers[j];
      j--;
    }
    numbers[j + 1] = key;
    console.log(numbers.join(' '));
  }
}

insertion_sort(nums);

Measured memory_bytes: 16676
import Control.Monad
import Data.List
import qualified Data.Vector.Unboxed.Mutable as UMVector
import qualified Data.Vector.Unboxed as UVector
import qualified Data.Vector as Vector

toTaple (x:y:_) = (x, y)

average :: (Fractional a) => [a] -> a
average [] = 0
average xs = sum' / fromIntegral count
	where
		(sum', count) = foldr sumCount (0, 0) xs
		sumCount x (sum', count) = (sum' + x, count + 1)

routes :: [Int] -> [(Int, Int)]
routes (from:to:xs) = (from, to) : routes (to:xs)
routes _ = []

distance :: (Double, Double) -> (Double, Double) -> Double
distance from to = sqrt $ (x - x') ^ 2 + (y - y') ^ 2
	where
		(x, y) = from
		(x', y') = to

calc :: Vector.Vector (Double, Double) -> [(Int, Int)] -> Double
calc points rs = sum $ do
	(from, to) <- rs
	return $ distance (points Vector.! from) (points Vector.! to)


main :: IO ()
main = do
	n <- readLn :: IO Int
	xys <- Vector.fromList . map (toTaple . map read . words) . take n . lines <$> getContents :: IO (Vector.Vector (Double, Double))
	-- print xys
	let rs = (map routes $ permutations ([0..(n-1)] :: [Int])) :: [[(Int, Int)]]
	-- print rs
	print $ average $ do
		route <- rs
		return $ calc xys route


Measured memory_bytes: 17788
from fractions import gcd
A, B, C, D = map(int, input().split())
c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
CD = C * D // gcd(C, D)
cd = B // CD - (A - 1) // CD
print((B - A) - (c + d - cd) + 1)


Measured memory_bytes: 5048
def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fac[n] * finv[r] * finv[n-r] % p

N = 2*pow(10,6)+100
MOD = pow(10,9)+7

fac = [-1]*(N+1); fac[0] = 1; fac[1] = 1
finv = [-1]*(N+1); finv[0] = 1; finv[1] = 1
inv = [-1]*(N+1); inv[0] = 0; inv[1] = 1
for i in range(2,N+1):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD


K = int(input())
S = str(input())
s = len(S)

ans = 0
for i in range(K+1):#後ろが0個からK個まで
  factor = pow(25,K-i,MOD)*pow(26,i,MOD)%MOD
  ans = (ans + factor*cmb(s+K-i-1,s-1,MOD))%MOD

ans = ans %MOD
print(ans)
  
  

Measured memory_bytes: 138292
while 1 :
    m,f,r=map(int,input().split())
    if (m,f,r)==(-1,-1,-1) : break
    if m==-1 or f==-1 : print("F")
    else:
        sm=m+f
        if sm>=80 : print("A")
        elif 65<=sm<80 : print("B")
        elif 50<=sm<65 : print("C")
        elif sm<30 : print("F")
        else :
            if r>=50 : print("C")
            else : print("D")



Measured memory_bytes: 5596
import sys
input = sys.stdin.readline

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

for i in range(len(l)):
    l[i] = i - l[i] + 1

l.sort()
t = l[int(len(l) / 2)]

for i in range(len(l)):
    l[i] = abs(l[i] - t)
    
print(sum(l))

Measured memory_bytes: 26744
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
	int n;
	string s;
	cin >> n >> s;
	//アルファベットの個数をカウントする
	ll alpha[26]={};
	for(int i=0; i<n; i++){
		alpha[s[i]-'a']++;
	}
	ll ans = 1;
	for(int i=0; i<26; i++){
		if(alpha[i]!=0){
			ans *= alpha[i]+1;
			ans %= 1000000007;
		}
	}
	ans -= 1;
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
#define w(x)            int x; cin>>x; while(x--)
#define fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll              long long
 
 
int main() {
    fast
    ll a;
    double b;
    cin >> a >> b;
    b = b * 100;
    cout << a * (ll)round(b) / 100 << endl;
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> a(N), b(N);
    for(int i=0; i<N; i++) cin >> a[i];
    for(int i=0; i<N; i++) cin >> b[i];

    ll cnt = 0;
    for(int i=0; i<N; i++){
        if(a[i] < b[i]) cnt += (b[i]-a[i])/2;
        else{
            cnt -= a[i] - b[i];
        }
    }
    if(cnt >= 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0;i < n;i++) cin >> a.at(i);
  vector<int> b(n);
  for(int i = 0;i < n;i++){
    b.at(a.at(i)-1) = i + 1;
  }
  for(int i = 0;i < n;i++) cout << b.at(i) << " ";
  cout << endl;
}

Measured memory_bytes: 1664
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
#include<regex>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)); //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline vector<T> convert_to_binary_number(T x) { vector<T> binary_num; while (x != 1) { binary_num.push_back(x % 2); x /= 2; } binary_num.push_back(1); return binary_num; }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl; }
const LL MOD = 1e9 + 7;
const LL INF = 1LL << 60;

LL N, Q;
vector<LL> counter(200010);
vector<LL> ans(200010);

map<LL, vector<LL> > graph;

void dfs(LL parent_node, LL current_node) {
	ans[current_node] = (ans[parent_node] + counter[current_node]);
	for (LL next_node:graph[current_node]) {
		if (next_node == parent_node) continue;
		dfs(current_node, next_node);
	}
}

int main(void) {
	cin >> N >> Q;
	
	rep(i,N-1) {
		LL a, b;
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	rep(i, Q) {
		LL p, x;
		cin >> p >> x;
		counter[p] += x;
	}

	dfs(0, 1);

	for (LL i = 1; i <= N; i++) {
		cout << ans[i];
		if (i == N) cout << endl;
		else cout << " ";
	}
	return 0;
}

Measured memory_bytes: 43008
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;

const int maxn = 200090;

int n,x[maxn],m,ans;

ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; }

int main(){
	ans=2e9+7,m=0;
	n = read();
	for(int i = 1;i <= n;i++) {
		x[i] = read();
		m=max(m,x[i]);
	}
	
	int t=0;
	for(int i = 1;i <= m ;i++) {
		for(int j = 1 ; j <= n; j++){
			t+=(i-x[j])*(i-x[j]);
		}
		ans=min(ans,t);
		t = 0;
	}  
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 3680
import java.util.Scanner;

public class Main {
    public static void main (String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int C = sc.nextInt();
        sc.nextLine();

        int s[] = new int[N];
        int t[] = new int[N];
        int c[] = new int[N];
        for (int i = 0; i < N; i++) {
            s[i] = sc.nextInt();
            t[i] = sc.nextInt();
            c[i] = sc.nextInt();
            sc.nextLine();
        }
        sc.close();

        int channelTotalTable[] = new int[100001];
        for(int i = 0; i < 100001; i++) {
            channelTotalTable[i] = 0;
        }

        int channelTable[][] = new int[C][100001]; 
        for (int i = 0; i < C; i++) {
            for (int j = 0; j < 100001; j++) {
                channelTable[i][j] = 0;
            }
            for (int k = 0; k < N; k++) {
                if (c[k] == i + 1) {
                    channelTable[i][s[k] - 1] += 1;
                    channelTable[i][t[k]] -= 1;
                }
            }
            for (int l = 1; l < 100001; l++) {
                channelTable[i][l] += channelTable[i][l - 1];
            }
            for (int m = 0; m < 100001; m++) {
                if (channelTable[i][m] > 0) {
                    channelTotalTable[m]++;
                }
            }
        }

        int max = 0;
        for (int i = 0; i < 100000; i++) {
            if (max < channelTotalTable[i]) {
                max = channelTotalTable[i];
            }
        }
        System.out.println(max);
    }
}


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

using namespace std;
typedef long long ll;

long long int k;
int cnt=0;
long long int prime[1000010];
bool vis[1000010];

ll eular(ll n)
{
    ll ans = n;
    for(int i=2; i*i <= n; ++i)
    {
        if(n%i == 0)
        {
            ans = ans/i*(i-1);
            while(n%i == 0)
                n/=i;
        }
    }
    if(n > 1) ans = ans/n*(n-1);
    return ans;
}

long long int gcd(long long int x,long long int y)
{
	if(x>y)
	    swap(x,y);
	if(x==0)
	    return y;
	else
	    return gcd(y%x,x);
}

ll pow_mod(ll a,ll b,ll c) 
{
	ll ans = 1; a %= c;
	while(b) 
	{
		if (b & 1) 
		    ans = ans * a % c;
		b >>= 1; 
		a = a * a % c;
	}
	return ans%c;
}

ll extend_bsgs(ll a,ll b,ll p) 
{
	if (b == 1) 
	    return 0;
	ll k = 0, d = 1, t, ans;
	while ((t = gcd(a,p)) != 1) 
	{
		if (b % t) 
		    return -1;
		k++; b /= t; p /= t; d *= a/t; d %= p;
		if (d == b) 
		    return k;
	}
	map<ll,ll> ma;
	ll m = sqrt(p * 1.0) +1, tmp = pow_mod(a, m, p), mul = b;
	for (int i = 1; i <= m; ++i) 
	{
		mul = mul * a % p;
		ma[mul] = i;
	}
	for (int i = 1; i <= m; ++i) 
	{
		d = d * tmp % p;
		if (ma[d]) 
		{
			ans = i * m - ma[d]; ans += k; 
			return ans;
		}
	}
	return -1;
}
int main()
{
    scanf("%lld",&k);
    long long int item=0;
	int bj=0,ans=-1;
    for(int i=1;i<=k;i++)
    {
    	item=(item*10+7)%k;
    	if(item==0)
    	{
    		bj=1;
    		ans=i;
    		break;
		}
	}
	if(bj==1)
	    printf("%d\n",ans);
	else
	    printf("-1\n");
	return 0;
}

Measured memory_bytes: 3792
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N = I()
A = LI()

from math import gcd

g = 0  # Aiたちの最大公約数
for i in range(N):
    g = gcd(g,A[i])

if g != 1:
    print('not coprime')
    exit()

B = []
for i in range(N):
    if A[i] != 1:
        B.append(A[i])
N = len(B)
# 以下、このB,Nで考えれば良い

if N == 0:
    print('pairwise coprime')
    exit()

primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
# 1000以下の素数のリスト

if N > 78498:  # 78498は10**6以下の素数の個数
    print('setwise coprime')
    exit()

C = [0]*(10**6+1)  # C[i] = 1 ⇔ Bの元に素因数iを持つものが存在する

for i in range(N):
    b = B[i]
    for p in primes:
        if b % p == 0:
            if C[p] == 1:
                print('setwise coprime')
                exit()
            else:
                C[p] = 1
            while b % p == 0:
                b //= p
    if b != 1:
        if C[b] == 1:
            print('setwise coprime')
            exit()
        else:
            C[b] = 1

print('pairwise coprime')


Measured memory_bytes: 206280
S = input(); K = int(input())
subs = []
for i in range(1, min(len(S), 5) + 1):
  for j in range(len(S) - i + 1):
    subs.append(S[j: j + i])
subsset = set(subs)
subs = sorted(list(subsset))
print(subs[K - 1])

Measured memory_bytes: 5196
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int a[maxn],b[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(i%2)
            b[1]+=a[i];
        else b[1]-=a[i];
    }

    for(int i=2;i<=n;i++)
    {
        b[i]=2*a[i-1]-b[i-1];
    }

    for(int i=1;i<=n;i++)
    {
        if(i==1) printf("%d",b[i]);
        else printf(" %d",b[i]);
    }

    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int X;
  cin>>X;
  
  long long ans=0;
  
  
  for(int i=1;i<=X;i++){
    for(int j=2;j<=10;j++){
      long long y=pow(i,j);
      if(y<=X){
        ans=max(ans,y);
      }
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 4140
n = int(input())
a = input()
b = a.rstrip().split()
d = 0
for e in b:
  c = int(e)
  if c%2 == 0:
    if c%3 != 0 and c%5 != 0:
      d += 1
if d == 0:
  print('APPROVED')
else:
  print('DENIED')

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
    int N=0;
    string word[101];

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

    for(int i=0; i<N-1; i++){
        for(int j=i+1;j<N; j++ ){
            if(word[i]==word[j]){
                printf("No");
                return 0;
            }
        }
    }

    word[N][0] = word[N-1][word[N-1].size()-1];

    for(int i=0; i<N; i++){
        if(word[i][word[i].size()-1]!=word[i+1][0]){
            printf("No");
            return 0;
        }
    }
    printf("Yes");

    return 0;

}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

// #define INF 1e9
const ll INF = 1LL << 61;

ll N, M;
vector<ll> A, ruiseki;
ll counting(ll x){
  ll cnt = 0, sum = 0;
  REP(i, N){
    int ok = -1, ng = N;
    while(abs(ok-ng) > 1){
      int mid = (ok+ng)/2;
      if(A[i]+A[mid] >= x){
        ok = mid;
      }
      else{
        ng = mid;
      }
    }
    ok++;
    sum += ruiseki[ok];
    sum += A[i] * ok;
    cnt += ok;
  }
  if(cnt < M){
    return -1;
  }
  else{
    return sum - (cnt-M)*x;
    // return sum;
  }
}
int main(){
  cin >> N >> M;
  A.resize(N);
  REP(i, N){
    cin >> A[i];
  }
  sort(A.rbegin(), A.rend());
  ruiseki.resize(N+1, 0);
  REP(i, N){
    ruiseki[i+1] = ruiseki[i] + A[i];
  }
  ll ok = 0, ng = INF, ans = 0;
  while(abs(ok-ng) > 1){
    ll mid = (ok+ng) / 2;
    ll sum = counting(mid);
    // cerr << "binary mid:" << mid << " sum:" << sum << endl;
    if(sum != -1){
      ok = mid;
      ans = sum;
    }
    else{
      ng = mid;
    }
  }
  cout << ans << endl;
  
  return 0;
}


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

void hyoji(int n,char ch){
	for(int i=0;i<n;i++){
    	cout<<ch;
    }
}

int main(){
	int sx,sy,tx,ty;
  	cin>>sx>>sy>>tx>>ty;
  	const int dx=tx-sx,dy=ty-sy;
  
  	//path 1
  	hyoji(dy,'U');	hyoji(dx,'R');
  
  	//path 2
  	hyoji(dy,'D');	hyoji(dx,'L');
  
  	//path 3
  	cout<<"L";hyoji(dy+1,'U');hyoji(dx+1,'R');cout<<"D";
  
  	//path 4
  	cout<<"R";hyoji(dy+1,'D');hyoji(dx+1,'L');cout<<"U";
  
  cout<<endl;
    	
}    

Measured memory_bytes: 256
/*
ID: Nipun Paul
LANG: C++
PROB: God knows
*/

#include<bits/stdc++.h>
using namespace std;

int main()
{
	long long int a, b,c=2019;
	cin >> a >> b;
	for (long long int i = a; i <= b; i++)
	{
		for (long long int j = i + 1; j <= b; j++)
		{
			c = min(c, (i * j) % 2019);
			if (c == 0)
			{
				break;
			}
		}
		if (c == 0)
		{
			break;
		}
	}
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)

ball = Array.new(n,0)
box = []
div = Array.new(n).map{Array.new()}
for i in 1..n do
    j = i
    while j <= n
        div[j-1].push(i)
        j += i
    end
end

tar = n
(1..n).each do |i|
    if a[n-i] != ball[n-i]
        box.push(n-i+1)
        for j in div[n-i] do
            ball[j-1] = 1-ball[j-1]
        end
        # (1..Math.sqrt(tar)).each do |j|
        #     if tar % j == 0
        #         ball[j-1] = 1 - ball[j-1]
        #         if j*j != tar
        #             ball[tar/j -1] = 1 - ball[tar/j -1]
        #         end
        #     end
        # end
    end
    tar -= 1
end

m = box.size
puts m
if m > 0
    puts box.join(' ')
end

Measured memory_bytes: 66312
import sys
sys.setrecursionlimit(10**9)

n, m, k = map(int, input().split())
F = [[] for i in range(n)]
B = [[] for i in range(n)]
l = [0]*n

for i in range(m):
    a, b = map(int, input().split())
    F[a - 1].append(b - 1)
    F[b - 1].append(a - 1)

for i in range(k):
    c, d = map(int, input().split())
    B[c - 1].append(d - 1)
    B[d - 1].append(c - 1)

seen = [0]*n
cnt = 0
r = []

def dfs(x):
    if seen[x] == 0:
        r[cnt].add(x)
        seen[x] = 1
        for i in F[x]:
            dfs(i)

for i in range(n):
    if seen[i] == 0:
        r.append(set())
        dfs(i)
        cnt += 1

ans = [0]*n

for i in r:
    lr = len(i)
    for j in i:
        ans[j] = lr - len(F[j]) - len(i & set(B[j])) - 1

print(*ans)

Measured memory_bytes: 65168
#include <bits/stdc++.h>
#define mo 1510
using namespace std;
int d[mo],a[mo][mo],l[mo],h[mo];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
            cin>>a[i][j];

        int maxs=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
                if(!a[i][j]) d[j]++;
                else d[j]=0;


            for(int j=1;j<=m;j++)
            {
                l[j]=j;
                while(l[j]>1&&d[j]<=d[l[j]-1])
                    l[j]=l[l[j]-1];
            }

            for(int j=m;j>0;j--)
            {
                h[j]=j;
                while(h[j]<m&&d[j]<=d[h[j]+1])
                    h[j]=h[h[j]+1];
            }
            for(int j=1;j<=m;j++)
            maxs=max(maxs,d[j]*(h[j]-l[j]+1));

        }
        cout<<maxs<<endl;
    }

}



Measured memory_bytes: 11288
n = int(input())
a = [0]
a.extend(list(map(int, input().split())))
ans = [0 for _ in range(n+1)]
for i in range(n//2 + 1, n + 1):
    ans[i] = a[i]
for j in range(2, n+1):
    for i in range(n//(j+1) + 1, n//j + 1):
        if sum([ans[k*i] for k in range(2, j+1)]) % 2 != a[i]:
            ans[i] = 1
answer = [i for i, x in enumerate(ans) if x == 1]
l = len(answer)
print(l)
for i in range(l):
    if i <= l-2:
        print(answer[i], end=" ")
    else:
        print(answer[i])

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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 100500;

int n, C, T, ans, a[N];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);

	//cout << setprecision(10) << fixed;
	
	cin >> n >> C >> T;

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

	sort(a + 1, a + 1 + n);

	for (int i = 1; i <= n; i++) {
		int j = i;
		while (j < n && a[j + 1] - a[i] <= T && j + 1 - i + 1 <= C)
			j++;
		ans++;
		i = j;
	}

	cout << ans;
	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
using namespace std;
 
 ll mod=1e9 +7;
 
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

const ll M=200006;
ll f[M],inv[M];

void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2,mod);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // compute();
    // Sieve();
    ll tests=1;
    // cin>>tests;
    while(tests--)
    {
      ll i,j,k,n;
      string s;
      cin>>n;
      cin>>s;
      // cout<<s<<"\n";
      vector<ll>r(n+1,0),g(n+1,0),b(n+1,0);
      for(i=n-1;i>=0;i--)
      {
        r[i]+=r[i+1];
        g[i]+=g[i+1];
        b[i]+=b[i+1];
        if(s[i]=='R') r[i]++;
        else if(s[i]=='G') g[i]++;
        else b[i]++;
      }
      // cout<<g[0]<<"\n";
      ll ans=0;
      rep(i,0,n-1)
      {
        rep(j,i+1,n-1)
        {
          if(s[i]==s[j]) continue;
          if((s[i]=='R' && s[j]=='G') || (s[i]=='G' && s[j]=='R'))
          {
            ans+=b[j+1];
            if(j+(j-i)<n && s[j+(j-i)]=='B') ans--;
          }
          else if((s[i]=='R' && s[j]=='B') || (s[i]=='B' && s[j]=='R'))
          {
            ans+=g[j+1];
            if(j+(j-i)<n && s[j+(j-i)]=='G') ans--;
          }
          else
          {
            ans+=r[j+1];
            if(j+(j-i)<n && s[j+(j-i)]=='R') ans--;
          }
        }
        // cout<<"--"<<ans<<"\n";
      }
      cout<<ans;

    }
    return 0;
   }

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

//#pragma gcc optimize("O3,unroll-loop")
//#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
#define int long long
//#define double long double

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

    char c;
    int h, w, k, arr[10][1000];
    cin >> h >> w >> k;
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            cin >> c, arr[i][j] = c - '0';

    int ans = 1e9;
    for (int i = 0; i < (1 << (h - 1)); i++)
    {
        bool c[10];
        int t = i, ct = 0;
        for (int j = 0; j < h - 1; j++)
            c[j] = t & 1, ct += t & 1, t /= 2;
        c[h - 1] = true;

        bool nan = false;
        for (int j = 0; !nan && j < w; j++)
        {
            int cc = 0;
            for (int m = 0; !nan && m < h; m++)
            {
                cc += arr[m][j];
                if (cc > k)
                    nan = true;
                if (c[m])
                    cc = 0;
            }
        }
        if (nan)
            continue;

        vector<int> v;
        v.resize(ct + 1);
        for (int j = 0; j < w; j++)
        {
            int sec = 0, cc = 0;
            for (int m = 0; m < h; m++)
            {
                cc += arr[m][j];
                if (c[m])
                    v[sec++] += cc, cc = 0;
            }

            bool fail = false;
            for (int m : v)
                if (m > k)
                {
                    ct++, fail = true;
                    break;
                }

            if (fail)
            {
                sec = cc = 0;
                for (int m = 0; m < h; m++)
                {
                    cc += arr[m][j];
                    if (c[m])
                        v[sec++] = cc, cc = 0;
                }
            }
        }
        ans = min(ans, ct);
    }
    cout << ans << '\n';

    return 0;
}

//      *   *  *****  *   *  *   *
//     *   *  *      **  *  *   *
//    *****  *****  * * *  *   *
//   *   *      *  *  **  *   *
//  *   *  *****  *   *   ***

//      ***** ***** *   * *     ***** *   * ***** *****
//        *  *   * *   * *       *   **  *   *   *   *
//       *  *   * ***** *       *   * * *   *   *****
//   *  *  *   *   *   *       *   *  **   *   *
//  ****  *****   *   ***** ***** *   *   *   *


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

#define fi first
#define se second

const int N = 200200;
const int mod = 1e9 + 7;

using namespace std;

int n;
int a[N];
int L[N];
int t[N][20];

int comb(int x, int y)
{
        if(!x || !y){
                return x + y;
        }
        if(a[x] < a[y]){
                return x;
        }
        return y;
}

int get(int l, int r)
{
        int g = L[(r - l + 1) / 2];
        return comb(t[l][g], t[r - (2 << g) + 1][g]);
}

pair < int, int > solve(int l, int r)
{
        int i = get(l, r);
        int j = get(i + 1, r + 1);
        return {i, j};
}

set < pair < int, pair < int, int > > > S;

void add(int l, int r)
{
        if(l > r){
                return;
        }
        S.insert({a[solve(l, r).fi], {l, r}});
}

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> n;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
                t[i][0] = i;
        }
        for(int i = 2; i < N; i++){
                L[i] = L[i / 2] + 1;
        }
        for(int i = 1; i < 20; i++){
                for(int j = 1; j <= n; j++) if(j + (2 << i) - 1 <= n + 1){
                        t[j][i] = comb(t[j][i - 1], t[j + (2 << i - 1)][i - 1]);
                }
        }

        add(1, n);
        vector < int > res;
        while(!S.empty()){
                auto p = S.begin()->se;
                S.erase(S.begin());
                auto cur = solve(p.fi, p.se);
                res.push_back(a[cur.fi]);
                res.push_back(a[cur.se]);
                //cout << cur.fi << " " << cur.se << ' ' << p.fi << " " << p.se << "\n";
                //exit(0);
                add(p.fi, cur.fi - 1);
                add(cur.fi + 1, cur.se - 1);
                add(cur.se + 1, p.se);
        }
        for(int i = 0; i < n; i++){
                cout << res[i] << " ";
        }
}


Measured memory_bytes: 22004
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, p[ohara], q[ohara];
priority_queue<P, vector<P>, greater<P>> que;

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

  cin >> w >> h;
  rep(i, w) cin >> p[i], que.push({p[i], 0});
  rep(i, h) cin >> q[i], que.push({q[i], 1});

  ll needw = w + 1, needh = h + 1;
  while (1) {
    if (que.empty()) break;
    P X = que.top();
    que.pop();
    if (X.se == 0) {
      ans += X.fi * needh;
      needw--;
    } else {
      ans += X.fi * needw;
      needh--;
    }
  }

  Cout(ans);
  return 0;
}

Measured memory_bytes: 10608
def resolve():
    K = int(input())

    m = 7 % K

    ans = -1
    for i in range(1, K+1):
        if m == 0:
            ans = i
            break
        m = (m * 10 + 7) % K
    print(ans)

if __name__ == "__main__":
    resolve()

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

int main(){
  int N, C;
  cin >> N >> C;
  int sum = 0;
  for ( int i = 0; i < C; i++ ){
    int x; cin >> x;
    sum += x;
  }
  N++;

  cout << sum/N + (sum%N==0?0:1) << endl;

  return 0;
}



Measured memory_bytes: 3124
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
    if(b==0)
        return a;
    return gcd(b,a%b);  //递归求最大公约数
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);    //递归求最小公倍数
}
int main()
{
    ll a,b;
    while(cin >> a >> b)
    {
        cout << gcd(a,b)<< " "<<lcm(a,b)<<endl;
    }
    return 0;
}




Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  priority_queue<long long> p;
  for(int i=0; i<N; i++){
    long long a;
    cin >> a;
    p.push(a);
  }
  for(int i=0; i<M; i++){
    long long b;
    b = p.top();
    p.pop();
    b /= 2;
    p.push(b);
  }
  long long ans=0;
  for(int i=0; i<N; i++){
    ans += p.top();
    p.pop();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,l,r) for (ll i = (ll)l; i < (ll)(r); i++)

const ll inf = 1e9;

int main(){
    ll N,M,X; cin >> N >> M >> X;
    vector<ll> c(N);
    vector<vector<ll> > a(N,vector<ll>(M));
    rep(i,0,N){
        cin >> c[i];
        rep(j,0,M) cin >> a[i][j];
    }
    ll ans = inf;
    for(ll mask=0;mask<(1<<N);mask++){
        vector<ll> x(M,0);
        ll sum = 0;
        rep(i,0,N){
            if(mask&(1<<i)){
                sum += c[i];
                rep(j,0,M){
                    x[j]+=a[i][j];
                }
            }
        }
        bool ok = true;
        rep(i,0,M){
            if(x[i]<X) ok = false;
        }
        if(ok) ans = min(ans,sum);
    }
    if(ans == inf){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int main(){

  


  int x,a,b;

  cin >> x;
  cin >> a;
  cin >> b;

  // cout << x <<endl;
  // cout << a <<endl;
  // cout << b <<endl;

  int c = x-a;
  
  
  cout << c % b<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    int t = sc.nextInt();
    sc.close();
    int answer = (n / x) * t;
    if(n % x != 0) answer += t;
    System.out.println(answer);
  }
}

Measured memory_bytes: 35676
#include<cctype>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define REP(a,b,c) for(int a=b;a<=c;++a)
#define RREP(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
using namespace std;

template<class T> inline
void read(T &x) {
	x=0; char c=getchar(); while(!isdigit(c)) c=getchar();
	while(isdigit(c)) {x=x*10+c-'0'; c=getchar();}
}


int main() {
	LL a,b;
	scanf("%lld%lld",&a,&b);
	if(a+a>b) printf("%lld\n",b>>1);
	else printf("%lld\n",a+(b-a-a)/4);
	return 0;
}

Measured memory_bytes: 128
using namespace std;

#include <bits/stdc++.h>

int main(){
    int N;
    cin >> N;
    int a[N];
    int ma = 0;
    int mai = -1;
    for ( int i = 0; i < N; i ++ ){
        cin >> a[i];
        if ( a[i] > ma ){ ma = a[i]; mai = i; }
    }
    ma = 0;
    for ( int i = 0; i < N; i ++ ){
        if ( i != mai ){
            if ( a[i] > ma ) ma = a[i];
        }
    }
    for ( int i = 0; i < N; i ++ ){
        if ( i != mai ) cout << a[mai] << endl;
        else cout << ma << endl;
    }

    return 0;
}


Measured memory_bytes: 2432